Ignition Transport

API Reference

8.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/config.hh"
37 #include "ignition/transport/Export.hh"
46 
47 namespace ignition
48 {
49  namespace transport
50  {
51  // Inline bracket to help doxygen filtering.
52  inline namespace IGNITION_TRANSPORT_VERSION_NAMESPACE {
53  //
54  // Forward declarations.
55  class Node;
56  class NodePrivate;
57 
59  class NodeSharedPrivate;
60 
64  class IGNITION_TRANSPORT_VISIBLE NodeShared
65  {
69  public: static NodeShared *Instance();
70 
72  public: void RunReceptionTask();
73 
85  public: bool Publish(const std::string &_topic,
86  char *_data,
87  const size_t _dataSize,
88  DeallocFunc *_ffn,
89  const std::string &_msgType);
90 
92  public: void RecvMsgUpdate();
93 
98  public: struct HandlerInfo
99  {
104 
109 
111  public: bool haveLocal;
112 
114  public: bool haveRaw;
115 
116  // Friendship. This allows HandlerInfo to be created by
117  // CheckHandlerInfo()
118  friend class NodeShared;
119 
120  // TODO(sloretz) private default constructor (visual studio 2017?)
121  };
122 
129  HandlerInfo CheckHandlerInfo(const std::string &_topic) const;
130 
139  public: struct SubscriberInfo : public HandlerInfo
140  {
142  // cppcheck-suppress unusedStructMember
143  public: bool haveRemote;
144 
145  // Friendship declaration
146  friend class NodeShared;
147 
148  // TODO(sloretz) private default constructor (visual studio 2017?)
149  };
150 
159  SubscriberInfo CheckSubscriberInfo(
160  const std::string &_topic,
161  const std::string &_msgType) const;
162 
170  public: void IGN_DEPRECATED(8.0) TriggerSubscriberCallbacks(
171  const std::string &_topic,
172  const std::string &_msgData,
173  const std::string &_msgType,
174  const HandlerInfo &_handlerInfo);
175 
182  public: void TriggerCallbacks(
183  const MessageInfo &_info,
184  const std::string &_msgData,
185  const HandlerInfo &_handlerInfo);
186 
190  public: void RecvControlUpdate();
191 
193  public: void RecvSrvRequest();
194 
196  public: void RecvSrvResponse();
197 
203  public: void SendPendingRemoteReqs(const std::string &_topic,
204  const std::string &_reqType,
205  const std::string &_repType);
206 
209  public: void OnNewConnection(const MessagePublisher &_pub);
210 
213  public: void OnNewDisconnection(const MessagePublisher &_pub);
214 
217  public: void OnNewSrvConnection(const ServicePublisher &_pub);
218 
221  public: void OnNewSrvDisconnection(const ServicePublisher &_pub);
222 
225  public: void OnNewRegistration(const MessagePublisher &_pub);
226 
229  public: void OnEndRegistration(const MessagePublisher &_pub);
230 
236  // there is at least one publisher.
239  public: bool TopicPublishers(const std::string &_topic,
240  SrvAddresses_M &_publishers) const;
241 
248  public: bool DiscoverService(const std::string &_topic) const;
249 
255  public: bool AdvertisePublisher(const ServicePublisher &_publisher);
256 
267  public: int RcvHwm();
268 
279  public: int SndHwm();
280 
282  protected: NodeShared();
283 
285  protected: virtual ~NodeShared();
286 
290  private: bool InitializeSockets();
291 
295 
297  public: Uuid responseReceiverId;
298 
300  public: Uuid replierId;
301 
302 #ifdef _WIN32
303 // Disable warning C4251 which is triggered by
304 // std::unique_ptr
305 #pragma warning(push)
306 #pragma warning(disable: 4251)
307 #endif
308  public: std::string pUuid;
310 
313 
315  public: mutable std::recursive_mutex mutex;
316 
318  public: static const int kMsgDiscPort = 10317;
319 
321  public: static const int kSrvDiscPort = 10318;
322 
324  private: TopicStorage<MessagePublisher> connections;
325 
327  private: std::vector<std::string> srvConnections;
328 
331 #ifdef _WIN32
332 #pragma warning(pop)
333 #endif
334 
340  {
347  public: bool HasSubscriber(
348  const std::string &_fullyQualifiedTopic,
349  const std::string &_msgType) const;
350 
356  public: bool HasSubscriber(
357  const std::string &_fullyQualifiedTopic) const;
358 
366  public: std::vector<std::string> NodeUuids(
367  const std::string &_fullyQualifiedTopic,
368  const std::string &_msgTypeName) const;
369 
377  public: bool RemoveHandlersForNode(
378  const std::string &_fullyQualifiedTopic,
379  const std::string &_nUuid);
380 
383 
388  };
389 
391 
392 #ifdef _WIN32
393 // Disable warning C4251 which is triggered by
394 // std::unique_ptr
395 #pragma warning(push)
396 #pragma warning(disable: 4251)
397 #endif
398  public: HandlerStorage<IRepHandler> repliers;
400 
403 
405  public: int verbose;
406 
409 
412 
415 
418 
421 
423  private: std::unique_ptr<NodeSharedPrivate> dataPtr;
424 #ifdef _WIN32
425 #pragma warning(pop)
426 #endif
427  private: friend Node;
428  private: friend NodePrivate;
429  };
430  }
431  }
432 }
433 #endif
bool haveRaw
True iff there are any raw local subscribers.
Definition: NodeShared.hh:114
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:103
bool haveLocal
True iff there are any standard local subscribers.
Definition: NodeShared.hh:111
bool haveRemote
True if this Publisher has any remote subscribers.
Definition: NodeShared.hh:143
TopicStorage< MessagePublisher > remoteSubscribers
Remote subscribers.
Definition: NodeShared.hh:330
HandlerStorage< RawSubscriptionHandler > raw
Raw local subscriptions. Keeping these separate from localSubscriptions allows us to avoid an unneces...
Definition: NodeShared.hh:387
std::string myControlAddress
My pub/sub control address.
Definition: NodeShared.hh:411
HandlerInfo contains information about callback handlers which is useful for local publishers and mes...
Definition: NodeShared.hh:98
STL namespace.
HandlerWrapper localSubscribers
Definition: NodeShared.hh:390
HandlerStorage< ISubscriptionHandler > normal
Normal local subscriptions.
Definition: NodeShared.hh:382
STL class.
STL class.
Class to store and manage service call handlers.
Definition: HandlerStorage.hh:39
std::string myReplierAddress
My replier service call address.
Definition: NodeShared.hh:417
Private data for the Node class. This class should not be directly used. You should use the Node clas...
Definition: NodeShared.hh:64
int verbose
Print activity to stdout.
Definition: NodeShared.hh:405
A portable class for representing a Universally Unique Identifier.
Definition: Uuid.hh:45
A class that provides information about the message received.
Definition: MessageInfo.hh:37
std::string hostAddr
IP address of this host.
Definition: NodeShared.hh:420
This struct wraps up the two different types of subscription handlers: normal (deserialized) and raw ...
Definition: NodeShared.hh:339
A class that allows a client to communicate with other peers. There are two main communication modes:...
Definition: Node.hh:93
void(void *_data, void *_hint) DeallocFunc
Definition: TransportTypes.hh:171
This class stores all the information about a message publisher.
Definition: Publisher.hh:222
This class stores all the information about a service publisher.
Definition: Publisher.hh:355
std::recursive_mutex mutex
Mutex to guarantee exclusive access between all threads.
Definition: NodeShared.hh:315
std::thread threadReception
thread in charge of receiving and handling incoming messages.
Definition: NodeShared.hh:312
std::string myRequesterAddress
My requester service call address.
Definition: NodeShared.hh:414
Definition: AdvertiseOptions.hh:28
Store address information about topics and provide convenient methods for adding new topics...
Definition: TopicStorage.hh:41
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:108
STL class.
This struct provides information about the Subscribers of a Publisher. It should only be retrieved us...
Definition: NodeShared.hh:139
HandlerStorage< IReqHandler > requests
Pending service call requests.
Definition: NodeShared.hh:402
std::string myAddress
My pub/sub address.
Definition: NodeShared.hh:408