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_INCLUDED__
19 #define _IGN_TRANSPORT_NODESHARED_HH_INCLUDED__
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 
45 
46 namespace ignition
47 {
48  namespace transport
49  {
54  {
58  public: static NodeShared *Instance();
59 
61  public: void RunReceptionTask();
62 
68  public: bool Publish(const std::string &_topic,
69  const std::string &_data,
70  const std::string &_msgType);
71 
73  public: void RecvMsgUpdate();
74 
77  public: void RecvControlUpdate();
78 
80  public: void RecvSrvRequest();
81 
83  public: void RecvSrvResponse();
84 
90  public: void SendPendingRemoteReqs(const std::string &_topic,
91  const std::string &_reqType,
92  const std::string &_repType);
93 
96  public: void OnNewConnection(const MessagePublisher &_pub);
97 
100  public: void OnNewDisconnection(const MessagePublisher &_pub);
101 
104  public: void OnNewSrvConnection(const ServicePublisher &_pub);
105 
108  public: void OnNewSrvDisconnection(const ServicePublisher &_pub);
109 
111  protected: NodeShared();
112 
114  protected: virtual ~NodeShared();
115 
117  public: static const int Timeout = 250;
118 
120  public: int verbose;
121 
123  public: std::string myAddress;
124 
126  public: std::string myControlAddress;
127 
129  public: std::string myRequesterAddress;
130 
132  public: std::string myReplierAddress;
133 
135  public: std::string hostAddr;
136 
138  public: std::unique_ptr<Discovery> discovery;
139 
141  public: zmq::context_t *context;
142 
144  public: std::unique_ptr<zmq::socket_t> publisher;
145 
147  public: std::unique_ptr<zmq::socket_t> subscriber;
148 
150  public: std::unique_ptr<zmq::socket_t> control;
151 
153  public: std::unique_ptr<zmq::socket_t> requester;
154 
156  public: std::unique_ptr<zmq::socket_t> responseReceiver;
157 
160 
162  public: Uuid replierId;
163 
165  public: std::unique_ptr<zmq::socket_t> replier;
166 
168  public: std::string pUuid;
169 
171  public: int timeout;
172 
174  public: std::thread threadReception;
175 
177  public: std::recursive_mutex mutex;
178 
180  public: bool exit;
181 
182 #ifdef _WIN32
183  public: bool threadReceptionExiting;
185 #endif
186 
188  private: std::mutex exitMutex;
189 
191  private: TopicStorage<MessagePublisher> connections;
192 
194  private: std::vector<std::string> srvConnections;
195 
198 
201 
204 
207  };
208  }
209 }
210 #endif
std::thread threadReception
thread in charge of receiving and handling incoming messages.
Definition: NodeShared.hh:174
Uuid replierId
Replier socket identity.
Definition: NodeShared.hh:162
std::unique_ptr< zmq::socket_t > control
ZMQ socket to receive control updates (new connections, ...).
Definition: NodeShared.hh:150
zmq::context_t * context
0MQ context.
Definition: NodeShared.hh:141
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
std::string hostAddr
IP address of this host.
Definition: NodeShared.hh:135
std::unique_ptr< zmq::socket_t > responseReceiver
ZMQ socket for receiving service call responses.
Definition: NodeShared.hh:156
Uuid responseReceiverId
Response receiver socket identity.
Definition: NodeShared.hh:159
int timeout
Timeout used for receiving requests.
Definition: NodeShared.hh:171
std::string myControlAddress
My pub/sub control address.
Definition: NodeShared.hh:126
HandlerStorage< IReqHandler > requests
Pending service call requests.
Definition: NodeShared.hh:206
std::string myReplierAddress
My replier service call address.
Definition: NodeShared.hh:132
bool exit
When true, the reception thread will finish.
Definition: NodeShared.hh:180
TopicStorage< MessagePublisher > remoteSubscribers
Remote subscribers.
Definition: NodeShared.hh:197
std::unique_ptr< zmq::socket_t > replier
ZMQ socket to receive service call requests.
Definition: NodeShared.hh:165
ignition/transport/HandlerStorage.hh
Definition: HandlerStorage.hh:33
Private data for the Node class.
Definition: NodeShared.hh:53
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:147
std::unique_ptr< zmq::socket_t > requester
ZMQ socket for sending service call requests.
Definition: NodeShared.hh:153
std::string myAddress
My pub/sub address.
Definition: NodeShared.hh:123
std::unique_ptr< zmq::socket_t > publisher
ZMQ socket to send topic updates.
Definition: NodeShared.hh:144
std::unique_ptr< Discovery > discovery
Discovery service.
Definition: NodeShared.hh:138
ignition/transport/Publisher.hh
Definition: Publisher.hh:175
ignition/transport/Publisher.hh
Definition: Publisher.hh:264
HandlerStorage< ISubscriptionHandler > localSubscriptions
Subscriptions.
Definition: NodeShared.hh:200
std::string myRequesterAddress
My requester service call address.
Definition: NodeShared.hh:129
Definition: AdvertiseOptions.hh:25
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:168
int verbose
Print activity to stdout.
Definition: NodeShared.hh:120
HandlerStorage< IRepHandler > repliers
Service call repliers.
Definition: NodeShared.hh:203
std::recursive_mutex mutex
Mutex to guarantee exclusive access between all threads.
Definition: NodeShared.hh:177