Robot Raconteur Companion C++ Library
Loading...
Searching...
No Matches
DeviceConnector.h
Go to the documentation of this file.
1
23
24#include <RobotRaconteur/RobotRaconteurNode.h>
25#include <RobotRaconteur/Subscription.h>
26#include "com__robotraconteur__identifier.h"
27#include <yaml-cpp/yaml.h>
28
29#include "UtilMacros.h"
30
31#pragma once
32
33namespace RobotRaconteur
34{
35namespace Companion
36{
37namespace Util
38{
39
54struct ROBOTRACONTEUR_COMPANION_UTIL_API DeviceConnectorDetails
55{
57 std::string DeviceNickname;
59 com::robotraconteur::identifier::IdentifierPtr Device;
61 std::string SerialNumber;
63 std::vector<com::robotraconteur::identifier::IdentifierPtr> Tags;
65 std::vector<RobotRaconteur::ServiceSubscriptionFilterNodePtr> ServiceNodes;
67 std::vector<std::string> Urls;
69 std::vector<std::string> RootObjectType;
71 RobotRaconteur::ServiceSubscriptionFilterPtr SubscriptionFilter;
73 std::vector<std::string> TransportSchemes;
75 RobotRaconteur::ServiceSubscriptionFilterNodePtr UrlAuth;
77 int32_t MaxConnections = 10;
79 RobotRaconteur::ServiceSubscriptionFilterAttributeGroupOperation TagMatchOperation =
80 RobotRaconteur::ServiceSubscriptionFilterAttributeGroupOperation_AND;
81
91 DeviceConnectorDetails(const std::string& device_nickname);
103 DeviceConnectorDetails(const std::string& device_nickname,
104 const com::robotraconteur::identifier::IdentifierPtr& device,
105 const std::vector<std::string>& root_object_type,
106 const std::vector<com::robotraconteur::identifier::IdentifierPtr>& tags = {},
107 const std::vector<RobotRaconteur::ServiceSubscriptionFilterNodePtr>& service_nodes = {});
115 DeviceConnectorDetails(const std::string& device_nickname, const std::string& url,
116 const RobotRaconteur::ServiceSubscriptionFilterNodePtr& url_auth = nullptr);
124 DeviceConnectorDetails(const std::string& device_nickname, const std::vector<std::string>& root_object_type,
125 const RobotRaconteur::ServiceSubscriptionFilterPtr& subscription_filter);
126};
127
208class ROBOTRACONTEUR_COMPANION_UTIL_API DeviceConnector
209{
210 public:
220 DeviceConnector(RobotRaconteur::RobotRaconteurNodePtr node = nullptr, bool autoconnect = true);
221
227 void Init();
233 void Init(const std::vector<DeviceConnectorDetails>& devices);
241 void InitFromYamlStr(const std::string& yaml);
249 void InitFromYamlFile(std::istream& file);
257 void InitFromYamlFile(const boost::filesystem::path& filename);
258
268 void AddDevice(const DeviceConnectorDetails& device_details, bool force_connect = false);
269
276 void RemoveDevice(const std::string& device_nickname, bool close = true);
277
285 void ConnectDevice(const std::string& device_nickname);
286
293 void DisconnectDevice(const std::string& device_nickname, bool close = true);
294
302 RobotRaconteur::ServiceSubscriptionPtr GetDevice(const std::string& device_nickname, bool force_create = false);
303
312 bool TryGetDevice(const std::string& device_nickname, RobotRaconteur::ServiceSubscriptionPtr& device);
313
320 void Close();
321
327 std::vector<std::string> GetDeviceNicknames();
328
334 RR_SHARED_PTR<RobotRaconteur::ServiceSubscriptionManager> GetServiceSubscriptionManager();
335
336 protected:
337 void DoUpdateDevice(const DeviceConnectorDetails& device_details, bool force_connect = false);
338
339 RobotRaconteur::RobotRaconteurNodePtr node;
340 bool autoconnect = true;
341 RR_SHARED_PTR<RobotRaconteur::ServiceSubscriptionManager> subscription_manager;
342};
343
352ROBOTRACONTEUR_COMPANION_UTIL_API std::vector<DeviceConnectorDetails> LoadDeviceDetailsFromFile(
353 const boost::filesystem::path& filename);
354
363ROBOTRACONTEUR_COMPANION_UTIL_API std::vector<DeviceConnectorDetails> LoadDeviceDetailsFromString(
364 const std::string& yaml_str);
365
374ROBOTRACONTEUR_COMPANION_UTIL_API std::vector<DeviceConnectorDetails> LoadDeviceDetailsFromStream(std::istream& stream);
375
386ROBOTRACONTEUR_COMPANION_UTIL_API std::vector<DeviceConnectorDetails> LoadDeviceDetailsFromYAMLNode(
387 const YAML::Node& node);
388
389} // namespace Util
390} // namespace Companion
391} // namespace RobotRaconteur
std::vector< DeviceConnectorDetails > LoadDeviceDetailsFromFile(const boost::filesystem::path &filename)
Load DeviceDetails list from a YAML file.
std::vector< DeviceConnectorDetails > LoadDeviceDetailsFromYAMLNode(const YAML::Node &node)
Load DeviceDetails list from a YAML node.
std::vector< DeviceConnectorDetails > LoadDeviceDetailsFromStream(std::istream &stream)
Load DeviceDetails list from a YAML stream.
std::vector< DeviceConnectorDetails > LoadDeviceDetailsFromString(const std::string &yaml_str)
Load DeviceDetails list from a YAML string.
std::vector< std::string > GetDeviceNicknames()
Get all nicknames of the devices.
void AddDevice(const DeviceConnectorDetails &device_details, bool force_connect=false)
Add a device to the DeviceConnector.
void DisconnectDevice(const std::string &device_nickname, bool close=true)
Disconnect a device.
void InitFromYamlFile(const boost::filesystem::path &filename)
Initialize the DeviceConnector from a YAML file.
void InitFromYamlFile(std::istream &file)
Initialize the DeviceConnector from a YAML stream.
void InitFromYamlStr(const std::string &yaml)
Initialize the DeviceConnector from a YAML string.
boost::shared_ptr< RobotRaconteur::ServiceSubscriptionManager > GetServiceSubscriptionManager()
Get the underlying ServiceSubscriptionManager used by the DeviceConnector.
void Init()
Initialize the DeviceConnector.
DeviceConnector(RobotRaconteur::RobotRaconteurNodePtr node=nullptr, bool autoconnect=true)
Construct a new DeviceConnector.
void RemoveDevice(const std::string &device_nickname, bool close=true)
Remove a device from the DeviceConnector.
void Init(const std::vector< DeviceConnectorDetails > &devices)
Initialize the DeviceConnector with a list of devices.
RobotRaconteur::ServiceSubscriptionPtr GetDevice(const std::string &device_nickname, bool force_create=false)
Get the Device object.
void Close()
Close the DeviceConnector.
bool TryGetDevice(const std::string &device_nickname, RobotRaconteur::ServiceSubscriptionPtr &device)
Try to get the Device object. Returns false if the device does not exist instead of throwing an excep...
void ConnectDevice(const std::string &device_nickname)
Connect to a device if not already connected.
Device connection information for use with DeviceConnector class.
Definition DeviceConnector.h:55
RobotRaconteur::ServiceSubscriptionFilterNodePtr UrlAuth
The URL auth to use when connecting to the device. Not used with Filter or "device".
Definition DeviceConnector.h:75
std::vector< std::string > RootObjectType
The root object type of the device. Empty if not used. May be necessary when "device" is used.
Definition DeviceConnector.h:69
DeviceConnectorDetails()=default
Construct an empty DeviceConnectorDetails.
std::string DeviceNickname
The nickname of the device.
Definition DeviceConnector.h:57
std::vector< com::robotraconteur::identifier::IdentifierPtr > Tags
The tags of the device. Empty if not used.
Definition DeviceConnector.h:63
std::string SerialNumber
The serial number of the device. Empty if not used.
Definition DeviceConnector.h:61
RobotRaconteur::ServiceSubscriptionFilterAttributeGroupOperation TagMatchOperation
The tag match operation to use with Tags. Defaults to "AND".
Definition DeviceConnector.h:79
RobotRaconteur::ServiceSubscriptionFilterPtr SubscriptionFilter
The subscription filter to use when connecting to the device. Not used with Url or "device".
Definition DeviceConnector.h:71
std::vector< std::string > Urls
A list of URLs to use for direct connection to the device. Empty if not used.
Definition DeviceConnector.h:67
com::robotraconteur::identifier::IdentifierPtr Device
The device identifier (name, uuid) of the device. null if not used.
Definition DeviceConnector.h:59
std::vector< RobotRaconteur::ServiceSubscriptionFilterNodePtr > ServiceNodes
The service nodes of the device. Empty if not used.
Definition DeviceConnector.h:65
DeviceConnectorDetails(const std::string &device_nickname, const std::string &url, const RobotRaconteur::ServiceSubscriptionFilterNodePtr &url_auth=nullptr)
Construct a new DeviceConnectorDetails for use with URL connection.
DeviceConnectorDetails(const std::string &device_nickname)
Construct a new DeviceConnectorDetails with nickname.
DeviceConnectorDetails(const std::string &device_nickname, const std::vector< std::string > &root_object_type, const RobotRaconteur::ServiceSubscriptionFilterPtr &subscription_filter)
Construct a new DeviceConnectorDetails for use with Robot Raconteur subscription filter.
int32_t MaxConnections
The maximum number of connections to the device. 0 for unlimited. Defaults to 10.
Definition DeviceConnector.h:77
DeviceConnectorDetails(const std::string &device_nickname, const com::robotraconteur::identifier::IdentifierPtr &device, const std::vector< std::string > &root_object_type, const std::vector< com::robotraconteur::identifier::IdentifierPtr > &tags={}, const std::vector< RobotRaconteur::ServiceSubscriptionFilterNodePtr > &service_nodes={})
Construct a new DeviceConnectorDetails for use with "device" identifier.
std::vector< std::string > TransportSchemes
The transport schemes to use when connecting to the device. Not used with Url or Filter.
Definition DeviceConnector.h:73