sbgInterface.h
Go to the documentation of this file.
1 
24 #ifndef __SBG_INTERFACE_H__
25 #define __SBG_INTERFACE_H__
26 
27 //----------------------------------------------------------------------//
28 //- Header (open extern C block) -//
29 //----------------------------------------------------------------------//
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sbgCommon.h>
35 
36 //----------------------------------------------------------------------//
37 //- Structure definitions -//
38 //----------------------------------------------------------------------//
39 
43 typedef enum _SbgInterfaceType
44 {
51 
52 //----------------------------------------------------------------------//
53 //- Predefinitions -//
54 //----------------------------------------------------------------------//
55 
59 typedef struct _SbgInterface SbgInterface;
60 
64 typedef void* SbgInterfaceHandle;
65 
66 //----------------------------------------------------------------------//
67 //- Callbacks definitions -//
68 //----------------------------------------------------------------------//
69 
77 typedef SbgErrorCode (*SbgInterfaceWriteFunc)(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite);
78 
87 typedef SbgErrorCode (*SbgInterfaceReadFunc)(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead);
88 
94 typedef bool (*SbgInterfaceIsValidFunc)(SbgInterface *pHandle);
95 
96 //----------------------------------------------------------------------//
97 //- Structures definitions -//
98 //----------------------------------------------------------------------//
99 
104 {
105  SbgInterfaceHandle handle;
106  SbgInterfaceType type;
111 };
112 
113 //----------------------------------------------------------------------//
114 //- Inline operations methods -//
115 //----------------------------------------------------------------------//
116 
122 {
123  //
124  // Test input argument
125  //
126  SBG_ASSERT(pHandle);
127 
128  //
129  // Initialize all fields to NULL
130  //
131  pHandle->handle = NULL;
132  pHandle->type = SBG_IF_TYPE_UNKNOW;
133  pHandle->pWriteFunc = NULL;
134  pHandle->pReadFunc = NULL;
135  pHandle->pIsValidFunc = NULL;
136 }
137 
144 {
145  //
146  // Check input arguments
147  //
148  SBG_ASSERT(pHandle);
149 
150  //
151  // To be valid, an interface should have a valid name, type and read / write method
152  // Optionally, we can also ask the interface to return a validity flag
153  //
154  if ( (pHandle->type != SBG_IF_TYPE_UNKNOW) && (pHandle->pWriteFunc) && (pHandle->pReadFunc) )
155  {
156  //
157  // Check if this interface has a specific valid method
158  //
159  if (pHandle->pIsValidFunc)
160  {
161  //
162  // Return the status of the interface specific valid method
163  //
164  return pHandle->pIsValidFunc(pHandle);
165  }
166  else
167  {
168  //
169  // This interface is valid
170  //
171  return true;
172  }
173  }
174  else
175  {
176  //
177  // This interface is invalid
178  //
179  return false;
180  }
181 }
182 
190 SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
191 {
192  //
193  // Test input arguments
194  //
195  SBG_ASSERT(pHandle);
196  SBG_ASSERT(pBuffer);
197 
198  //
199  // Call the correct write method according to the interface
200  //
201  return pHandle->pWriteFunc(pHandle, pBuffer, bytesToWrite);
202 }
203 
212 SBG_INLINE SbgErrorCode sbgInterfaceRead(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
213 {
214  //
215  // Test input arguments
216  //
217  SBG_ASSERT(pHandle);
218  SBG_ASSERT(pBuffer);
219  SBG_ASSERT(pReadBytes);
220 
221  //
222  // Call the correct read method according to the interface
223  //
224  return pHandle->pReadFunc(pHandle, pBuffer, pReadBytes, bytesToRead);
225 }
226 
227 //----------------------------------------------------------------------//
228 //- Footer (close extern C block) -//
229 //----------------------------------------------------------------------//
230 #ifdef __cplusplus
231 }
232 #endif
233 
234 #endif /* __INTERFACE_H__ */
_SbgInterfaceType
Definition: sbgInterface.h:43
bool(* SbgInterfaceIsValidFunc)(SbgInterface *pHandle)
Definition: sbgInterface.h:94
enum _SbgInterfaceType SbgInterfaceType
SbgInterfaceIsValidFunc pIsValidFunc
Definition: sbgInterface.h:110
SbgErrorCode(* SbgInterfaceWriteFunc)(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
Definition: sbgInterface.h:77
SbgInterfaceHandle handle
Definition: sbgInterface.h:105
SbgInterfaceReadFunc pReadFunc
Definition: sbgInterface.h:109
SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
Definition: sbgInterface.h:190
SBG_INLINE bool sbgInterfaceIsValid(SbgInterface *pHandle)
Definition: sbgInterface.h:143
#define NULL
Definition: sbgDefines.h:43
#define SBG_INLINE
Definition: sbgDefines.h:94
Main header file for SBG Systems common C library.
SbgErrorCode(* SbgInterfaceReadFunc)(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
Definition: sbgInterface.h:87
void * SbgInterfaceHandle
Definition: sbgInterface.h:64
SBG_INLINE SbgErrorCode sbgInterfaceRead(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
Definition: sbgInterface.h:212
#define SBG_ASSERT(expression)
Definition: sbgDebug.h:52
SBG_INLINE void sbgInterfaceZeroInit(SbgInterface *pHandle)
Definition: sbgInterface.h:121
SbgInterfaceType type
Definition: sbgInterface.h:106
SbgInterfaceWriteFunc pWriteFunc
Definition: sbgInterface.h:108
enum _SbgErrorCode SbgErrorCode


sbg_driver
Author(s):
autogenerated on Sun Jan 27 2019 03:42:20