| eRPC API Reference Rev. 1.8.1 NXP Semiconductors

- Main Page
- API Reference
- Classes
- Files

- File List
- File Members

erpc_message_buffer.h
Go to the documentation of this file.
1 /*
2 * Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
3 * Copyright 2016 NXP
4 * All rights reserved.
5 *
6 *
7 * SPDX-License-Identifier: BSD-3-Clause
8 */
9
10 #ifndef _EMBEDDED_RPC__MESSAGE_BUFFER_H_
11 #define _EMBEDDED_RPC__MESSAGE_BUFFER_H_
12
13 #include "erpc_common.h"
14
15 #include <cstddef>
16 #include <stdint.h>
17
24 // Classes
27
28 namespace erpc {
37 class MessageBuffer
38 {
39 public:
45 MessageBuffer(void)
46 : m_buf(NULL)
47 , m_len(0)
48 , m_used(0)
49 {
50 }
51
60 MessageBuffer(uint8_t *buffer, uint16_t length)
61 : m_buf(buffer)
62 , m_len(length)
63 , m_used(0)
64 {
65 }
66
75 void set(uint8_t *buffer, uint16_t length)
76 {
77 m_buf = buffer;
78 m_len = length;
79 m_used = 0;
80 }
81
87 uint8_t *get(void) { return m_buf; }
88
94 const uint8_t *get(void) const { return m_buf; }
95
101 uint16_t getLength(void) const { return m_len; }
102
108 uint16_t getUsed(void) const { return m_used; }
109
115 uint16_t getFree(void) const { return m_len - m_used; }
116
122 void setUsed(uint16_t used) { m_used = used; }
123
133 erpc_status_t read(uint16_t offset, void *data, uint32_t length);
134
144 erpc_status_t write(uint16_t offset, const void *data, uint32_t length);
145
153 erpc_status_t copy(const MessageBuffer *other);
154
160 void swap(MessageBuffer *other);
161
165 operator uint8_t *(void) { return m_buf; }
166
170 operator const uint8_t *(void) const { return m_buf; }
171
177 uint8_t &operator[](int index) { return m_buf[index]; }
178
184 const uint8_t &operator[](int index) const { return m_buf[index]; }
185
189 class Cursor
190 {
191 public:
197 Cursor(void)
198 : m_buffer(NULL)
199 , m_pos(NULL)
200 , m_remaining(0)
201 {
202 }
203
211 Cursor(MessageBuffer *buffer)
212 : m_buffer(buffer)
213 , m_pos(buffer->get())
214 , m_remaining(buffer->getLength())
215 {
216 }
217
223 void set(MessageBuffer *buffer);
224
232 uint8_t *get(void) { return m_pos; }
233
241 const uint8_t *get(void) const { return m_pos; }
242
248 uint16_t getRemaining(void) const { return m_remaining; }
249
259 erpc_status_t read(void *data, uint32_t length);
260
270 erpc_status_t write(const void *data, uint32_t length);
271
275 operator uint8_t *(void) { return m_pos; }
276
280 operator const uint8_t *(void) const { return m_pos; }
281
287 uint8_t &operator[](int index) { return m_pos[index]; }
288
294 const uint8_t &operator[](int index) const { return m_pos[index]; }
295
303 Cursor &operator+=(uint16_t n)
304 {
305 m_pos += n;
306 m_remaining -= n;
307 return *this;
308 }
309
317 Cursor &operator-=(uint16_t n)
318 {
319 m_pos -= n;
320 m_remaining += n;
321 return *this;
322 }
323
329 Cursor &operator++(void)
330 {
331 ++m_pos;
332 --m_remaining;
333 return *this;
334 }
335
341 Cursor &operator--(void)
342 {
343 --m_pos;
344 ++m_remaining;
345 return *this;
346 }
347
348 private:
349 MessageBuffer *m_buffer;
350 uint8_t *m_pos;
351 uint16_t m_remaining;
352 };
353
354 private:
355 uint8_t *volatile m_buf;
356 uint16_t volatile m_len;
357 uint16_t volatile m_used;
358 };
359
365 class MessageBufferFactory
366 {
367 public:
373 MessageBufferFactory(void) {}
374
378 virtual ~MessageBufferFactory(void) {}
379
385 virtual MessageBuffer create(void) = 0;
386
392 virtual bool createServerBuffer(void) { return true; }
393
402 virtual erpc_status_t prepareServerBufferForSend(MessageBuffer *message);
403
409 virtual void dispose(MessageBuffer *buf) = 0;
410 };
411
412 } // namespace erpc
413
416 #endif // _EMBEDDED_RPC__MESSAGE_BUFFER_H_
erpc::MessageBuffer::Cursor::getRemaining
uint16_t getRemaining(void) const
Return remaining free space in current buffer.
Definition: erpc_message_buffer.h:248
erpc::MessageBuffer::read
erpc_status_t read(uint16_t offset, void *data, uint32_t length)
This function read data from local buffer.
Definition: erpc_message_buffer.cpp:23
erpc::MessageBuffer::Cursor::operator[]
const uint8_t & operator[](int index) const
Array operator return value of buffer at given index.
Definition: erpc_message_buffer.h:294
erpc::MessageBuffer::Cursor::Cursor
Cursor(MessageBuffer *buffer)
Constructor.
Definition: erpc_message_buffer.h:211
erpc::MessageBuffer::copy
erpc_status_t copy(const MessageBuffer *other)
This function copy given message buffer to local instance.
Definition: erpc_message_buffer.cpp:65
erpc_status_t
enum _erpc_status erpc_status_t
Type used for all status and error return values.
Definition: erpc_common.h:87
erpc::MessageBuffer::MessageBuffer
MessageBuffer(void)
Constructor.
Definition: erpc_message_buffer.h:45
erpc::MessageBuffer::setUsed
void setUsed(uint16_t used)
This function sets length of used space of buffer.
Definition: erpc_message_buffer.h:122
erpc::MessageBufferFactory::~MessageBufferFactory
virtual ~MessageBufferFactory(void)
ClientManager destructor.
Definition: erpc_message_buffer.h:378
erpc::MessageBuffer::Cursor
Cursor within a MessageBuffer.
Definition: erpc_message_buffer.h:189
erpc::MessageBuffer::operator[]
uint8_t & operator[](int index)
Array operator return value of buffer at given index.
Definition: erpc_message_buffer.h:177
erpc::MessageBuffer::getUsed
uint16_t getUsed(void) const
This function returns length of used space of buffer.
Definition: erpc_message_buffer.h:108
erpc::MessageBuffer::Cursor::read
erpc_status_t read(void *data, uint32_t length)
Read data from current buffer.
Definition: erpc_message_buffer.cpp:99
erpc::MessageBuffer::Cursor::operator--
Cursor & operator--(void)
Substract -1 operator.
Definition: erpc_message_buffer.h:341
erpc::MessageBuffer::Cursor::get
uint8_t * get(void)
Return position in buffer.
Definition: erpc_message_buffer.h:232
erpc::MessageBufferFactory::MessageBufferFactory
MessageBufferFactory(void)
Constructor.
Definition: erpc_message_buffer.h:373
erpc::MessageBuffer::Cursor::operator[]
uint8_t & operator[](int index)
Array operator return value of buffer at given index.
Definition: erpc_message_buffer.h:287
erpc::MessageBuffer::Cursor::operator++
Cursor & operator++(void)
Sum +1 operator.
Definition: erpc_message_buffer.h:329
erpc::MessageBuffer::getLength
uint16_t getLength(void) const
This function returns length of buffer.
Definition: erpc_message_buffer.h:101
erpc::MessageBuffer::getFree
uint16_t getFree(void) const
This function returns length of free space of buffer.
Definition: erpc_message_buffer.h:115
erpc::MessageBuffer
Represents a memory buffer containing a message.
Definition: erpc_message_buffer.h:37
erpc
Definition: erpc_arbitrated_client_manager.h:25
erpc::MessageBuffer::swap
void swap(MessageBuffer *other)
This function swap message buffer attributes between given instance and local instance.
Definition: erpc_message_buffer.cpp:75
erpc::MessageBuffer::Cursor::Cursor
Cursor(void)
Constructor.
Definition: erpc_message_buffer.h:197
erpc::MessageBufferFactory::createServerBuffer
virtual bool createServerBuffer(void)
This function informs server if it has to create buffer for received message.
Definition: erpc_message_buffer.h:392
erpc::MessageBuffer::MessageBuffer
MessageBuffer(uint8_t *buffer, uint16_t length)
Constructor.
Definition: erpc_message_buffer.h:60
erpc::MessageBuffer::Cursor::write
erpc_status_t write(const void *data, uint32_t length)
Read data from current buffer.
Definition: erpc_message_buffer.cpp:121
erpc::MessageBufferFactory
Abstract interface for message buffer factory.
Definition: erpc_message_buffer.h:365
erpc::MessageBuffer::Cursor::operator-=
Cursor & operator-=(uint16_t n)
Substract operator return local buffer.
Definition: erpc_message_buffer.h:317
erpc::MessageBuffer::write
erpc_status_t write(uint16_t offset, const void *data, uint32_t length)
This function write data to local buffer.
Definition: erpc_message_buffer.cpp:44
erpc::MessageBuffer::Cursor::operator+=
Cursor & operator+=(uint16_t n)
Sum operator return local buffer.
Definition: erpc_message_buffer.h:303
erpc::MessageBuffer::operator[]
const uint8_t & operator[](int index) const
Array operator return value of buffer at given index.
Definition: erpc_message_buffer.h:184