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

Last change on this file since 2376 was 2376, checked in by gah, 13 years ago
  • Property svn:eol-style set to native
File size: 1.7 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    close(2);
39    dup2(fileno(NanoVis::logfile), 2);
40    /* dup2(2,1); */
41
42    // clean up malloc'd memory
43    if (logName != NULL) {
44        free(logName);
45    }
46}
47
48void NvExitService()
49{
50    //close log file
51    if (NanoVis::logfile != NULL) {
52        fclose(NanoVis::logfile);
53        NanoVis::logfile = NULL;
54    }
55}
56#endif
57
58void NvInitEventLog()
59{
60    event_log = fopen("event.txt", "w");
61    assert(event_log!=0);
62
63    struct timeval time;
64    gettimeofday(&time, NULL);
65    cur_time = time.tv_sec*1000. + time.tv_usec/1000.;
66}
67
68void NvExitEventLog()
69{
70    fclose(event_log);
71}
72
73double NvGetTimeInterval()
74{
75    struct timeval time;
76    gettimeofday(&time, NULL);
77    double new_time = time.tv_sec*1000. + time.tv_usec/1000.;
78
79    double interval = new_time - cur_time;
80    cur_time = new_time;
81    return interval;
82}
83
Note: See TracBrowser for help on using the repository browser.