Skip to content

Commit

Permalink
iox-eclipse-iceoryx#252 first subscriber draft implemented
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <[email protected]>
  • Loading branch information
elfenpiff committed Aug 19, 2020
1 parent af476e1 commit 4ce1297
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
//
// 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.

#include "iceoryx_posh/internal/popo/ports/subscriber_port_data.hpp"
#include "iceoryx_posh/mepoo/chunk_header.hpp"

using SubscriberPortData = iox::popo::SubscriberPortData;
using ChunkHeader = iox::mepoo::ChunkHeader;

extern "C" {
#include "iceoryx_binding_c/subscriber.h"
}
58 changes: 58 additions & 0 deletions iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
//
// 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.

#include <stdint.h>

#ifndef IOX_BINDING_C_SUBSCRIBER_H_
#define IOX_BINDING_C_SUBSCRIBER_H_

enum subscriber_SubscriptionState
{
NOT_SUBSCRIBED = 0,
SUBSCRIBE_REQUESTED,
SUBSCRIBED,
UNSUBSCRIBE_REQUESTED,
WAIT_FOR_OFFER
};

enum subscriber_AllocateError
{
SUCCESS,
TOO_MANY_CHUNKS_HELD_IN_PARALLEL,
NO_CHUNK_RECEIVED,
INTERNAL_ERROR,
};

#ifdef __cplusplus
#define CLASS
#else
#define CLASS struct
#endif

CLASS SubscriberPortData* subscriber_new();
void subscriber_delete(CLASS SubscriberPortData* const self);
void subscriber_subscribe(CLASS SubscriberPortData* const self, const uint64_t queueCapacity);
void subscriber_unsubscribe(CLASS SubscriberPortData* const self);
subscriber_SubscriptionState subscriber_getSubscriptionState(CLASS SubscriberPortData* const self);
subscriber_AllocateError subscriber_getChunk(CLASS SubscriberPortData* const self, const CLASS ChunkHeader** const);
void subscriber_releaseChunk(CLASS SubscriberPortData* const self, const CLASS ChunkHeader* const);
void subscriber_releaseQueuedChunks(CLASS SubscriberPortData* const self);
bool subscriber_hasNewChunks(CLASS SubscriberPortData* const self);
bool subscriber_hasLostChunks(CLASS SubscriberPortData* const self);
void subscriber_attachConditionVariable(CLASS SubscriberPortData* const self);
void subscriber_detachConditionVariable(CLASS SubscriberPortData* const self);
bool subscriber_isConditionVariableAttached(CLASS SubscriberPortData* const self);

#endif

103 changes: 103 additions & 0 deletions iceoryx_binding_c/source/subscriber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
//
// 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.

#include "iceoryx_binding_c/internal/subscriber.hpp"
#include "iceoryx_posh/internal/popo/ports/subscriber_port_user.hpp"

using namespace iox;
using namespace iox::cxx;
using namespace iox::popo;
using namespace iox::capro;


SubscriberPortData* subscriber_new()
{
return new SubscriberPortData(
ServiceDescription{1, 2, 3}, "bla", VariantQueueTypes::FiFo_SingleProducerSingleConsumer);
}

void subscriber_delete(SubscriberPortData* const self)
{
delete self;
}

void subscriber_subscribe(SubscriberPortData* const self, const uint64_t queueCapacity)
{
SubscriberPortUser(self).subscribe(queueCapacity);
}

void subscriber_unsubscribe(SubscriberPortData* const self)
{
SubscriberPortUser(self).unsubscribe();
}

subscriber_SubscriptionState subscriber_getSubscriptionState(SubscriberPortData* const self)
{
return static_cast<subscriber_SubscriptionState>(static_cast<int>(SubscriberPortUser(self).getSubscriptionState()));
}

subscriber_AllocateError subscriber_getChunk(SubscriberPortData* const self, const ChunkHeader** const header)
{
auto result = SubscriberPortUser(self).getChunk();
if (result.has_error())
{
return (result.get_error() == ChunkReceiveError::TOO_MANY_CHUNKS_HELD_IN_PARALLEL)
? subscriber_AllocateError::TOO_MANY_CHUNKS_HELD_IN_PARALLEL
: subscriber_AllocateError::INTERNAL_ERROR;
}

if (!result->has_value())
{
return subscriber_AllocateError::NO_CHUNK_RECEIVED;
}

*header = **result;
return subscriber_AllocateError::SUCCESS;
}

void subscriber_releaseChunk(SubscriberPortData* const self, const ChunkHeader* const chunkHeader)
{
SubscriberPortUser(self).releaseChunk(chunkHeader);
}

void subscriber_releaseQueuedChunks(SubscriberPortData* const self)
{
SubscriberPortUser(self).releaseQueuedChunks();
}

bool subscriber_hasNewChunks(SubscriberPortData* const self)
{
return SubscriberPortUser(self).hasNewChunks();
}

bool subscriber_hasLostChunks(SubscriberPortData* const self)
{
return SubscriberPortUser(self).hasLostChunks();
}

void subscriber_attachConditionVariable(SubscriberPortData* const self)
{
SubscriberPortUser(self).attachConditionVariable();
}

void subscriber_detachConditionVariable(SubscriberPortData* const self)
{
SubscriberPortUser(self).detachConditionVariable();
}

bool subscriber_isConditionVariableAttached(SubscriberPortData* const self)
{
return SubscriberPortUser(self).isConditionVariableAttached();
}

Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class SubscriberPortUser

/// @todo we first need the new condition variable
void attachConditionVariable() noexcept;
void detachConditionVaribale() noexcept;
void detachConditionVariable() noexcept;
bool isConditionVariableAttached() noexcept;

private:
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_posh/source/popo/ports/subscriber_port_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void SubscriberPortUser::attachConditionVariable() noexcept
{
}

void SubscriberPortUser::detachConditionVaribale() noexcept
void SubscriberPortUser::detachConditionVariable() noexcept
{
}

Expand Down

0 comments on commit 4ce1297

Please sign in to comment.