Ignition Transport

API Reference

4.0.0
NodeShared.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef IGN_TRANSPORT_NODESHARED_HH_
19#define IGN_TRANSPORT_NODESHARED_HH_
20
21#ifdef _MSC_VER
22#pragma warning(push, 0)
23#endif
24#include <google/protobuf/message.h>
25#ifdef _MSC_VER
26#pragma warning(pop)
27#endif
28
29#include <memory>
30#include <mutex>
31#include <string>
32#include <thread>
33#include <vector>
34#include <map>
35
36#include "ignition/transport/Export.hh"
45
46namespace ignition
47{
48 namespace transport
49 {
50 class Node;
51 class NodePrivate;
52
54 class NodeSharedPrivate;
55
59 class IGNITION_TRANSPORT_VISIBLE NodeShared
60 {
64 public: static NodeShared *Instance();
65
67 public: void RunReceptionTask();
68
80 public: bool Publish(const std::string &_topic,
81 char *_data,
82 const size_t _dataSize,
83 DeallocFunc *_ffn,
84 const std::string &_msgType);
85
87 public: void RecvMsgUpdate();
88
93 public: struct HandlerInfo
94 {
99
104
106 public: bool haveLocal;
107
109 public: bool haveRaw;
110
111 // Friendship. This allows HandlerInfo to be created by
112 // CheckHandlerInfo()
113 friend class NodeShared;
114
115 // TODO(sloretz) private default constructor (visual studio 2017?)
116 };
117
125
134 public: struct SubscriberInfo : public HandlerInfo
135 {
137 public: bool haveRemote;
138
139 // Friendship declaration
140 friend class NodeShared;
141
142 // TODO(sloretz) private default constructor (visual studio 2017?)
143 };
144
154 const std::string &_topic,
155 const std::string &_msgType) const;
156
165 const std::string &_topic,
166 const std::string &_msgData,
167 const std::string &_msgType,
168 const HandlerInfo &_handlerInfo);
169
172 public: void RecvControlUpdate();
173
175 public: void RecvSrvRequest();
176
178 public: void RecvSrvResponse();
179
185 public: void SendPendingRemoteReqs(const std::string &_topic,
186 const std::string &_reqType,
187 const std::string &_repType);
188
191 public: void OnNewConnection(const MessagePublisher &_pub);
192
195 public: void OnNewDisconnection(const MessagePublisher &_pub);
196
199 public: void OnNewSrvConnection(const ServicePublisher &_pub);
200
203 public: void OnNewSrvDisconnection(const ServicePublisher &_pub);
204
210 // there is at least one publisher.
213 public: bool TopicPublishers(const std::string &_topic,
214 SrvAddresses_M &_publishers) const;
215
222 public: bool DiscoverService(const std::string &_topic) const;
223
229 public: bool AdvertisePublisher(const ServicePublisher &_publisher);
230
232 protected: NodeShared();
233
235 protected: virtual ~NodeShared();
236
240 private: bool InitializeSockets();
241
245
248
251
254
257
260
262 private: const int kMsgDiscPort = 11317;
263
265 private: const int kSrvDiscPort = 11318;
266
268 private: TopicStorage<MessagePublisher> connections;
269
271 private: std::vector<std::string> srvConnections;
272
275
281 {
288 public: bool HasSubscriber(
289 const std::string &_fullyQualifiedTopic,
290 const std::string &_msgType) const;
291
297 public: bool HasSubscriber(
298 const std::string &_fullyQualifiedTopic) const;
299
308 const std::string &_fullyQualifiedTopic,
309 const std::string &_msgTypeName) const;
310
319 const std::string &_fullyQualifiedTopic,
320 const std::string &_nUuid);
321
324
329 };
330
332
335
338
340 public: int verbose;
341
344
347
350
353
356
358 private: std::unique_ptr<NodeSharedPrivate> dataPtr;
359
360 private: friend Node;
361 private: friend NodePrivate;
362 };
363 }
364}
365#endif
Node(const NodeOptions &_options=NodeOptions())
Constructor.
Class to store and manage service call handlers.
Definition HandlerStorage.hh:34
This class stores all the information about a message publisher.
Definition Publisher.hh:199
Private data for the Node class. This class should not be directly used. You should use the Node clas...
Definition NodeShared.hh:60
std::string myControlAddress
My pub/sub control address.
Definition NodeShared.hh:346
HandlerWrapper localSubscribers
Definition NodeShared.hh:331
int verbose
Print activity to stdout.
Definition NodeShared.hh:340
void OnNewDisconnection(const MessagePublisher &_pub)
Callback executed when the discovery detects disconnections.
void OnNewSrvDisconnection(const ServicePublisher &_pub)
Callback executed when a service call is no longer available.
void RecvMsgUpdate()
Method in charge of receiving the topic updates.
std::string hostAddr
IP address of this host.
Definition NodeShared.hh:355
static NodeShared * Instance()
NodeShared is a singleton. This method gets the NodeShared instance shared between all the nodes.
SubscriberInfo CheckSubscriberInfo(const std::string &_topic, const std::string &_msgType) const
Get information about the nodes that are subscribed to the publishers of this NodeShared.
void RecvSrvRequest()
Method in charge of receiving the service call requests.
std::string pUuid
Process UUID.
Definition NodeShared.hh:253
std::string myRequesterAddress
My requester service call address.
Definition NodeShared.hh:349
std::string myAddress
My pub/sub address.
Definition NodeShared.hh:343
TopicStorage< MessagePublisher > remoteSubscribers
Remote subscribers.
Definition NodeShared.hh:274
std::recursive_mutex mutex
Mutex to guarantee exclusive access between all threads.
Definition NodeShared.hh:259
bool TopicPublishers(const std::string &_topic, SrvAddresses_M &_publishers) const
Pass through to bool Publishers(const std::string &_topic, Addresses_M<Pub> &_publishers) const.
bool DiscoverService(const std::string &_topic) const
Pass through to bool Discovery::Discover(const std::string &_topic) const.
void OnNewSrvConnection(const ServicePublisher &_pub)
Callback executed when the discovery detects a new service call.
virtual ~NodeShared()
Destructor.
HandlerStorage< IRepHandler > repliers
Service call repliers.
Definition NodeShared.hh:334
void SendPendingRemoteReqs(const std::string &_topic, const std::string &_reqType, const std::string &_repType)
Try to send all the requests for a given service call and a pair of request/response types.
bool AdvertisePublisher(const ServicePublisher &_publisher)
Pass through to bool Advertise(const Pub &_publisher)
HandlerStorage< IReqHandler > requests
Pending service call requests.
Definition NodeShared.hh:337
std::string myReplierAddress
My replier service call address.
Definition NodeShared.hh:352
bool Publish(const std::string &_topic, char *_data, const size_t _dataSize, DeallocFunc *_ffn, const std::string &_msgType)
Publish data.
HandlerInfo CheckHandlerInfo(const std::string &_topic) const
Get information about the local and raw subscribers that are attached to this NodeShared.
void OnNewConnection(const MessagePublisher &_pub)
Callback executed when the discovery detects new topics.
void RecvSrvResponse()
Method in charge of receiving the service call responses.
void TriggerSubscriberCallbacks(const std::string &_topic, const std::string &_msgData, const std::string &_msgType, const HandlerInfo &_handlerInfo)
Call the SubscriptionHandler callbacks (local and raw) for this NodeShared.
Uuid responseReceiverId
Response receiver socket identity.
Definition NodeShared.hh:247
void RunReceptionTask()
Receive data and control messages.
void RecvControlUpdate()
Method in charge of receiving the control updates (when a new remote subscriber notifies its presence...
Uuid replierId
Replier socket identity.
Definition NodeShared.hh:250
std::thread threadReception
thread in charge of receiving and handling incoming messages.
Definition NodeShared.hh:256
A class that allows a client to communicate with other peers. There are two main communication modes:...
Definition Node.hh:65
This class stores all the information about a service publisher.
Definition Publisher.hh:315
Store address information about topics and provide convenient methods for adding new topics,...
Definition TopicStorage.hh:38
A portable class for representing a Universally Unique Identifier.
Definition Uuid.hh:42
void(void *_data, void *_hint) DeallocFunc
Definition TransportTypes.hh:167
Definition AdvertiseOptions.hh:28
HandlerInfo contains information about callback handlers which is useful for local publishers and mes...
Definition NodeShared.hh:94
std::map< std::string, ISubscriptionHandler_M > localHandlers
This is a map of the standard local callback handlers. The key is the topic name, and the value is an...
Definition NodeShared.hh:98
bool haveRaw
True iff there are any raw local subscribers.
Definition NodeShared.hh:109
bool haveLocal
True iff there are any standard local subscribers.
Definition NodeShared.hh:106
std::map< std::string, RawSubscriptionHandler_M > rawHandlers
This is a map of the raw local callback handlers. The key is the topic name, and the value is another...
Definition NodeShared.hh:103
This struct wraps up the two different types of subscription handlers: normal (deserialized) and raw ...
Definition NodeShared.hh:281
bool HasSubscriber(const std::string &_fullyQualifiedTopic) const
Returns true if this wrapper contains any subscriber that matches the given fully-qualified topic nam...
HandlerStorage< ISubscriptionHandler > normal
Normal local subscriptions.
Definition NodeShared.hh:323
bool HasSubscriber(const std::string &_fullyQualifiedTopic, const std::string &_msgType) const
Returns true if this wrapper contains any subscriber that matches the given topic name and message ty...
bool RemoveHandlersForNode(const std::string &_fullyQualifiedTopic, const std::string &_nUuid)
Remove the handlers for the given topic name that belong to a specific node.
HandlerStorage< RawSubscriptionHandler > raw
Raw local subscriptions. Keeping these separate from localSubscriptions allows us to avoid an unneces...
Definition NodeShared.hh:328
std::vector< std::string > NodeUuids(const std::string &_fullyQualifiedTopic, const std::string &_msgTypeName) const
Get a set of node UUIDs for subscribers in this wrapper that match the topic and message type criteri...
This struct provides information about the Subscribers of a Publisher. It should only be retrieved us...
Definition NodeShared.hh:135
bool haveRemote
True iff this Publisher has any remote subscribers.
Definition NodeShared.hh:137