eRPC API Reference  Rev. 1.7.0
NXP Semiconductors
erpc_server.h
Go to the documentation of this file.
1 /*
2  * The Clear BSD License
3  * Copyright (c) 2014, 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__SERVER_H_
37 #define _EMBEDDED_RPC__SERVER_H_
38 
39 #include "erpc_codec.h"
40 #include "erpc_config_internal.h"
41 #if ERPC_NESTED_CALLS
42 #include "erpc_client_manager.h"
43 #endif
44 #if ERPC_MESSAGE_LOGGING
45 #include "erpc_message_loggers.h"
46 #endif
47 
54 // Classes
57 
58 namespace erpc {
59 #if ERPC_NESTED_CALLS
60 class RequestContext;
61 #endif
62 
67 class Service
68 {
69 public:
75  Service(uint32_t serviceId)
76  : m_serviceId(serviceId)
77  , m_next(NULL)
78  {
79  }
80 
84  virtual ~Service(void) {}
85 
91  uint32_t getServiceId(void) const { return m_serviceId; }
92 
98  Service *getNext(void) { return m_next; }
99 
105  void setNext(Service *next) { m_next = next; }
106 
117  virtual erpc_status_t handleInvocation(uint32_t methodId, uint32_t sequence, Codec *codec,
118  MessageBufferFactory *messageFactory) = 0;
119 
120 protected:
121  uint32_t m_serviceId;
123 };
124 
130 #if ERPC_MESSAGE_LOGGING
131 class Server : public MessageLoggers
132 #else
133 class Server
134 #endif
135 {
136 public:
142  Server(void)
143  : m_messageFactory()
144  , m_codecFactory()
145  , m_transport()
146  , m_firstService()
148  , MessageLoggers()
149 #endif
150  {
151  }
152 
156  virtual ~Server(void) {}
157 
163  void setMessageBufferFactory(MessageBufferFactory *factory) { m_messageFactory = factory; }
164 
170  void setCodecFactory(CodecFactory *factory) { m_codecFactory = factory; }
171 
179  void setTransport(Transport *transport);
180 
186  void addService(Service *service);
187 
191  virtual erpc_status_t run(void) = 0;
192 
196  virtual void stop(void) = 0;
197 
198 protected:
215  virtual erpc_status_t processMessage(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
216  uint32_t sequence);
217 
229  virtual erpc_status_t readHeadOfMessage(Codec *codec, message_type_t &msgType, uint32_t &serviceId,
230  uint32_t &methodId, uint32_t &sequence);
231 
239  virtual Service *findServiceWithId(uint32_t serviceId);
240 
241 #if ERPC_NESTED_CALLS
242  friend class ClientManager;
243  friend class ArbitratedClientManager;
244 
250  virtual erpc_status_t run(RequestContext &request) = 0;
251 #endif
252 
253 private:
254  // Disable copy ctor.
255  Server(const Server &);
256  Server &operator=(const Server &);
257 };
258 
259 } // namespace erpc
260 
263 #endif // _EMBEDDED_RPC__SERVER_H_
Abstract interface for transport layer.
Definition: erpc_transport.h:61
void setCodecFactory(CodecFactory *factory)
Set CodecFactory to use.
Definition: erpc_server.h:170
Service(uint32_t serviceId)
Constructor.
Definition: erpc_server.h:75
int32_t erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:112
message_type_t
Types of messages that can be encoded.
Definition: erpc_codec.h:59
Transport * m_transport
Definition: erpc_server.h:201
Base client implementation.
Definition: erpc_client_manager.h:83
Abstract interface for service, which can be executed on server side.
Definition: erpc_server.h:67
uint32_t m_serviceId
Definition: erpc_server.h:121
Abstract serialization encoder/decoder interface.
Definition: erpc_codec.h:76
CodecFactory * m_codecFactory
Definition: erpc_server.h:200
#define ERPC_MESSAGE_LOGGING
virtual ~Service(void)
Service destructor.
Definition: erpc_server.h:84
Service * m_next
Definition: erpc_server.h:122
Server(void)
Constructor.
Definition: erpc_server.h:142
virtual ~Server(void)
ClientManager destructor.
Definition: erpc_server.h:156
Abstract interface for codec factory.
Definition: erpc_codec.h:446
Service * getNext(void)
Return next service.
Definition: erpc_server.h:98
Client that can share a transport with a server.
Definition: erpc_arbitrated_client_manager.h:66
Based server functionality.
Definition: erpc_server.h:133
Definition: erpc_arbitrated_client_manager.h:51
void setMessageBufferFactory(MessageBufferFactory *factory)
Set MessageBufferFactory to use.
Definition: erpc_server.h:163
uint32_t getServiceId(void) const
Return service id number.
Definition: erpc_server.h:91
void setNext(Service *next)
Set next service.
Definition: erpc_server.h:105
MessageBufferFactory * m_messageFactory
Definition: erpc_server.h:199
virtual erpc_status_t handleInvocation(uint32_t methodId, uint32_t sequence, Codec *codec, MessageBufferFactory *messageFactory)=0
This function call function implementation of current service.
Abstract interface for message buffer factory.
Definition: erpc_message_buffer.h:390
Service * m_firstService
Definition: erpc_server.h:202
Logging messages functionality.
Definition: erpc_message_loggers.h:103
Encapsulates all information about a request.
Definition: erpc_client_manager.h:245