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 #include <unistd.h>
15 #include <stdio.h>
16 #include <sys/wait.h>
17 
18 #define GAUGER(category, counter, value, unit) \
19  { \
20  char* __gauger_v[10]; \
21  char __gauger_s[32]; \
22  pid_t __gauger_p; \
23  if (!(__gauger_p = fork())) { \
24  close(1); \
25  close(2); \
26  if (!fork()) { \
27  sprintf(__gauger_s, "%Lf", (long double)(value)); \
28  __gauger_v[0] = "gauger"; \
29  __gauger_v[1] = "-n"; \
30  __gauger_v[2] = (char*)(counter); \
31  __gauger_v[3] = "-d"; \
32  __gauger_v[4] = __gauger_s; \
33  __gauger_v[5] = "-u"; \
34  __gauger_v[6] = (char*)(unit); \
35  __gauger_v[7] = "-c"; \
36  __gauger_v[8] = (char*)(category); \
37  __gauger_v[9] = (char*)NULL; \
38  execvp("gauger", __gauger_v); \
39  _exit(1); \
40  }else{ \
41  _exit(0); \
42  } \
43  }else{ \
44  waitpid(__gauger_p, NULL, 0); \
45  } \
46  }
47 
48 #define GAUGER_ID(category, counter, value, unit, id) \
49  { \
50  char* __gauger_v[12]; \
51  char __gauger_s[32]; \
52  pid_t __gauger_p; \
53  if (!(__gauger_p = fork())) { \
54  close(1); \
55  close(2); \
56  if (!fork()) { \
57  sprintf(__gauger_s, "%Lf", (long double)(value)); \
58  __gauger_v[0] = "gauger"; \
59  __gauger_v[1] = "-n"; \
60  __gauger_v[2] = (char*)(counter); \
61  __gauger_v[3] = "-d"; \
62  __gauger_v[4] = __gauger_s; \
63  __gauger_v[5] = "-u"; \
64  __gauger_v[6] = (char*)(unit); \
65  __gauger_v[7] = "-i"; \
66  __gauger_v[8] = id; \
67  __gauger_v[9] = "-c"; \
68  __gauger_v[10] = (char *)(category); \
69  __gauger_v[11] = (char *)NULL; \
70  execvp("gauger", __gauger_v); \
71  _exit(1); \
72  }else{ \
73  _exit(0); \
74  } \
75  }else{ \
76  waitpid(__gauger_p, NULL, 0); \
77  } \
78  }
79 
80 #endif