sbgPlatform.c
Go to the documentation of this file.
1 #include "sbgPlatform.h"
2 #include <stdarg.h>
3 #include <time.h>
4 
5 //----------------------------------------------------------------------//
6 //- Include specific header for WIN32 and UNIX platforms -//
7 //----------------------------------------------------------------------//
8 #ifdef WIN32
9  #include <windows.h>
10 #elif defined(__APPLE__)
11  #include <mach/mach_time.h>
12 #else
13  #include <unistd.h>
14 #endif
15 
16 //----------------------------------------------------------------------//
17 //- Specific timing methods to reimplement for your platform -//
18 //----------------------------------------------------------------------//
19 
25 {
26 #ifdef WIN32
27  //
28  // Return the current time in ms
29  //
30  return clock() / (CLOCKS_PER_SEC / 1000);
31 #elif defined(__APPLE__)
32  mach_timebase_info_data_t timeInfo;
33  mach_timebase_info(&timeInfo);
34 
35  //
36  // Return the current time in ms
37  //
38  return (mach_absolute_time() * timeInfo.numer / timeInfo.denom) / 1000000.0;
39 #else
40  struct timespec now;
41  clock_gettime(CLOCK_REALTIME, &now);
42 
43  //
44  // Return the current time in ms
45  //
46  return now.tv_sec * 1000 + now.tv_nsec / 1000000;
47 #endif
48 }
49 
54 void sbgSleep(uint32 ms)
55 {
56  //
57  // Implementation valid for both WIN and UNIX systems
58  //
59  #ifdef WIN32
60  Sleep(ms);
61  #else
62  usleep(ms*1000);
63  #endif
64 }
65 
66 //----------------------------------------------------------------------//
67 //- Specific logging methods to reimplement for your platform -//
68 //----------------------------------------------------------------------//
69 
80 void sbgPlatformDebugLogMsg(const char *pFileName, const char *pFunctionName, uint32 line, SbgDebugLogType logType, SbgErrorCode errorCode, const char *pFormat, ...)
81 {
82  char errorMsg[1024];
83  va_list args;
84  //const char *pFileNameTmp;
85 
86  //
87  // Initialize the list of variable arguments on the latest function argument
88  //
89  va_start(args, pFormat);
90 
91  //
92  // Generate the error message string
93  //
94  vsprintf(errorMsg, pFormat, args);
95 
96  //
97  // Close the list of variable arguments
98  //
99  va_end(args);
100 
101  //
102  // Log the correct message according to the log type
103  //
104  switch (logType)
105  {
107  //
108  // Write the complete error messages
109  //
110  fprintf(stderr, "* ERROR * [%s]%s: %s\n\r", sbgErrorCodeToString(errorCode), pFunctionName, errorMsg);
111  break;
113  //
114  // Write the complete warning messages
115  //
116  fprintf(stderr, "*WARNING* [%s]%s: %s\n\r", sbgErrorCodeToString(errorCode), pFunctionName, errorMsg);
117  break;
119  //
120  // Write the complete information messages
121  //
122  fprintf(stderr, "* INFO * %s\n\r", errorMsg);
123  break;
125  //
126  // Write the complete verbose messages
127  //
128  fprintf(stderr, "*VERBOSE* %s\n\r", errorMsg);
129  break;
130  default:
131  //
132  // Write the complete unknown type messages
133  //
134  fprintf(stderr, "*UNKNOWN*\t[%s]%s(%u): %s\n\r", sbgErrorCodeToString(errorCode), pFunctionName, line, errorMsg);
135  }
136 }
void sbgPlatformDebugLogMsg(const char *pFileName, const char *pFunctionName, uint32 line, SbgDebugLogType logType, SbgErrorCode errorCode, const char *pFormat,...)
Definition: sbgPlatform.c:80
unsigned int uint32
Definition: sbgTypes.h:58
void sbgSleep(uint32 ms)
Definition: sbgPlatform.c:54
Header file that contains all platform specific definitions.
SBG_INLINE const char * sbgErrorCodeToString(SbgErrorCode errorCode)
Definition: sbgErrorCodes.h:71
enum _SbgDebugLogType SbgDebugLogType
uint32 sbgGetTime(void)
Definition: sbgPlatform.c:24
enum _SbgErrorCode SbgErrorCode


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