DiscoveryPrivate.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_DISCOVERY_PRIVATE_HH_INCLUDED__
19 #define __IGN_TRANSPORT_DISCOVERY_PRIVATE_HH_INCLUDED__
20 
21 #ifdef _WIN32
22  #include <Winsock2.h>
23 #else
24  #include <arpa/inet.h>
25 #endif
26 #include <condition_variable>
27 #include <map>
28 #include <memory>
29 #include <mutex>
30 #include <thread>
31 #include <string>
32 #include <vector>
33 
38 
39 namespace ignition
40 {
41  namespace transport
42  {
47  {
49  public: DiscoveryPrivate() = default;
50 
52  public: virtual ~DiscoveryPrivate() = default;
53 
57  public: static const unsigned int DefActivityInterval = 100;
58 
62  public: static const unsigned int DefHeartbeatInterval = 1000;
63 
67  public: static const unsigned int DefSilenceInterval = 3000;
68 
72  public: static const unsigned int DefAdvertiseInterval = 1000;
73 
75  public: static const int DiscoveryPort = 11319;
76 
78  public: const std::string MulticastGroup = "224.0.0.7";
79 
81  public: static const int Timeout = 250;
82 
84  public: static const int MaxRcvStr = 65536;
85 
88  static const uint8_t Version = 3;
89 
91  public: std::string hostAddr;
92 
94  public: std::vector<std::string> hostInterfaces;
95 
97  public: std::string pUuid;
98 
102  public: unsigned int silenceInterval;
103 
107  public: unsigned int activityInterval;
108 
112  public: unsigned int advertiseInterval;
113 
117  public: unsigned int heartbeatInterval;
118 
121 
124 
127 
130 
133 
136 
141  public: std::map<std::string, Timestamp> activity;
142 
144  public: bool verbose;
145 
147  public: std::vector<int> sockets;
148 
150  public: sockaddr_in mcastAddr;
151 
153  public: std::recursive_mutex mutex;
154 
156  public: std::thread threadReception;
157 
159  public: std::thread threadHeartbeat;
160 
162  public: std::thread threadActivity;
163 
165  public: std::recursive_mutex exitMutex;
166 
171  public: bool initialized;
172 
174  public: unsigned int numHeartbeatsUninitialized = 0;
175 
177  public: std::condition_variable_any initializedCv;
178 
180  public: bool exit;
181 
182 #ifdef _WIN32
183  public: bool threadReceptionExiting = true;
186  public: bool threadHeartbeatExiting = true;
188  public: bool threadActivityExiting = true;
189 #endif
190 
192  public: bool enabled;
193  };
194  }
195 }
196 #endif
std::vector< int > sockets
UDP socket used for sending/receiving discovery messages.
Definition: DiscoveryPrivate.hh:147
ignition/transport/DiscoveryPrivate.hh
Definition: DiscoveryPrivate.hh:46
#define IGNITION_VISIBLE
Use to represent "symbol visible" if supported.
Definition: Helpers.hh:56
std::thread threadHeartbeat
Thread in charge of sending heartbeats.
Definition: DiscoveryPrivate.hh:159
TopicStorage< ServicePublisher > infoSrv
Service addressing information.
Definition: DiscoveryPrivate.hh:135
bool exit
When true, the service threads will finish.
Definition: DiscoveryPrivate.hh:180
std::condition_variable_any initializedCv
Used to block/unblock until the initialization phase finishes.
Definition: DiscoveryPrivate.hh:177
std::string pUuid
Process UUID.
Definition: DiscoveryPrivate.hh:97
MsgDiscoveryCallback disconnectionCb
Callback executed when new topics are invalid.
Definition: DiscoveryPrivate.hh:123
TopicStorage< MessagePublisher > infoMsg
Message addressing information.
Definition: DiscoveryPrivate.hh:132
bool enabled
When true, the service is enabled.
Definition: DiscoveryPrivate.hh:192
unsigned int heartbeatInterval
Heartbeat interval value (ms.).
Definition: DiscoveryPrivate.hh:117
std::map< std::string, Timestamp > activity
Activity information.
Definition: DiscoveryPrivate.hh:141
std::vector< std::string > hostInterfaces
List of host network interfaces.
Definition: DiscoveryPrivate.hh:94
MsgDiscoveryCallback connectionCb
Callback executed when new topics are discovered.
Definition: DiscoveryPrivate.hh:120
std::thread threadReception
Thread in charge of receiving and handling incoming messages.
Definition: DiscoveryPrivate.hh:156
sockaddr_in mcastAddr
Internet socket address for sending to the multicast group.
Definition: DiscoveryPrivate.hh:150
std::function< void(const ServicePublisher &_publisher)> SrvDiscoveryCallback
Definition: TransportTypes.hh:110
std::function< void(const MessagePublisher &_publisher)> MsgDiscoveryCallback
Definition: TransportTypes.hh:102
std::recursive_mutex exitMutex
Mutex to guarantee exclusive access to the exit variable.
Definition: DiscoveryPrivate.hh:165
unsigned int silenceInterval
Silence interval value (ms.).
Definition: DiscoveryPrivate.hh:102
bool initialized
Once the discovery starts, it can take up to HeartbeatInterval milliseconds to discover the existing ...
Definition: DiscoveryPrivate.hh:171
bool verbose
Print discovery information to stdout.
Definition: DiscoveryPrivate.hh:144
SrvDiscoveryCallback connectionSrvCb
Callback executed when new services are discovered.
Definition: DiscoveryPrivate.hh:126
std::recursive_mutex mutex
Mutex to guarantee exclusive access between the threads.
Definition: DiscoveryPrivate.hh:153
unsigned int advertiseInterval
Advertise interval value (ms.).
Definition: DiscoveryPrivate.hh:112
std::string hostAddr
Host IP address.
Definition: DiscoveryPrivate.hh:91
unsigned int activityInterval
Activity interval value (ms.).
Definition: DiscoveryPrivate.hh:107
Definition: AdvertiseOptions.hh:25
Store address information about topics and provide convenient methods for adding new topics...
Definition: TopicStorage.hh:37
std::thread threadActivity
Thread in charge of update the activity.
Definition: DiscoveryPrivate.hh:162
SrvDiscoveryCallback disconnectionSrvCb
Callback executed when a service is no longer available.
Definition: DiscoveryPrivate.hh:129