From d7c00e31f4e9eef507a64e061c82721f3ef2eda1 Mon Sep 17 00:00:00 2001 From: Gabbla Date: Wed, 8 May 2024 10:24:14 +0200 Subject: [PATCH 1/2] client manager: added user context to error handler --- erpc_c/infra/erpc_client_manager.cpp | 2 +- erpc_c/infra/erpc_client_manager.h | 15 +++++++++++---- erpc_c/setup/erpc_arbitrated_client_setup.cpp | 4 ++-- erpc_c/setup/erpc_client_setup.cpp | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/erpc_c/infra/erpc_client_manager.cpp b/erpc_c/infra/erpc_client_manager.cpp index ef064b3d..f0b578a0 100644 --- a/erpc_c/infra/erpc_client_manager.cpp +++ b/erpc_c/infra/erpc_client_manager.cpp @@ -219,6 +219,6 @@ void ClientManager::callErrorHandler(erpc_status_t err, uint32_t functionID) { if (m_errorHandler != NULL) { - m_errorHandler(err, functionID); + m_errorHandler(err, functionID, m_errorHandlerContext); } } diff --git a/erpc_c/infra/erpc_client_manager.h b/erpc_c/infra/erpc_client_manager.h index 63a8bd12..4cc41824 100644 --- a/erpc_c/infra/erpc_client_manager.h +++ b/erpc_c/infra/erpc_client_manager.h @@ -29,8 +29,9 @@ extern "C" { #include "erpc_common.h" #endif -typedef void (*client_error_handler_t)(erpc_status_t err, - uint32_t functionID); /*!< eRPC error handler function type. */ +typedef void (*client_error_handler_t)(erpc_status_t err, /*!< eRPC error code. */ + uint32_t functionID, /*!< eRPC error handler function type. */ + void *context); /*!< User supplied context. */ //! @brief Opaque client object type. typedef struct ClientType *erpc_client_t; @@ -62,7 +63,7 @@ class ClientManager : public ClientServerCommon * This function initializes object attributes. */ ClientManager(void) : - ClientServerCommon(), m_sequence(0), m_errorHandler(NULL) + ClientServerCommon(), m_sequence(0), m_errorHandler(NULL), m_errorHandlerContext(NULL) #if ERPC_NESTED_CALLS , m_server(NULL), m_serverThreadId(NULL) @@ -100,8 +101,13 @@ class ClientManager : public ClientServerCommon * @brief This function sets error handler function for infrastructure errors. * * @param[in] error_handler Pointer to error handler function. + * @param[in] error_handler_context Pointer to error handler user context. */ - void setErrorHandler(client_error_handler_t error_handler) { m_errorHandler = error_handler; } + void setErrorHandler(client_error_handler_t error_handler, void *error_handler_context) + { + m_errorHandler = error_handler; + m_errorHandlerContext = error_handler_context; + } /*! * @brief This function calls error handler callback function with given status. @@ -132,6 +138,7 @@ class ClientManager : public ClientServerCommon protected: uint32_t m_sequence; //!< Sequence number. client_error_handler_t m_errorHandler; //!< Pointer to function error handler. + void *m_errorHandlerContext; //!< Pointer to a user supplied context. #if ERPC_NESTED_CALLS Server *m_server; //!< Server used for nested calls. Thread::thread_id_t m_serverThreadId; //!< Thread in which server run function is called. diff --git a/erpc_c/setup/erpc_arbitrated_client_setup.cpp b/erpc_c/setup/erpc_arbitrated_client_setup.cpp index 5ebcdbee..76f0f82f 100644 --- a/erpc_c/setup/erpc_arbitrated_client_setup.cpp +++ b/erpc_c/setup/erpc_arbitrated_client_setup.cpp @@ -34,7 +34,7 @@ ERPC_MANUALLY_CONSTRUCTED_STATIC(ArbitratedClientManager, s_client); #if defined(__MINGW32__) __declspec(selectany) #endif - ClientManager *g_client; +ClientManager *g_client; #if !defined(__MINGW32__) #pragma weak g_client #endif @@ -162,7 +162,7 @@ void erpc_arbitrated_client_set_error_handler(erpc_client_t client, client_error ArbitratedClientManager *clientManager = reinterpret_cast(client); - clientManager->setErrorHandler(error_handler); + clientManager->setErrorHandler(error_handler, NULL); } void erpc_arbitrated_client_set_crc(erpc_client_t client, uint32_t crcStart) diff --git a/erpc_c/setup/erpc_client_setup.cpp b/erpc_c/setup/erpc_client_setup.cpp index cd669f7e..6c674506 100644 --- a/erpc_c/setup/erpc_client_setup.cpp +++ b/erpc_c/setup/erpc_client_setup.cpp @@ -32,7 +32,7 @@ ERPC_MANUALLY_CONSTRUCTED_STATIC(ClientManager, s_client); #if defined(__MINGW32__) __declspec(selectany) #endif - ClientManager *g_client; +ClientManager *g_client; #if !defined(__MINGW32__) #pragma weak g_client #endif @@ -121,7 +121,7 @@ void erpc_client_set_error_handler(erpc_client_t client, client_error_handler_t ClientManager *clientManager = reinterpret_cast(client); - clientManager->setErrorHandler(error_handler); + clientManager->setErrorHandler(error_handler, NULL); } void erpc_client_set_crc(erpc_client_t client, uint32_t crcStart) From cd5429194a065a69856dd65661b6e652392fcb89 Mon Sep 17 00:00:00 2001 From: Gabbla Date: Wed, 8 May 2024 10:39:51 +0200 Subject: [PATCH 2/2] formatting: restored whitespaces --- erpc_c/setup/erpc_arbitrated_client_setup.cpp | 2 +- erpc_c/setup/erpc_client_setup.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/erpc_c/setup/erpc_arbitrated_client_setup.cpp b/erpc_c/setup/erpc_arbitrated_client_setup.cpp index 76f0f82f..6fbd37de 100644 --- a/erpc_c/setup/erpc_arbitrated_client_setup.cpp +++ b/erpc_c/setup/erpc_arbitrated_client_setup.cpp @@ -34,7 +34,7 @@ ERPC_MANUALLY_CONSTRUCTED_STATIC(ArbitratedClientManager, s_client); #if defined(__MINGW32__) __declspec(selectany) #endif -ClientManager *g_client; + ClientManager *g_client; #if !defined(__MINGW32__) #pragma weak g_client #endif diff --git a/erpc_c/setup/erpc_client_setup.cpp b/erpc_c/setup/erpc_client_setup.cpp index 6c674506..567d41ff 100644 --- a/erpc_c/setup/erpc_client_setup.cpp +++ b/erpc_c/setup/erpc_client_setup.cpp @@ -32,7 +32,7 @@ ERPC_MANUALLY_CONSTRUCTED_STATIC(ClientManager, s_client); #if defined(__MINGW32__) __declspec(selectany) #endif -ClientManager *g_client; + ClientManager *g_client; #if !defined(__MINGW32__) #pragma weak g_client #endif