eRPC API Reference  Rev. 1.7.0
NXP Semiconductors
erpc_client_manager.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
4  * Copyright 2016-2017 NXP
5  * All rights reserved.
6  *
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted (subject to the limitations in the disclaimer below) provided
10  * that the following conditions are met:
11  *
12  * o Redistributions of source code must retain the above copyright notice, this list
13  * of conditions and the following disclaimer.
14  *
15  * o Redistributions in binary form must reproduce the above copyright notice, this
16  * list of conditions and the following disclaimer in the documentation and/or
17  * other materials provided with the distribution.
18  *
19  * o Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from this
21  * software without specific prior written permission.
22  *
23  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef _EMBEDDED_RPC__CLIENT_MANAGER_H_
37 #define _EMBEDDED_RPC__CLIENT_MANAGER_H_
38 
39 #ifdef __cplusplus
40 #include "erpc_codec.h"
41 #include "erpc_config_internal.h"
42 #if ERPC_MESSAGE_LOGGING
43 #include "erpc_message_loggers.h"
44 #endif
45 #if ERPC_NESTED_CALLS
46 #include "erpc_server.h"
47 #include "erpc_threading.h"
48 #endif
49 
56 extern "C" {
57 #endif
58 
60  uint32_t functionID);
62 #ifdef __cplusplus
63 }
64 
66 // Classes
68 
69 namespace erpc {
70 class RequestContext;
71 #if ERPC_NESTED_CALLS
72 class Server;
73 #endif
74 
80 #if ERPC_MESSAGE_LOGGING
81 class ClientManager : public MessageLoggers
82 #else
84 #endif
85 {
86 public:
93  : m_messageFactory(NULL)
94  , m_codecFactory(NULL)
95  , m_transport(NULL)
96  , m_sequence(0)
97  , m_errorHandler(NULL)
99  , m_server(NULL)
100  , m_serverThreadId(NULL)
101 #endif
103  , MessageLoggers()
104 #endif
105  {
106  }
107 
111  virtual ~ClientManager(void) {}
112 
119 
125  void setCodecFactory(CodecFactory *factory) { m_codecFactory = factory; }
126 
134  void setTransport(Transport *transport);
135 
141  virtual RequestContext createRequest(bool isOneway);
142 
148  virtual erpc_status_t performRequest(RequestContext &request);
149 
155  virtual void releaseRequest(RequestContext &request);
156 
162  void setErrorHandler(client_error_handler_t error_handler) { m_errorHandler = error_handler; }
163 
172  void callErrorHandler(erpc_status_t err, uint32_t functionID);
173 
174 #if ERPC_NESTED_CALLS
175 
180  void setServer(Server *server) { m_server = server; }
181 
187  void setServerThreadId(Thread::thread_id_t serverThreadId) { m_serverThreadId = serverThreadId; }
188 #endif
189 
190 protected:
194  uint32_t m_sequence;
196 #if ERPC_NESTED_CALLS
197  Server *m_server;
198  Thread::thread_id_t m_serverThreadId;
199 #endif
200 
210 
211 #if ERPC_NESTED_CALLS
212 
219  virtual erpc_status_t performNestedClientRequest(RequestContext &request);
220 #endif
221 
223  virtual erpc_status_t verifyReply(RequestContext &request);
224 
234 
235 private:
236  ClientManager(const ClientManager &);
237  ClientManager &operator=(const ClientManager &);
238 };
239 
246 {
247 public:
257  RequestContext(uint32_t sequence, Codec *codec, bool isOneway)
258  : m_sequence(sequence)
259  , m_codec(codec)
260  , m_oneway(isOneway)
261  {
262  }
263 
269  Codec *getCodec(void) { return m_codec; }
270 
276  uint32_t getSequence(void) const { return m_sequence; }
277 
283  bool isOneway(void) const { return m_oneway; }
284 
290  void setIsOneway(bool oneway) { m_oneway = oneway; }
291 
292 protected:
293  uint32_t m_sequence;
295  bool m_oneway;
296 };
297 
298 } // namespace erpc
299 
302 #endif
303 
304 #endif // _EMBEDDED_RPC__CLIENT_MANAGER_H_
Abstract interface for transport layer.
Definition: erpc_transport.h:61
int32_t erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:112
Transport * m_transport
Transport layer to use.
Definition: erpc_client_manager.h:193
virtual erpc_status_t performClientRequest(RequestContext &request)
This function performs request.
Definition: erpc_client_manager.cpp:76
virtual erpc_status_t performRequest(RequestContext &request)
This function performs request.
Definition: erpc_client_manager.cpp:64
Base client implementation.
Definition: erpc_client_manager.h:83
uint32_t m_sequence
Sequence number.
Definition: erpc_client_manager.h:194
Abstract serialization encoder/decoder interface.
Definition: erpc_codec.h:76
CodecFactory * m_codecFactory
Codec to use.
Definition: erpc_client_manager.h:192
bool m_oneway
When true, request context will be oneway type (only send data).
Definition: erpc_client_manager.h:295
uint32_t m_sequence
Sequence number. To be sure that reply belong to current request.
Definition: erpc_client_manager.h:293
void setIsOneway(bool oneway)
Set request context to be oneway type (only send data).
Definition: erpc_client_manager.h:290
#define ERPC_MESSAGE_LOGGING
void callErrorHandler(erpc_status_t err, uint32_t functionID)
This function calls error handler callback function with given status.
Definition: erpc_client_manager.cpp:238
bool isOneway(void) const
Returns information if request context is oneway or not.
Definition: erpc_client_manager.h:283
Abstract interface for codec factory.
Definition: erpc_codec.h:446
ClientManager(void)
Constructor.
Definition: erpc_client_manager.h:92
void setTransport(Transport *transport)
This function sets transport layer to use.
Definition: erpc_client_manager.cpp:51
virtual erpc_status_t verifyReply(RequestContext &request)
Validate that an incoming message is a reply.
Definition: erpc_client_manager.cpp:184
Based server functionality.
Definition: erpc_server.h:133
uint32_t getSequence(void) const
Get sequence number (be sure that reply belong to current request).
Definition: erpc_client_manager.h:276
#define ERPC_NESTED_CALLS
Definition: erpc_arbitrated_client_manager.h:51
MessageBufferFactory * m_messageFactory
Message buffer factory to use.
Definition: erpc_client_manager.h:191
virtual ~ClientManager(void)
ClientManager destructor.
Definition: erpc_client_manager.h:111
Codec * getCodec(void)
Get inout codec (for writing).
Definition: erpc_client_manager.h:269
Codec * m_codec
Inout codec. Codec for receiving and sending data.
Definition: erpc_client_manager.h:294
Codec * createBufferAndCodec(void)
Create message buffer and codec.
Definition: erpc_client_manager.cpp:211
void(* client_error_handler_t)(erpc_status_t err, uint32_t functionID)
Definition: erpc_client_manager.h:59
void * thread_id_t
Unique identifier for a thread.
Definition: erpc_threading.h:86
virtual RequestContext createRequest(bool isOneway)
This function creates request context.
Definition: erpc_client_manager.cpp:56
Abstract interface for message buffer factory.
Definition: erpc_message_buffer.h:390
RequestContext(uint32_t sequence, Codec *codec, bool isOneway)
Constructor.
Definition: erpc_client_manager.h:257
void setCodecFactory(CodecFactory *factory)
This function sets codec factory to use.
Definition: erpc_client_manager.h:125
void setErrorHandler(client_error_handler_t error_handler)
This function sets error handler function for infrastructure errors.
Definition: erpc_client_manager.h:162
void setMessageBufferFactory(MessageBufferFactory *factory)
This function sets message buffer factory to use.
Definition: erpc_client_manager.h:118
Logging messages functionality.
Definition: erpc_message_loggers.h:103
virtual void releaseRequest(RequestContext &request)
This function releases request context.
Definition: erpc_client_manager.cpp:232
Encapsulates all information about a request.
Definition: erpc_client_manager.h:245
client_error_handler_t m_errorHandler
Pointer to function error handler.
Definition: erpc_client_manager.h:195