All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #include <zmq.hpp>
26 #ifdef _MSC_VER
27 #pragma warning(pop)
28 #endif
29 
30 #include <memory>
31 #include <mutex>
32 #include <string>
33 #include <thread>
34 #include <vector>
35 
46 
47 namespace ignition
48 {
49  namespace transport
50  {
55  {
59  public: static NodeShared *Instance();
60 
62  public: void RunReceptionTask();
63 
69  public: bool Publish(const std::string &_topic,
70  const std::string &_data,
71  const std::string &_msgType);
72 
74  public: void RecvMsgUpdate();
75 
78  public: void RecvControlUpdate();
79 
81  public: void RecvSrvRequest();
82 
84  public: void RecvSrvResponse();
85 
91  public: void SendPendingRemoteReqs(const std::string &_topic,
92  const std::string &_reqType,
93  const std::string &_repType);
94 
97  public: void OnNewConnection(const MessagePublisher &_pub);
98 
101  public: void OnNewDisconnection(const MessagePublisher &_pub);
102 
105  public: void OnNewSrvConnection(const ServicePublisher &_pub);
106 
109  public: void OnNewSrvDisconnection(const ServicePublisher &_pub);
110 
112  protected: NodeShared();
113 
115  protected: virtual ~NodeShared();
116 
120  private: bool InitializeSockets();
121 
123  public: static const int Timeout = 250;
124 
128 
131 
133  public: Uuid replierId;
134 
136  public: std::string pUuid;
137 
139  public: int timeout;
140 
142  public: std::thread threadReception;
143 
145  public: std::recursive_mutex mutex;
146 
148  public: bool exit;
149 
150 #ifdef _WIN32
151  public: bool threadReceptionExiting;
153 #endif
154 
156  private: const int kMsgDiscPort = 11317;
157 
159  private: const int kSrvDiscPort = 11318;
160 
162  private: std::mutex exitMutex;
163 
165  private: TopicStorage<MessagePublisher> connections;
166 
168  private: std::vector<std::string> srvConnections;
169 
172 
175 
178 
181 
183  public: int verbose;
184 
186  public: std::string myAddress;
187 
189  public: std::string myControlAddress;
190 
192  public: std::string myRequesterAddress;
193 
195  public: std::string myReplierAddress;
196 
198  public: std::string hostAddr;
199 
203 
206  public: std::unique_ptr<zmq::context_t> context;
207 
211 
213  public: std::unique_ptr<zmq::socket_t> publisher;
214 
216  public: std::unique_ptr<zmq::socket_t> subscriber;
217 
219  public: std::unique_ptr<zmq::socket_t> control;
220 
222  public: std::unique_ptr<zmq::socket_t> requester;
223 
225  public: std::unique_ptr<zmq::socket_t> responseReceiver;
226 
228  public: std::unique_ptr<zmq::socket_t> replier;
229 
233 
235  public: std::unique_ptr<MsgDiscovery> msgDiscovery;
236 
238  public: std::unique_ptr<SrvDiscovery> srvDiscovery;
239  };
240  }
241 }
242 #endif
std::thread threadReception
thread in charge of receiving and handling incoming messages.
Definition: NodeShared.hh:142
Uuid replierId
Replier socket identity.
Definition: NodeShared.hh:133
std::unique_ptr< zmq::socket_t > control
ZMQ socket to receive control updates (new connections, ...).
Definition: NodeShared.hh:219
std::string hostAddr
IP address of this host.
Definition: NodeShared.hh:198
std::unique_ptr< zmq::socket_t > responseReceiver
ZMQ socket for receiving service call responses.
Definition: NodeShared.hh:225
Uuid responseReceiverId
Response receiver socket identity.
Definition: NodeShared.hh:130
int timeout
Timeout used for receiving requests.
Definition: NodeShared.hh:139
std::string myControlAddress
My pub/sub control address.
Definition: NodeShared.hh:189
HandlerStorage< IReqHandler > requests
Pending service call requests.
Definition: NodeShared.hh:180
std::string myReplierAddress
My replier service call address.
Definition: NodeShared.hh:195
bool exit
When true, the reception thread will finish.
Definition: NodeShared.hh:148
TopicStorage< MessagePublisher > remoteSubscribers
Remote subscribers.
Definition: NodeShared.hh:171
std::unique_ptr< SrvDiscovery > srvDiscovery
Discovery service (services).
Definition: NodeShared.hh:238
std::unique_ptr< zmq::socket_t > replier
ZMQ socket to receive service call requests.
Definition: NodeShared.hh:228
ignition/transport/HandlerStorage.hh
Definition: HandlerStorage.hh:33
Private data for the Node class.
Definition: NodeShared.hh:54
A portable class for representing a Universally Unique Identifier.
Definition: Uuid.hh:41
std::unique_ptr< zmq::socket_t > subscriber
ZMQ socket to receive topic updates.
Definition: NodeShared.hh:216
std::unique_ptr< zmq::socket_t > requester
ZMQ socket for sending service call requests.
Definition: NodeShared.hh:222
std::string myAddress
My pub/sub address.
Definition: NodeShared.hh:186
std::unique_ptr< zmq::socket_t > publisher
ZMQ socket to send topic updates.
Definition: NodeShared.hh:213
#define IGNITION_TRANSPORT_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:57
ignition/transport/Publisher.hh
Definition: Publisher.hh:198
ignition/transport/Publisher.hh
Definition: Publisher.hh:314
HandlerStorage< ISubscriptionHandler > localSubscriptions
Subscriptions.
Definition: NodeShared.hh:174
std::unique_ptr< MsgDiscovery > msgDiscovery
Discovery service (messages).
Definition: NodeShared.hh:235
std::string myRequesterAddress
My requester service call address.
Definition: NodeShared.hh:192
std::unique_ptr< zmq::context_t > context
0MQ context.
Definition: NodeShared.hh:206
Store address information about topics and provide convenient methods for adding new topics...
Definition: TopicStorage.hh:37
std::string pUuid
Process UUID.
Definition: NodeShared.hh:136
int verbose
Print activity to stdout.
Definition: NodeShared.hh:183
HandlerStorage< IRepHandler > repliers
Service call repliers.
Definition: NodeShared.hh:177
std::recursive_mutex mutex
Mutex to guarantee exclusive access between all threads.
Definition: NodeShared.hh:145