GNUnet  0.10.x
gauger.h
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  * This software is in the public domain, furnished "as is", without technical
3  * support, and with no warranty, express or implied, as to its usefulness for
4  * any purpose.
5  *
6  * gauger.h
7  * Interface for C programs to log remotely to a gauger server
8  *
9  * Author: Bartlomiej Polot
10  * -------------------------------------------------------------------------*/
11 #ifndef __GAUGER_H__
12 #define __GAUGER_H__
13 
14 #ifndef WINDOWS
15 
16 #include <unistd.h>
17 #include <stdio.h>
18 #include <sys/wait.h>
19 
20 #define GAUGER(category, counter, value, unit)\
21 {\
22  char* __gauger_v[10];\
23  char __gauger_s[32];\
24  pid_t __gauger_p;\
25  if(!(__gauger_p=fork())){\
26  close (1); \
27  close (2); \
28  if(!fork()){\
29  sprintf(__gauger_s,"%Lf", (long double) (value));\
30  __gauger_v[0] = "gauger";\
31  __gauger_v[1] = "-n";\
32  __gauger_v[2] = (char*) (counter); \
33  __gauger_v[3] = "-d";\
34  __gauger_v[4] = __gauger_s;\
35  __gauger_v[5] = "-u";\
36  __gauger_v[6] = (char*) (unit); \
37  __gauger_v[7] = "-c";\
38  __gauger_v[8] = (char*) (category); \
39  __gauger_v[9] = (char*) NULL;\
40  execvp("gauger",__gauger_v);\
41  _exit(1);\
42  }else{\
43  _exit(0);\
44  }\
45  }else{\
46  waitpid(__gauger_p,NULL,0);\
47  }\
48 }
49 
50 #define GAUGER_ID(category, counter, value, unit, id)\
51 {\
52  char* __gauger_v[12];\
53  char __gauger_s[32];\
54  pid_t __gauger_p;\
55  if(!(__gauger_p=fork())){\
56  close (1); \
57  close (2); \
58  if(!fork()){\
59  sprintf(__gauger_s,"%Lf", (long double) (value));\
60  __gauger_v[0] = "gauger";\
61  __gauger_v[1] = "-n";\
62  __gauger_v[2] = (char*) (counter); \
63  __gauger_v[3] = "-d";\
64  __gauger_v[4] = __gauger_s;\
65  __gauger_v[5] = "-u";\
66  __gauger_v[6] = (char*) (unit); \
67  __gauger_v[7] = "-i";\
68  __gauger_v[8] = id;\
69  __gauger_v[9] = "-c";\
70  __gauger_v[10] = (char *) (category); \
71  __gauger_v[11] = (char *) NULL;\
72  execvp("gauger",__gauger_v);\
73  _exit(1);\
74  }else{\
75  _exit(0);\
76  }\
77  }else{\
78  waitpid(__gauger_p, NULL, 0);\
79  }\
80 }
81 
82 #else /* WINDOWS */
83 
84 #include <stdlib.h>
85 #include <stdio.h>
86 #include <windef.h>
87 
88 #define GAUGER(category, counter, value, unit)\
89 {\
90  char __gauger_commandline[MAX_PATH];\
91  \
92  snprintf (__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -c \"%s\"",\
93  (counter), (long double) (value), (unit), (category)); \
94  __gauger_commandline[MAX_PATH - 1] = '\0';\
95  system (__gauger_commandline);\
96 }
97 
98 #define GAUGER_ID(category, counter, value, unit, id)\
99 {\
100  char __gauger_commandline[MAX_PATH];\
101  \
102  snprintf (__gauger_commandline, MAX_PATH, "gauger.py -n \"%s\" -d \"%Lf\" -u \"%s\" -i \"%s\" -c \"%s\"",\
103  (counter), (long double) (value), (unit), (id), (category)); \
104  __gauger_commandline[MAX_PATH - 1] = '\0';\
105  system (__gauger_commandline);\
106 }
107 
108 #endif // WINDOWS
109 
110 #endif