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

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

Remove XINETD define from nanovis. We only support server mode now, no glut
interaction loop with mouse/keyboard handlers. Fixes for trace logging to make
output closer to vtkvis: inlcude function name for trace messages, remove
newlines from format strings in macros since newlines get added by syslog.

  • 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
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    } else {
29        logNameLen = 17+1+strlen(user);
30        logName = (char *)calloc(logNameLen, sizeof(char));
31        strncpy(logName, "/tmp/nanovis_log_", logNameLen);
32        strncat(logName, user, strlen(user));
33    }
34
35    //open log and map stderr to log file
36    NanoVis::logfile = fopen(logName, "w");
37    dup2(fileno(NanoVis::logfile), 2);
38    /* dup2(2,1); */
39
40    // clean up malloc'd memory
41    if (logName != NULL) {
42        free(logName);
43    }
44}
45
46void NvExitService()
47{
48    //close log file
49    if (NanoVis::logfile != NULL) {
50        fclose(NanoVis::logfile);
51        NanoVis::logfile = NULL;
52    }
53}
54
55void NvInitEventLog()
56{
57    event_log = fopen("event.txt", "w");
58    assert(event_log != NULL);
59
60    struct timeval time;
61    gettimeofday(&time, NULL);
62    cur_time = time.tv_sec*1000. + time.tv_usec/1000.;
63}
64
65void NvExitEventLog()
66{
67    fclose(event_log);
68}
69
70double NvGetTimeInterval()
71{
72    struct timeval time;
73
74    gettimeofday(&time, NULL);
75    double new_time = time.tv_sec*1000. + time.tv_usec/1000.;
76
77    double interval = new_time - cur_time;
78    cur_time = new_time;
79    return interval;
80}
Note: See TracBrowser for help on using the repository browser.