Gazebo Transport
API Reference
15.0.0~pre1
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
#include <unordered_set>
38
39
#include "gz/transport/config.hh"
40
#include "gz/transport/Export.hh"
41
#include "
gz/transport/HandlerStorage.hh
"
42
#include "
gz/transport/NodeOptions.hh
"
43
#include "
gz/transport/Publisher.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
zenoh
51
{
52
// Forward declaration.
53
class
Session;
54
}
55
56
namespace
gz::transport
57
{
58
// Inline bracket to help doxygen filtering.
59
inline
namespace
GZ_TRANSPORT_VERSION_NAMESPACE {
60
//
61
// Forward declarations.
62
class
IRepHandler;
63
class
IReqHandler;
64
class
Node;
65
class
NodePrivate;
66
68
class
NodeSharedPrivate;
69
73
class
GZ_TRANSPORT_VISIBLE
NodeShared
74
{
78
public
:
static
NodeShared
*
Instance
();
79
81
public
:
void
RunReceptionTask
();
82
94
public
:
bool
Publish
(
const
std::string
&_topic,
95
char
*_data,
96
const
size_t
_dataSize,
97
DeallocFunc
*_ffn,
98
const
std::string
&_msgType);
99
101
public
:
void
RecvMsgUpdate
();
102
104
public
:
void
SrvPublishThread
();
105
110
public
:
struct
HandlerInfo
111
{
115
public
:
std::map<std::string, ISubscriptionHandler_M>
localHandlers
;
116
120
public
:
std::map<std::string, RawSubscriptionHandler_M>
rawHandlers
;
121
123
public
:
bool
haveLocal
;
124
126
public
:
bool
haveRaw
;
127
128
// Friendship. This allows HandlerInfo to be created by
129
// CheckHandlerInfo()
130
friend
class
NodeShared
;
131
132
// TODO(sloretz) private default constructor (visual studio 2017?)
133
};
134
141
HandlerInfo
CheckHandlerInfo
(
const
std::string
&_topic)
const
;
142
151
public
:
struct
SubscriberInfo
:
public
HandlerInfo
152
{
154
// cppcheck-suppress unusedStructMember
155
public
:
bool
haveRemote
;
156
157
// Friendship declaration
158
friend
class
NodeShared
;
159
160
// TODO(sloretz) private default constructor (visual studio 2017?)
161
};
162
171
SubscriberInfo
CheckSubscriberInfo
(
172
const
std::string
&_topic,
173
const
std::string
&_msgType)
const
;
174
181
public
:
void
TriggerCallbacks
(
182
const
MessageInfo
&_info,
183
const
std::string
&_msgData,
184
const
HandlerInfo
&_handlerInfo);
185
187
public
:
void
RecvSrvRequest
();
188
190
public
:
void
RecvSrvResponse
();
191
197
public
:
void
SendPendingRemoteReqs
(
const
std::string
&_topic,
198
const
std::string
&_reqType,
199
const
std::string
&_repType);
200
203
public
:
void
OnNewConnection
(
const
MessagePublisher
&_pub);
204
207
public
:
void
OnNewDisconnection
(
const
MessagePublisher
&_pub);
208
211
public
:
void
OnNewSrvConnection
(
const
ServicePublisher
&_pub);
212
215
public
:
void
OnNewSrvDisconnection
(
const
ServicePublisher
&_pub);
216
219
public
:
void
OnNewRegistration
(
const
MessagePublisher
&_pub);
220
223
public
:
void
OnEndRegistration
(
const
MessagePublisher
&_pub);
224
226
public
:
void
OnSubscribers
();
227
233
// there is at least one publisher.
236
public
:
bool
TopicPublishers
(
const
std::string
&_topic,
237
SrvAddresses_M
&_publishers)
const
;
238
245
public
:
bool
DiscoverService
(
const
std::string
&_topic)
const
;
246
252
public
:
bool
AdvertisePublisher
(
const
ServicePublisher
&_publisher);
253
264
public
:
int
RcvHwm
();
265
276
public
:
int
SndHwm
();
277
284
public
:
void
EnableStats
(
const
std::string
&_topic,
bool
_enable,
285
std::function
<
void
(
const
TopicStatistics
&_stats)> _cb);
286
293
public
: std::optional<TopicStatistics>
TopicStats
(
294
const
std::string
&_topic)
const
;
295
302
public
:
void
AddGlobalRelay
(
const
std::string
& _relayAddress);
303
307
public
:
std::vector<std::string>
GlobalRelays
()
const
;
308
311
public
:
std::string
GzImplementation
()
const
;
312
313
#ifdef HAVE_ZENOH
316
public
:
std::shared_ptr<zenoh::Session>
Session();
317
#endif
318
327
public
:
bool
Unsubscribe
(
const
std::string
&_topic,
328
const
std::string
&_nUuid,
329
const
NodeOptions
&_nOpt,
330
const
std::string
&_hUuid =
""
);
331
335
private
:
std::unordered_set<std::string>
&TopicsSubscribed(
336
const
std::string
&_nUuid)
const
;
337
342
private
:
bool
RemoveSubscribedTopic(
const
std::string
&_topic,
343
const
std::string
&_nUuid);
344
350
public
:
bool
RemoveHandlersFromPubQueue
(
const
std::string
&_topic,
351
const
std::string
&_nUuid);
352
360
public
:
bool
RemoveHandlerFromPubQueue
(
const
std::string
&_topic,
361
const
std::string
&_nUuid,
362
const
std::string
&_hUuid);
363
371
public
:
bool
SubscribeHelper
(
const
std::string
&_fullyQualifiedTopic,
372
const
std::string
&_nUuid);
373
376
public
:
std::string
ReplierAddress
()
const
;
377
380
public
:
std::string
MyAddress
()
const
;
381
384
public
:
HandlerStorage<IReqHandler>
&
Requests
();
385
388
public
:
HandlerStorage<IRepHandler>
&
Repliers
();
389
391
protected
:
NodeShared
();
392
394
protected
:
virtual
~NodeShared
();
395
399
private
:
bool
InitializeSockets();
400
404
406
public
:
Uuid
responseReceiverId
;
407
409
public
:
Uuid
replierId
;
410
411
#ifdef _WIN32
412
// Disable warning C4251 which is triggered by
413
// std::unique_ptr
414
#pragma warning(push)
415
#pragma warning(disable: 4251)
416
#endif
418
public
:
std::string
pUuid
;
419
421
public
:
std::thread
threadReception
;
422
424
public
:
mutable
std::recursive_mutex
mutex
;
425
427
public
:
std::string
discoveryIP =
"239.255.0.7"
;
428
430
public
:
static
const
int
kDefaultMsgDiscPort = 10317;
431
433
public
:
static
const
int
kDefaultSrvDiscPort = 10318;
434
436
public
:
int
msgDiscPort = kDefaultMsgDiscPort;
437
439
public
:
int
srvDiscPort = kDefaultSrvDiscPort;
440
442
private
:
TopicStorage<MessagePublisher>
connections;
443
445
private
:
std::vector<std::string>
srvConnections;
446
448
public
:
TopicStorage<MessagePublisher>
remoteSubscribers
;
449
#ifdef _WIN32
450
#pragma warning(pop)
451
#endif
452
457
struct
HandlerWrapper
458
{
465
public
:
bool
HasSubscriber
(
466
const
std::string
&_fullyQualifiedTopic,
467
const
std::string
&_msgType)
const
;
468
474
public
:
bool
HasSubscriber
(
475
const
std::string
&_fullyQualifiedTopic)
const
;
476
483
public
:
bool
HasSubscriberForNode
(
484
const
std::string
&_fullyQualifiedTopic,
const
std::string
&_nUuid)
485
const
;
486
494
public
:
std::vector<std::string>
NodeUuids
(
495
const
std::string
&_fullyQualifiedTopic,
496
const
std::string
&_msgTypeName)
const
;
497
505
public
:
bool
RemoveHandlersForNode
(
506
const
std::string
&_fullyQualifiedTopic,
507
const
std::string
&_nUuid);
508
517
public
:
bool
RemoveHandler
(
518
const
std::string
&_fullyQualifiedTopic,
519
const
std::string
&_nUuid,
520
const
std::string
&_hUuid);
521
526
public
:
std::vector<MessagePublisher>
Convert
(
const
std::string
&_addr,
527
const
std::string
&_pUuid);
528
530
public
:
HandlerStorage<ISubscriptionHandler>
normal
;
531
535
public
:
HandlerStorage<RawSubscriptionHandler>
raw
;
536
};
537
538
public
:
HandlerWrapper
localSubscribers
;
539
540
#ifdef _WIN32
541
// Disable warning C4251 which is triggered by
542
// std::unique_ptr
543
#pragma warning(push)
544
#pragma warning(disable: 4251)
545
#endif
547
public
:
HandlerStorage<IRepHandler>
repliers
;
548
550
public
:
HandlerStorage<IReqHandler>
requests
;
551
553
public
:
int
verbose
;
554
556
public
:
std::string
myAddress
;
557
559
public
:
std::string
myControlAddress
;
560
562
public
:
std::string
myRequesterAddress
;
563
565
public
:
std::string
myReplierAddress
;
566
568
public
:
std::string
hostAddr
;
569
571
private
:
std::unique_ptr<NodeSharedPrivate>
dataPtr;
572
#ifdef _WIN32
573
#pragma warning(pop)
574
#endif
575
private
:
friend
Node
;
576
private
:
friend
NodePrivate;
577
};
578
}
579
}
580
#endif