Skip to content

Commit

Permalink
iox-#10 Do not offer iceoryx services on creation
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Hoinkis <[email protected]>
  • Loading branch information
mossmaurice committed Jun 21, 2022
1 parent a34b2e1 commit bee1e54
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
4 changes: 4 additions & 0 deletions include/owl/kom/field_publisher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FieldPublisher
public:
using FieldType = T;
static constexpr uint64_t HISTORY_CAPACITY{1U};
static constexpr bool NOT_OFFERED_ON_CREATE{false};

FieldPublisher(const ServiceIdentifier& service,
const InstanceIdentifier& instance,
Expand All @@ -46,6 +47,9 @@ class FieldPublisher
FieldPublisher& operator=(const FieldPublisher&) = delete;
FieldPublisher& operator=(FieldPublisher&&) = delete;

void Offer() noexcept;
void StopOffer() noexcept;

bool Update(const FieldType& userField) noexcept;

void RegisterGetHandler(const iox::cxx::function<void()>) noexcept;
Expand Down
19 changes: 16 additions & 3 deletions include/owl/kom/field_publisher.inl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ inline FieldPublisher<T>::FieldPublisher(const ServiceIdentifier& service,
const InstanceIdentifier& instance,
const FieldIdentifier& field,
const FieldType& fieldValue) noexcept
: m_publisher({service, instance, field}, {HISTORY_CAPACITY})
, m_server({service, instance, field})
: m_publisher({service, instance, field}, {HISTORY_CAPACITY, iox::NodeName_t(), NOT_OFFERED_ON_CREATE})
, m_server({service, instance, field}, {HISTORY_CAPACITY, iox::NodeName_t(), NOT_OFFERED_ON_CREATE})
, m_latestValue(fieldValue)
{
// publisher is automatically offered
Update(m_latestValue);

//! [FieldPublisher attach]
Expand All @@ -51,6 +50,20 @@ inline FieldPublisher<T>::~FieldPublisher() noexcept
m_publisher.stopOffer();
}

template <typename T>
void FieldPublisher<T>::Offer() noexcept
{
m_publisher.offer();
m_server.offer();
}

template <typename T>
void FieldPublisher<T>::StopOffer() noexcept
{
m_publisher.stopOffer();
m_server.stopOffer();
}

template <typename T>
inline bool FieldPublisher<T>::Update(const FieldType& userField) noexcept
{
Expand Down
6 changes: 6 additions & 0 deletions include/owl/kom/method_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ namespace kom
class MethodServer
{
public:
static constexpr uint64_t HISTORY_CAPACITY{1U};
static constexpr bool NOT_OFFERED_ON_CREATE{false};

MethodServer(const ServiceIdentifier& service,
const InstanceIdentifier& instance,
const MethodIdentifier& method) noexcept;
Expand All @@ -42,6 +45,9 @@ class MethodServer
MethodServer& operator=(const MethodServer&) = delete;
MethodServer& operator=(MethodServer&&) = delete;

void Offer() noexcept;
void StopOffer() noexcept;

Future<AddResponse> computeSum(const uint64_t addend1, const uint64_t addend2);

private:
Expand Down
4 changes: 4 additions & 0 deletions src/minimal_skeleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ MinimalSkeleton::~MinimalSkeleton() noexcept
void MinimalSkeleton::Offer() noexcept
{
m_event.Offer();
m_field.Offer();
computeSum.Offer();
}

void MinimalSkeleton::StopOffer() noexcept
{
m_event.StopOffer();
m_field.StopOffer();
computeSum.StopOffer();
}
12 changes: 11 additions & 1 deletion src/owl/kom/method_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace kom
MethodServer::MethodServer(const ServiceIdentifier& service,
const InstanceIdentifier& instance,
const MethodIdentifier& method) noexcept
: m_server({service, instance, method})
: m_server({service, instance, method}, {HISTORY_CAPACITY, iox::NodeName_t(), NOT_OFFERED_ON_CREATE})
{
m_listener
.attachEvent(m_server,
Expand All @@ -37,6 +37,16 @@ MethodServer::~MethodServer() noexcept
m_listener.detachEvent(m_server, iox::popo::ServerEvent::REQUEST_RECEIVED);
}

void MethodServer::Offer() noexcept
{
m_server.offer();
}

void MethodServer::StopOffer() noexcept
{
m_server.stopOffer();
}

Future<AddResponse> MethodServer::computeSum(const uint64_t addend1, const uint64_t addend2)
{
// for simplicity we don't create thread here and make the call synchronous
Expand Down

0 comments on commit bee1e54

Please sign in to comment.