Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/src/cpp/fastdds/rpc/ReplierImpl.hpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2025 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
#ifndef FASTDDS_RPC__REPLIERIMPL_HPP
16
#define FASTDDS_RPC__REPLIERIMPL_HPP
17
18
#include <fastdds/dds/core/detail/DDSReturnCode.hpp>
19
#include <fastdds/dds/core/LoanableCollection.hpp>
20
#include <fastdds/dds/core/LoanableSequence.hpp>
21
#include <fastdds/dds/domain/qos/ReplierQos.hpp>
22
#include <fastdds/dds/publisher/DataWriter.hpp>
23
#include <fastdds/dds/publisher/Publisher.hpp>
24
#include <fastdds/dds/rpc/Replier.hpp>
25
#include <fastdds/dds/rpc/RequestInfo.hpp>
26
#include <fastdds/dds/subscriber/DataReader.hpp>
27
#include <fastdds/dds/subscriber/Subscriber.hpp>
28
29
namespace eprosima {
30
namespace fastdds {
31
namespace dds {
32
namespace rpc {
33
34
class ServiceImpl;
35
36
/**
37
 * @brief Class that represents the implementation of a replier entity
38
 */
39
class ReplierImpl : public Replier
40
{
41
42
public:
43
44
    /**
45
     * @brief Constructor
46
     * Don't use it directly, use create_service_replier from DomainParticipant instead
47
     */
48
    ReplierImpl(
49
            ServiceImpl* service,
50
            const ReplierQos& qos);
51
52
    /**
53
     * @brief Destructor
54
     */
55
    virtual ~ReplierImpl();
56
57
    /**
58
     * @brief Returns the name of the service to which the replier belongs
59
     */
60
    const std::string& get_service_name() const override;
61
62
    /**
63
     * @brief Send a reply message to a requester
64
     *
65
     * @param data Data to send
66
     * @param info Information about the reply sample. This information is used to match the reply with the request through the SampleIdentity
67
     * @return RETCODE_OK if the reply was sent successfully or a ReturnCode related to the specific error otherwise
68
     */
69
    ReturnCode_t send_reply(
70
            void* data,
71
            const RequestInfo& info) override;
72
73
    /**
74
     * @brief Take a request message from the Replier DataReader's history.
75
     *
76
     * @param data Data to receive the request
77
     * @param info Information about the request sample
78
     * @return RETCODE_OK if the request was taken successfully or a ReturnCode related to the specific error otherwise
79
     */
80
    ReturnCode_t take_request(
81
            void* data,
82
            RequestInfo& info) override;
83
84
    /**
85
     * @brief Take all request messages stored in the Replier DataReader's history.
86
     * @note This method does not allow to take only the samples associated to a given request. User must implement a zero-copy solution to link request and reply samples.
87
     *
88
     * @param data Data to receive the request
89
     * @param info Information about the request sample
90
     * @return RETCODE_OK if the request was taken successfully or a ReturnCode related to the specific error otherwise
91
     */
92
    ReturnCode_t take_request(
93
            LoanableCollection& data,
94
            LoanableSequence<RequestInfo>& info) override;
95
96
    /**
97
     * @brief This operation indicates to the Replier's DataReader that
98
     * the application is done accessing the collection of Request @c datas and @c infos obtained by
99
     * some earlier invocation of @ref take_request.
100
     *
101
     * @param [in,out] data          A LoanableCollection object where the received data samples were obtained from
102
     *                               an earlier invocation of take_request on this Replier.
103
     * @param [in,out] sample        A LoanableSequence where the received request infos were obtained from
104
     *                               an earlier invocation of take_request on this Replier.
105
     */
106
    ReturnCode_t return_loan(
107
            LoanableCollection& data,
108
            LoanableSequence<RequestInfo>& info) override;
109
110
    /**
111
     * @brief Enable the Replier
112
     */
113
    ReturnCode_t enable() override;
114
115
    /**
116
     * @brief Disable the Replier
117
     */
118
    ReturnCode_t close() override;
119
120
    /**
121
     * @brief Check if the replier is enabled (i.e: all DDS entities are correctly created)
122
     */
123
    inline bool is_enabled() const override
124
0
    {
125
0
        return enabled_;
126
0
    }
127
128
    // Getters for DDS Endpoints
129
    inline DataWriter* get_replier_writer() const override
130
0
    {
131
0
        return replier_writer_;
132
0
    }
133
134
    inline DataReader* get_replier_reader() const override
135
0
    {
136
0
        return replier_reader_;
137
0
    }
138
139
private:
140
141
    /**
142
     * @brief Create required DDS entities to enable communication with the requester
143
     *
144
     * @param qos Replier QoS to configure the DDS entities
145
     *
146
     * @return RETCODE_OK if all DDS entities were created successfully, RETCODE_ERROR otherwise
147
     */
148
    ReturnCode_t create_dds_entities(
149
            const ReplierQos& qos);
150
151
    /**
152
     * @brief Delete all internal DDS Entities
153
     *
154
     * @return RETCODE_OK if all entities were deleted successfully, RETCODE_PRECONDITION_NOT_MET
155
     * if any entity cannot be deleted
156
     */
157
    ReturnCode_t delete_contained_entities();
158
159
    /**
160
     * @brief Possible states of the replier with respect to a requester
161
     */
162
    enum class RequesterMatchStatus
163
    {
164
        UNMATCHED,          // Request topic not matched
165
        PARTIALLY_MATCHED,  // Request topic matched but Reply topic not matched
166
        MATCHED             // Both topics matched
167
    };
168
169
    /**
170
     * @brief Check the matched status of the replier with respect to a requester
171
     *
172
     * @param info Information about the request for which to check the status
173
     *
174
     * @return The matched status of the replier with respect to the requester that sent the request
175
     */
176
    RequesterMatchStatus requester_match_status(
177
            const RequestInfo& info) const;
178
179
    bool is_fully_matched() const;
180
181
    DataReader* replier_reader_;
182
    DataWriter* replier_writer_;
183
    ReplierQos qos_;
184
    ServiceImpl* service_;
185
    bool enabled_;
186
187
};
188
189
} // namespace rpc
190
} // namespace dds
191
} // namespace fastdds
192
} // namespace eprosima
193
194
#endif // FASTDDS_RPC__REPLIERIMPL_HPP