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