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

Adds API to get status of DDScObjectDelegate #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class OMG_DDS_API DDScObjectDelegate : public virtual org::eclipse::cyclonedds::
dds_entity_t get_ddsc_entity ();
void set_ddsc_entity (dds_entity_t e);
void add_to_entity_map (org::eclipse::cyclonedds::core::ObjectDelegate::weak_ref_type weak_ref);
bool is_valid () const;

public:
static ObjectDelegate::ref_type extract_strong_ref(dds_entity_t e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#ifndef CYCLONEDDS_CORE_OBJECT_DELEGATE_HPP_
#define CYCLONEDDS_CORE_OBJECT_DELEGATE_HPP_

#include <atomic>
#include "dds/core/macros.hpp"
#include "dds/core/refmacros.hpp"
#include "org/eclipse/cyclonedds/core/Mutex.hpp"
Expand Down Expand Up @@ -46,6 +47,7 @@ class OMG_DDS_API ObjectDelegate
virtual void close ();
void lock() const;
void unlock() const;
virtual bool is_valid() const;

virtual void init (ObjectDelegate::weak_ref_type weak_ref) = 0;
ObjectDelegate::weak_ref_type get_weak_ref () const;
Expand All @@ -57,7 +59,7 @@ class OMG_DDS_API ObjectDelegate
void set_weak_ref (ObjectDelegate::weak_ref_type weak_ref);

Mutex mutex;
bool closed;
std::atomic_bool closed {false};
ObjectDelegate::weak_ref_type myself;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ org::eclipse::cyclonedds::core::DDScObjectDelegate::add_to_entity_map(org::eclip
DDScObjectDelegate::entity_map_mutex.unlock ();
}

bool org::eclipse::cyclonedds::core::DDScObjectDelegate::is_valid() const
{
return org::eclipse::cyclonedds::core::ObjectDelegate::is_valid();
}

void
org::eclipse::cyclonedds::core::DDScObjectDelegate::delete_from_entity_map()
{
Expand Down
24 changes: 10 additions & 14 deletions src/ddscxx/src/org/eclipse/cyclonedds/core/ObjectDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
#include "org/eclipse/cyclonedds/core/ObjectDelegate.hpp"
#include <org/eclipse/cyclonedds/core/ReportUtils.hpp>

org::eclipse::cyclonedds::core::ObjectDelegate::ObjectDelegate () :
closed (false)
org::eclipse::cyclonedds::core::ObjectDelegate::ObjectDelegate ()
{
}

Expand All @@ -27,34 +26,31 @@ org::eclipse::cyclonedds::core::ObjectDelegate::~ObjectDelegate ()

void org::eclipse::cyclonedds::core::ObjectDelegate::check () const
{
/* This method is not-thread-safe, and should only be used with a lock. */
if (closed) {
if (closed.load()) {
ISOCPP_THROW_EXCEPTION (ISOCPP_ALREADY_CLOSED_ERROR, "Trying to invoke an oparation on an object that was already closed");
}
}

void org::eclipse::cyclonedds::core::ObjectDelegate::lock () const
{
check();
this->mutex.lock ();
try
{
check();
}
catch (...)
{
this->mutex.unlock ();
throw;
}
}

void org::eclipse::cyclonedds::core::ObjectDelegate::unlock () const
{
this->mutex.unlock ();
}

bool org::eclipse::cyclonedds::core::ObjectDelegate::is_valid() const
{
bool is_closed = this->closed.load(std::memory_order_acquire);
return !is_closed;
}

void org::eclipse::cyclonedds::core::ObjectDelegate::close ()
{
this->closed = true;
this->closed.store(true);
}

void org::eclipse::cyclonedds::core::ObjectDelegate::set_weak_ref (ObjectDelegate::weak_ref_type weak_ref)
Expand Down