HEBI C++ API  1.0.0-rc1
lookup.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstddef>
4 
5 #include "hebi_lookup.h"
6 #include "mac_address.hpp"
7 #include "group.hpp"
8 
9 #include <memory> // For shared_ptr
10 #include <vector>
11 
12 namespace hebi {
13 
33 class Lookup final
34 {
35  private:
36  static const long DEFAULT_TIMEOUT = 500;
37 
41  HebiLookupPtr lookup_;
42 
43  public:
52  Lookup();
53 
58  virtual ~Lookup() noexcept; /* annotating specified destructor as noexcept is best-practice */
59 
81  std::shared_ptr<Group> getGroupFromNames(const std::vector<std::string>& families, const std::vector<std::string>& names, long timeout_ms=DEFAULT_TIMEOUT);
82 
97  std::shared_ptr<Group> getGroupFromMacs(const std::vector<MacAddress>& addresses, long timeout_ms=DEFAULT_TIMEOUT);
98 
113  std::shared_ptr<Group> getGroupFromFamily(const std::string& family, long timeout_ms=DEFAULT_TIMEOUT);
114 
133  std::shared_ptr<Group> getConnectedGroupFromName(const std::string& family, const std::string& name, long timeout_ms=DEFAULT_TIMEOUT);
134 
150  std::shared_ptr<Group> getConnectedGroupFromMac(const MacAddress& address, long timeout_ms=DEFAULT_TIMEOUT);
151 
152  class EntryList final
153  {
154  typedef struct Entry final
155  {
156  std::string name_;
157  std::string family_;
158  MacAddress mac_address_;
159  } Entry;
160 
161  private:
165  HebiLookupEntryListPtr lookup_list_;
166  public:
170  EntryList(HebiLookupEntryListPtr lookup_list) : lookup_list_(lookup_list) {}
171 
172  virtual ~EntryList() noexcept;
173 
174  Entry getEntry(int index);
175 
176  int size();
177 
178  private:
183  };
184 
185  std::shared_ptr<EntryList> getEntryList();
186 
187  private:
192 };
193 
194 } // namespace hebi
EntryList(HebiLookupEntryListPtr lookup_list)
Definition: lookup.hpp:170
std::shared_ptr< Group > getGroupFromNames(const std::vector< std::string > &families, const std::vector< std::string > &names, long timeout_ms=DEFAULT_TIMEOUT)
Get a group from modules with the given names and families.
Definition: lookup.cpp:17
std::shared_ptr< Group > getConnectedGroupFromMac(const MacAddress &address, long timeout_ms=DEFAULT_TIMEOUT)
Get a group from all modules known to connect to a module with the given mac address.
Definition: lookup.cpp:67
Lookup()
Creates a Lookup object which can create Module and Group references. Typically, only one Lookup obje...
Definition: lookup.cpp:7
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
Definition: lookup.hpp:152
#define HEBI_DISABLE_COPY_MOVE(Class)
Definition: util.hpp:7
std::shared_ptr< EntryList > getEntryList()
Definition: lookup.cpp:110
std::shared_ptr< Group > getGroupFromMacs(const std::vector< MacAddress > &addresses, long timeout_ms=DEFAULT_TIMEOUT)
Get a group from modules with the given mac addresses.
Definition: lookup.cpp:36
virtual ~EntryList() noexcept
Definition: lookup.cpp:76
int size()
Definition: lookup.cpp:105
virtual ~Lookup() noexcept
Destructor frees all resources created by Lookup object, and stops the background query thread...
Definition: lookup.cpp:12
std::shared_ptr< Group > getConnectedGroupFromName(const std::string &family, const std::string &name, long 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:58
Maintains a registry of network-connected modules and returns Group objects to the user...
Definition: lookup.hpp:33
std::shared_ptr< Group > getGroupFromFamily(const std::string &family, long timeout_ms=DEFAULT_TIMEOUT)
Get a group from all known modules with the given family.
Definition: lookup.cpp:49
Entry getEntry(int index)
Definition: lookup.cpp:82