HEBI C++ API  3.3.0
lookup.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "hebi.h"
4 
5 #include <cstddef>
6 #include <iterator>
7 #include <memory> // For shared_ptr
8 #include <vector>
9 
10 #include "group.hpp"
11 #include "mac_address.hpp"
12 
13 namespace hebi {
14 
24 class Lookup final {
25 private:
26  static const int32_t DEFAULT_TIMEOUT = 500;
27 
31  HebiLookupPtr lookup_;
32 
36  float initial_group_feedback_frequency_{100.0f};
37 
41  int32_t initial_group_command_lifetime_{250};
42 
43 public:
52  Lookup();
53 
58  ~Lookup() noexcept; /* annotating specified destructor as noexcept is best-practice */
59 
81  std::shared_ptr<Group> getGroupFromNames(const std::vector<std::string>& families,
82  const std::vector<std::string>& names, int32_t timeout_ms = DEFAULT_TIMEOUT);
83 
98  std::shared_ptr<Group> getGroupFromMacs(const std::vector<MacAddress>& addresses,
99  int32_t timeout_ms = DEFAULT_TIMEOUT);
100 
115  std::shared_ptr<Group> getGroupFromFamily(const std::string& family, int32_t timeout_ms = DEFAULT_TIMEOUT);
116 
135  std::shared_ptr<Group> getConnectedGroupFromName(const std::string& family, const std::string& name,
136  int32_t timeout_ms = DEFAULT_TIMEOUT);
137 
153  std::shared_ptr<Group> getConnectedGroupFromMac(const MacAddress& address, int32_t timeout_ms = DEFAULT_TIMEOUT);
154 
172  void setInitialGroupFeedbackFrequencyHz(float frequency);
173 
191  void setInitialGroupCommandLifetimeMs(int32_t ms);
192 
198  double getLookupFrequencyHz() const;
199 
208  bool setLookupFrequencyHz(double frequency);
209 
210  class EntryList final {
211  struct Entry final {
212  std::string name_;
213  std::string family_;
214  MacAddress mac_address_;
215  };
216 
217  private:
221  HebiLookupEntryListPtr lookup_list_;
222 
227  class Iterator final {
228  public:
229  // Iterator traits (not from std::iterator to be C++17 compliant)
230  using value_type = Entry;
231  using difference_type = int;
232  using pointer = Entry*;
233  using reference = Entry;
234  using iterator_category = std::bidirectional_iterator_tag;
235 
236  // Default constructable
237  Iterator() = default;
238  explicit Iterator(const EntryList& list, size_t current);
239 
240  // Dereferencable
241  reference operator*() const;
242 
243  // Pre- and post-incrementable/decrementable
244  Iterator& operator++();
245  Iterator operator++(int);
246  Iterator& operator--();
247  Iterator operator--(int);
248 
249  // Equality / inequality
250  bool operator==(const Iterator& rhs) const;
251  bool operator!=(const Iterator& rhs) const;
252 
253  private:
254  const EntryList& list_;
255  size_t current_{0};
256  };
257 
258  public:
262  EntryList(HebiLookupEntryListPtr lookup_list) : lookup_list_(lookup_list) {}
263 
264  ~EntryList() noexcept;
265 
266  Entry operator[](size_t index) const;
267 
268  size_t size() const;
269 
270  Iterator begin() const;
271  Iterator end() const;
272 
273  private:
278  };
279 
280  std::shared_ptr<EntryList> getEntryList();
281 
282 private:
287 };
288 
289 } // namespace hebi
EntryList(HebiLookupEntryListPtr lookup_list)
Definition: lookup.hpp:262
Lookup()
Creates a Lookup object which can create Module and Group references. Typically, only one Lookup obje...
Definition: lookup.cpp:7
double getLookupFrequencyHz() const
Gets the rate [Hz] at which "discovery" packets are broadcast.
Definition: lookup.cpp:76
Definition: bit_set.hpp:5
A simple wrapper class for internal C-API HebiMacAddress objects to allow interfacing with API calls ...
Definition: mac_address.hpp:13
Iterator begin() const
Definition: lookup.cpp:144
Definition: lookup.hpp:210
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:6
std::shared_ptr< EntryList > getEntryList()
Definition: lookup.cpp:148
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:43
~EntryList() noexcept
Definition: lookup.cpp:114
~Lookup() noexcept
Destructor frees all resources created by Lookup object, and stops the background query thread.
Definition: lookup.cpp:9
std::shared_ptr< Group > getConnectedGroupFromMac(const MacAddress &address, int32_t timeout_ms=DEFAULT_TIMEOUT)
Get a group from all modules known to connect to a module with the given mac address.
Definition: lookup.cpp:60
std::shared_ptr< Group > getGroupFromMacs(const std::vector< MacAddress > &addresses, int32_t timeout_ms=DEFAULT_TIMEOUT)
Get a group from modules with the given mac addresses.
Definition: lookup.cpp:31
int32_t getInitialGroupCommandLifetimeMs()
Gets the default command lifetime value for groups created from this lookup.
Definition: lookup.cpp:72
void setInitialGroupFeedbackFrequencyHz(float frequency)
Sets the default feedback frequency value for groups created from this lookup.
Definition: lookup.cpp:70
Iterator end() const
Definition: lookup.cpp:146
bool setLookupFrequencyHz(double frequency)
Sets the lookup rate [Hz].
Definition: lookup.cpp:78
void setInitialGroupCommandLifetimeMs(int32_t ms)
Sets the default command lifetime value for groups created from this lookup.
Definition: lookup.cpp:74
std::shared_ptr< Group > getConnectedGroupFromName(const std::string &family, const std::string &name, int32_t timeout_ms=DEFAULT_TIMEOUT)
Get a group from all modules known to connect to a module with the given name and family.
Definition: lookup.cpp:51
Maintains a registry of network-connected modules and returns Group objects to the user.
Definition: lookup.hpp:24
float getInitialGroupFeedbackFrequencyHz()
Gets the default feedback frequency value for groups created from this lookup.
Definition: lookup.cpp:68
std::shared_ptr< Group > getGroupFromNames(const std::vector< std::string > &families, const std::vector< std::string > &names, int32_t timeout_ms=DEFAULT_TIMEOUT)
Get a group from modules with the given names and families.
Definition: lookup.cpp:11
size_t size() const
Definition: lookup.cpp:142