Skip to content

Commit

Permalink
Feature/support multiple clients (EmbeddedRPC#271)
Browse files Browse the repository at this point in the history
* Implementing better C++ eRPC support

Signed-off-by: Cervenka Dusan <[email protected]>

* Moving C interface related function declarations into interface header file.

Signed-off-by: Cervenka Dusan <[email protected]>

* Move C generated code into it's own files.

Signed-off-by: Cervenka Dusan <[email protected]>

* Many C++ minor fixes

Signed-off-by: Cervenka Dusan <[email protected]>

* C support multiple clients

Signed-off-by: Cervenka Dusan <[email protected]>

* Tests can be built.

Signed-off-by: Cervenka Dusan <[email protected]>

* Fixed infinity loops in tests (c++ vs c scope)

Signed-off-by: Cervenka Dusan <[email protected]>

* test_callbacks works

Signed-off-by: Cervenka Dusan <[email protected]>

* test_arbitrator is working now

Signed-off-by: Cervenka Dusan <[email protected]>

* Many minor code improvements.

Signed-off-by: Cervenka Dusan <[email protected]>

* Namespace can be defined by user. Default erpcshim

Signed-off-by: Cervenka Dusan <[email protected]>

* Putting function declaration under interface.

Signed-off-by: Cervenka Dusan <[email protected]>

* Refactored code

Signed-off-by: Cervenka Dusan <[email protected]>

* Fixed yml tests.

Signed-off-by: Cervenka Dusan <[email protected]>

* Added c++ enum classes

Signed-off-by: Cervenka Dusan <[email protected]>

* Change based on PR review

Signed-off-by: Cervenka Dusan <[email protected]>

* Revert "Added c++ enum classes"

This reverts commit d5acf06.

Signed-off-by: Cervenka Dusan <[email protected]>

* Fixes based on Michal observations

Signed-off-by: Cervenka Dusan <[email protected]>

* Fix wrong name in server function call

Signed-off-by: Cervenka Dusan <[email protected]>

---------

Signed-off-by: Cervenka Dusan <[email protected]>
Co-authored-by: Michal Princ <[email protected]>
  • Loading branch information
Hadatko and MichalPrincNXP authored Oct 17, 2023
1 parent 7f98fda commit 8616dbe
Show file tree
Hide file tree
Showing 140 changed files with 3,658 additions and 1,599 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ BraceWrapping:
AfterUnion: true
BeforeCatch: true
BeforeElse: true
#IncludeBlocks: "Preserve" # for future version of clang
IncludeBlocks: "Preserve" # for future version of clang
IncludeCategories:
- Regex: "^<" # system includes
Priority: 10
Expand Down
2 changes: 2 additions & 0 deletions erpc_c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ SOURCES += $(ERPC_C_ROOT)/infra/erpc_arbitrated_client_manager.cpp \
$(ERPC_C_ROOT)/infra/erpc_server.cpp \
$(ERPC_C_ROOT)/infra/erpc_simple_server.cpp \
$(ERPC_C_ROOT)/infra/erpc_transport_arbitrator.cpp \
$(ERPC_C_ROOT)/infra/erpc_utils.cpp \
$(ERPC_C_ROOT)/infra/erpc_pre_post_action.cpp \
$(ERPC_C_ROOT)/port/erpc_port_stdlib.cpp \
$(ERPC_C_ROOT)/port/erpc_threading_pthreads.cpp \
Expand Down Expand Up @@ -93,6 +94,7 @@ HEADERS += $(ERPC_C_ROOT)/config/erpc_config.h \
$(ERPC_C_ROOT)/infra/erpc_static_queue.hpp \
$(ERPC_C_ROOT)/infra/erpc_transport_arbitrator.hpp \
$(ERPC_C_ROOT)/infra/erpc_transport.hpp \
$(ERPC_C_ROOT)/infra/erpc_utils.hpp \
$(ERPC_C_ROOT)/infra/erpc_client_server_common.hpp \
$(ERPC_C_ROOT)/infra/erpc_pre_post_action.h \
$(ERPC_C_ROOT)/port/erpc_setup_extensions.h \
Expand Down
2 changes: 1 addition & 1 deletion erpc_c/infra/erpc_arbitrated_client_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ArbitratedClientManager : public ClientManager
*
* @return TransportArbitrator * Transport arbitrator instance.
*/
TransportArbitrator *getArbitrator(void) { return m_arbitrator; };
TransportArbitrator * getArbitrator(void) { return m_arbitrator; };

protected:
TransportArbitrator *m_arbitrator; //!< Optional transport arbitrator. May be NULL.
Expand Down
59 changes: 0 additions & 59 deletions erpc_c/infra/erpc_basic_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,37 +161,6 @@ void BasicCodec::writeNullFlag(bool isNull)
write(static_cast<uint8_t>(isNull ? null_flag_t::kIsNull : null_flag_t::kNotNull));
}

void BasicCodec::writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback)
{
uint8_t i;

erpc_assert(callbacksCount > 1U);

// callbacks = callbacks table
for (i = 0; i < callbacksCount; i++)
{
if (callbacks[i] == callback)
{
write(i);
break;
}
if ((i + 1U) == callbacksCount)
{
updateStatus(kErpcStatus_UnknownCallback);
}
}
}

void BasicCodec::writeCallback(funPtr callback1, funPtr callback2)
{
// callbacks = callback directly
// When declared only one callback function no serialization is needed.
if (callback1 != callback2)
{
updateStatus(kErpcStatus_UnknownCallback);
}
}

void BasicCodec::startReadMessage(message_type_t &type, uint32_t &service, uint32_t &request, uint32_t &sequence)
{
uint32_t header;
Expand Down Expand Up @@ -396,34 +365,6 @@ void BasicCodec::readNullFlag(bool &isNull)
}
}

void BasicCodec::readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback)
{
uint8_t _tmp_local;

erpc_assert(callbacksCount > 1U);

// callbacks = callbacks table
read(_tmp_local);
if (isStatusOk())
{
if (_tmp_local < callbacksCount)
{
*callback = callbacks[_tmp_local];
}
else
{
*callback = NULL;
m_status = kErpcStatus_UnknownCallback;
}
}
}

void BasicCodec::readCallback(funPtr callbacks1, funPtr *callback2)
{
// callbacks = callback directly
*callback2 = callbacks1;
}

ERPC_MANUALLY_CONSTRUCTED_ARRAY_STATIC(BasicCodec, s_basicCodecManual, ERPC_CODEC_COUNT);

Codec *BasicCodecFactory::create(void)
Expand Down
34 changes: 0 additions & 34 deletions erpc_c/infra/erpc_basic_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,6 @@ class BasicCodec : public Codec
* @param[in] isNull Null flag to send.
*/
virtual void writeNullFlag(bool isNull) override;

/*!
* @brief Writes an order ID of callback function.
*
* @param[in] callbacks Pointer to array of callbacks.
* @param[in] callbacksCount Size of array of callbacks.
* @param[in] callback Callback which ID should be serialized.
*/
virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback) override;

/*!
* @brief Writes an order ID of callback function.
*
* @param[in] callback1 Pointer to existing callback.
* @param[out] callback2 Callback which ID should be serialized.
*/
virtual void writeCallback(funPtr callback1, funPtr callback2) override;
//@}

//! @name Decoding
Expand Down Expand Up @@ -350,23 +333,6 @@ class BasicCodec : public Codec
* @param[in] isNull Null flag to read.
*/
virtual void readNullFlag(bool &isNull) override;

/*!
* @brief Read an callback function id and return address of callback function.
*
* @param[in] callbacks Pointer to array of callbacks.
* @param[in] callbacksCount Size of array of callbacks.
* @param[out] callback Callback which is deserialized. Null in case of error.
*/
virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback) override;

/*!
* @brief Read an callback function id and return address of callback function.
*
* @param[in] callback1 Pointer to existing callback.
* @param[out] callback2 Callback which is deserialized.
*/
virtual void readCallback(funPtr callbacks1, funPtr *callback2) override;
//@}
};

Expand Down
2 changes: 2 additions & 0 deletions erpc_c/infra/erpc_client_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/

extern "C" {
#else
#include "erpc_common.h"
#endif

typedef void (*client_error_handler_t)(erpc_status_t err,
Expand Down
13 changes: 8 additions & 5 deletions erpc_c/infra/erpc_client_server_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#ifndef _EMBEDDED_RPC__CLIENTSERVERCOMMON_H_
#define _EMBEDDED_RPC__CLIENTSERVERCOMMON_H_

#include "erpc_config_internal.h"
#include "erpc_codec.hpp"
#include "erpc_config_internal.h"
#if ERPC_MESSAGE_LOGGING
#include "erpc_message_loggers.hpp"
#endif
Expand Down Expand Up @@ -66,7 +66,7 @@ class ClientServerCommon
#endif
#if ERPC_MESSAGE_LOGGING
#ifdef ERPC_OTHER_INHERITANCE
,
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
Expand All @@ -75,20 +75,23 @@ class ClientServerCommon
#endif
#if ERPC_PRE_POST_ACTION
#ifdef ERPC_OTHER_INHERITANCE
,
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
PrePostAction()
#endif
#ifdef ERPC_OTHER_INHERITANCE
,
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
m_messageFactory(NULL), m_codecFactory(NULL), m_transport(NULL){};
m_messageFactory(NULL)
, m_codecFactory(NULL)
, m_transport(NULL)
{};

/*!
* @brief ClientServerCommon destructor
Expand Down
36 changes: 1 addition & 35 deletions erpc_c/infra/erpc_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "erpc_message_buffer.hpp"
#include "erpc_transport.hpp"

#include <cstdint>
#include <cstring>
#include <stdint.h>

/*!
* @addtogroup infra_codec
Expand Down Expand Up @@ -257,23 +257,6 @@ class Codec
* @param[in] isNull Null flag to send.
*/
virtual void writeNullFlag(bool isNull) = 0;

/*!
* @brief Writes an order ID of callback function.
*
* @param[in] callbacks Pointer to array of callbacks.
* @param[in] callbacksCount Size of array of callbacks.
* @param[in] callback Callback which ID should be serialized.
*/
virtual void writeCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr callback) = 0;

/*!
* @brief Writes an order ID of callback function.
*
* @param[in] callback1 Pointer to existing callback.
* @param[out] callback2 Callback which ID should be serialized.
*/
virtual void writeCallback(funPtr callback1, funPtr callback2) = 0;
//@}

//! @name Decoding
Expand Down Expand Up @@ -410,23 +393,6 @@ class Codec
*/
virtual void readNullFlag(bool &isNull) = 0;

/*!
* @brief Read an callback function id and return address of callback function.
*
* @param[in] callbacks Pointer to array of callbacks.
* @param[in] callbacksCount Size of array of callbacks.
* @param[out] callback Callback which is deserialized. Null in case of error.
*/
virtual void readCallback(arrayOfFunPtr callbacks, uint8_t callbacksCount, funPtr *callback) = 0;

/*!
* @brief Read an callback function id and return address of callback function.
*
* @param[in] callback1 Pointer to existing callback.
* @param[out] callback2 Callback which is deserialized.
*/
virtual void readCallback(funPtr callbacks1, funPtr *callback2) = 0;

protected:
MessageBuffer m_buffer; /*!< Message buffer object */
MessageBuffer::Cursor m_cursor; /*!< Copy data to message buffers. */
Expand Down
2 changes: 1 addition & 1 deletion erpc_c/infra/erpc_framed_transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class FramedTransport : public Transport
*
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
*/
virtual Crc16 *getCrc16() override;
virtual Crc16 *getCrc16(void) override;

protected:
Crc16 *m_crcImpl; /*!< CRC object. */
Expand Down
2 changes: 1 addition & 1 deletion erpc_c/infra/erpc_manually_constructed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ManuallyConstructed
* @brief Returns information if object is free or is used.
*
* @return true Object is constructed and used.
* @return false Object wasn't constructer or it is destructed and free.
* @return false Object wasn't constructed or it was destructed already.
*/
bool isUsed(void) { return m_isConstructed; }

Expand Down
6 changes: 3 additions & 3 deletions erpc_c/infra/erpc_message_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ class MessageBuffer
Cursor &operator+=(uint16_t n);

/*!
* @brief Substract operator return local buffer.
* @brief Subtract operator return local buffer.
*
* @param[in] n Substracting with n.
* @param[in] n Subtracting with n.
*
* @return Current cursor instance.
*/
Expand All @@ -324,7 +324,7 @@ class MessageBuffer
Cursor &operator++(void);

/*!
* @brief Substract -1 operator.
* @brief Subtract -1 operator.
*
* @return Current cursor instance.
*/
Expand Down
1 change: 1 addition & 0 deletions erpc_c/infra/erpc_static_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define __embedded_rpc__static_queue__

#include <cstring>
#include <cstdint>

/*!
* @addtogroup infra_utility
Expand Down
6 changes: 3 additions & 3 deletions erpc_c/infra/erpc_transport_arbitrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TransportArbitrator : public Transport
*
* @return Transport * Returns shared client/server transport.
*/
Transport *getSharedTransport(void) { return m_sharedTransport; }
Transport * getSharedTransport(void) { return m_sharedTransport; }

/*!
* @brief This function set codec.
Expand All @@ -79,7 +79,7 @@ class TransportArbitrator : public Transport
*
* @return Codec * Pointer to codec used within transport.
*/
Codec *getCodec(void) { return m_codec; }
Codec * getCodec(void) { return m_codec; }

/*!
* @brief Prototype for receiving message.
Expand Down Expand Up @@ -140,7 +140,7 @@ class TransportArbitrator : public Transport
*
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
*/
virtual Crc16 *getCrc16(void) override;
virtual Crc16 * getCrc16(void) override;

/*!
* @brief Check if the underlying shared transport has a message
Expand Down
26 changes: 26 additions & 0 deletions erpc_c/infra/erpc_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "erpc_utils.hpp"

bool erpc::findIndexOfFunction(const arrayOfFunctionPtr_t sourceArrayOfFunctionPtr, uint16_t sourceArrayLength,
const functionPtr_t functionPtr, uint16_t &retVal)
{
uint32_t index;
bool find = false;
for (index = 0; index < sourceArrayLength; index++)
{
if (sourceArrayOfFunctionPtr[index] == functionPtr)
{
retVal = index;
find = true;
break;
}
}
return find;
}
17 changes: 17 additions & 0 deletions erpc_c/infra/erpc_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stdint.h>

namespace erpc {
typedef void *functionPtr_t;
typedef functionPtr_t *arrayOfFunctionPtr_t;

bool findIndexOfFunction(const arrayOfFunctionPtr_t sourceArrayOfFunctionPtr, uint16_t sourceArrayLength,
const functionPtr_t functionPtr, uint16_t &retVal);
}
2 changes: 1 addition & 1 deletion erpc_c/port/erpc_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int serial_setup(int fd, speed_t speed)

#ifdef __APPLE__
return ioctl(fd, IOSSIOSPEED, &speed);
#endif //#ifdef __APPLE__
#endif // #ifdef __APPLE__

#endif // _WIN32
return 0;
Expand Down
Loading

0 comments on commit 8616dbe

Please sign in to comment.