Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1032 Replace IOX_EXPECTS WITH IOX_ENFORCE
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Feb 2, 2024
1 parent 7135c57 commit 83788e3
Show file tree
Hide file tree
Showing 71 changed files with 546 additions and 542 deletions.
14 changes: 7 additions & 7 deletions iceoryx_binding_c/source/c_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "iceoryx_posh/mepoo/chunk_header.hpp"

#include "iox/assertions.hpp"

extern "C" {
#include "iceoryx_binding_c/chunk.h"
Expand All @@ -25,36 +25,36 @@ using namespace iox::mepoo;

void* iox_chunk_header_to_user_payload(iox_chunk_header_t* const chunkHeader)
{
IOX_EXPECTS(chunkHeader != nullptr);
IOX_ENFORCE(chunkHeader != nullptr, "'chunkHeader' must not be a 'nullptr'");
return reinterpret_cast<ChunkHeader*>(chunkHeader)->userPayload();
}

const void* iox_chunk_header_to_user_payload_const(const iox_chunk_header_t* const chunkHeader)
{
IOX_EXPECTS(chunkHeader != nullptr);
IOX_ENFORCE(chunkHeader != nullptr, "'chunkHeader' must not be a 'nullptr'");
return reinterpret_cast<const ChunkHeader*>(chunkHeader)->userPayload();
}

void* iox_chunk_header_to_user_header(iox_chunk_header_t* const chunkHeader)
{
IOX_EXPECTS(chunkHeader != nullptr);
IOX_ENFORCE(chunkHeader != nullptr, "'chunkHeader' must not be a 'nullptr'");
return reinterpret_cast<ChunkHeader*>(chunkHeader)->userHeader();
}

const void* iox_chunk_header_to_user_header_const(const iox_chunk_header_t* const chunkHeader)
{
IOX_EXPECTS(chunkHeader != nullptr);
IOX_ENFORCE(chunkHeader != nullptr, "'chunkHeader' must not be a 'nullptr'");
return reinterpret_cast<const ChunkHeader*>(chunkHeader)->userHeader();
}

iox_chunk_header_t* iox_chunk_header_from_user_payload(void* const userPayload)
{
IOX_EXPECTS(userPayload != nullptr);
IOX_ENFORCE(userPayload != nullptr, "'userPayload' must not be a 'nullptr'");
return reinterpret_cast<iox_chunk_header_t*>(ChunkHeader::fromUserPayload(userPayload));
}

const iox_chunk_header_t* iox_chunk_header_from_user_payload_const(const void* const userPayload)
{
IOX_EXPECTS(userPayload != nullptr);
IOX_ENFORCE(userPayload != nullptr, "'userPayload' must not be a 'nullptr'");
return reinterpret_cast<const iox_chunk_header_t*>(ChunkHeader::fromUserPayload(userPayload));
}
47 changes: 24 additions & 23 deletions iceoryx_binding_c/source/c_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ constexpr uint64_t CLIENT_OPTIONS_INIT_CHECK_CONSTANT = 47113130815;

void iox_client_options_init(iox_client_options_t* options)
{
IOX_EXPECTS(options != nullptr);
IOX_ENFORCE(options != nullptr, "'options' must not be a 'nullptr'");

ClientOptions clientOptions;
options->responseQueueCapacity = clientOptions.responseQueueCapacity;
Expand All @@ -49,7 +49,7 @@ void iox_client_options_init(iox_client_options_t* options)

bool iox_client_options_is_initialized(const iox_client_options_t* const options)
{
IOX_EXPECTS(options != nullptr);
IOX_ENFORCE(options != nullptr, "'options' must not be a 'nullptr'");

return options->initCheck == CLIENT_OPTIONS_INIT_CHECK_CONSTANT;
}
Expand All @@ -60,11 +60,12 @@ iox_client_t iox_client_init(iox_client_storage_t* self,
const char* const event,
const iox_client_options_t* const options)
{
IOX_EXPECTS(self != nullptr);
IOX_EXPECTS(service != nullptr);
IOX_EXPECTS(instance != nullptr);
IOX_EXPECTS(event != nullptr);
IOX_EXPECTS(options == nullptr || (options != nullptr && iox_client_options_is_initialized(options)));
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
IOX_ENFORCE(service != nullptr, "'service' must not be a 'nullptr'");
IOX_ENFORCE(instance != nullptr, "'instance' must not be a 'nullptr'");
IOX_ENFORCE(event != nullptr, "'event' must not be a 'nullptr'");
IOX_ENFORCE(options == nullptr || (options != nullptr && iox_client_options_is_initialized(options)),
"'options' must be either a 'nullptr' or the data behind the pointer must be initialized");

ClientOptions clientOptions;
if (options != nullptr)
Expand All @@ -87,7 +88,7 @@ iox_client_t iox_client_init(iox_client_storage_t* self,

void iox_client_deinit(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");

delete self;
}
Expand All @@ -102,8 +103,8 @@ iox_AllocationResult iox_client_loan_aligned_request(iox_client_t const self,
const uint64_t payloadSize,
const uint32_t payloadAlignment)
{
IOX_EXPECTS(self != nullptr);
IOX_EXPECTS(payload != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
IOX_ENFORCE(payload != nullptr, "'payload' must not be a 'nullptr'");

auto result = self->loan(payloadSize, payloadAlignment);
if (result.has_error())
Expand All @@ -117,15 +118,15 @@ iox_AllocationResult iox_client_loan_aligned_request(iox_client_t const self,

void iox_client_release_request(iox_client_t const self, void* const payload)
{
IOX_EXPECTS(self != nullptr);
IOX_EXPECTS(payload != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
IOX_ENFORCE(payload != nullptr, "'payload' must not be a 'nullptr'");

self->releaseRequest(payload);
}

iox_ClientSendResult iox_client_send(iox_client_t const self, void* const payload)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");

auto result = self->send(payload);
if (result.has_error())
Expand All @@ -138,26 +139,26 @@ iox_ClientSendResult iox_client_send(iox_client_t const self, void* const payloa

void iox_client_connect(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
self->connect();
}

void iox_client_disconnect(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
self->disconnect();
}

iox_ConnectionState iox_client_get_connection_state(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
return cpp2c::connectionState(self->getConnectionState());
}

iox_ChunkReceiveResult iox_client_take_response(iox_client_t const self, const void** const payload)
{
IOX_EXPECTS(self != nullptr);
IOX_EXPECTS(payload != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
IOX_ENFORCE(payload != nullptr, "'payload' must not be a 'nullptr'");

auto result = self->take();
if (result.has_error())
Expand All @@ -171,27 +172,27 @@ iox_ChunkReceiveResult iox_client_take_response(iox_client_t const self, const v

void iox_client_release_response(iox_client_t const self, const void* const payload)
{
IOX_EXPECTS(self != nullptr);
IOX_EXPECTS(payload != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
IOX_ENFORCE(payload != nullptr, "'payload' must not be a 'nullptr'");

self->releaseResponse(payload);
}

void iox_client_release_queued_responses(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
self->releaseQueuedResponses();
}

bool iox_client_has_responses(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
return self->hasResponses();
}

bool iox_client_has_missed_responses(iox_client_t const self)
{
IOX_EXPECTS(self != nullptr);
IOX_ENFORCE(self != nullptr, "'self' must not be a 'nullptr'");
return self->hasMissedResponses();
}

Expand Down
Loading

0 comments on commit 83788e3

Please sign in to comment.