Skip to content

Commit

Permalink
iox-eclipse-iceoryx#252 getInstance** c binding created
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 5090d9a commit 2dc68a1
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 87 deletions.

This file was deleted.

This file was deleted.

24 changes: 24 additions & 0 deletions iceoryx_binding_c/include/iceoryx_binding_c/posh_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,28 @@

#include "internal/c2cpp_bridge.h"

void PoshRuntime_getInstance(const char* const name);

/// @brief retrieves the instance-name of the current posh runtime instance
/// @param[in] name char pointer to preallocated memory
/// @param[in] nameLength size of the preallocated memory.
/// @return The length of the instance-name. If the instance-name is longer then nameLength a
/// number greater nameLength is returned and the instance-name, truncated
/// to nameLength, is written into the memory location of name.
uint64_t PoshRuntime_getInstanceName(char* const name, const uint64_t nameLength);

void PoshRuntime_findService();
void PoshRuntime_offerService();
void PoshRuntime_stopOfferService();

void PoshRuntime_getMiddlewareSender();
void PoshRuntime_getMiddlewareReceiver();
void PoshRuntime_getMiddlewareInterface();
void PoshRuntime_getMiddlewareApplication();

void PoshRuntime_getMiddlewareConditionVariable();
void PoshRuntime_createRunnable();
uint64_t* PoshRuntime_getServiceRegistryChangeCounter();
bool PoshRuntime_sendRequestToRouDi();

#endif
26 changes: 13 additions & 13 deletions iceoryx_binding_c/include/iceoryx_binding_c/subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
#include "iceoryx_binding_c/internal/c2cpp_bridge.h"
#include "iceoryx_binding_c/types.h"

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);
ENUM subscriber_SubscriptionState subscriber_getSubscriptionState(CLASS SubscriberPortData* const self);
ENUM subscriber_AllocateError subscriber_getChunk(CLASS SubscriberPortData* const self,
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);
ENUM Subscriber_SubscriptionState Subscriber_getSubscriptionState(CLASS SubscriberPortData* const self);
ENUM 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);
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

4 changes: 2 additions & 2 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 Subscriber_SubscriptionState
{
NOT_SUBSCRIBED = 0,
SUBSCRIBE_REQUESTED,
Expand All @@ -24,7 +24,7 @@ enum subscriber_SubscriptionState
WAIT_FOR_OFFER
};

enum subscriber_AllocateError
enum Subscriber_AllocateError
{
SUCCESS,
TOO_MANY_CHUNKS_HELD_IN_PARALLEL,
Expand Down
22 changes: 22 additions & 0 deletions iceoryx_binding_c/source/binding_c_posh_runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "iceoryx_posh/runtime/posh_runtime.hpp"

using namespace iox;
using namespace iox::runtime;

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

void PoshRuntime_getInstance(const char* const name)
{
PoshRuntime::getInstance(name);
}

uint64_t PoshRuntime_getInstanceName(char* const name, const uint64_t nameLength)
{
auto instanceName = PoshRuntime::getInstance().getInstanceName();
uint64_t instanceNameSize = instanceName.size();
strncpy(name, instanceName.c_str(), std::min(nameLength, instanceNameSize));
return instanceNameSize;
}

48 changes: 25 additions & 23 deletions iceoryx_binding_c/source/binding_c_subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,95 +12,97 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "iceoryx_binding_c/internal/binding_c_subscriber.hpp"

#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"

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

#include <iostream>
extern "C" {
#include "iceoryx_binding_c/subscriber.h"
}

SubscriberPortData* subscriber_new()
SubscriberPortData* Subscriber_new()
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
return new SubscriberPortData(
ServiceDescription{1, 2, 3}, "bla", VariantQueueTypes::FiFo_SingleProducerSingleConsumer);
}

void subscriber_delete(SubscriberPortData* const self)
void Subscriber_delete(SubscriberPortData* const self)
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
delete self;
}

void subscriber_subscribe(SubscriberPortData* const self, const uint64_t queueCapacity)
void Subscriber_subscribe(SubscriberPortData* const self, const uint64_t queueCapacity)
{
std::cout << __PRETTY_FUNCTION__ << std::endl;
SubscriberPortUser(self).subscribe(queueCapacity);
}

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

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

subscriber_AllocateError subscriber_getChunk(SubscriberPortData* const self, const ChunkHeader** const header)
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;
? Subscriber_AllocateError::TOO_MANY_CHUNKS_HELD_IN_PARALLEL
: Subscriber_AllocateError::INTERNAL_ERROR;
}

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

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

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

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

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

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

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

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

bool subscriber_isConditionVariableAttached(SubscriberPortData* const self)
bool Subscriber_isConditionVariableAttached(SubscriberPortData* const self)
{
return SubscriberPortUser(self).isConditionVariableAttached();
}
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_examples/icedelivery_on_c/ice_c_subscriber.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void receiving()

int main()
{
struct SubscriberPortData* subscriber = subscriber_new();
subscriber_subscribe(subscriber, 10);
subscriber_delete(subscriber);
struct SubscriberPortData* subscriber = Subscriber_new();
Subscriber_subscribe(subscriber, 10);
Subscriber_delete(subscriber);
return 0;
}

0 comments on commit 2dc68a1

Please sign in to comment.