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

Last change on this file since 2844 was 2836, checked in by ldelgass, 12 years ago

More cleanups, remove NEW_FLOW_ENGINE define flag

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
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
11#include "config.h"
12#include "nanovis.h"
13#include "NvEventLog.h"
14
15static FILE *event_log;
16static double cur_time; //in seconds
17
18#ifdef XINETD
19void NvInitService()
20{
21    const char* user = getenv("USER");
22    char* logName = NULL;
23    int logNameLen = 0;
24
25    if (user == NULL) {
26        logNameLen = 20+1;
27        logName = (char *)calloc(logNameLen, sizeof(char));
28        strncpy(logName, "/tmp/nanovis_log.txt", logNameLen);
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 != NULL);
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
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.