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 /* sbgCommonLib headers */
35 #include <sbgCommon.h>
36 
37 //----------------------------------------------------------------------//
38 //- Constant definitions -//
39 //----------------------------------------------------------------------//
40 
41 #define SBG_IF_NAME_MAX_SIZE (48)
46 #define SBG_IF_TYPE_UNKNOW (0)
47 #define SBG_IF_TYPE_SERIAL (1)
48 #define SBG_IF_TYPE_ETH_UDP (2)
49 #define SBG_IF_TYPE_ETH_TCP_IP (3)
50 #define SBG_IF_TYPE_FILE (4)
51 #define SBG_IF_TYPE_LAST_RESERVED (999)
53 //----------------------------------------------------------------------//
54 //- Predefinitions -//
55 //----------------------------------------------------------------------//
56 
60 typedef struct _SbgInterface SbgInterface;
61 
65 typedef void* SbgInterfaceHandle;
66 
67 //----------------------------------------------------------------------//
68 //- Callbacks definitions -//
69 //----------------------------------------------------------------------//
70 
82 typedef SbgErrorCode (*SbgInterfaceWriteFunc)(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite);
83 
97 typedef SbgErrorCode (*SbgInterfaceReadFunc)(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead);
98 
105 
115 typedef uint32_t (*SbgInterfaceGetDelayFunc)(SbgInterface *pHandle, size_t numBytes);
116 
117 //----------------------------------------------------------------------//
118 //- Structures definitions -//
119 //----------------------------------------------------------------------//
120 
132 {
133  SbgInterfaceHandle handle;
134  uint32_t type;
141 };
142 
143 //----------------------------------------------------------------------//
144 //- Public methods -//
145 //----------------------------------------------------------------------//
146 
153 
165 SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
166 {
167  assert(pHandle);
168  assert(pBuffer);
169  assert(pHandle->pWriteFunc);
170 
171  //
172  // Call the correct write method according to the interface
173  //
174  return pHandle->pWriteFunc(pHandle, pBuffer, bytesToWrite);
175 }
176 
190 SBG_INLINE SbgErrorCode sbgInterfaceRead(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
191 {
192  assert(pHandle);
193  assert(pBuffer);
194  assert(pReadBytes);
195  assert(pHandle->pReadFunc);
196 
197  //
198  // Call the correct read method according to the interface
199  //
200  return pHandle->pReadFunc(pHandle, pBuffer, pReadBytes, bytesToRead);
201 }
202 
212 {
213  SbgErrorCode errorCode;
214 
215  assert(pHandle);
216 
217  //
218  // The Flush method is optional so check if it has been defined.
219  //
220  if (pHandle->pFlushFunc)
221  {
222  //
223  // Call the correct flush method according to the interface
224  //
225  errorCode = pHandle->pFlushFunc(pHandle);
226  }
227  else
228  {
229  errorCode = SBG_NO_ERROR;
230  }
231 
232  return errorCode;
233 }
234 
244 SBG_INLINE uint32_t sbgInterfaceGetDelay(SbgInterface *pHandle, size_t numBytes)
245 {
246  assert(pHandle);
247 
248  //
249  // The get delay method is optional so check if it has been defined.
250  //
251  if (pHandle->pDelayFunc)
252  {
253  //
254  // Call the correct flush method according to the interface
255  //
256  return pHandle->pDelayFunc(pHandle, numBytes);
257  }
258 
259  return 0;
260 }
261 
268 SBG_INLINE uint32_t sbgInterfaceTypeGet(const SbgInterface *pInterface)
269 {
270  assert(pInterface);
271 
272  return pInterface->type;
273 }
274 
281 SBG_COMMON_LIB_API const char *sbgInterfaceTypeGetAsString(const SbgInterface *pInterface);
282 
289 SBG_INLINE const char *sbgInterfaceNameGet(const SbgInterface *pInterface)
290 {
291  assert(pInterface);
292 
293  return pInterface->name;
294 }
295 
308 SBG_COMMON_LIB_API void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName);
309 
310 //----------------------------------------------------------------------//
311 //- Footer (close extern C block) -//
312 //----------------------------------------------------------------------//
313 #ifdef __cplusplus
314 }
315 #endif
316 
317 #endif /* SBG_INTERFACE_H */
#define SBG_COMMON_LIB_API
Definition: sbgDefines.h:58
SBG_INLINE SbgErrorCode sbgInterfaceFlush(SbgInterface *pHandle)
Definition: sbgInterface.h:211
SBG_INLINE uint32_t sbgInterfaceGetDelay(SbgInterface *pHandle, size_t numBytes)
Definition: sbgInterface.h:244
SbgErrorCode(* SbgInterfaceWriteFunc)(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
Definition: sbgInterface.h:82
SBG_INLINE const char * sbgInterfaceNameGet(const SbgInterface *pInterface)
Definition: sbgInterface.h:289
uint32_t type
Definition: sbgInterface.h:134
SbgInterfaceHandle handle
Definition: sbgInterface.h:133
SbgInterfaceGetDelayFunc pDelayFunc
Definition: sbgInterface.h:140
SbgInterfaceReadFunc pReadFunc
Definition: sbgInterface.h:138
SBG_COMMON_LIB_API void sbgInterfaceZeroInit(SbgInterface *pHandle)
Definition: sbgInterface.c:24
SBG_INLINE SbgErrorCode sbgInterfaceWrite(SbgInterface *pHandle, const void *pBuffer, size_t bytesToWrite)
Definition: sbgInterface.h:165
#define SBG_IF_NAME_MAX_SIZE
Definition: sbgInterface.h:41
SBG_INLINE uint32_t sbgInterfaceTypeGet(const SbgInterface *pInterface)
Definition: sbgInterface.h:268
uint32_t(* SbgInterfaceGetDelayFunc)(SbgInterface *pHandle, size_t numBytes)
Definition: sbgInterface.h:115
#define SBG_INLINE
Definition: sbgDefines.h:186
Main header file for SBG Systems common C library.
SbgErrorCode(* SbgInterfaceReadFunc)(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
Definition: sbgInterface.h:97
void * SbgInterfaceHandle
Definition: sbgInterface.h:65
SBG_INLINE SbgErrorCode sbgInterfaceRead(SbgInterface *pHandle, void *pBuffer, size_t *pReadBytes, size_t bytesToRead)
Definition: sbgInterface.h:190
SbgInterfaceFlushFunc pFlushFunc
Definition: sbgInterface.h:139
char name[SBG_IF_NAME_MAX_SIZE]
Definition: sbgInterface.h:135
SbgInterfaceWriteFunc pWriteFunc
Definition: sbgInterface.h:137
enum _SbgErrorCode SbgErrorCode
SBG_COMMON_LIB_API void sbgInterfaceNameSet(SbgInterface *pInterface, const char *pName)
Definition: sbgInterface.c:61
SBG_COMMON_LIB_API const char * sbgInterfaceTypeGetAsString(const SbgInterface *pInterface)
Definition: sbgInterface.c:46
SbgErrorCode(* SbgInterfaceFlushFunc)(SbgInterface *pHandle)
Definition: sbgInterface.h:104


sbg_driver
Author(s): SBG Systems
autogenerated on Thu Oct 22 2020 03:47:22