Initial Commit
[apps/agl-service-unicens.git] / ucs2-lib / inc / ucs_memory.h
1 /*------------------------------------------------------------------------------------------------*/
2 /* UNICENS V2.1.0-3491                                                                            */
3 /* Copyright (c) 2017 Microchip Technology Germany II GmbH & Co. KG.                              */
4 /*                                                                                                */
5 /* This program is free software: you can redistribute it and/or modify                           */
6 /* it under the terms of the GNU General Public License as published by                           */
7 /* the Free Software Foundation, either version 2 of the License, or                              */
8 /* (at your option) any later version.                                                            */
9 /*                                                                                                */
10 /* This program is distributed in the hope that it will be useful,                                */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of                                 */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                  */
13 /* GNU General Public License for more details.                                                   */
14 /*                                                                                                */
15 /* You should have received a copy of the GNU General Public License                              */
16 /* along with this program.  If not, see <http://www.gnu.org/licenses/>.                          */
17 /*                                                                                                */
18 /* You may also obtain this software under a propriety license from Microchip.                    */
19 /* Please contact Microchip for further information.                                              */
20 /*------------------------------------------------------------------------------------------------*/
21
22 /*!
23  * \file
24  * \brief Declaration of internal memory buffer
25  *
26  * \cond UCS_INTERNAL_DOC
27  * \addtogroup  G_MEMORY
28  * @{
29  */
30
31 #ifndef UCS_MEMORY_H
32 #define UCS_MEMORY_H
33
34 /*------------------------------------------------------------------------------------------------*/
35 /* Includes                                                                                       */
36 /*------------------------------------------------------------------------------------------------*/
37 #include "ucs_memory_pb.h"
38
39 #ifdef __cplusplus
40 extern "C"
41 {
42 #endif
43
44 /*------------------------------------------------------------------------------------------------*/
45 /* IAllocator Types                                                                               */
46 /*------------------------------------------------------------------------------------------------*/
47 /*! \brief      Callback function which frees memory 
48  *  \param      allocator       Reference to the Mem_Allocator_t object
49  *  \param      mem_ptr         Reference to memory chunk 
50  *  \param      mem_info_ptr    Customer specific information needed to free 
51  *                              the related memory chunk
52  */
53 typedef void  (*Mem_Free_t)(void *allocator, void* mem_ptr, void* mem_info_ptr);
54
55 /*! \brief      Callback function which allocated memory 
56  *  \param      allocator       Reference to the Mem_Allocator_t object
57  *  \param      size            Size of the demanded memory chunk 
58  *  \param      mem_info_ptr    Customer specific information needed to free 
59  *                              the related memory chunk
60  *  \return     Reference to a memory chunk with a minimum size of \c size. 
61  *              Otherwise NULL.
62  */
63 typedef void* (*Mem_Allocate_t)(void *allocator, uint16_t size, void** mem_info_ptr);
64
65 /*------------------------------------------------------------------------------------------------*/
66 /* Interface IAllocator                                                                           */
67 /*------------------------------------------------------------------------------------------------*/
68 /*! \brief Interface which is needed to be implemented by a memory allocator */
69 typedef struct IAllocator_
70 {
71     void*              base;            /*!< Reference to the base class */
72     Mem_Allocate_t     allocate_fptr;   /*!< Callback function required to allocate memory */
73     Mem_Free_t         free_fptr;       /*!< Callback function required to free memory */
74
75 } IAllocator;
76
77
78 /*------------------------------------------------------------------------------------------------*/
79 /* Memory buffer                                                                                  */
80 /*------------------------------------------------------------------------------------------------*/
81 /*! \brief Memory chunk comprising non public fields */
82 typedef struct Mem_IntBuffer_
83 {
84     Ucs_Mem_Buffer_t   public_buffer;  /*!< \brief      Public attributes of memory buffer
85                                         *   \details    This has to be the first member in this 
86                                         *               struct
87                                         */
88     IAllocator        *allocator_ptr;  /*!< \brief      Reference to the allocator which is 
89                                         *               required to free the memory chunk 
90                                         */
91     void              *mem_info_ptr;   /*!< \brief      Customer specific information needed to 
92                                         *               free the related memory chunk
93                                         */
94 } Mem_IntBuffer_t;
95
96 #ifdef __cplusplus
97 }                                                   /* extern "C" */
98 #endif
99
100 #endif /* #ifndef UCS_MEMORY_H */
101
102 /*!
103  * @}
104  * \endcond
105  */
106
107 /*------------------------------------------------------------------------------------------------*/
108 /* End of file                                                                                    */
109 /*------------------------------------------------------------------------------------------------*/
110