Program Listing for File LivelinessManager.h
↰ Return to documentation for file (/tmp/ws/src/fastrtps/include/fastdds/rtps/writer/LivelinessManager.h
)
// Copyright 2016-2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _FASTDDS_RTPS_LIVELINESS_MANAGER_H_
#define _FASTDDS_RTPS_LIVELINESS_MANAGER_H_
#include <fastdds/rtps/resources/TimedEvent.h>
#include <fastdds/rtps/writer/LivelinessData.h>
#include <fastrtps/utils/collections/ResourceLimitedVector.hpp>
#include <fastrtps/utils/shared_mutex.hpp>
#include <mutex>
namespace eprosima {
namespace fastrtps {
namespace rtps {
using LivelinessCallback = std::function<void (
const GUID_t&,
const LivelinessQosPolicyKind&,
const Duration_t&,
int32_t alive_change,
int32_t not_alive_change)>;
class LivelinessManager
{
public:
LivelinessManager(
const LivelinessCallback& callback,
ResourceEvent& service,
bool manage_automatic = true);
~LivelinessManager();
LivelinessManager(
const LivelinessManager& other) = delete;
bool add_writer(
GUID_t guid,
LivelinessQosPolicyKind kind,
Duration_t lease_duration);
bool remove_writer(
GUID_t guid,
LivelinessQosPolicyKind kind,
Duration_t lease_duration);
bool assert_liveliness(
GUID_t guid,
LivelinessQosPolicyKind kind,
Duration_t lease_duration);
bool assert_liveliness(
LivelinessQosPolicyKind kind);
bool is_any_alive(
LivelinessQosPolicyKind kind);
const ResourceLimitedVector<LivelinessData>& get_liveliness_data() const;
private:
void assert_writer_liveliness(
LivelinessData& writer);
bool calculate_next();
bool timer_expired();
const LivelinessCallback callback_;
const bool manage_automatic_;
ResourceLimitedVector<LivelinessData> writers_;
std::mutex mutex_;
eprosima::shared_mutex col_mutex_;
LivelinessData* timer_owner_;
TimedEvent timer_;
};
} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */
#endif /* _FASTDDS_RTPS_LIVELINESS_MANAGER_H_ */