forked from eclipse-iceoryx/iceoryx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iox-eclipse-iceoryx#252 first subscriber draft implemented
Signed-off-by: Christian Eltzschig <[email protected]>
- Loading branch information
Showing
5 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters