00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "AuditFile.hh"
00027
00028 #include <iostream>
00029 #include <cstdarg>
00030 #include <sstream>
00031
00032 using std::ofstream ;
00033 using std::ios ;
00034 using std::cerr ;
00035 using std::endl ;
00036 using std::string ;
00037
00038 namespace certi {
00039
00040
00042
00044 AuditFile::AuditFile(const std::string logfile)
00045 : auditFile(logfile.c_str(), ios::app)
00046 {
00047 if (!auditFile.is_open()) {
00048 cerr << "Could not open Audit file � " << logfile.c_str()
00049 << " �." << endl ;
00050 throw RTIinternalError("Could not open Audit file.");
00051 }
00052
00053
00054 putLine(AUDITEVENT_START_AUDIT, AUDIT_MAX_LEVEL, e_NO_EXCEPTION, "");
00055 }
00056
00057
00059
00062 AuditFile::~AuditFile()
00063 {
00064 endLine(e_NO_EXCEPTION, "");
00065 putLine(AUDITEVENT_STOP_AUDIT, AUDIT_MAX_LEVEL, e_NO_EXCEPTION, "");
00066 auditFile.close();
00067 }
00068
00069
00071
00074 void
00075 AuditFile::endLine(unsigned short event_status, std::string reason)
00076 {
00077 if (currentLine.started())
00078 currentLine.end(event_status, reason);
00079
00080
00081 if (currentLine.getLevel() >= AUDIT_CURRENT_LEVEL ||
00082 currentLine.getStatus())
00083 currentLine.write(auditFile);
00084
00085 currentLine = AuditLine();
00086 }
00087
00088
00090
00091
00092
00093
00094
00095
00096
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00114
00119 void
00120 AuditFile::putLine(unsigned short event_type,
00121 unsigned short event_level,
00122 unsigned short event_status,
00123 std::string reason)
00124 {
00125 if (event_level >= AUDIT_CURRENT_LEVEL) {
00126 AuditLine line(event_type, event_level, event_status, reason);
00127 line.write(auditFile);
00128 }
00129 }
00130
00131
00133 void
00134 AuditFile::startLine(Handle federation,
00135 FederateHandle federate,
00136 unsigned short event_type)
00137 {
00138
00139 if (currentLine.started()) {
00140 cerr << "Audit Error : Current line already valid !" << endl ;
00141 return ;
00142 }
00143
00144 currentLine = AuditLine(event_type, AUDIT_MIN_LEVEL, 0, "");
00145 currentLine.setFederation(federation);
00146 currentLine.setFederate(federate);
00147 }
00148
00149
00151
00154 void
00155 AuditFile::setLevel(unsigned short eventLevel)
00156 {
00157 currentLine.setLevel(eventLevel);
00158 }
00159
00160
00163 AuditFile &
00164 AuditFile::operator<<(const char *s)
00165 {
00166 if (s != 0)
00167 currentLine.addComment(s);
00168 return *this ;
00169 }
00170
00171 AuditFile &
00172 AuditFile::operator<<(int n)
00173 {
00174 std::ostringstream s ;
00175 s << n ;
00176 currentLine.addComment(s.str());
00177 return *this ;
00178 }
00179
00180 AuditFile &
00181 AuditFile::operator<<(long n)
00182 {
00183 std::ostringstream s ;
00184 s << n ;
00185 currentLine.addComment(s.str());
00186 return *this ;
00187 }
00188
00189 AuditFile &
00190 AuditFile::operator<<(unsigned int n)
00191 {
00192 std::ostringstream s ;
00193 s << n ;
00194 currentLine.addComment(s.str());
00195 return *this ;
00196 }
00197
00198 AuditFile &
00199 AuditFile::operator<<(unsigned long n)
00200 {
00201 std::ostringstream s ;
00202 s << n ;
00203 currentLine.addComment(s.str());
00204 return *this ;
00205 }
00206
00207 AuditFile &
00208 AuditFile::operator<<(double n)
00209 {
00210 std::ostringstream s ;
00211 s << n ;
00212 currentLine.addComment(s.str());
00213 return *this ;
00214 }
00215
00216 }
00217
00218