Embedded Wireless Framework
ewf_allocator.h
Go to the documentation of this file.
1 /************************************************************************/
10 #ifndef __ewf_allocator__h__included__
11 #define __ewf_allocator__h__included__
12 
13 #include "ewf.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /************************************************************************/
27 {
28 #ifdef EWF_PARAMETER_CHECKING
29  uint32_t struct_magic;
30  uint32_t struct_size;
31  uint32_t struct_version;
32  uint32_t struct_type;
33 #endif /* EWF_PARAMETER_CHECKING */
34 
35  uint32_t block_size;
36  uint32_t block_count;
37 
38  ewf_result(*start)(ewf_allocator* allocator_ptr);
39  ewf_result(*stop)(ewf_allocator* allocator_ptr);
40  ewf_result(*allocate)(ewf_allocator* allocator_ptr, void** p);
41  ewf_result(*release)(ewf_allocator* allocator_ptr, void* p);
42 
43  void* implementation_ptr;
44 };
45 
46 #define EWF_ALLOCATOR_STRUCT_MAGIC (0xA110CA70) /* ~~ allocato(r) */
47 #define EWF_ALLOCATOR_STRUCT_SIZE (sizeof(struct _ewf_allocator))
48 #define EWF_ALLOCATOR_VERSION (EWF_DEVELOPER_MICROSOFT | 0x0001)
49 
50 #ifdef EWF_PARAMETER_CHECKING
51 #define EWF_ALLOCATOR_VALIDATE_POINTER(allocator_ptr) \
52 do { \
53  if ((allocator_ptr == NULL) || \
54  (allocator_ptr->struct_magic != EWF_ALLOCATOR_STRUCT_MAGIC) || \
55  (allocator_ptr->struct_size != EWF_ALLOCATOR_STRUCT_SIZE) || \
56  (allocator_ptr->struct_version != EWF_ALLOCATOR_VERSION) || \
57  (allocator_ptr->implementation_ptr == NULL)) \
58  { \
59  EWF_LOG_ERROR("The allocator pointer is invalid."); \
60  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
61  } \
62 } while(0)
63 #else
64 #define EWF_ALLOCATOR_VALIDATE_POINTER(allocator_ptr) \
65 do { \
66  if ((allocator_ptr == NULL) || \
67  (allocator_ptr->implementation_ptr == NULL)) \
68  { \
69  EWF_LOG_ERROR("The allocator pointer is invalid."); \
70  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
71  } \
72 } while(0)
73 #endif /* EWF_PARAMETER_CHECKING */
74 
75 #ifdef EWF_PARAMETER_CHECKING
76 #define EWF_ALLOCATOR_VALIDATE_POINTER_TYPE(allocator_ptr, allocator_type) \
77 do { \
78  if ((allocator_ptr == NULL) || \
79  (allocator_ptr->struct_type != allocator_type)) \
80  { \
81  EWF_LOG_ERROR("The allocator pointer type is invalid."); \
82  return EWF_RESULT_INVALID_FUNCTION_ARGUMENT; \
83  } \
84 } while(0)
85 #else
86 #define EWF_ALLOCATOR_VALIDATE_POINTER_TYPE(allocator_ptr, allocator_type)
87 #endif
88 
89 
96 
103 
110 ewf_result ewf_allocator_allocate(ewf_allocator* allocator_ptr, void ** p);
111 
118 ewf_result ewf_allocator_release(ewf_allocator* allocator_ptr, void * p);
119 
120 /************************************************************************/
124 #ifdef __cplusplus
125 }
126 #endif
127 
128 #endif /* __ewf_allocator__h__included__ */
The Embedded Wireless Framework.
ewf_result ewf_allocator_allocate(ewf_allocator *allocator_ptr, void **p)
Allocate a block from the allocator.
Definition: ewf_allocator.c:33
ewf_result ewf_allocator_release(ewf_allocator *allocator_ptr, void *p)
Release a block back to the allocator.
Definition: ewf_allocator.c:44
ewf_result ewf_allocator_start(ewf_allocator *allocator_ptr)
Start the allocator.
Definition: ewf_allocator.c:11
ewf_result ewf_allocator_stop(ewf_allocator *allocator_ptr)
Stop the allocator.
Definition: ewf_allocator.c:22
enum _ewf_result ewf_result
Success and error result codes specific to the EWF API.
The allocator structure definition.
Definition: ewf_allocator.h:27