OpenClovis Logo

clCommon.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2012 OpenClovis Solutions Inc. All Rights Reserved.
3  *
4  * This file is available under a commercial license from the
5  * copyright holder or the GNU General Public License Version 2.0.
6  *
7  * The source code for this program is not published or otherwise
8  * divested of its trade secrets, irrespective of what has been
9  * deposited with the U.S. Copyright office.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * For more information, see the file COPYING provided with this
17  * material.
18  */
19 /*******************************************************************************
20  * ModuleName : include
21  * File : clCommon.h
22  *******************************************************************************/
23 
24 /*******************************************************************************
25  * Description :
26  *
27  * This header file contains all the common data types used across ASP
28  *
29  *
30  *****************************************************************************/
31 
44 #ifndef _CL_COMMON_H_
45 #define _CL_COMMON_H_
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #include <clArchHeaders.h>
52 
53 /******************************************************************************
54  * Clovis Data Types
55  *****************************************************************************/
56 
58 #define CL_TRUE 1
59 
60 #define CL_FALSE 0
61 
63 #define CL_YES 1
64 
65 #define CL_NO 0
66 
68 #define CL_ENABLE 1
69 
70 #define CL_DISABLE 0
71 
75 typedef enum {
80 
85 } ClStatusT;
86 
87 
88 
90 #define CL_MIN(a,b) ( (a) < (b) ? (a) : (b) )
91 
92 #define CL_MAX(a,b) ( (a) > (b) ? (a) : (b) )
93 
95 #define CL_ROUNDUP(VAL,BASE) (((VAL) + (BASE) - 1)/(BASE) * (BASE))
96 
97 #define CL_ROUNDDOWN(VAL,BASE) ((VAL)/(BASE) * (BASE))
98 
100 #define CL_SIZEOF_ARRAY(__ArrayName__) sizeof((__ArrayName__)) / sizeof((__ArrayName__)[0])
101 
103 #define CL_IN
104 
105 #define CL_INOUT
106 
107 #define CL_OUT
108 
109 /* Note: for the 64 bit types, align yourself using "__attribute__((__aligned__(8)))".
110  We cannot align automatically as part of this typedef, since SAF does not align its
111  corresponding type. See bug 7155 */
112 typedef unsigned long long ClUint64T;
113 typedef signed long long ClInt64T;
114 
115 typedef unsigned int ClUint32T;
116 typedef signed int ClInt32T;
117 typedef unsigned short ClUint16T;
118 typedef signed short ClInt16T;
119 typedef unsigned char ClUint8T;
120 typedef signed char ClInt8T;
121 typedef char ClCharT; /* Use this for strings */
122 typedef signed int ClFdT; /* Use this for file descriptors */
123 /*
124  * Special type with word size for portability b/n 32 & 64 bit
125  * Recommended type would be intptr_t but not working for some
126  * reason. Need to fix this - Mynk
127  */
128 typedef unsigned long ClWordT;
129 
130 
131 typedef ClUint16T ClBoolT;
132 
133 typedef ClWordT ClPidT;
134 
136 #define CL_MICRO_TO_NANO 1000ULL
137 
138 #define CL_MILLI_TO_MICRO 1000ULL
139 
140 #define CL_SEC_TO_MILLI 1000ULL
141 
142 #define CL_MILLI_TO_NANO (CL_MICRO_TO_NANO * CL_MILLI_TO_MICRO)
143 
144 #define CL_SEC_TO_NANO (CL_MILLI_TO_NANO * CL_SEC_TO_MILLI)
145 
146 #define CL_TIME_END 0x7fffffffffffffffULL
147 
148 #define CL_TIME_FOREVER 0x7fffffffffffffffULL
149 
151 typedef ClInt64T ClTimeT;
152 typedef ClUint64T ClHandleT;
154 typedef ClUint64T ClSizeT;
156 typedef ClInt64T ClOffsetT;
157 typedef ClUint64T ClInvocationT;
158 typedef ClUint64T ClSelectionObjectT;
159 typedef ClUint64T ClNtfIdentifierT;
160 typedef ClInt8T *ClAddrT;
161 typedef void* ClPtrT;
162 
165 typedef ClUint32T ClRcT;
166 
176 typedef ClRcT (*ClCallbackT) (CL_IN ClPtrT invocation);
177 
178 typedef union cl_u64_u /* FIXME: This is not endian-safe; shouldn't be used */
179  {
180  struct {
181  ClUint32T high;
182  ClUint32T low;
183  } DWord;
184  ClUint32T dWords[2];
185  ClUint16T words[4];
186  ClInt8T bytes[8];
187  } ClUnion64T;
188 
189 
191 #define CL_MAX_NAME_LENGTH 256
192 
194 typedef struct {
196  ClUint16T length;
198  ClCharT value[CL_MAX_NAME_LENGTH];
199 } ClNameT;
200 
207 void clNameSet(ClNameT* name, const char* str);
208 
215 void clNameCopy(ClNameT* nameOut, const ClNameT *nameIn);
216 
225 void clNameConcat(ClNameT* nameOut, const ClNameT *prefix, const char* separator, const ClNameT *suffix);
226 
236 ClCharT *clStrdup(const ClCharT *str);
237 
238 ClBoolT clParseEnvBoolean(ClCharT* envvar);
239 
240 ClCharT *clParseEnvStr(const ClCharT* envvar);
241 
242 ClInt32T clCreatePipe(ClInt32T fds[2], ClUint32T numMsgs, ClUint32T msgSize);
243 
244 ClUint32T clBinaryPower(ClUint32T size);
245 
247 typedef struct {
249  ClUint8T releaseCode;
251  ClUint8T majorVersion;
253  ClUint8T minorVersion;
254 } ClVersionT;
255 
257 typedef enum {
258  CL_DISPATCH_ONE = 1,
259  CL_DISPATCH_ALL = 2,
260  CL_DISPATCH_BLOCKING = 3,
262 
263 /*****************************************************************************
264  * Bit related Types
265  *****************************************************************************/
266 #define CL_FORCED_TO_8BITS 0xff
267 #define CL_FORCED_TO_16BITS 0xffff
268 #define CL_FORCED_TO_32BITS 0xffffffff
269 #define CL_BITS_PER_BYTE 8
270 #define CL_BIT(X) (0x1 << (X))
271 
272 #if 0
273 typedef enum ClMetricId
274 {
275  CL_METRIC_ALL,
276  CL_METRIC_CPU,
277  CL_METRIC_MEM,
278  CL_METRIC_MAX,
279 }ClMetricIdT;
280 
281 typedef struct ClMetric
282 {
283  const ClCharT *pType;
284  ClMetricIdT id;
285  ClUint32T maxThreshold;
286  ClUint32T currentThreshold;
287  ClUint32T maxOccurences;
288  ClUint32T numOccurences;
289 }ClMetricT;
290 
291 #define CL_METRIC_STR(id) \
292  ((id) == CL_METRIC_ALL) ? "all" : \
293  ((id) == CL_METRIC_CPU) ? "cpu" : \
294  ((id) == CL_METRIC_MEM) ? "mem" : \
295  "unknown"
296 #endif
297 
301 typedef enum {
304 
306  CL_CID_OSAL = 0x01,
307 
309  CL_CID_HAL = 0x02,
310 
312  CL_CID_DBAL = 0x03,
313 
315  CL_CID_EO = 0x04,
316 
318  CL_CID_IOC = 0x05,
319 
321  CL_CID_RMD = 0x06,
322 
324  CL_CID_NAMES = 0x07,
325 
327  CL_CID_TIMER = 0x08,
328 
330  CL_CID_SHM = 0x09,
331 
333  CL_CID_DSHM = 0x0a,
334 
336  CL_CID_LOG = 0x0b,
337 
339  CL_CID_MSG = 0x0c,
340 
342  CL_CID_DIAG = 0x0d,
343 
345  CL_CID_DEBUG = 0x0e,
346 
348  CL_CID_CPM = 0x0f,
349 
351  CL_CID_CAP = 0x10,
352 
354  CL_CID_RES = 0x11,
355 
357  CL_CID_GMS = 0x12,
358 
361 
363  CL_CID_DLOCK = 0x14,
364 
366  CL_CID_TXN = 0x15,
367 
369  CL_CID_CKPT = 0x16,
370 
372  CL_CID_COR = 0x17,
373 
375  CL_CID_CNT = 0x18,
376 
378  CL_CID_DCNT = 0x19,
379 
381  CL_CID_RCNT = 0x1a,
382 
385 
388 
390  CL_CID_RULE = 0x1d,
391 
394 
396  CL_CID_CM = 0x1f,
397 
399  CL_CID_HPI = 0x20,
400 
403 
405  CL_CID_AMS = 0x22,
406 
408  CL_CID_MED = 0x23,
409 
412 
414  CL_CID_QUEUE = 0x25,
415 
417  CL_CID_CLIST = 0x26,
418 
420  CL_CID_SNMP = 0x27,
421 
423  CL_CID_NS = 0x28,
424 
426  CL_CID_OM = 0x29,
427 
429  CL_CID_POOL = 0x2a,
430 
432  CL_CID_CD = 0x2b,
433 
435  CL_CID_DM = 0x2c,
436 
439 
441  CL_CID_PROV = 0x2e,
442 
444  CL_CID_UM = 0x2f,
445 
448 
451 
453  CL_CID_XDR = 0x32,
454 
456  CL_CID_IDL = 0x33,
457 
459  CL_CID_HEAP = 0x34,
460 
462  CL_CID_MEM = 0x35,
463 
466 
467  CL_CID_BACKING_STORAGE = 0x37,
468 
469  CL_CID_JOB = 0x38,
470  CL_CID_JOBQUEUE = 0x38,
471 
472  CL_CID_THREADPOOL = 0x39,
473  CL_CID_TASKPOOL = 0x39,
474 
477 
478 
479  /* Add more CID here if required */
480  CL_CID_LEAKY_BUCKET = 0x3b,
481 
483  CL_CID_MSO = 0x3c,
484 
486  CL_CID_PM = 0x3d,
487 
489  CL_CID_NF = 0x3e,
490 
493 
494 } ClCompIdT;
495 
496 typedef struct ClWaterMark
497 {
498  ClUint64T lowLimit;
499  ClUint64T highLimit;
500 } ClWaterMarkT;
501 
502 typedef enum
503 {
504  CL_WM_LOW_LIMIT = 0,
505  CL_WM_HIGH_LIMIT = 1,
506 }
507 ClEoWaterMarkFlagT;
508 
509 typedef enum{
510  CL_WM_LOW,
511  CL_WM_HIGH,
512  CL_WM_MED,
513  CL_WM_SENDQ,
514  CL_WM_RECVQ,
515  CL_WM_MAX
516 }ClWaterMarkIdT;
517 
518 #define CL_WEAK __attribute__((weak))
519 
520 #define CL_EO_ACTION_CUSTOM (1<<0)
521 #define CL_EO_ACTION_EVENT (1<<1)
522 #define CL_EO_ACTION_LOG (1<<2)
523 #define CL_EO_ACTION_NOT (1<<3)
524 #define CL_EO_ACTION_MAX (1<<31) // ClUnt8T type bieng used for bitMap
525 
526 typedef struct ClEoActionInfo {
527  ClUint32T bitMap;
528 } ClEoActionInfoT;
529 
534 typedef ClPtrT* ClEoActionArgListT;
535 
536 typedef struct
537 {
538  ClUint32T length;
539  ClCharT *pValue;
540 }ClStringT;
541 
542 extern ClStringT *clStringDup(const ClStringT *);
543 
544 /* Macro to print into the name */
549 #define clNamePrintf(name, ...) \
550 do \
551 { \
552  name.length = snprintf(name.value, CL_MAX_NAME_LENGTH - 1, __VA_ARGS__);\
553  name.value[CL_MIN(name.length, CL_MAX_NAME_LENGTH - 1)] = '\0'; \
554 }while(0)
555 
556 #ifdef __GNUC__
557 #define CL_DEPRECATED __attribute__((__deprecated__))
558 #define CL_PRINTF_FORMAT(fmtPos, argPos) __attribute__((format(printf, fmtPos, argPos)))
559 #else
560 #define CL_DEPRECATED
561 #define CL_PRINTF_FORMAT(fmtPos, argPos)
562 #endif
563 
564 #ifdef __cplusplus
565 }
566 #endif
567 
572 #endif /* _CL_COMMON_H_ */

Generated on Tue Jan 10 10:29:15 PST 2012 for OpenClovis SDK using Doxygen