Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12371] Waitset implementation #2128

Merged
merged 7 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions include/fastdds/dds/core/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Entity
RTPS_DllAPI Entity(
const StatusMask& mask = StatusMask::all())
: status_mask_(mask)
, status_changes_(StatusMask::none())
, status_condition_(this)
, enable_(false)
{
}
Expand Down Expand Up @@ -91,10 +91,7 @@ class Entity
*
* @return const reference to the StatusMask with the triggered statuses set to 1
*/
RTPS_DllAPI const StatusMask& get_status_changes() const
{
return status_changes_;
}
RTPS_DllAPI const StatusMask& get_status_changes() const;

/**
* @brief Retrieves the instance handler that represents the Entity
Expand Down Expand Up @@ -124,9 +121,8 @@ class Entity
* @brief Allows access to the StatusCondition associated with the Entity
* @return Reference to StatusCondition object
*/
RTPS_DllAPI const StatusCondition& get_statuscondition() const
RTPS_DllAPI StatusCondition& get_statuscondition()
{
logWarning(CONDITION, "get_statuscondition method not implemented");
return status_condition_;
}

Expand All @@ -145,9 +141,6 @@ class Entity
//! StatusMask with relevant statuses set to 1
StatusMask status_mask_;

//! StatusMask with triggered statuses set to 1
StatusMask status_changes_;

//! Condition associated to the Entity
StatusCondition status_condition_;

Expand Down
26 changes: 21 additions & 5 deletions include/fastdds/dds/core/condition/Condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,52 @@
#ifndef _FASTDDS_CONDITION_HPP_
#define _FASTDDS_CONDITION_HPP_

#include <fastrtps/fastrtps_dll.h>
#include <memory>
#include <vector>

#include <fastdds/dds/log/Log.hpp>
#include <fastrtps/fastrtps_dll.h>

namespace eprosima {
namespace fastdds {
namespace dds {

// Forward declaration of implementation details
namespace detail {
struct ConditionNotifier;
} // namespace detail

/**
* @brief The Condition class is the root base class for all the conditions that may be attached to a WaitSet.
*/
class Condition
{
public:

// Condition class not implemented.

/**
* @brief Retrieves the trigger_value of the Condition
* @return true if trigger_value is set to 'true', 'false' otherwise
*/
RTPS_DllAPI bool get_trigger_value() const
RTPS_DllAPI virtual bool get_trigger_value() const
{
logWarning(CONDITION, "get_trigger_value public member function not implemented");
return false; // TODO return trigger value
}

detail::ConditionNotifier* get_notifier() const
{
return notifier_.get();
}

protected:

Condition();
virtual ~Condition();

std::unique_ptr<detail::ConditionNotifier> notifier_;
};

typedef std::vector<Condition> ConditionSeq;
using ConditionSeq = std::vector<Condition*>;

} // namespace dds
} // namespace fastdds
Expand Down
20 changes: 12 additions & 8 deletions include/fastdds/dds/core/condition/GuardCondition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef _FASTDDS_GUARD_CONDITION_HPP_
#define _FASTDDS_GUARD_CONDITION_HPP_

#include <atomic>

#include <fastdds/dds/core/condition/Condition.hpp>
#include <fastrtps/fastrtps_dll.h>
#include <fastrtps/types/TypesBase.h>
Expand All @@ -43,23 +45,25 @@ class GuardCondition : public Condition
{
public:

// GuardCondition not implemented.
RTPS_DllAPI GuardCondition();

RTPS_DllAPI ~GuardCondition();

RTPS_DllAPI bool get_trigger_value() const override;

/**
* @brief Set the trigger_value
* @param value new value for trigger
* @return RETURN_OK
*/
RTPS_DllAPI ReturnCode_t set_trigger_value(
bool value)
{
static_cast<void>(value);
return ReturnCode_t::RETCODE_UNSUPPORTED;
}
bool value);

};
private:

std::atomic<bool> trigger_value_;

typedef std::vector<Condition> ConditionSeq;
};

} // namespace dds
} // namespace fastdds
Expand Down
41 changes: 38 additions & 3 deletions include/fastdds/dds/core/condition/StatusCondition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ namespace eprosima {
namespace fastdds {
namespace dds {

namespace detail {

struct StatusConditionImpl;

} // namespace detail

class Entity;

/**
Expand All @@ -41,7 +47,28 @@ class StatusCondition : public Condition
{
public:

// StatusCondition not implemented.
StatusCondition(
Entity* parent);

~StatusCondition() final;

// Non-copyable
StatusCondition(
const StatusCondition&) = delete;
StatusCondition& operator =(
const StatusCondition&) = delete;

// Non-movable
StatusCondition(
StatusCondition&&) = delete;
StatusCondition& operator =(
StatusCondition&&) = delete;

/**
* @brief Retrieves the trigger_value of the Condition
* @return true if trigger_value is set to 'true', 'false' otherwise
*/
RTPS_DllAPI bool get_trigger_value() const override;

/**
* @brief Defines the list of communication statuses that are taken into account to determine the trigger_value
Expand All @@ -63,10 +90,18 @@ class StatusCondition : public Condition
*/
RTPS_DllAPI Entity* get_entity() const;

detail::StatusConditionImpl* get_impl() const
{
return impl_.get();
}

protected:

//! StatusMask with relevant statuses set to 1
StatusMask status_mask;
//! DDS Entity for which this condition is monitoring the status
Entity* entity_ = nullptr;

//! Class implementation
std::unique_ptr<detail::StatusConditionImpl> impl_;

};

Expand Down
24 changes: 23 additions & 1 deletion include/fastdds/dds/core/condition/WaitSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef _FASTDDS_WAIT_SET_HPP_
#define _FASTDDS_WAIT_SET_HPP_

#include <memory>

#include <fastdds/dds/core/condition/Condition.hpp>
#include <fastdds/rtps/common/Time_t.h>
#include <fastrtps/fastrtps_dll.h>
Expand All @@ -31,6 +33,11 @@ namespace eprosima {
namespace fastdds {
namespace dds {

// Forward declaration of implementation details
namespace detail {
struct WaitSetImpl;
} // namespace detail

/**
* @brief The WaitSet class allows an application to wait until one or more of the attached Condition objects
* has a trigger_value of TRUE or until timeout expires.
Expand All @@ -40,7 +47,18 @@ class WaitSet
{
public:

// WaitSet class not implemented.
RTPS_DllAPI WaitSet();

RTPS_DllAPI ~WaitSet();

WaitSet(
const WaitSet&) = delete;
WaitSet(
WaitSet&&) = delete;
WaitSet& operator = (
const WaitSet&) = delete;
WaitSet& operator = (
WaitSet&&) = delete;

/**
* @brief Attaches a Condition to the Wait Set.
Expand Down Expand Up @@ -79,6 +97,10 @@ class WaitSet
*/
RTPS_DllAPI ReturnCode_t get_conditions(
ConditionSeq& attached_conditions) const;

private:

std::unique_ptr<detail::WaitSetImpl> impl_;
};

} // namespace dds
Expand Down
6 changes: 6 additions & 0 deletions src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ set(${PROJECT_NAME}_source_files
dynamic-types/DynamicDataHelper.cpp

fastrtps_deprecated/attributes/TopicAttributes.cpp
fastdds/core/Entity.cpp
fastdds/core/condition/Condition.cpp
fastdds/core/condition/ConditionNotifier.cpp
fastdds/core/condition/GuardCondition.cpp
fastdds/core/condition/StatusCondition.cpp
fastdds/core/condition/StatusConditionImpl.cpp
fastdds/core/condition/WaitSet.cpp
fastdds/core/condition/WaitSetImpl.cpp
fastdds/core/policy/ParameterList.cpp
fastdds/core/policy/QosPolicyUtils.cpp
fastdds/publisher/qos/WriterQos.cpp
Expand Down
35 changes: 35 additions & 0 deletions src/cpp/fastdds/core/Entity.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 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.

/**
* @file Entity.cpp
*
*/

#include <fastdds/dds/core/Entity.hpp>

#include <fastdds/core/condition/StatusConditionImpl.hpp>

namespace eprosima {
namespace fastdds {
namespace dds {

const StatusMask& Entity::get_status_changes() const
{
return status_condition_.get_impl()->get_raw_status();
}

} // namespace dds
} // namespace fastdds
} // namespace eprosima
39 changes: 39 additions & 0 deletions src/cpp/fastdds/core/condition/Condition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2021 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.

/**
* @file Condition.cpp
*/

#include <fastdds/dds/core/condition/Condition.hpp>

#include <fastdds/core/condition/ConditionNotifier.hpp>

namespace eprosima {
namespace fastdds {
namespace dds {

Condition::Condition()
: notifier_ (new detail::ConditionNotifier())
{
}

Condition::~Condition()
{
notifier_->will_be_deleted(*this);
}

} // namespace dds
} // namespace fastdds
} // namespace eprosima
Loading