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 **
|
73 mike 1.1 ** UNREACHABLE_RETURN
74 **
75 **==============================================================================
76 */
77
78 #if defined(CONFIG_PLATFORM_HPUX_IA64_HP)
79 # define UNREACHABLE_RETURN(EXPR) EXPR
80 #else
81 # define UNREACHABLE_RETURN(EXPR) /* empty */
82 #endif
83
84 /*
85 **==============================================================================
86 **
87 ** TRACE macro
88 **
89 **==============================================================================
90 */
91
92 #define TRACE printf("TRACE: %s(%u)\n", __FILE__, __LINE__)
93
94 mike 1.1 /*
95 **==============================================================================
96 **
97 ** Extended error codes (requires casting).
98 **
99 **==============================================================================
100 */
101
102 #define MI_RESULT_CANCELED ((MI_Result)1000)
103 #define MI_RESULT_OPEN_FAILED ((MI_Result)1001)
104 #define MI_RESULT_INVALID_CLASS_HIERARCHY ((MI_Result)1002)
105 #define MI_RESULT_WOULD_BLOCK ((MI_Result)1003)
106 #define MI_RESULT_TIME_OUT ((MI_Result)1004)
107 #define MI_RESULT_IN_PROGRESS ((MI_Result)1005)
108
109 /*
110 **==============================================================================
111 **
112 ** For testing the array bit of the MI_Type enumeration.
113 **
114 **==============================================================================
115 mike 1.1 */
116
117 #define MI_ARRAY_BIT 0x10
118
119 /*
120 **==============================================================================
121 **
122 ** ATTN: Temporary placeholders for various following argument types (replace
123 ** these later with correct parameters).
124 **
125 **==============================================================================
126 */
127
128 #define __nameSpace ((const MI_Char*)0)
129 #define __className ((const MI_Char*)0)
130 #define __methodName ((const MI_Char*)0)
131 #define __bookmark ((const MI_Char*)0)
132 #define __subscriptionIDCount ((MI_Uint32)0)
133 #define __subscriptionSelfPtr ((void**)0)
134 #define __subscriptionSelf ((void*)0)
135 #define __postIndication NULL
136 mike 1.1
137 /*
138 **==============================================================================
139 **
140 ** Basic type definitions.
141 **
142 **==============================================================================
143 */
144
145 typedef MI_Char* MI_String;
146 typedef const MI_Char* MI_ConstString;
147
148 /*
149 **==============================================================================
150 **
151 ** MI_UNUSED
152 **
153 **==============================================================================
154 */
155 #define MI_UNUSED(X) ((void)X)
156
157 mike 1.1 /*
158 **==============================================================================
159 **
160 ** EXTERNC
161 ** BEGIN_EXTERNC
162 ** END_EXTERNC
163 **
164 **==============================================================================
165 */
166
167 #if defined(__cplusplus)
168 # define EXTERNC extern "C"
169 # define BEGIN_EXTERNC extern "C" {
170 # define END_EXTERNC }
171 #else
172 # define EXTERNC /* empty */
173 # define BEGIN_EXTERNC /* empty */
174 # define END_EXTERNC /* empty */
175 #endif
176
177 /*
178 mike 1.1 **==============================================================================
179 **
180 ** INLINE macro
181 **
182 **==============================================================================
183 */
184
185 #if defined(_MSC_VER)
186 # define INLINE static __inline
187 #elif defined(__GNUC__)
188 # define INLINE static __inline
189 #elif defined(sun)
190 # define INLINE static inline
191 #elif defined(aix)
192 # define INLINE static inline
193 #else
194 # define INLINE static __inline
195 #endif
196
197 /*
198 **==============================================================================
199 mike 1.1 **
200 ** FUNCTION_NEVER_RETURNS macro
201 **
202 **==============================================================================
203 */
204
205 #if defined(_MSC_VER)
206 # define FUNCTION_NEVER_RETURNS __declspec(noreturn)
207 #else
208 # define FUNCTION_NEVER_RETURNS
209 #endif
210
211 /*
212 **==============================================================================
213 **
214 ** UINT64_FMT macro
215 ** SINT64_FMT macro
216 **
217 **==============================================================================
218 */
219
220 mike 1.1 #if defined(_MSC_VER)
221 # define UINT64_FMT "%I64u"
222 # define SINT64_FMT "%I64d"
223 # define UINT64_FMT_T MI_T("%I64u")
224 # define SINT64_FMT_T MI_T("%I64d")
225 #else
226 # define UINT64_FMT "%llu"
227 # define SINT64_FMT "%lld"
228 # define UINT64_FMT_T MI_T("%llu")
229 # define SINT64_FMT_T MI_T("%lld")
230 #endif
231
232 /*
233 **==============================================================================
234 **
235 ** MI_RETURN(RESULT)
236 **
237 ** Macro to return the given RESULT (other modules may override this macro
238 ** to add tracing or logging of error return values).
239 **
240 **==============================================================================
241 mike 1.1 */
242
243 #define MI_RETURN(RESULT) \
244 for (;;) \
245 { \
246 return RESULT; \
247 }
248
249 /*
250 **==============================================================================
251 **
252 ** MI_RETURN_ERR(RESULT)
253 **
254 ** Macro to return when RESULT is not MI_RESULT_OK (other modules may
255 ** override this macro to add tracing and logging of error return values).
256 **
257 **==============================================================================
258 */
259
260 #define MI_RETURN_ERR(RESULT) \
261 for (;;) \
262 mike 1.1 { \
263 MI_Result r = RESULT; \
264 if (r != MI_RESULT_OK) \
265 return r; \
266 break; \
267 }
268
269 /*
270 **==============================================================================
271 **
272 ** PRINTF_FORMAT(N,M)
273 **
274 ** Use this macro on functions that support a printf-style format argument.
275 ** This permits some compilers to check the arguments.
276 **
277 **==============================================================================
278 */
279
280 #if defined(__GNUC__) && (__GNUC__ >= 4)
281 # define PRINTF_FORMAT(N,M) __attribute__((format(printf, N, M)))
282 #else
283 mike 1.1 # define PRINTF_FORMAT(N,M) /* empty */
284 #endif
285
286 /*
287 **==============================================================================
288 **
289 ** DEBUG_ASSERT()
290 **
291 **==============================================================================
292 */
293
294 #if defined(CONFIG_ENABLE_DEBUG)
295 # define DEBUG_ASSERT(COND) assert(COND)
296 #else
297 # define DEBUG_ASSERT(COND) /* empty */
298 #endif
299
300 /*
301 **==============================================================================
302 **
303 ** stat() macros
304 mike 1.1 **
305 **==============================================================================
306 */
307
308 #if defined(_MSC_VER)
309 # define access _access
310 # define F_OK 0
311 # define W_OK 2
312 # define R_OK 4
313 #endif
314
315 /*
316 **==============================================================================
317 **
318 ** NULL_FILE macro
319 **
320 **==============================================================================
321 */
322
323 /* null-file - always can be opened/written and always ignored */
324 #if defined(_MSC_VER)
325 mike 1.1 # define NULL_FILE "nul"
326 #else
327 # define NULL_FILE "/dev/null"
328 #endif
329
330 /*
331 **==============================================================================
332 **
333 ** __FUNCTION__
334 **
335 **==============================================================================
336 */
337
338 #if !defined(CONFIG_HAVE_FUNCTION_MACRO)
339 # if !defined(_MSC_VER)
340 # define __FUNCTION__ "<unknown>"
341 # endif
342 #endif
343
344 /*
345 **==============================================================================
346 mike 1.1 **
347 ** CallSite type (used to track site of function invocations when enabled).
348 **
349 **==============================================================================
350 */
351
352 #if defined(CONFIG_ENABLE_DEBUG)
353
354 typedef struct _CallSite
355 {
356 const char* file;
357 size_t line;
358 const char* func;
359 }
360 CallSite;
361
362 MI_INLINE CallSite MakeCallSite(const char* file, size_t line, const char* func)
363 {
364 CallSite result;
365 result.file = file;
366 result.line = line;
367 mike 1.1 result.func = func;
368 return result;
369 }
370
371 # define CALLSITE MakeCallSite(__FILE__, __LINE__, __FUNCTION__)
372
373 #else /* defined(CONFIG_ENABLE_DEBUG) */
374
375 typedef int CallSite;
376
377 # define CALLSITE 0
378
379 #endif /* !defined(CONFIG_ENABLE_DEBUG) */
380
381 #endif /* _common_h */
|