Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/network/ReceiverResource.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 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_RTPS_RECEIVER_RESOURCE_H
16
#define _FASTDDS_RTPS_RECEIVER_RESOURCE_H
17
18
#include <condition_variable>
19
#include <functional>
20
#include <memory>
21
#include <vector>
22
23
#include <fastdds/rtps/messages/MessageReceiver.h>
24
#include <fastdds/rtps/transport/TransportInterface.h>
25
26
namespace eprosima {
27
namespace fastrtps {
28
namespace rtps {
29
30
/**
31
 * RAII object that encapsulates the Receive operation over one channel in an unknown transport.
32
 * A Receiver resource is always univocally associated to a transport channel; the
33
 * act of constructing a Receiver Resource opens the channel and its destruction
34
 * closes it.
35
 * @ingroup NETWORK_MODULE
36
 */
37
class ReceiverResource : public fastdds::rtps::TransportReceiverInterface
38
{
39
    //! Only NetworkFactory is ever allowed to construct a ReceiverResource from scratch.
40
    //! In doing so, it guarantees the transport and channel are in a valid state for
41
    //! this resource to exist.
42
    friend class NetworkFactory;
43
44
public:
45
46
    /**
47
     * Method called by the transport when receiving data.
48
     * @param data Pointer to the received data.
49
     * @param size Number of bytes received.
50
     * @param localLocator Locator identifying the local endpoint.
51
     * @param remoteLocator Locator identifying the remote endpoint.
52
     */
53
    virtual void OnDataReceived(
54
            const octet* data,
55
            const uint32_t size,
56
            const Locator_t& localLocator,
57
            const Locator_t& remoteLocator) override;
58
59
    /**
60
     * Reports whether this resource supports the given local locator (i.e., said locator
61
     * maps to the transport channel managed by this resource).
62
     */
63
    bool SupportsLocator(
64
            const Locator_t& localLocator);
65
66
    /**
67
     * Register a MessageReceiver object to be called upon reception of data.
68
     * @param receiver The message receiver to register.
69
     */
70
    void RegisterReceiver(
71
            MessageReceiver* receiver);
72
73
    /**
74
     * Unregister a MessageReceiver object to be called upon reception of data.
75
     * @param receiver The message receiver to unregister.
76
     */
77
    void UnregisterReceiver(
78
            MessageReceiver* receiver);
79
80
    /**
81
     * Closes related ChannelResources.
82
     */
83
    void disable();
84
85
    inline uint32_t max_message_size() const
86
0
    {
87
0
        return max_message_size_;
88
0
    }
89
90
    /**
91
     * Resources can only be transfered through move semantics. Copy, assignment, and
92
     * construction outside of the factory are forbidden.
93
     */
94
    ReceiverResource(
95
            ReceiverResource&&);
96
97
    ~ReceiverResource() override;
98
99
private:
100
101
    ReceiverResource() = delete;
102
    ReceiverResource(
103
            const ReceiverResource&) = delete;
104
    ReceiverResource& operator =(
105
            const ReceiverResource&) = delete;
106
107
    ReceiverResource(
108
            fastdds::rtps::TransportInterface&,
109
            const Locator_t&,
110
            uint32_t);
111
    std::function<void()> Cleanup;
112
    std::function<bool(const Locator_t&)> LocatorMapsToManagedChannel;
113
    bool mValid; // Post-construction validity check for the NetworkFactory
114
115
    std::mutex mtx;
116
    std::condition_variable cv_;
117
    MessageReceiver* receiver;
118
    uint32_t max_message_size_;
119
    int active_callbacks_;
120
};
121
122
} // namespace rtps
123
} // namespace fastrtps
124
} // namespace eprosima
125
126
#endif /* _FASTDDS_RTPS_RECEIVER_RESOURCE_H */