1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _common_h
26 #define _common_h
27
28 #include "config.h"
29
30 #if defined(CONFIG_OS_LINUX)
31 #ifndef _GNU_SOURCE
32 #define _GNU_SOURCE
33 #endif
34 #endif
35
36 #include <MI.h>
37 #include <stdio.h>
38 #include <assert.h>
39 #include <stdarg.h>
40 #include <string.h>
41 #include <stdlib.h>
42 #include <errno.h>
43 mike 1.1
44 #if defined(_MSC_VER)
45 # define GetPath __GetPath__
46 # include <winsock2.h>
47 # include <windows.h>
48 # include <io.h>
49 # include <sal.h>
50 # include <direct.h>
51 # undef GetPath
52 #else
53 # include <sys/types.h>
54 # include <sys/stat.h>
55 # include <unistd.h>
56 # include <wchar.h>
57 #endif
58
59 /*
60 **==============================================================================
61 **
62 ** UNREACHABLE_RETURN
63 **
64 mike 1.1 **==============================================================================
65 */
66
67 #if defined(CONFIG_PLATFORM_HPUX_IA64_HP)
68 # define UNREACHABLE_RETURN(EXPR) EXPR
69 #else
70 # define UNREACHABLE_RETURN(EXPR) /* empty */
71 #endif
72
73 /*
74 **==============================================================================
75 **
76 ** TRACE macro
77 **
78 **==============================================================================
79 */
80
81 #define TRACE printf("TRACE: %s(%u)\n", __FILE__, __LINE__)
82
83 /*
84 **==============================================================================
85 mike 1.1 **
86 ** Extended error codes (requires casting).
87 **
88 **==============================================================================
89 */
90
91 #define MI_RESULT_CANCELED ((MI_Result)1000)
92 #define MI_RESULT_OPEN_FAILED ((MI_Result)1001)
93 #define MI_RESULT_INVALID_CLASS_HIERARCHY ((MI_Result)1002)
94 #define MI_RESULT_WOULD_BLOCK ((MI_Result)1003)
95 #define MI_RESULT_TIME_OUT ((MI_Result)1004)
96 #define MI_RESULT_IN_PROGRESS ((MI_Result)1005)
97
98 /*
99 **==============================================================================
100 **
101 ** For testing the array bit of the MI_Type enumeration.
102 **
103 **==============================================================================
104 */
105
106 mike 1.1 #define MI_ARRAY_BIT 0x10
107
108 /*
109 **==============================================================================
110 **
111 ** ATTN: Temporary placeholders for various following argument types (replace
112 ** these later with correct parameters).
113 **
114 **==============================================================================
115 */
116
117 #define __nameSpace ((const MI_Char*)0)
118 #define __className ((const MI_Char*)0)
119 #define __methodName ((const MI_Char*)0)
120 #define __bookmark ((const MI_Char*)0)
121 #define __subscriptionIDCount ((MI_Uint32)0)
122 #define __subscriptionSelfPtr ((void**)0)
123 #define __subscriptionSelf ((void*)0)
124 #define __postIndication NULL
125
126 /*
127 mike 1.1 **==============================================================================
128 **
129 ** Basic type definitions.
130 **
131 **==============================================================================
132 */
133
134 typedef MI_Char* MI_String;
135 typedef const MI_Char* MI_ConstString;
136
137 /*
138 **==============================================================================
139 **
140 ** MI_UNUSED
141 **
142 **==============================================================================
143 */
144 #define MI_UNUSED(X) ((void)X)
145
146 /*
147 **==============================================================================
148 mike 1.1 **
149 ** EXTERNC
150 ** BEGIN_EXTERNC
151 ** END_EXTERNC
152 **
153 **==============================================================================
154 */
155
156 #if defined(__cplusplus)
157 # define EXTERNC extern "C"
158 # define BEGIN_EXTERNC extern "C" {
159 # define END_EXTERNC }
160 #else
161 # define EXTERNC /* empty */
162 # define BEGIN_EXTERNC /* empty */
163 # define END_EXTERNC /* empty */
164 #endif
165
166 /*
167 **==============================================================================
168 **
169 mike 1.1 ** INLINE macro
170 **
171 **==============================================================================
172 */
173
174 #if defined(_MSC_VER)
175 # define INLINE static __inline
176 #elif defined(__GNUC__)
177 # define INLINE static __inline
178 #elif defined(sun)
179 # define INLINE static inline
180 #elif defined(aix)
181 # define INLINE static inline
182 #else
183 # define INLINE static __inline
184 #endif
185
186 /*
187 **==============================================================================
188 **
189 ** FUNCTION_NEVER_RETURNS macro
190 mike 1.1 **
191 **==============================================================================
192 */
193
194 #if defined(_MSC_VER)
195 # define FUNCTION_NEVER_RETURNS __declspec(noreturn)
196 #else
197 # define FUNCTION_NEVER_RETURNS
198 #endif
199
200 /*
201 **==============================================================================
202 **
203 ** UINT64_FMT macro
204 ** SINT64_FMT macro
205 **
206 **==============================================================================
207 */
208
209 #if defined(_MSC_VER)
210 # define UINT64_FMT "%I64u"
211 mike 1.1 # define SINT64_FMT "%I64d"
212 # define UINT64_FMT_T MI_T("%I64u")
213 # define SINT64_FMT_T MI_T("%I64d")
214 #else
215 # define UINT64_FMT "%llu"
216 # define SINT64_FMT "%lld"
217 # define UINT64_FMT_T MI_T("%llu")
218 # define SINT64_FMT_T MI_T("%lld")
219 #endif
220
221 /*
222 **==============================================================================
223 **
224 ** MI_RETURN(RESULT)
225 **
226 ** Macro to return the given RESULT (other modules may override this macro
227 ** to add tracing or logging of error return values).
228 **
229 **==============================================================================
230 */
231
232 mike 1.1 #define MI_RETURN(RESULT) \
233 for (;;) \
234 { \
235 return RESULT; \
236 }
237
238 /*
239 **==============================================================================
240 **
241 ** MI_RETURN_ERR(RESULT)
242 **
243 ** Macro to return when RESULT is not MI_RESULT_OK (other modules may
244 ** override this macro to add tracing and logging of error return values).
245 **
246 **==============================================================================
247 */
248
249 #define MI_RETURN_ERR(RESULT) \
250 for (;;) \
251 { \
252 MI_Result r = RESULT; \
253 mike 1.1 if (r != MI_RESULT_OK) \
254 return r; \
255 break; \
256 }
257
258 /*
259 **==============================================================================
260 **
261 ** PRINTF_FORMAT(N,M)
262 **
263 ** Use this macro on functions that support a printf-style format argument.
264 ** This permits some compilers to check the arguments.
265 **
266 **==============================================================================
267 */
268
269 #if defined(__GNUC__) && (__GNUC__ >= 4)
270 # define PRINTF_FORMAT(N,M) __attribute__((format(printf, N, M)))
271 #else
272 # define PRINTF_FORMAT(N,M) /* empty */
273 #endif
274 mike 1.1
275 /*
276 **==============================================================================
277 **
278 ** DEBUG_ASSERT()
279 **
280 **==============================================================================
281 */
282
283 #if defined(CONFIG_ENABLE_DEBUG)
284 # define DEBUG_ASSERT(COND) assert(COND)
285 #else
286 # define DEBUG_ASSERT(COND) /* empty */
287 #endif
288
289 /*
290 **==============================================================================
291 **
292 ** stat() macros
293 **
294 **==============================================================================
295 mike 1.1 */
296
297 #if defined(_MSC_VER)
298 # define access _access
299 # define F_OK 0
300 # define W_OK 2
301 # define R_OK 4
302 #endif
303
304 /*
305 **==============================================================================
306 **
307 ** NULL_FILE macro
308 **
309 **==============================================================================
310 */
311
312 /* null-file - always can be opened/written and always ignored */
313 #if defined(_MSC_VER)
314 # define NULL_FILE "nul"
315 #else
316 mike 1.1 # define NULL_FILE "/dev/null"
317 #endif
318
319 /*
320 **==============================================================================
321 **
322 ** __FUNCTION__
323 **
324 **==============================================================================
325 */
326
327 #if !defined(CONFIG_HAVE_FUNCTION_MACRO)
328 # if !defined(_MSC_VER)
329 # define __FUNCTION__ "<unknown>"
330 # endif
331 #endif
332
333 /*
334 **==============================================================================
335 **
336 ** CallSite type (used to track site of function invocations when enabled).
337 mike 1.1 **
338 **==============================================================================
339 */
340
341 #if defined(CONFIG_ENABLE_DEBUG)
342
343 typedef struct _CallSite
344 {
345 const char* file;
346 size_t line;
347 const char* func;
348 }
349 CallSite;
350
351 MI_INLINE CallSite MakeCallSite(const char* file, size_t line, const char* func)
352 {
353 CallSite result;
354 result.file = file;
355 result.line = line;
356 result.func = func;
357 return result;
358 mike 1.1 }
359
360 # define CALLSITE MakeCallSite(__FILE__, __LINE__, __FUNCTION__)
361
362 #else /* defined(CONFIG_ENABLE_DEBUG) */
363
364 typedef int CallSite;
365
366 # define CALLSITE 0
367
368 #endif /* !defined(CONFIG_ENABLE_DEBUG) */
369
370 #endif /* _common_h */
|