Gazebo Transport
API Reference
13.1.0
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
include
gz
transport
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 GZ_TRANSPORT_NODESHARED_HH_
19
#define GZ_TRANSPORT_NODESHARED_HH_
20
21
#ifdef _MSC_VER
22
#pragma warning(push)
23
#pragma warning(disable: 4251)
24
#endif
25
#include <google/protobuf/message.h>
26
#ifdef _MSC_VER
27
#pragma warning(pop)
28
#endif
29
30
#include <memory>
31
#include <mutex>
32
#include <optional>
33
#include <string>
34
#include <thread>
35
#include <vector>
36
#include <map>
37
38
#include "gz/transport/config.hh"
39
#include "gz/transport/Export.hh"
40
#include "
gz/transport/HandlerStorage.hh
"
41
#include "
gz/transport/Publisher.hh
"
42
#include "
gz/transport/RepHandler.hh
"
43
#include "
gz/transport/ReqHandler.hh
"
44
#include "
gz/transport/SubscriptionHandler.hh
"
45
#include "
gz/transport/TopicStorage.hh
"
46
#include "
gz/transport/TopicStatistics.hh
"
47
#include "
gz/transport/TransportTypes.hh
"
48
#include "
gz/transport/Uuid.hh
"
49
50
namespace
gz
51
{
52
namespace
transport
53
{
54
// Inline bracket to help doxygen filtering.
55
inline
namespace
GZ_TRANSPORT_VERSION_NAMESPACE {
56
//
57
// Forward declarations.
58
class
Node;
59
class
NodePrivate;
60
62
class
NodeSharedPrivate;
63
67
class
GZ_TRANSPORT_VISIBLE
NodeShared
68
{
72
public
:
static
NodeShared
*
Instance
();
73
75
public
:
void
RunReceptionTask
();
76
88
public
:
bool
Publish
(
const
std::string
&_topic,
89
char
*_data,
90
const
size_t
_dataSize,
91
DeallocFunc
*_ffn,
92
const
std::string
&_msgType);
93
95
public
:
void
RecvMsgUpdate
();
96
101
public
:
struct
HandlerInfo
102
{
106
public
:
std::map<std::string, ISubscriptionHandler_M>
localHandlers
;
107
111
public
:
std::map<std::string, RawSubscriptionHandler_M>
rawHandlers
;
112
114
public
:
bool
haveLocal
;
115
117
public
:
bool
haveRaw
;
118
119
// Friendship. This allows HandlerInfo to be created by
120
// CheckHandlerInfo()
121
friend
class
NodeShared
;
122
123
// TODO(sloretz) private default constructor (visual studio 2017?)
124
};
125
132
HandlerInfo
CheckHandlerInfo
(
const
std::string
&_topic)
const
;
133
142
public
:
struct
SubscriberInfo
:
public
HandlerInfo
143
{
145
// cppcheck-suppress unusedStructMember
146
public
:
bool
haveRemote
;
147
148
// Friendship declaration
149
friend
class
NodeShared
;
150
151
// TODO(sloretz) private default constructor (visual studio 2017?)
152
};
153
162
SubscriberInfo
CheckSubscriberInfo
(
163
const
std::string
&_topic,
164
const
std::string
&_msgType)
const
;
165
172
public
:
void
TriggerCallbacks
(
173
const
MessageInfo
&_info,
174
const
std::string
&_msgData,
175
const
HandlerInfo
&_handlerInfo);
176
178
public
:
void
RecvSrvRequest
();
179
181
public
:
void
RecvSrvResponse
();
182
188
public
:
void
SendPendingRemoteReqs
(
const
std::string
&_topic,
189
const
std::string
&_reqType,
190
const
std::string
&_repType);
191
194
public
:
void
OnNewConnection
(
const
MessagePublisher
&_pub);
195
198
public
:
void
OnNewDisconnection
(
const
MessagePublisher
&_pub);
199
202
public
:
void
OnNewSrvConnection
(
const
ServicePublisher
&_pub);
203
206
public
:
void
OnNewSrvDisconnection
(
const
ServicePublisher
&_pub);
207
210
public
:
void
OnNewRegistration
(
const
MessagePublisher
&_pub);
211
214
public
:
void
OnEndRegistration
(
const
MessagePublisher
&_pub);
215
217
public
:
void
OnSubscribers
();
218
224
// there is at least one publisher.
227
public
:
bool
TopicPublishers
(
const
std::string
&_topic,
228
SrvAddresses_M
&_publishers)
const
;
229
236
public
:
bool
DiscoverService
(
const
std::string
&_topic)
const
;
237
243
public
:
bool
AdvertisePublisher
(
const
ServicePublisher
&_publisher);
244
255
public
:
int
RcvHwm
();
256
267
public
:
int
SndHwm
();
268
275
public
:
void
EnableStats
(
const
std::string
&_topic,
bool
_enable,
276
std::function
<
void
(
const
TopicStatistics
&_stats)> _cb);
277
284
public
: std::optional<TopicStatistics>
TopicStats
(
285
const
std::string
&_topic)
const
;
286
288
protected
:
NodeShared
();
289
291
protected
:
virtual
~NodeShared
();
292
296
private
:
bool
InitializeSockets();
297
301
303
public
:
Uuid
responseReceiverId
;
304
306
public
:
Uuid
replierId
;
307
308
#ifdef _WIN32
309
// Disable warning C4251 which is triggered by
310
// std::unique_ptr
311
#pragma warning(push)
312
#pragma warning(disable: 4251)
313
#endif
315
public
:
std::string
pUuid
;
316
318
public
:
std::thread
threadReception
;
319
321
public
:
mutable
std::recursive_mutex
mutex
;
322
324
public
:
std::string
discoveryIP =
"239.255.0.7"
;
325
327
public
:
static
const
int
kDefaultMsgDiscPort = 10317;
328
330
public
:
static
const
int
kDefaultSrvDiscPort = 10318;
331
333
public
:
int
msgDiscPort = kDefaultMsgDiscPort;
334
336
public
:
int
srvDiscPort = kDefaultSrvDiscPort;
337
339
private
:
TopicStorage<MessagePublisher>
connections;
340
342
private
:
std::vector<std::string>
srvConnections;
343
345
public
:
TopicStorage<MessagePublisher>
remoteSubscribers
;
346
#ifdef _WIN32
347
#pragma warning(pop)
348
#endif
349
354
struct
HandlerWrapper
355
{
362
public
:
bool
HasSubscriber
(
363
const
std::string
&_fullyQualifiedTopic,
364
const
std::string
&_msgType)
const
;
365
371
public
:
bool
HasSubscriber
(
372
const
std::string
&_fullyQualifiedTopic)
const
;
373
381
public
:
std::vector<std::string>
NodeUuids
(
382
const
std::string
&_fullyQualifiedTopic,
383
const
std::string
&_msgTypeName)
const
;
384
392
public
:
bool
RemoveHandlersForNode
(
393
const
std::string
&_fullyQualifiedTopic,
394
const
std::string
&_nUuid);
395
400
public
:
std::vector<MessagePublisher>
Convert
(
const
std::string
&_addr,
401
const
std::string
&_pUuid);
402
404
public
:
HandlerStorage<ISubscriptionHandler>
normal
;
405
409
public
:
HandlerStorage<RawSubscriptionHandler>
raw
;
410
};
411
412
public
:
HandlerWrapper
localSubscribers
;
413
414
#ifdef _WIN32
415
// Disable warning C4251 which is triggered by
416
// std::unique_ptr
417
#pragma warning(push)
418
#pragma warning(disable: 4251)
419
#endif
421
public
:
HandlerStorage<IRepHandler>
repliers
;
422
424
public
:
HandlerStorage<IReqHandler>
requests
;
425
427
public
:
int
verbose
;
428
430
public
:
std::string
myAddress
;
431
433
public
:
std::string
myControlAddress
;
434
436
public
:
std::string
myRequesterAddress
;
437
439
public
:
std::string
myReplierAddress
;
440
442
public
:
std::string
hostAddr
;
443
445
private
:
std::unique_ptr<NodeSharedPrivate>
dataPtr;
446
#ifdef _WIN32
447
#pragma warning(pop)
448
#endif
449
private
:
friend
Node
;
450
private
:
friend
NodePrivate;
451
};
452
}
453
}
454
}
455
#endif