lookup.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstddef>
4 #include <iterator>
5 
6 #include "hebi.h"
7 #include "mac_address.hpp"
8 #include "group.hpp"
9 
10 #include <memory> // For shared_ptr
11 #include <vector>
12 
13 namespace hebi {
14 
34 class Lookup final
35 {
36  private:
37  static const int32_t DEFAULT_TIMEOUT = 500;
38 
43 
48 
53 
54  public:
63  Lookup();
64 
69  ~Lookup() noexcept; /* annotating specified destructor as noexcept is best-practice */
70 
92  std::shared_ptr<Group> getGroupFromNames(const std::vector<std::string>& families, const std::vector<std::string>& names, int32_t timeout_ms=DEFAULT_TIMEOUT);
93 
108  std::shared_ptr<Group> getGroupFromMacs(const std::vector<MacAddress>& addresses, int32_t timeout_ms=DEFAULT_TIMEOUT);
109 
124  std::shared_ptr<Group> getGroupFromFamily(const std::string& family, int32_t timeout_ms=DEFAULT_TIMEOUT);
125 
144  std::shared_ptr<Group> getConnectedGroupFromName(const std::string& family, const std::string& name, int32_t timeout_ms=DEFAULT_TIMEOUT);
145 
161  std::shared_ptr<Group> getConnectedGroupFromMac(const MacAddress& address, int32_t timeout_ms=DEFAULT_TIMEOUT);
162 
180  void setInitialGroupFeedbackFrequencyHz(float frequency);
181 
199  void setInitialGroupCommandLifetimeMs(int32_t ms);
200 
201  class EntryList final
202  {
203  struct Entry final
204  {
205  std::string name_;
206  std::string family_;
208  };
209 
210  private:
215 
220  class Iterator final
221  {
222  public:
223  // Iterator traits (not from std::iterator to be C++17 compliant)
224  using value_type = Entry;
225  using difference_type = int;
226  using pointer = Entry*;
227  using reference = Entry;
228  using iterator_category = std::bidirectional_iterator_tag;
229 
230  // Default constructable
231  Iterator() = default;
232  explicit Iterator(const EntryList& list, size_t current);
233 
234  // Dereferencable
235  reference operator*() const;
236 
237  // Pre- and post-incrementable/decrementable
238  Iterator& operator++();
239  Iterator operator++(int);
240  Iterator& operator--();
241  Iterator operator--(int);
242 
243  // Equality / inequality
244  bool operator==(const Iterator& rhs) const;
245  bool operator!=(const Iterator& rhs) const;
246 
247  private:
248  const EntryList& list_;
249  size_t current_ { 0 };
250  };
251 
252  public:
253 
257  EntryList(HebiLookupEntryListPtr lookup_list) : lookup_list_(lookup_list) {}
258 
259  ~EntryList() noexcept;
260 
261  Entry operator[](size_t index) const;
262 
263  size_t size() const;
264 
265  Iterator begin() const;
266  Iterator end() const;
267 
268  private:
273  };
274 
275  std::shared_ptr<EntryList> getEntryList();
276 
277  private:
282 };
283 
284 } // namespace hebi
EntryList(HebiLookupEntryListPtr lookup_list)
Definition: lookup.hpp:257
float initial_group_feedback_frequency_
Definition: lookup.hpp:47
struct _HebiLookupEntryList * HebiLookupEntryListPtr
Definition: hebi.h:402
Iterator begin() const
Definition: lookup.cpp:175
Lookup()
Creates a Lookup object which can create Module and Group references. Typically, only one Lookup obje...
Definition: lookup.cpp:6
Definition: color.hpp:5
A simple wrapper class for internal C-API HebiMacAddress objects to allow interfacing with API calls ...
Definition: mac_address.hpp:12
struct _HebiLookup * HebiLookupPtr
Definition: hebi.h:395
static const int32_t DEFAULT_TIMEOUT
Definition: lookup.hpp:37
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half &a, const half &b)
Definition: Half.h:210
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:7
size_t size() const
Definition: lookup.cpp:170
std::shared_ptr< EntryList > getEntryList()
Definition: lookup.cpp:185
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:48
~EntryList() noexcept
Definition: lookup.cpp:140
~Lookup() noexcept
Destructor frees all resources created by Lookup object, and stops the background query thread...
Definition: lookup.cpp:11
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:66
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:35
int32_t getInitialGroupCommandLifetimeMs()
Gets the default command lifetime value for groups created from this lookup.
Definition: lookup.cpp:85
HebiLookupEntryListPtr lookup_list_
Definition: lookup.hpp:214
TFSIMD_FORCE_INLINE bool operator!=(const Vector3 &other) const
void setInitialGroupFeedbackFrequencyHz(float frequency)
Sets the default feedback frequency value for groups created from this lookup.
Definition: lookup.cpp:80
HebiLookupPtr lookup_
Definition: lookup.hpp:42
void setInitialGroupCommandLifetimeMs(int32_t ms)
Sets the default command lifetime value for groups created from this lookup.
Definition: lookup.cpp:90
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:57
Maintains a registry of network-connected modules and returns Group objects to the user...
Definition: lookup.hpp:34
Entry operator[](size_t index) const
Definition: lookup.cpp:146
std::bidirectional_iterator_tag iterator_category
Definition: lookup.hpp:228
Iterator end() const
Definition: lookup.cpp:180
int32_t initial_group_command_lifetime_
Definition: lookup.hpp:52
float getInitialGroupFeedbackFrequencyHz()
Gets the default feedback frequency value for groups created from this lookup.
Definition: lookup.cpp:75
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:16
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const half &a, const half &b)
Definition: Half.h:240


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:21