pnd-cpp-sdk 1.5.1
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
8namespace Pnd {
9
16class 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(const std::string &family, int32_t timeout_ms = DEFAULT_TIMEOUT);
56
57 std::shared_ptr<Group> getGroupFromIps(const std::vector<std::string> &ips);
58
64 float getLookupFrequencyHz() const;
65
74 bool setLookupFrequencyHz(float frequency);
75
76 class EntryList final {
77 struct Entry final {
78 std::string name_;
79 std::string family_;
80 std::string serial_number_;
81 };
82
83 private:
87 PndLookupEntryListPtr lookup_list_;
88
93 class Iterator final {
94 public:
95 // Iterator traits (not from std::iterator to be C++17 compliant)
96 using value_type = Entry;
97 using difference_type = int;
98 using pointer = Entry *;
99 using reference = Entry;
100 using iterator_category = std::bidirectional_iterator_tag;
101
102 Iterator() = delete;
103 explicit Iterator(const EntryList &list, size_t current);
104
105 reference operator*() const;
106
107 Iterator &operator++();
108 Iterator operator++(int);
109 Iterator &operator--();
110 Iterator operator--(int);
111
112 bool operator==(const Iterator &rhs) const;
113 bool operator!=(const Iterator &rhs) const;
114
115 private:
116 const EntryList &list_;
117 size_t current_{0};
118 };
119
120 public:
124 EntryList(PndLookupEntryListPtr lookup_list) : lookup_list_(lookup_list) {}
125
126 ~EntryList() noexcept;
127
128 Entry operator[](size_t index) const;
129
130 size_t size() const;
131
132 Iterator begin() const;
133 Iterator end() const;
134
135 private:
139 PND_DISABLE_COPY_MOVE(EntryList)
140 };
141
142 std::shared_ptr<EntryList> getEntryList();
143
144 DeviceList *getDeviceList();
145
146 private:
150 PndLookupPtr lookup_;
151
152 static const int32_t DEFAULT_TIMEOUT = 500;
153};
154
155} // namespace Pnd
Definition lookup.hpp:76
Maintains a registry of network-connected modules and returns Group objects to the user.
Definition lookup.hpp:16
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:30
~Lookup() noexcept
Destructor frees all resources created by Lookup object, and stops the background query thread.
Definition lookup.cpp:20
std::string getCtrlBoxIP()
Get CtrlBox ip address.
Definition lookup.cpp:24
bool setLookupFrequencyHz(float frequency)
Sets the lookup rate [Hz].
Definition lookup.cpp:51
float getLookupFrequencyHz() const
Gets the rate [Hz] at which "discovery" packets are broadcast.
Definition lookup.cpp:49
void setNetWorks(std::string networks)
Sets the broadcast address for the lookup.
Definition lookup.cpp:22