]> git.mxchange.org Git - flightgear.git/blob - src/Main/logger.cxx
Fix several signed vs. unsigned warning messages.
[flightgear.git] / src / Main / logger.cxx
1 // logger.cxx - log properties.
2 // Written by David Megginson, started 2002.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #include "logger.hxx"
7
8 #include STL_FSTREAM
9 #ifndef SG_HAVE_NATIVE_SGI_COMPILERS
10 SG_USING_STD(ofstream);
11 SG_USING_STD(endl);
12 #endif
13
14 #include <string>
15 SG_USING_STD(string);
16
17 #include <simgear/debug/logstream.hxx>
18
19 #include "fg_props.hxx"
20
21
22 \f
23 ////////////////////////////////////////////////////////////////////////
24 // Implementation of FGLogger
25 ////////////////////////////////////////////////////////////////////////
26
27 FGLogger::FGLogger ()
28 {
29 }
30
31 FGLogger::~FGLogger ()
32 {
33 }
34
35 void
36 FGLogger::init ()
37 {
38   SGPropertyNode * logging = fgGetNode("/logging");
39   if (logging == 0)
40     return;
41
42   vector<SGPropertyNode *> children = logging->getChildren("log");
43   for (unsigned int i = 0; i < children.size(); i++) {
44     _logs.push_back(Log());
45     Log &log = _logs[_logs.size()-1];
46     SGPropertyNode * child = children[i];
47     string filename = child->getStringValue("filename", "fg_log.csv");
48     log.interval_ms = child->getLongValue("interval-ms", 0);
49     log.delimiter = child->getStringValue("delimiter", ",")[0];
50     log.output = new ofstream(filename.c_str());
51     if (!log.output) {
52       SG_LOG(SG_INPUT, SG_ALERT, "Cannot write log to " << filename);
53       continue;
54     }
55     vector<SGPropertyNode *> entries = child->getChildren("entry");
56     (*log.output) << "Time";
57     for (unsigned int j = 0; j < entries.size(); j++) {
58       SGPropertyNode * entry = entries[j];
59       SGPropertyNode * node =
60         fgGetNode(entry->getStringValue("property"), true);
61       log.nodes.push_back(node);
62       (*log.output) << log.delimiter
63                     << entry->getStringValue("title", node->getPath());
64     }
65     (*log.output) << endl;
66   }
67 }
68
69 void
70 FGLogger::bind ()
71 {
72 }
73
74 void
75 FGLogger::unbind ()
76 {
77 }
78
79 void
80 FGLogger::update (int dt)
81 {
82   long elapsed_ms = globals->get_elapsed_time_ms();
83   for (unsigned int i = 0; i < _logs.size(); i++) {
84     if ((elapsed_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
85       _logs[i].last_time_ms = elapsed_ms;
86       (*_logs[i].output) << globals->get_elapsed_time_ms();
87       for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) {
88         (*_logs[i].output) << _logs[i].delimiter
89                            << _logs[i].nodes[j]->getStringValue();
90       }
91       (*_logs[i].output) << endl;
92     }
93   }
94 }
95
96
97 \f
98 ////////////////////////////////////////////////////////////////////////
99 // Implementation of FGLogger::Log
100 ////////////////////////////////////////////////////////////////////////
101
102 FGLogger::Log::Log ()
103   : output(0),
104     interval_ms(0),
105     last_time_ms(-999999L),
106     delimiter(',')
107 {
108 }
109
110 FGLogger::Log::~Log ()
111 {
112   delete output;
113 }
114
115 // end of logger.cxx