keep a list of discovered universes
This commit is contained in:
parent
7a0fbb0e41
commit
8f7463b67f
|
@ -192,6 +192,20 @@ void Pdu::iStream(ACN::PDU::Stream stream)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief discoveredUniverse operator ==
|
||||
* @param a
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
bool operator== (const discoveredUniverse& a, const discoveredUniverse& b)
|
||||
{
|
||||
return (a.description == b.description &&
|
||||
a.universe == b.universe &&
|
||||
a.source == b.source);
|
||||
}
|
||||
|
||||
} // DISCOVERY
|
||||
} // EXTENDED
|
||||
} // SACN
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "acn/pdu.h"
|
||||
#include "sacn.h"
|
||||
#include "uuid/uuid.h"
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* @brief both Discovery and Syncronization
|
||||
|
@ -144,15 +143,12 @@ struct discoveredUniverse
|
|||
UUID::uuid source; //!< CID of source
|
||||
std::string description; //!< universe description
|
||||
uint16_t universe; //!< universe number
|
||||
|
||||
friend bool operator== (const discoveredUniverse& a,
|
||||
const discoveredUniverse& b);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief a callback function interested in discovered universes
|
||||
*/
|
||||
using Watcher = std::function<void(std::shared_ptr<discoveredUniverse>)>;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The discovery_list_data struct
|
||||
*/
|
||||
|
@ -185,3 +181,28 @@ public:
|
|||
|
||||
} // DISCOVERY
|
||||
} // SACN::EXTENDED
|
||||
|
||||
namespace std
|
||||
{
|
||||
/**
|
||||
* @brief The hash struct specialization for
|
||||
* sACN::EXTENDED::DISCOVERY::discoveredUniverse
|
||||
*/
|
||||
template<>
|
||||
struct hash<sACN::EXTENDED::DISCOVERY::discoveredUniverse>
|
||||
{
|
||||
/**
|
||||
* @brief operator ()
|
||||
* @param disc
|
||||
* @return
|
||||
*/
|
||||
size_t operator()(sACN::EXTENDED::DISCOVERY::discoveredUniverse const& disc) const noexcept
|
||||
{
|
||||
size_t h1 = hash<string>{}(disc.description);
|
||||
size_t h2 = hash<uint16_t>{}(disc.universe);
|
||||
size_t h3 = hash<UUID::uuid>{}(disc.source);
|
||||
size_t h = h1 ^ h2 ^ h3; // or use boost::hash_combine
|
||||
return h;
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
|
|
@ -60,7 +60,8 @@ Receiver::~Receiver()
|
|||
* @brief Receiver::subscribe
|
||||
* @param num
|
||||
*/
|
||||
void Receiver::subscribe(const uint16_t num) {
|
||||
void Receiver::subscribe(const uint16_t num)
|
||||
{
|
||||
if (universes_.count(num))
|
||||
return;
|
||||
universes_.emplace(num, new ArbitratingUniverse());
|
||||
|
@ -71,7 +72,8 @@ void Receiver::subscribe(const uint16_t num) {
|
|||
* @brief Receiver::unsubscribe
|
||||
* @param num
|
||||
*/
|
||||
void Receiver::unsubscribe(const uint16_t num) {
|
||||
void Receiver::unsubscribe(const uint16_t num)
|
||||
{
|
||||
if (universes_.count(num))
|
||||
{
|
||||
delete universes_.at(num);
|
||||
|
@ -85,7 +87,8 @@ void Receiver::unsubscribe(const uint16_t num) {
|
|||
* @param num
|
||||
* @return
|
||||
*/
|
||||
Universe * Receiver::universe(const uint16_t num) {
|
||||
Universe * Receiver::universe(const uint16_t num)
|
||||
{
|
||||
if (!universes_.count(num))
|
||||
return nullptr;
|
||||
return universes_.at(num);
|
||||
|
@ -95,7 +98,8 @@ Universe * Receiver::universe(const uint16_t num) {
|
|||
/**
|
||||
* @brief Receiver::discoveryStart
|
||||
*/
|
||||
void Receiver::discoveryStart() {
|
||||
void Receiver::discoveryStart()
|
||||
{
|
||||
subscribe(sACN::E131_DISCOVERY_UNIVERSE);
|
||||
}
|
||||
|
||||
|
@ -103,8 +107,10 @@ void Receiver::discoveryStart() {
|
|||
/**
|
||||
* @brief Receiver::discoveryStop
|
||||
*/
|
||||
void Receiver::discoveryStop() {
|
||||
void Receiver::discoveryStop()
|
||||
{
|
||||
unsubscribe(sACN::E131_DISCOVERY_UNIVERSE);
|
||||
discovered.clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,7 +118,8 @@ void Receiver::discoveryStop() {
|
|||
* @brief Receiver::onDiscovered
|
||||
* @param cb something that wants to know about available universes.
|
||||
*/
|
||||
void Receiver::onDiscovered(const EXTENDED::DISCOVERY::Watcher cb) {
|
||||
void Receiver::onDiscovered(const std::function<void()> cb)
|
||||
{
|
||||
discoveryCallbacks_.push_back(cb);
|
||||
}
|
||||
|
||||
|
@ -306,10 +313,15 @@ void Receiver::discoveryFrameHandler(ACN::PDU::Message<EXTENDED::Pdu> frame) {
|
|||
* @param pdu
|
||||
*/
|
||||
void Receiver::discoveryListHanlder(ACN::PDU::Message<EXTENDED::DISCOVERY::Pdu> pdu) {
|
||||
auto header = static_cast<EXTENDED::DISCOVERY::discovery_list_header*>(pdu->header());
|
||||
auto data = static_cast<EXTENDED::DISCOVERY::discovery_list_data*>(pdu->data());
|
||||
for (auto& f : data->found)
|
||||
|
||||
for (auto& found : data->found)
|
||||
discovered.insert(found);
|
||||
|
||||
if (header->page == header->last_page)
|
||||
for (const auto &cb : discoveryCallbacks_)
|
||||
cb(std::make_shared<EXTENDED::DISCOVERY::discoveredUniverse>(f));
|
||||
cb();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "arbitratinguniverse.h"
|
||||
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace sACN {
|
||||
|
@ -74,7 +75,9 @@ public:
|
|||
|
||||
void discoveryStart();
|
||||
void discoveryStop();
|
||||
void onDiscovered(const EXTENDED::DISCOVERY::Watcher);
|
||||
void onDiscovered(const std::function<void()>);
|
||||
/// The listing of discovered universes.
|
||||
std::unordered_set<EXTENDED::DISCOVERY::discoveredUniverse> discovered;
|
||||
|
||||
protected:
|
||||
// 5 - E1.31 use of the ACN Root Layer Protocol
|
||||
|
@ -94,7 +97,7 @@ protected:
|
|||
|
||||
private:
|
||||
std::unordered_map<uint16_t, ArbitratingUniverse*> universes_;
|
||||
std::vector<EXTENDED::DISCOVERY::Watcher> discoveryCallbacks_;
|
||||
std::vector<std::function<void()>> discoveryCallbacks_;
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue