(file) Return to common.h CVS log (file) (dir) Up to [OMI] / omi / common

  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 krisbash 1.4 #include <pal/memory.h>
 30 mike     1.1 
 31              #if defined(CONFIG_OS_LINUX)
 32              #ifndef _GNU_SOURCE
 33              #define _GNU_SOURCE
 34              #endif
 35              #endif
 36              
 37 krisbash 1.4 /* Define version for omigen:gen.cpp */
 38              #define _MIAPIVERSION 2
 39              
 40 mike     1.1 #include <MI.h>
 41              #include <stdio.h>
 42              #include <assert.h>
 43              #include <stdarg.h>
 44              #include <string.h>
 45              #include <stdlib.h>
 46 krisbash 1.4 #include <stdio.h>
 47 mike     1.1 #include <errno.h>
 48              
 49              #if defined(_MSC_VER)
 50              # include <winsock2.h>
 51              # include <windows.h>
 52              # include <io.h>
 53              # include <sal.h>
 54              # include <direct.h>
 55 krisbash 1.4 # include <ntassert.h>
 56 mike     1.1 #else
 57              # include <sys/types.h>
 58              # include <sys/stat.h>
 59              # include <unistd.h>
 60              # include <wchar.h>
 61 krisbash 1.4 # include <linux/sal.h>
 62 mike     1.1 #endif
 63              
 64 krisbash 1.4 #include "localizestr.h"
 65              
 66              
 67              // Following will be used to limit the buffere size server can accept from provider host.
 68              // This is also used to limit the max size on http transport
 69              #define MAX_ENVELOPE_SIZE   (250*1024)
 70              
 71              
 72 mike     1.1 /*
 73              **==============================================================================
 74              **
 75 mike     1.2 ** Binary form of version:
 76              **
 77              **==============================================================================
 78              */
 79              
 80              #define CONFIG_VERSION_MASK \
 81                  ((CONFIG_MAJOR << 16) | (CONFIG_MINOR << 8) | CONFIG_REVISION)
 82              
 83              /*
 84              **==============================================================================
 85              **
 86 mike     1.1 ** UNREACHABLE_RETURN
 87              **
 88              **==============================================================================
 89              */
 90              
 91              #if defined(CONFIG_PLATFORM_HPUX_IA64_HP)
 92              # define UNREACHABLE_RETURN(EXPR) EXPR
 93              #else
 94              # define UNREACHABLE_RETURN(EXPR) /* empty */
 95              #endif
 96              
 97              /*
 98              **==============================================================================
 99              **
100              ** TRACE macro
101              **
102              **==============================================================================
103              */
104              
105 krisbash 1.4 #if defined(CONFIG_ENABLE_WCHAR)
106              # define TRACE Wprintf(L"TRACE: %s(%u)\n", __FILE__, __LINE__)
107              #else
108              # define TRACE Printf("TRACE: %s(%u)\n", __FILE__, __LINE__)
109              #endif
110 mike     1.1 
111              /*
112              **==============================================================================
113              **
114              ** Extended error codes (requires casting).
115              **
116              **==============================================================================
117              */
118              
119              #define MI_RESULT_CANCELED ((MI_Result)1000)
120              #define MI_RESULT_OPEN_FAILED ((MI_Result)1001)
121              #define MI_RESULT_INVALID_CLASS_HIERARCHY ((MI_Result)1002)
122              #define MI_RESULT_WOULD_BLOCK ((MI_Result)1003)
123              #define MI_RESULT_TIME_OUT ((MI_Result)1004)
124              #define MI_RESULT_IN_PROGRESS ((MI_Result)1005)
125              
126              /*
127              **==============================================================================
128              **
129              ** For testing the array bit of the MI_Type enumeration.
130              **
131 mike     1.1 **==============================================================================
132              */
133              
134              #define MI_ARRAY_BIT 0x10
135              
136              /*
137              **==============================================================================
138              **
139              ** ATTN: Temporary placeholders for various following argument types (replace
140              ** these later with correct parameters).
141              **
142              **==============================================================================
143              */
144              
145              #define __nameSpace ((const MI_Char*)0)
146              #define __className ((const MI_Char*)0)
147              #define __methodName ((const MI_Char*)0)
148              
149              /*
150              **==============================================================================
151              **
152 mike     1.1 ** Basic type definitions.
153              **
154              **==============================================================================
155              */
156              
157              typedef MI_Char* MI_String;
158              typedef const MI_Char* MI_ConstString;
159 krisbash 1.4 typedef MI_Char ZChar;
160              
161              #define ZT MI_T
162 mike     1.1 
163              /*
164              **==============================================================================
165              **
166              ** MI_UNUSED
167              **
168              **==============================================================================
169              */
170              #define MI_UNUSED(X) ((void)X)
171              
172              /*
173              **==============================================================================
174              **
175              ** EXTERNC
176              ** BEGIN_EXTERNC
177              ** END_EXTERNC
178              **
179              **==============================================================================
180              */
181              
182              #if defined(__cplusplus)
183 mike     1.1 # define EXTERNC extern "C"
184              # define BEGIN_EXTERNC extern "C" {
185              # define END_EXTERNC }
186              #else
187              # define EXTERNC /* empty */
188              # define BEGIN_EXTERNC /* empty */
189              # define END_EXTERNC /* empty */
190              #endif
191              
192              /*
193              **==============================================================================
194              **
195              ** INLINE macro
196              **
197              **==============================================================================
198              */
199              
200              #if defined(_MSC_VER)
201              # define INLINE static __inline
202              #elif defined(__GNUC__)
203              # define INLINE static __inline
204 mike     1.1 #elif defined(sun)
205              # define INLINE static inline
206 krisbash 1.4 #elif defined(__PPC)
207              # define INLINE __inline__
208 mike     1.1 #else
209              # define INLINE static __inline
210              #endif
211              
212              /*
213              **==============================================================================
214              **
215              ** FUNCTION_NEVER_RETURNS macro
216              **
217              **==============================================================================
218              */
219              
220              #if defined(_MSC_VER)
221              # define FUNCTION_NEVER_RETURNS __declspec(noreturn)
222              #else
223              # define FUNCTION_NEVER_RETURNS
224              #endif
225              
226              /* 
227              **==============================================================================
228              **
229 mike     1.1 ** UINT64_FMT macro
230              ** SINT64_FMT macro
231              **
232              **==============================================================================
233              */
234              
235              #if defined(_MSC_VER)
236              # define UINT64_FMT "%I64u"
237              # define SINT64_FMT "%I64d"
238              # define UINT64_FMT_T MI_T("%I64u")
239              # define SINT64_FMT_T MI_T("%I64d")
240              #else
241              # define UINT64_FMT "%llu"
242              # define SINT64_FMT "%lld"
243              # define UINT64_FMT_T MI_T("%llu")
244              # define SINT64_FMT_T MI_T("%lld")
245              #endif
246              
247              /*
248              **==============================================================================
249              **
250 mike     1.1 ** MI_RETURN(RESULT)
251              **
252              **     Macro to return the given RESULT (other modules may override this macro 
253              **     to add tracing or logging of error return values).
254              **
255              **==============================================================================
256              */
257              
258              #define MI_RETURN(RESULT) \
259                  for (;;) \
260                  { \
261                      return RESULT; \
262                  }
263              
264              /*
265              **==============================================================================
266              **
267              ** MI_RETURN_ERR(RESULT)
268              **
269              **     Macro to return when RESULT is not MI_RESULT_OK (other modules may
270              **     override this macro to add tracing and logging of error return values).
271 mike     1.1 **
272              **==============================================================================
273              */
274              
275              #define MI_RETURN_ERR(RESULT) \
276                  for (;;) \
277                  { \
278                      MI_Result r = RESULT; \
279                      if (r != MI_RESULT_OK) \
280                          return r; \
281                      break; \
282                  }
283              
284              /*
285              **==============================================================================
286              **
287              ** PRINTF_FORMAT(N,M)
288              **
289              **     Use this macro on functions that support a printf-style format argument.
290              **     This permits some compilers to check the arguments.
291              **
292 mike     1.1 **==============================================================================
293              */
294              
295 krisbash 1.4 #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(CONFIG_ENABLE_WCHAR)
296 mike     1.1 # define PRINTF_FORMAT(N,M) __attribute__((format(printf, N, M)))
297              #else
298              # define PRINTF_FORMAT(N,M) /* empty */
299              #endif
300              
301              /*
302              **==============================================================================
303              **
304 krisbash 1.4 **  TIMEOUT FOR CALLS TO select()
305              **
306              **     Value, in msec, that different platforms need to fill or empty a
307              **     communications socket.
308              **
309              **==============================================================================
310              */
311              
312              #if defined(CONFIG_PLATFORM_SUNOS_I86PC_SUNPRO)
313              # define SELECT_BASE_TIMEOUT_MSEC 10
314              #elif defined(CONFIG_PLATFORM_SUNOS_SPARC_SUNPRO)
315              # define SELECT_BASE_TIMEOUT_MSEC 10
316              #elif defined(CONFIG_PLATFORM_HPUX_IA64_HP)
317              # define SELECT_BASE_TIMEOUT_MSEC 30
318              #elif defined(CONFIG_PLATFORM_HPUX_PARISC_HP)
319              # define SELECT_BASE_TIMEOUT_MSEC 30
320              #elif defined(CONFIG_PLATFORM_AIX_PPC_IBM)
321              # define SELECT_BASE_TIMEOUT_MSEC 20
322              #elif defined(LINUX_IX86_GNU) || defined (LINUX_X86_64_GNU)
323              # define SELECT_BASE_TIMEOUT_MSEC 2
324              #else
325 krisbash 1.4 # define SELECT_BASE_TIMEOUT_MSEC 1
326              #endif
327              
328              /*
329              **==============================================================================
330              **
331 mike     1.1 **  DEBUG_ASSERT()
332              **
333              **==============================================================================
334              */
335              
336 krisbash 1.4 #if defined(CONFIG_OS_WINDOWS)
337              #if defined(CONFIG_ENABLE_DEBUG)
338              #define DEBUG_ASSERT(x)    NT_ASSERT(x)
339              #else
340              #ifdef _PREFAST_
341              // Copy same thing as a NT_ASSERT debug assert for a CHK build here, 
342              // to make PREFast happy (actual FRE build will not enter here)
343              #define DEBUG_ASSERT(_exp) \
344                  ((!(_exp)) ? \
345                      (__annotation(L"Debug", L"AssertFail", L#_exp), \
346                       DbgRaiseAssertionFailure(), FALSE) : \
347                      TRUE)
348              #else
349              #define DEBUG_ASSERT(x)
350              #endif
351              #endif
352              #else
353 mike     1.1 #if defined(CONFIG_ENABLE_DEBUG)
354              # define DEBUG_ASSERT(COND) assert(COND)
355              #else
356              # define DEBUG_ASSERT(COND) /* empty */
357              #endif
358 krisbash 1.4 #endif
359 mike     1.1 
360              /*
361              **==============================================================================
362              **
363              **  stat() macros
364              **
365              **==============================================================================
366              */
367              
368              #if defined(_MSC_VER)
369              # define access _access
370              # define F_OK 0
371              # define W_OK 2
372              # define R_OK 4
373              #endif
374              
375              /*
376              **==============================================================================
377              **
378              ** NULL_FILE macro
379              **
380 mike     1.1 **==============================================================================
381              */
382              
383              /* null-file - always can be opened/written and always ignored */
384              #if defined(_MSC_VER)
385              # define NULL_FILE "nul"
386              #else
387              # define NULL_FILE "/dev/null"
388              #endif
389              
390              /*
391              **==============================================================================
392              **
393              **  __FUNCTION__
394              **
395              **==============================================================================
396              */
397              
398              #if !defined(CONFIG_HAVE_FUNCTION_MACRO)
399              # if !defined(_MSC_VER)
400              #  define __FUNCTION__ "<unknown>"
401 mike     1.1 # endif
402              #endif
403              
404              /*
405              **==============================================================================
406              **
407              **  CallSite type (used to track site of function invocations when enabled).
408              **
409              **==============================================================================
410              */
411              
412              #if defined(CONFIG_ENABLE_DEBUG)
413              
414              typedef struct _CallSite
415              {
416                  const char* file;
417                  size_t line;
418                  const char* func;
419              }
420              CallSite;
421              
422 mike     1.1 MI_INLINE CallSite MakeCallSite(const char* file, size_t line, const char* func)
423              {
424                  CallSite result;
425                  result.file = file;
426                  result.line = line;
427                  result.func = func;
428                  return result;
429              }
430              
431              # define CALLSITE MakeCallSite(__FILE__, __LINE__, __FUNCTION__)
432              
433              #else /* defined(CONFIG_ENABLE_DEBUG) */
434              
435              typedef int CallSite;
436              
437              # define CALLSITE 0
438              
439              #endif /* !defined(CONFIG_ENABLE_DEBUG) */
440              
441 krisbash 1.4 /*
442              **==============================================================================
443              **
444              ** NAMESPACE_SEPARATOR
445              **
446              **     The separator character for namespace names used on disk (note that
447              **     '/' cannot be used since it is the file system path separator).
448              **
449              **==============================================================================
450              */
451              
452              #define NAMESPACE_SEPARATOR '-'
453              
454              typedef _Null_terminated_ const char* ConstCharPtr;
455              typedef _Null_terminated_ char* CharPtr;
456              typedef _Null_terminated_ CharPtr* CharPtrPtr;
457              
458              typedef _Null_terminated_ const wchar_t* ConstWcharPtr;
459              typedef _Null_terminated_ wchar_t* WcharPtr;
460              typedef _Null_terminated_ WcharPtr* WcharPtrPtr;
461              
462 krisbash 1.4 
463              #define MI_VERSION_GET_MAJOR(VERSION) ((VERSION & 0xFFFF0000) >> 16)
464              #define MI_VERSION_GET_MINOR(VERSION) ((VERSION & 0x0000FF00) >> 8)
465              #define MI_VERSION_GET_REVISION(VERSION) (VERSION & 0x000000FF)
466              
467              /*
468              **==============================================================================
469              **
470              ** union MI_ValuePtr
471              **
472              **     A union that reflects the types of things that are pointed to by the
473              **     class, attribute and qualifier _value_ fields present in the structures
474              **     passed in the callbacks from the MOF compiler.
475              **
476              **==============================================================================
477              */
478              
479              typedef union _MI_ValuePtr
480              {
481                  MI_Boolean* boolean;
482                  MI_Uint8* uint8;
483 krisbash 1.4     MI_Sint8* sint8;
484                  MI_Uint16* uint16;
485                  MI_Sint16* sint16;
486                  MI_Uint32* uint32;
487                  MI_Sint32* sint32;
488                  MI_Uint64* uint64;
489                  MI_Sint64* sint64;
490                  MI_Real32* real32;
491                  MI_Real64* real64;
492                  MI_Char16* char16;
493                  MI_Datetime* datetime;
494                  MI_Char* string;
495                  MI_Instance* instance;
496                  MI_Instance* reference;
497              
498                  MI_BooleanA* booleana;
499                  MI_Uint8A* uint8a;
500                  MI_Sint8A* sint8a;
501                  MI_Uint16A* uint16a;
502                  MI_Sint16A* sint16a;
503                  MI_Uint32A* uint32a;
504 krisbash 1.4     MI_Sint32A* sint32a;
505                  MI_Uint64A* uint64a;
506                  MI_Sint64A* sint64a;
507                  MI_Real32A* real32a;
508                  MI_Real64A* real64a;
509                  MI_Char16A* char16a;
510                  MI_DatetimeA* datetimea;
511                  MI_StringA* stringa;
512                  MI_ReferenceA* referencea;
513                  MI_InstanceA* instancea;
514                  MI_Array* array;
515              
516                  void* generic;
517              
518              } MI_ValuePtr;
519              
520 mike     1.1 #endif /* _common_h */

ViewCVS 0.9.2