/src/Fast-DDS/src/cpp/rtps/DataSharing/DataSharingNotifier.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | /** |
16 | | * @file DataSharingNotifier.hpp |
17 | | */ |
18 | | |
19 | | #ifndef RTPS_DATASHARING_DATASHARINGNOTIFIER_HPP |
20 | | #define RTPS_DATASHARING_DATASHARINGNOTIFIER_HPP |
21 | | |
22 | | #include "rtps/DataSharing/IDataSharingNotifier.hpp" |
23 | | #include "rtps/DataSharing/DataSharingNotification.hpp" |
24 | | |
25 | | #include <map> |
26 | | #include <memory> |
27 | | |
28 | | namespace eprosima { |
29 | | namespace fastrtps { |
30 | | namespace rtps { |
31 | | |
32 | | class DataSharingNotifier : public IDataSharingNotifier |
33 | | { |
34 | | |
35 | | public: |
36 | | |
37 | | /** |
38 | | * Initializes a datasharing notifier for a reader |
39 | | * @param directory Sahred memory directory to use to open the shared notification |
40 | | */ |
41 | | DataSharingNotifier( |
42 | | std::string directory) |
43 | | : directory_(directory) |
44 | 0 | { |
45 | 0 | } |
46 | | |
47 | 0 | ~DataSharingNotifier() = default; |
48 | | |
49 | | /** |
50 | | * Links the notifier to a reader that will be notified |
51 | | * @param reader_guid GUID of the reader to notify |
52 | | */ |
53 | | void enable( |
54 | | const GUID_t& reader_guid) override |
55 | 0 | { |
56 | 0 | shared_notification_ = DataSharingNotification::open_notification(reader_guid, directory_); |
57 | 0 | } |
58 | | |
59 | | /** |
60 | | * Unlinks the notifier and its reader |
61 | | */ |
62 | | void disable() override |
63 | 0 | { |
64 | 0 | shared_notification_.reset(); |
65 | 0 | } |
66 | | |
67 | | /** |
68 | | * @return whether the notifier is linked to a reader or not |
69 | | */ |
70 | | bool is_enabled() override |
71 | 0 | { |
72 | 0 | return shared_notification_ != nullptr; |
73 | 0 | } |
74 | | |
75 | | /** |
76 | | * Notifies to the reader |
77 | | */ |
78 | | void notify() override |
79 | 0 | { |
80 | 0 | if (is_enabled()) |
81 | 0 | { |
82 | 0 | logInfo(RTPS_WRITER, "Notifying reader " << shared_notification_->reader()); |
83 | 0 | shared_notification_->notify(); |
84 | 0 | } |
85 | 0 | } |
86 | | |
87 | | protected: |
88 | | |
89 | | std::shared_ptr<DataSharingNotification> shared_notification_; |
90 | | std::string directory_; |
91 | | }; |
92 | | |
93 | | |
94 | | } // namespace rtps |
95 | | } // namespace fastrtps |
96 | | } // namespace eprosima |
97 | | |
98 | | #endif // RTPS_DATASHARING_DATASHARINGNOTIFIER_HPP |