Gazebo Transport
API Reference
14.0.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
src
gz-transport
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
293
public
:
void
AddGlobalRelay
(
const
std::string
& _relayAddress);
294
298
public
:
std::vector<std::string>
GlobalRelays
()
const
;
299
301
protected
:
NodeShared
();
302
304
protected
:
virtual
~NodeShared
();
305
309
private
:
bool
InitializeSockets();
310
314
316
public
:
Uuid
responseReceiverId
;
317
319
public
:
Uuid
replierId
;
320
321
#ifdef _WIN32
322
// Disable warning C4251 which is triggered by
323
// std::unique_ptr
324
#pragma warning(push)
325
#pragma warning(disable: 4251)
326
#endif
328
public
:
std::string
pUuid
;
329
331
public
:
std::thread
threadReception
;
332
334
public
:
mutable
std::recursive_mutex
mutex
;
335
337
public
:
std::string
discoveryIP =
"239.255.0.7"
;
338
340
public
:
static
const
int
kDefaultMsgDiscPort = 10317;
341
343
public
:
static
const
int
kDefaultSrvDiscPort = 10318;
344
346
public
:
int
msgDiscPort = kDefaultMsgDiscPort;
347
349
public
:
int
srvDiscPort = kDefaultSrvDiscPort;
350
352
private
:
TopicStorage<MessagePublisher>
connections;
353
355
private
:
std::vector<std::string>
srvConnections;
356
358
public
:
TopicStorage<MessagePublisher>
remoteSubscribers
;
359
#ifdef _WIN32
360
#pragma warning(pop)
361
#endif
362
367
struct
HandlerWrapper
368
{
375
public
:
bool
HasSubscriber
(
376
const
std::string
&_fullyQualifiedTopic,
377
const
std::string
&_msgType)
const
;
378
384
public
:
bool
HasSubscriber
(
385
const
std::string
&_fullyQualifiedTopic)
const
;
386
394
public
:
std::vector<std::string>
NodeUuids
(
395
const
std::string
&_fullyQualifiedTopic,
396
const
std::string
&_msgTypeName)
const
;
397
405
public
:
bool
RemoveHandlersForNode
(
406
const
std::string
&_fullyQualifiedTopic,
407
const
std::string
&_nUuid);
408
413
public
:
std::vector<MessagePublisher>
Convert
(
const
std::string
&_addr,
414
const
std::string
&_pUuid);
415
417
public
:
HandlerStorage<ISubscriptionHandler>
normal
;
418
422
public
:
HandlerStorage<RawSubscriptionHandler>
raw
;
423
};
424
425
public
:
HandlerWrapper
localSubscribers
;
426
427
#ifdef _WIN32
428
// Disable warning C4251 which is triggered by
429
// std::unique_ptr
430
#pragma warning(push)
431
#pragma warning(disable: 4251)
432
#endif
434
public
:
HandlerStorage<IRepHandler>
repliers
;
435
437
public
:
HandlerStorage<IReqHandler>
requests
;
438
440
public
:
int
verbose
;
441
443
public
:
std::string
myAddress
;
444
446
public
:
std::string
myControlAddress
;
447
449
public
:
std::string
myRequesterAddress
;
450
452
public
:
std::string
myReplierAddress
;
453
455
public
:
std::string
hostAddr
;
456
458
private
:
std::unique_ptr<NodeSharedPrivate>
dataPtr;
459
#ifdef _WIN32
460
#pragma warning(pop)
461
#endif
462
private
:
friend
Node
;
463
private
:
friend
NodePrivate;
464
};
465
}
466
}
467
}
468
#endif