Changeset 216 for Evidence/Evidence.cc
- Timestamp:
- 05/28/10 09:01:45 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r212 r216 5 5 - The server is started with the given name. 6 6 - DIM exit and error handlers are implemented. 7 - The Statusservice is published (special format, see below).8 It can be updated with the State() method. The text will also be logged.9 - If the severity of a State() call is FATAL, exit() will be called (with10 this severity, the call to State() is guranteed not to return).7 - The Message service is published (special format, see below). 8 It can be updated with the Message() method. The text will also be logged. 9 - If the severity of a Message() call is FATAL, exit() will be called (with 10 this severity, the call to Message() is guranteed not to return). 11 11 - Configuration data can be requested by GetConfig(). 12 12 - Signal handlers to ignore common signals are installed. … … 60 60 snprintf(InitMsg, sizeof(InitMsg), "Server started (%s, compiled %s %s)", Rev.c_str(),__DATE__, __TIME__); 61 61 62 Status = new DimService((ServerName+"/ Status").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1);62 Status = new DimService((ServerName+"/Message").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1); 63 63 StdOut = new DimService((ServerName+"/Textout").c_str(), (char *) ""); 64 64 … … 70 70 EvidenceServer::~EvidenceServer() { 71 71 72 State(INFO, "Server stopped");72 Message(INFO, "Server stopped"); 73 73 74 74 for (unsigned int i=0; i<ConfigList.size(); i++) { … … 84 84 void EvidenceServer::exitHandler(int Code) { 85 85 86 State(INFO, "Exit handler called (DIM exit code %d)", Code);86 Message(INFO, "Exit handler called (DIM exit code %d)", Code); 87 87 exit(EXIT_SUCCESS); 88 88 } 89 89 90 90 // DIM error handler 91 void EvidenceServer::errorHandler(int Severity, int Code, char * Message) {92 State(ERROR, "%s (DIM error code %d, severity %d)\n", Message, Code, Severity);91 void EvidenceServer::errorHandler(int Severity, int Code, char *Text) { 92 Message(ERROR, "%s (DIM error code %d, severity %d)\n", Text, Code, Severity); 93 93 } 94 94 … … 98 98 // is given, terminated by another '\0' The buffer for the DIM service must have 99 99 // the same lifetime as the DIM service. If Severity is FATAL, exit() will be invoked. 100 void EvidenceServer:: State(StateType Severity, const char *Format, ...) {100 void EvidenceServer::Message(MessageType Severity, const char *Format, ...) { 101 101 102 102 static const char* StateString[] = {"Info", "Warn", "Error", "Fatal"}; 103 static char ErrorString[] = "vasprintf() failed in State()";103 static char ErrorString[] = "vasprintf() failed in Message()"; 104 104 static char SBuf[STATUS_SIZE]; 105 105 char TBuf[STATUS_SIZE]; … … 116 116 117 117 // Create string with severity encoding 118 snprintf(SBuf, sizeof(SBuf), "%s* *", Tmp);119 SBuf[strlen(SBuf)- 2] = '\0';120 SBuf[strlen(SBuf)+1] = Severity; 118 snprintf(SBuf, sizeof(SBuf), "%s*", Tmp); 119 SBuf[strlen(SBuf)-1] = '\0'; // new string terminiation replaces '*' 120 SBuf[strlen(SBuf)+1] = Severity; // Severity after new string termination 121 121 122 122 if (Tmp != ErrorString) free(Tmp); … … 174 174 // Terminate if not successful 175 175 if (!EvidenceServer::ServiceOK(&Config)) { 176 State(FATAL, "Configuration server unreachable, can't get '%s'", Item.c_str());176 Message(FATAL, "Configuration server unreachable, can't get '%s'", Item.c_str()); 177 177 } 178 178 179 179 if (strlen(Result) == 0) { 180 if (Default == NULL) State(FATAL, "Missing configuration data '%s'", Item.c_str());180 if (Default == NULL) Message(FATAL, "Missing configuration data '%s'", Item.c_str()); 181 181 Result = (char *) Default; 182 182 } … … 214 214 215 215 // If invoked twice, call exit() 216 ThisServer-> State(ThisServer->WARN, "Signal handler called again, invoking exit() (signal %d)", Signal);216 ThisServer->Message(ThisServer->WARN, "Signal handler called again, invoking exit() (signal %d)", Signal); 217 217 exit(EXIT_FAILURE); 218 218 } … … 253 253 else snprintf(Msg, sizeof(Msg), "Terminate() called without an active exception"); 254 254 255 ThisServer-> State(FATAL, Msg);255 ThisServer->Message(FATAL, Msg); 256 256 } 257 257 258 258 259 259 // Translates DIMInfo to string (memory has to be freed by caller) 260 // Static method: it cannot report memory allocation errors via Message() 260 261 char *EvidenceServer::ToString(DimInfo *Item) { 261 262 … … 355 356 356 357 // Marker for history buffer 357 const int EvidenceHistory::WrapMark[] = {0, -1};358 const int EvidenceHistory::EndMark[] = {0, 0};358 const struct EvidenceHistory::Item EvidenceHistory::WrapMark = {0, -1, {}}; 359 const struct EvidenceHistory::Item EvidenceHistory::EndMark = {0, 0, {}}; 359 360 360 361 // Constructor … … 392 393 393 394 // Returns next item in history buffer 394 bool EvidenceHistory::Next(int &Time, int &Size, void *&Data) {395 396 if (Buffer == NULL) return false;395 const struct EvidenceHistory::Item *EvidenceHistory::Next() { 396 397 if (Buffer == NULL) return NULL; 397 398 398 399 // Check for wrap around 399 if (memcmp( Buffer+Offset, WrapMark, sizeof(WrapMark)) == 0) Offset = 4;400 if (memcmp(Pointer, &WrapMark, sizeof(WrapMark)) == 0) Pointer = (struct Item *) (Buffer + 4); 400 401 401 402 // Check if at end of ring buffer 402 if (memcmp(Buffer+Offset, EndMark, sizeof(EndMark)) == 0) return false; 403 404 Time = *(int *) (Buffer + Offset); 405 Size = *(int *) (Buffer + Offset + sizeof(int)); 406 Data = Buffer + Offset + 2*sizeof(int); 407 408 Offset += *((int *) (Buffer + Offset) + 1) + 2*sizeof(int); 409 410 return true; 403 if (memcmp(Pointer, &EndMark, sizeof(EndMark)) == 0) return NULL; 404 405 const struct Item *Ret = Pointer; 406 Pointer = (struct Item *) ((char *) (Pointer + 1) + Pointer->Size); 407 408 return Ret; 411 409 } 412 410 … … 414 412 void EvidenceHistory::Rewind() { 415 413 416 if (Buffer != NULL) Offset = *(int *) Buffer;417 } 414 if (Buffer != NULL) Pointer = (struct Item *) (Buffer + (*(int *) Buffer)); 415 }
Note:
See TracChangeset
for help on using the changeset viewer.