22
22
#include < map>
23
23
#include < string>
24
24
25
+ #include < fastdds/dds/domain/DomainParticipant.hpp>
26
+ #include < fastdds/dds/domain/DomainParticipantFactory.hpp>
27
+ #include < fastdds/dds/domain/DomainParticipantListener.hpp>
28
+ #include < fastdds/dds/domain/qos/DomainParticipantQos.hpp>
29
+ #include < fastdds/dds/subscriber/DataReader.hpp>
30
+ #include < fastdds/dds/subscriber/DataReaderListener.hpp>
31
+ #include < fastdds/dds/subscriber/qos/DataReaderQos.hpp>
32
+ #include < fastdds/dds/subscriber/qos/SubscriberQos.hpp>
33
+ #include < fastdds/dds/subscriber/Subscriber.hpp>
34
+ #include < fastdds/dds/topic/qos/TopicQos.hpp>
35
+ #include < fastdds/dds/topic/Topic.hpp>
36
+
25
37
#include < fastdds_statistics_backend/listener/DomainListener.hpp>
26
38
#include < fastdds_statistics_backend/listener/CallbackMask.hpp>
27
39
#include < fastdds_statistics_backend/types/EntityId.hpp>
28
40
29
41
namespace eprosima {
30
- namespace fastdds {
31
- namespace dds {
32
-
33
- class DomainParticipant ;
34
- class DomainParticipantListener ;
35
- class Subscriber ;
36
- class Topic ;
37
- class DataReader ;
38
- class DataReaderListener ;
39
-
40
- } // namespace dds
41
- } // namespace fastdds
42
-
43
42
namespace statistics_backend {
44
43
namespace details {
45
44
@@ -50,51 +49,95 @@ namespace details {
50
49
*/
51
50
struct Monitor
52
51
{
52
+ /* *
53
+ * @brief Destroy the Monitor object
54
+ *
55
+ * Destroy every pointer that has been set.
56
+ * This method works even if the monitor creation has failed
57
+ *
58
+ * @warning this may not be the best way to implement the destruction of subentities, as they are not created
59
+ * under this class. But it is very convenience so it is reused during Monitor creation in case an error occurs
60
+ * and also it is used to normally destroy the Monitor.
61
+ */
62
+ ~Monitor ()
63
+ {
64
+ // These values are not always set, as could come from an error creating Monitor, or for test sake.
65
+ if (participant)
66
+ {
67
+ if (subscriber)
68
+ {
69
+ for (auto & reader : readers)
70
+ {
71
+ subscriber->delete_datareader (reader.second );
72
+ }
73
+
74
+ participant->delete_subscriber (subscriber);
75
+ }
76
+
77
+ for (auto & topic : topics)
78
+ {
79
+ participant->delete_topic (topic.second );
80
+ }
81
+
82
+ fastdds::dds::DomainParticipantFactory::get_instance ()->delete_participant (participant);
83
+ }
84
+
85
+ if (reader_listener)
86
+ {
87
+ delete reader_listener;
88
+ }
89
+
90
+ if (participant_listener)
91
+ {
92
+ delete participant_listener;
93
+ }
94
+ }
95
+
53
96
// ! The EntityId of the monitored domain
54
- EntityId id;
97
+ EntityId id{} ;
55
98
56
99
// ! The user listener for this monitor
57
- DomainListener* domain_listener;
100
+ DomainListener* domain_listener = nullptr ;
58
101
59
102
// ! The callback mask applied to the \c domain_listener
60
- CallbackMask domain_callback_mask;
103
+ CallbackMask domain_callback_mask{} ;
61
104
62
105
// ! The data mask applied to the \c domain_listener->on_data_available
63
- DataKindMask data_mask;
106
+ DataKindMask data_mask{} ;
64
107
65
108
// ! The participant created to communicate with the statistics reporting endpoints in this monitor
66
- fastdds::dds::DomainParticipant* participant;
109
+ fastdds::dds::DomainParticipant* participant = nullptr ;
67
110
68
111
// ! The listener linked to the \c participant
69
112
// ! It will process the entity discoveries
70
- fastdds::dds::DomainParticipantListener* participant_listener;
113
+ fastdds::dds::DomainParticipantListener* participant_listener = nullptr ;
71
114
72
115
73
116
// ! The participant created to communicate with the statistics reporting publishers in this monitor
74
- fastdds::dds::Subscriber* subscriber;
117
+ fastdds::dds::Subscriber* subscriber = nullptr ;
75
118
76
119
// ! Holds the topic object created for each of the statistics topics
77
- std::map<std::string, fastdds::dds::Topic*> topics;
120
+ std::map<std::string, fastdds::dds::Topic*> topics{} ;
78
121
79
122
// ! Holds the datareader object created for each of the statistics topics
80
- std::map<std::string, fastdds::dds::DataReader*> readers;
123
+ std::map<std::string, fastdds::dds::DataReader*> readers{} ;
81
124
82
125
// ! The listener linked to the \c readers
83
126
// ! All readers will use the same listener
84
127
// ! The listener will decide how to process the data according to the topic of the reader
85
- fastdds::dds::DataReaderListener* reader_listener;
128
+ fastdds::dds::DataReaderListener* reader_listener = nullptr ;
86
129
87
130
// ! Participant discovery status. Used in the participant discovery user callback
88
- DomainListener::Status participant_status_;
131
+ DomainListener::Status participant_status_{} ;
89
132
90
133
// ! Topic discovery status. Used in the topic discovery user callback
91
- DomainListener::Status topic_status_;
134
+ DomainListener::Status topic_status_{} ;
92
135
93
136
// ! Datareader discovery status. Used in the datareader discovery user callback
94
- DomainListener::Status datareader_status_;
137
+ DomainListener::Status datareader_status_{} ;
95
138
96
139
// ! DataWriter discovery status. Used in the datawriter discovery user callback
97
- DomainListener::Status datawriter_status_;
140
+ DomainListener::Status datawriter_status_{} ;
98
141
};
99
142
100
143
} // namespace details
0 commit comments