Coverage Report

Created: 2022-08-24 06:19

/src/Fast-DDS/include/fastdds/rtps/writer/LivelinessData.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016-2019 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 LivelinessData.h
17
 */
18
#ifndef _FASTDDS_RTPS_LIVELINESS_DATA_H_
19
#define _FASTDDS_RTPS_LIVELINESS_DATA_H_
20
21
#include <fastrtps/qos/QosPolicies.h>
22
#include <fastdds/rtps/common/Time_t.h>
23
24
#include <chrono>
25
26
namespace eprosima {
27
namespace fastrtps {
28
namespace rtps {
29
30
/**
31
 * @brief A struct keeping relevant liveliness information of a writer
32
 * @ingroup WRITER_MODULE
33
 */
34
struct LivelinessData
35
{
36
    enum WriterStatus
37
    {
38
        //! Writer is matched but liveliness has not been asserted yet
39
        NOT_ASSERTED = 0,
40
        //! Writer is alive
41
        ALIVE = 1,
42
        //! Writer is not alive
43
        NOT_ALIVE = 2
44
    };
45
46
    /**
47
     * @brief Constructor
48
     * @param guid_in GUID of the writer
49
     * @param kind_in Liveliness kind
50
     * @param lease_duration_in Liveliness lease duration
51
     */
52
    LivelinessData(
53
            GUID_t guid_in,
54
            LivelinessQosPolicyKind kind_in,
55
            Duration_t lease_duration_in)
56
        : guid(guid_in)
57
        , kind(kind_in)
58
        , lease_duration(lease_duration_in)
59
        , status(WriterStatus::NOT_ASSERTED)
60
0
    {}
61
62
    LivelinessData()
63
        : guid()
64
        , kind(LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS)
65
        , lease_duration(TIME_T_INFINITE_SECONDS, TIME_T_INFINITE_NANOSECONDS)
66
        , status(WriterStatus::NOT_ASSERTED)
67
0
    {}
68
69
    ~LivelinessData()
70
0
    {}
71
72
    /**
73
     * @brief Equality operator
74
     * @param other Liveliness data to compare to
75
     * @return True if equal
76
     */
77
    bool operator==(
78
            const LivelinessData& other) const
79
0
    {
80
0
        return ((guid == other.guid) &&
81
0
               (kind == other.kind) &&
82
0
               (lease_duration == other.lease_duration));
83
0
    }
84
85
    /**
86
     * @brief Inequality operator
87
     * @param other Liveliness data to compare to
88
     * @return True if different
89
     */
90
    bool operator!=(
91
            const LivelinessData& other) const
92
0
    {
93
0
        return (!operator==(other));
94
0
    }
95
96
    //! GUID of the writer
97
    GUID_t guid;
98
99
    //! Writer liveliness kind
100
    LivelinessQosPolicyKind kind;
101
102
    //! The lease duration
103
    Duration_t lease_duration;
104
105
    //! The number of times the writer is being counted
106
    unsigned int count = 1;
107
108
    //! The writer status
109
    WriterStatus status;
110
111
    //! The time when the writer will lose liveliness
112
    std::chrono::steady_clock::time_point time;
113
};
114
115
} /* namespace rtps */
116
} /* namespace fastrtps */
117
} /* namespace eprosima */
118
119
#endif /* _FASTDDS_RTPS_LIVELINESS_DATA_H_ */