Skip to content

Commit

Permalink
iox-eclipse-iceoryx#252 added publisher c binding
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Eltzschig <christian.eltzschig2@de.bosch.com>
  • Loading branch information
elfenpiff committed Aug 19, 2020
1 parent dc5da0b commit 11ae087
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 10 deletions.
3 changes: 2 additions & 1 deletion iceoryx_binding_c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ set(${PROJECT_NAME}_DIR ${CMAKE_CURRENT_LIST_DIR}/cmake
#
add_library(${PROJECT_NAME}
STATIC
source/binding_c_subscriber.cpp
source/binding_c_posh_runtime.cpp
source/binding_c_publisher.cpp
source/binding_c_subscriber.cpp
)
add_library(${PROJECT_NAMESPACE}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

Expand Down
33 changes: 33 additions & 0 deletions iceoryx_binding_c/include/iceoryx_binding_c/publisher.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

#ifndef IOX_BINDING_C_PUBLISHER_H_
#define IOX_BINDING_C_PUBLISHER_H_

#include "iceoryx_binding_c/internal/c2cpp_bridge.h"
#include "iceoryx_binding_c/types.h"

CLASS PublisherPortData* Publisher_new();
void Publisher_delete(CLASS PublisherPortData* const self);
iox_popo_AllocationError
Publisher_allocateChunk(CLASS PublisherPortData* const self, void** const chunk, const uint32_t payloadSize);
void Publisher_freeChunk(CLASS PublisherPortData* const self, void* const chunk);
void Publisher_sendChunk(CLASS PublisherPortData* const self, void* const chunk);
const void* Publisher_getLastChunk(CLASS PublisherPortData* const self);
void Publisher_offer(CLASS PublisherPortData* const self);
void Publisher_stopOffer(CLASS PublisherPortData* const self);
bool Publisher_isOffered(CLASS PublisherPortData* const self);
bool Publisher_hasSubscribers(CLASS PublisherPortData* const self);

#endif
4 changes: 2 additions & 2 deletions iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Subscriber_new(const char* const service, const char* const instance, const char
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);
ENUM Subscriber_SubscriptionState Subscriber_getSubscriptionState(CLASS SubscriberPortData* const self);
ENUM Subscriber_AllocateError Subscriber_getChunk(CLASS SubscriberPortData* const self, const void** const);
ENUM iox_SubscribeState Subscriber_getSubscriptionState(CLASS SubscriberPortData* const self);
ENUM iox_popo_ChunkReceiveError Subscriber_getChunk(CLASS SubscriberPortData* const self, const void** const);
void Subscriber_releaseChunk(CLASS SubscriberPortData* const self, const void* const);
void Subscriber_releaseQueuedChunks(CLASS SubscriberPortData* const self);
bool Subscriber_hasNewChunks(CLASS SubscriberPortData* const self);
Expand Down
13 changes: 10 additions & 3 deletions iceoryx_binding_c/include/iceoryx_binding_c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef IOX_BINDING_C_TYPES_H_
#define IOX_BINDING_C_TYPES_H_

enum Subscriber_SubscriptionState
enum iox_SubscribeState
{
SubscribeState_NOT_SUBSCRIBED = 0,
SubscribeState_SUBSCRIBE_REQUESTED,
Expand All @@ -24,12 +24,19 @@ enum Subscriber_SubscriptionState
SubscribeState_WAIT_FOR_OFFER
};

enum Subscriber_AllocateError
enum iox_popo_ChunkReceiveError
{
ChunkReceiveError_SUCCESS,
ChunkReceiveError_TOO_MANY_CHUNKS_HELD_IN_PARALLEL,
ChunkReceiveError_NO_CHUNK_RECEIVED,
ChunkReceiveError_INTERNAL_ERROR,
ChunkReceiveError_SUCCESS,
};

enum iox_popo_AllocationError
{
AllocationError_RUNNING_OUT_OF_CHUNKS,
AllocationError_TOO_MANY_CHUNKS_ALLOCATED_IN_PARALLEL,
AllocationError_SUCCESS,
};


Expand Down
86 changes: 86 additions & 0 deletions iceoryx_binding_c/source/binding_c_publisher.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// 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/publisher_port_user.hpp"

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

extern "C" {
#include "iceoryx_binding_c/publisher.h"
}

PublisherPortData* Publisher_new()
{
return new PublisherPortData(ServiceDescription{1, 2, 3}, "JoinTheChurchOfHypnotoad!", nullptr, 0u);
}

void Publisher_delete(PublisherPortData* const self)
{
delete self;
}

iox_popo_AllocationError
Publisher_allocateChunk(PublisherPortData* const self, void** const chunk, const uint32_t payloadSize)
{
auto result =
PublisherPortUser(self).allocateChunk(payloadSize).and_then([&](ChunkHeader* h) { *chunk = h->payload(); });
if (result.has_error())
{
return static_cast<iox_popo_AllocationError>(static_cast<int>(result.get_error()));
}

return AllocationError_SUCCESS;
}

void Publisher_freeChunk(PublisherPortData* const self, void* const chunk)
{
PublisherPortUser(self).freeChunk(convertPayloadPointerToChunkHeader(chunk));
}

void Publisher_sendChunk(PublisherPortData* const self, void* const chunk)
{
PublisherPortUser(self).sendChunk(convertPayloadPointerToChunkHeader(chunk));
}

const void* Publisher_getLastChunk(PublisherPortData* const self)
{
const void* returnValue = nullptr;
PublisherPortUser(self).getLastChunk().and_then([&](const ChunkHeader* h) { returnValue = h->payload(); });
return returnValue;
}

void Publisher_offer(PublisherPortData* const self)
{
PublisherPortUser(self).offer();
}

void Publisher_stopOffer(PublisherPortData* const self)
{
PublisherPortUser(self).stopOffer();
}

bool Publisher_isOffered(PublisherPortData* const self)
{
return PublisherPortUser(self).isOffered();
}

bool Publisher_hasSubscribers(PublisherPortData* const self)
{
return PublisherPortUser(self).hasSubscribers();
}

7 changes: 3 additions & 4 deletions iceoryx_binding_c/source/binding_c_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.


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

Expand Down Expand Up @@ -55,12 +54,12 @@ void Subscriber_unsubscribe(SubscriberPortData* const self)
SubscriberPortUser(self).unsubscribe();
}

Subscriber_SubscriptionState Subscriber_getSubscriptionState(SubscriberPortData* const self)
iox_SubscribeState Subscriber_getSubscriptionState(SubscriberPortData* const self)
{
return static_cast<Subscriber_SubscriptionState>(static_cast<int>(SubscriberPortUser(self).getSubscriptionState()));
return static_cast<iox_SubscribeState>(static_cast<int>(SubscriberPortUser(self).getSubscriptionState()));
}

Subscriber_AllocateError Subscriber_getChunk(SubscriberPortData* const self, const void** const header)
iox_popo_ChunkReceiveError Subscriber_getChunk(SubscriberPortData* const self, const void** const header)
{
auto result = SubscriberPortUser(self).getChunk();
if (result.has_error())
Expand Down

0 comments on commit 11ae087

Please sign in to comment.