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 const char * __gauger_v[10]; \ 23 char __gauger_s[32];\ 24 pid_t __gauger_p;\ 25 if(!(__gauger_p=fork())){\ 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] = counter; \ 31 __gauger_v[3] = "-d";\ 32 __gauger_v[4] = __gauger_s;\ 33 __gauger_v[5] = "-u";\ 34 __gauger_v[6] = unit; \ 35 __gauger_v[7] = "-c";\ 36 __gauger_v[8] = category; \ 37 __gauger_v[9] = (char *)NULL;\ 38 execvp("gauger", (char*const*) __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 if(!fork()){\ 55 sprintf(__gauger_s,"%Lf", (long double) (value));\ 56 __gauger_v[0] = "gauger";\ 57 __gauger_v[1] = "-n";\ 58 __gauger_v[2] = counter;\ 59 __gauger_v[3] = "-d";\ 60 __gauger_v[4] = __gauger_s;\ 61 __gauger_v[5] = "-u";\ 62 __gauger_v[6] = unit;\ 63 __gauger_v[7] = "-i";\ 64 __gauger_v[8] = id;\ 65 __gauger_v[9] = "-c";\ 66 __gauger_v[10] = category;\ 67 __gauger_v[11] = (char *)NULL;\ 68 execvp("gauger",__gauger_v);\ 69 perror("gauger");\ 70 _exit(1);\ 71 }else{\ 72 _exit(0);\ 73 }\ 74 }else{\ 75 waitpid(__gauger_p,NULL,0);\ 76 }\ 77 } 78 79 #else 80 81 #define GAUGER_ID(category, counter, value, unit, id) {} 82 #define GAUGER(category, counter, value, unit) {} 83 84 #endif // WINDOWS 85 86 #endif 87