source: trunk/packages/vizservers/nanovis/NvEventLog.cpp @ 2377

Last change on this file since 2377 was 2377, checked in by gah, 13 years ago
  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1#include "config.h"
2#include <stdio.h>
3#include <assert.h>
4#include <sys/time.h>
5#include <sys/types.h>
6#include <unistd.h>
7#include <fcntl.h>
8#include <stdlib.h>
9#include <string.h>
10#include "NvEventLog.h"
11#include "nanovis.h"
12
13
14FILE* event_log;
15double cur_time;        //in seconds
16
17#ifdef XINETD
18void NvInitService()
19{
20    const char* user = getenv("USER");
21    char* logName = NULL;
22    int logNameLen = 0;
23
24    if (user == NULL) {
25        logNameLen = 20+1;
26        logName = (char*) calloc(logNameLen,sizeof(char));
27        strncpy(logName,"/tmp/nanovis_log.txt",logNameLen);
28    }
29    else {
30        logNameLen = 17+1+strlen(user);
31        logName = (char*) calloc(logNameLen,sizeof(char));
32        strncpy(logName,"/tmp/nanovis_log_",logNameLen);
33        strncat(logName,user,strlen(user));
34    }
35
36    //open log and map stderr to log file
37    NanoVis::logfile = fopen(logName, "w");
38    dup2(fileno(NanoVis::logfile), 2);
39    /* dup2(2,1); */
40
41    // clean up malloc'd memory
42    if (logName != NULL) {
43        free(logName);
44    }
45}
46
47void NvExitService()
48{
49    //close log file
50    if (NanoVis::logfile != NULL) {
51        fclose(NanoVis::logfile);
52        NanoVis::logfile = NULL;
53    }
54}
55#endif
56
57void NvInitEventLog()
58{
59    event_log = fopen("event.txt", "w");
60    assert(event_log!=0);
61
62    struct timeval time;
63    gettimeofday(&time, NULL);
64    cur_time = time.tv_sec*1000. + time.tv_usec/1000.;
65}
66
67void NvExitEventLog()
68{
69    fclose(event_log);
70}
71
72double NvGetTimeInterval()
73{
74    struct timeval time;
75    gettimeofday(&time, NULL);
76    double new_time = time.tv_sec*1000. + time.tv_usec/1000.;
77
78    double interval = new_time - cur_time;
79    cur_time = new_time;
80    return interval;
81}
82
Note: See TracBrowser for help on using the repository browser.