Coverage Report

Created: 2025-06-13 06:46

/src/Fast-DDS/src/cpp/fastdds/rpc/RequesterImpl.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__REQUESTERIMPL_HPP
16
#define FASTDDS_RPC__REQUESTERIMPL_HPP
17
18
#include <fastdds/dds/core/LoanableCollection.hpp>
19
#include <fastdds/dds/core/LoanableSequence.hpp>
20
#include <fastdds/dds/domain/qos/RequesterQos.hpp>
21
#include <fastdds/dds/publisher/DataWriter.hpp>
22
#include <fastdds/dds/publisher/Publisher.hpp>
23
#include <fastdds/dds/rpc/Requester.hpp>
24
#include <fastdds/dds/rpc/RequestInfo.hpp>
25
#include <fastdds/dds/subscriber/DataReader.hpp>
26
#include <fastdds/dds/subscriber/Subscriber.hpp>
27
#include <fastdds/rtps/common/SampleIdentity.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 a the implementation of a requester entity
38
 */
39
class RequesterImpl : public Requester
40
{
41
42
public:
43
44
    /**
45
     * @brief Constructor
46
     * Don't use it directly, use create_service_requester from DomainParticipant instead
47
     */
48
    RequesterImpl(
49
            ServiceImpl* service,
50
            const RequesterQos& qos);
51
52
    /**
53
     * @brief Destructor
54
     */
55
    virtual ~RequesterImpl();
56
57
    /**
58
     * @brief Returns the name of the service to which the requester belongs
59
     */
60
    const std::string& get_service_name() const override;
61
62
    /**
63
     * @brief Send a request message to a replier
64
     *
65
     * @param data Data to send
66
     * @param info Information about the request sample. This information is used to match the request with the reply 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_request(
70
            void* data,
71
            RequestInfo& info) override;
72
73
    /**
74
     * @brief Take a reply message from the Requester DataReader's history.
75
     *
76
     * @param data Data to receive the reply
77
     * @param info Information about the reply sample
78
     * @return RETCODE_OK if the reply was taken successfully or a ReturnCode related to the specific error otherwise
79
     */
80
    ReturnCode_t take_reply(
81
            void* data,
82
            RequestInfo& info) override;
83
84
    /**
85
     * @brief Take all reply messages stored in the Requester 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 replies
89
     * @param info Information about the reply samples
90
     * @return RETCODE_OK if the replies were taken successfully or a ReturnCode related to the specific error otherwise
91
     */
92
    ReturnCode_t take_reply(
93
            LoanableCollection& data,
94
            LoanableSequence<RequestInfo>& info) override;
95
96
    /**
97
     * @brief This operation indicates to the Requester's DataReader that
98
     * the application is done accessing the collection of Reply @c datas and @c infos obtained by
99
     * some earlier invocation of @ref take_reply.
100
     *
101
     * @param [in,out] data          A LoanableCollection object where the received data samples were obtained from
102
     *                               an earlier invocation of take_reply on this Requester.
103
     * @param [in,out] sample        A LoanableSequence where the received request infos were obtained from
104
     *                               an earlier invocation of take_reply on this Requester.
105
     */
106
    ReturnCode_t return_loan(
107
            LoanableCollection& data,
108
            LoanableSequence<RequestInfo>& info) override;
109
110
    /**
111
     * @brief Enable the Requester
112
     */
113
    ReturnCode_t enable() override;
114
115
    /**
116
     * @brief Disable the Requester
117
     */
118
    ReturnCode_t close() override;
119
120
    /**
121
     * @brief Check if the requester 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_requester_writer() const override
130
0
    {
131
0
        return requester_writer_;
132
0
    }
133
134
    inline DataReader* get_requester_reader() const override
135
0
    {
136
0
        return requester_reader_;
137
0
    }
138
139
private:
140
141
    /**
142
     * @brief Create required DDS entities to enable communication with the replier
143
     *
144
     * @param qos Requester 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 RequesterQos& 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 Check if the requester is fully matched with a replier
161
     *
162
     * @return true if the requester is fully matched, false otherwise
163
     */
164
    bool is_fully_matched() const;
165
166
    DataReader* requester_reader_;
167
    DataWriter* requester_writer_;
168
    RequesterQos qos_;
169
    ServiceImpl* service_;
170
    bool enabled_;
171
172
};
173
174
} // namespace rpc
175
} // namespace dds
176
} // namespace fastdds
177
} // namespace eprosima
178
179
#endif // FASTDDS_RPC__REQUESTERIMPL_HPP