Line | |
---|
1 | #include "NvEventLog.h" |
---|
2 | #include "config.h" |
---|
3 | #include <stdio.h> |
---|
4 | #include <assert.h> |
---|
5 | #include <sys/time.h> |
---|
6 | #include <sys/types.h> |
---|
7 | #include <unistd.h> |
---|
8 | #include <fcntl.h> |
---|
9 | |
---|
10 | |
---|
11 | |
---|
12 | #ifdef XINETD |
---|
13 | FILE* xinetd_log; |
---|
14 | #endif |
---|
15 | |
---|
16 | FILE* event_log; |
---|
17 | double cur_time; //in seconds |
---|
18 | |
---|
19 | #ifdef XINETD |
---|
20 | void NvInitService() |
---|
21 | { |
---|
22 | //open log and map stderr to log file |
---|
23 | xinetd_log = fopen("/tmp/log.txt", "w"); |
---|
24 | close(2); |
---|
25 | dup2(fileno(xinetd_log), 2); |
---|
26 | dup2(2,1); |
---|
27 | |
---|
28 | //flush junk |
---|
29 | fflush(stdout); |
---|
30 | fflush(stderr); |
---|
31 | } |
---|
32 | |
---|
33 | void NvExitService() |
---|
34 | { |
---|
35 | //close log file |
---|
36 | fclose(xinetd_log); |
---|
37 | } |
---|
38 | #endif |
---|
39 | |
---|
40 | void NvInitEventLog() |
---|
41 | { |
---|
42 | event_log = fopen("event.txt", "w"); |
---|
43 | assert(event_log!=0); |
---|
44 | |
---|
45 | struct timeval time; |
---|
46 | gettimeofday(&time, NULL); |
---|
47 | cur_time = time.tv_sec*1000. + time.tv_usec/1000.; |
---|
48 | } |
---|
49 | |
---|
50 | void NvExitEventLog() |
---|
51 | { |
---|
52 | fclose(event_log); |
---|
53 | } |
---|
54 | |
---|
55 | double NvGetTimeInterval() |
---|
56 | { |
---|
57 | struct timeval time; |
---|
58 | gettimeofday(&time, NULL); |
---|
59 | double new_time = time.tv_sec*1000. + time.tv_usec/1000.; |
---|
60 | |
---|
61 | double interval = new_time - cur_time; |
---|
62 | cur_time = new_time; |
---|
63 | return interval; |
---|
64 | } |
---|
65 | |
---|
Note: See
TracBrowser
for help on using the repository browser.