-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathDDSBridge.hpp
More file actions
144 lines (121 loc) · 4.45 KB
/
DDSBridge.hpp
File metadata and controls
144 lines (121 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @file DDSBridge.hpp
*/
#ifndef __SRC_DDSROUTERCORE_COMMUNICATION_DDSBRIDGE_HPP_
#define __SRC_DDSROUTERCORE_COMMUNICATION_DDSBRIDGE_HPP_
#include <mutex>
#include <communication/Bridge.hpp>
#include <communication/Track.hpp>
#include <ddsrouter_core/types/topic/RealTopic.hpp>
namespace eprosima {
namespace ddsrouter {
namespace core {
/**
* Bridge object manages the communication of a \c RealTopic.
* It could be seen as a channel of communication as a DDS Topic, whit several Participants that
* could publish or subscribe in this specific Topic.
*
* It contains N \c Tracks that will manage each direction of the communication,
* being N the number of Participants of this communication channel.
*/
class DDSBridge : public Bridge
{
public:
/**
* Bridge constructor by required values
*
* In Bridge construction, the inside \c Tracks are created.
* In Bridge construction, a Writer and a Reader are created for each Participant.
*
* @param topic: Topic of which this Bridge manages communication
* @param participant_database: Collection of Participants to manage communication
* @param payload_pool: Payload Pool that handles the reservation/release of payloads throughout the DDS Router
* @param thread_manager: Shared pool of threads in charge of data transmission.
* @param enable: Whether the Bridge should be initialized as enabled
*
* @throw InitializationException in case \c IWriters or \c IReaders creation fails.
*/
DDSBridge(
const types::RealTopic& topic,
std::shared_ptr<ParticipantsDatabase> participants_database,
std::shared_ptr<PayloadPool> payload_pool,
std::shared_ptr<utils::thread::IManager> thread_manager,
bool enable = false);
/**
* @brief Destructor
*
* Before deleting, it calls \c disable.
* It deletes all the tracks created and all Writers and Readers.
*/
virtual ~DDSBridge();
// virtual void init_();
/**
* Copy method not allowed
*
* Bridge creates in constructor all the inside Tracks needed, and thus it should not be copied
*/
void operator =(
const Track&) = delete;
/**
* Enable bridge in case it is not enabled
* Does nothing if it is already enabled
*
* Thread safe
*/
void enable() noexcept override;
/**
* Disable bridge in case it is not enabled
* Does nothing if it is disabled
*
* Thread safe
*/
void disable() noexcept override;
protected:
/**
* Topic of which this Bridge manages communication
*
* @note: This variable is only used for log
*/
const types::RealTopic topic_;
/**
* Inside \c Tracks
* They are indexed by the Id of the participant that is source
*/
std::map<types::ParticipantId, std::unique_ptr<Track>> tracks_;
//! One writer for each Participant, indexed by \c ParticipantId of the Participant the writer belongs to
std::map<types::ParticipantId, std::shared_ptr<IWriter>> writers_;
//! One reader for each Participant, indexed by \c ParticipantId of the Participant the reader belongs to
std::map<types::ParticipantId, std::shared_ptr<IReader>> readers_;
//! Mutex to prevent simultaneous calls to enable and/or disable
std::recursive_mutex mutex_;
// Allow operator << to use private variables
friend std::ostream& operator <<(
std::ostream&,
const DDSBridge&);
};
/**
* @brief \c DDSBridge to stream serialization
*
* This method is merely a to_string of a Bridge definition.
* It serialize the topic
*/
std::ostream& operator <<(
std::ostream& os,
const DDSBridge& bridge);
} /* namespace core */
} /* namespace ddsrouter */
} /* namespace eprosima */
#endif /* __SRC_DDSROUTERCORE_COMMUNICATION_DDSBRIDGE_HPP_ */