| pnd-cpp-sdk 1.0.0

Loading...
Searching...
No Matches
lookup.hpp
1#pragma once
2#include <memory>
3
4#include "aios.h"
5#include "group.hpp"
6#include "util.hpp"
7
8 namespace Pnd {
9
16 class Lookup final {
17 public:
26 Lookup(std::string *addr = nullptr);
27
32 ~Lookup() noexcept;
33
40 void setNetWorks(std::string networks);
41
45 std::string getCtrlBoxIP();
46
55 std::shared_ptr<Group> getGroupFromFamily(
56 const std::string &family, int32_t timeout_ms = DEFAULT_TIMEOUT);
57
63 float getLookupFrequencyHz() const;
64
73 bool setLookupFrequencyHz(float frequency);
74
75 class EntryList final {
76 struct Entry final {
77 std::string name_;
78 std::string family_;
79 std::string serial_number_;
80 };
81
82 private:
86 PndLookupEntryListPtr lookup_list_;
87
92 class Iterator final {
93 public:
94 // Iterator traits (not from std::iterator to be C++17 compliant)
95 using value_type = Entry;
96 using difference_type = int;
97 using pointer = Entry *;
98 using reference = Entry;
99 using iterator_category = std::bidirectional_iterator_tag;
100
101 Iterator() = default;
102 explicit Iterator(const EntryList &list, size_t current);
103
104 reference operator*() const;
105
106 Iterator &operator++();
107 Iterator operator++(int);
108 Iterator &operator--();
109 Iterator operator--(int);
110
111 bool operator==(const Iterator &rhs) const;
112 bool operator!=(const Iterator &rhs) const;
113
114 private:
115 const EntryList &list_;
116 size_t current_{0};
117 };
118
119 public:
123 EntryList(PndLookupEntryListPtr lookup_list) : lookup_list_(lookup_list) {}
124
125 ~EntryList() noexcept;
126
127 Entry operator[](size_t index) const;
128
129 size_t size() const;
130
131 Iterator begin() const;
132 Iterator end() const;
133
134 private:
138 PND_DISABLE_COPY_MOVE(EntryList)
139 };
140
141 std::shared_ptr<EntryList> getEntryList();
142
143 private:
147 PndLookupPtr lookup_;
148
149 static const int32_t DEFAULT_TIMEOUT = 500;
150};
151
152} // namespace Pnd
Pnd::Lookup::EntryList
Definition lookup.hpp:75
Pnd::Lookup
Maintains a registry of network-connected modules and returns Group objects to the user.
Definition lookup.hpp:16
Pnd::Lookup::getGroupFromFamily
std::shared_ptr< Group > getGroupFromFamily(const std::string &family, int32_t timeout_ms=DEFAULT_TIMEOUT)
Get a group from all known modules with the given family.
Definition lookup.cpp:32
Pnd::Lookup::~Lookup
~Lookup() noexcept
Destructor frees all resources created by Lookup object, and stops the background query thread.
Definition lookup.cpp:20
Pnd::Lookup::getCtrlBoxIP
std::string getCtrlBoxIP()
Get CtrlBox ip address.
Definition lookup.cpp:26
Pnd::Lookup::setLookupFrequencyHz
bool setLookupFrequencyHz(float frequency)
Sets the lookup rate [Hz].
Definition lookup.cpp:45
Pnd::Lookup::getLookupFrequencyHz
float getLookupFrequencyHz() const
Gets the rate [Hz] at which "discovery" packets are broadcast.
Definition lookup.cpp:41
Pnd::Lookup::setNetWorks
void setNetWorks(std::string networks)
Sets the broadcast address for the lookup.
Definition lookup.cpp:22