Changeset 216 for Evidence/Evidence.cc


Ignore:
Timestamp:
05/28/10 09:01:45 (14 years ago)
Author:
ogrimm
Message:
Changed service 'Status' to 'Message' for clarity, added client information in log file entries
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Evidence.cc

    r212 r216  
    55  - The server is started with the given name.
    66  - DIM exit and error handlers are implemented.
    7   - The Status service 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 (with
    10     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).
    1111  - Configuration data can be requested by GetConfig().
    1212  - Signal handlers to ignore common signals are installed.
     
    6060  snprintf(InitMsg, sizeof(InitMsg), "Server started (%s, compiled %s %s)", Rev.c_str(),__DATE__, __TIME__);
    6161 
    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);
    6363  StdOut = new DimService((ServerName+"/Textout").c_str(), (char *) "");
    6464
     
    7070EvidenceServer::~EvidenceServer() {
    7171
    72   State(INFO, "Server stopped");
     72  Message(INFO, "Server stopped");
    7373 
    7474  for (unsigned int i=0; i<ConfigList.size(); i++) {
     
    8484void EvidenceServer::exitHandler(int Code) {
    8585
    86   State(INFO, "Exit handler called (DIM exit code %d)", Code);
     86  Message(INFO, "Exit handler called (DIM exit code %d)", Code);
    8787  exit(EXIT_SUCCESS);
    8888}
    8989
    9090// 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);
     91void EvidenceServer::errorHandler(int Severity, int Code, char *Text) {   
     92  Message(ERROR, "%s (DIM error code %d, severity %d)\n", Text, Code, Severity);
    9393}
    9494
     
    9898// is given, terminated by another '\0'  The buffer for the DIM service must have
    9999// the same lifetime as the DIM service. If Severity is FATAL, exit() will be invoked.
    100 void EvidenceServer::State(StateType Severity, const char *Format, ...) {
     100void EvidenceServer::Message(MessageType Severity, const char *Format, ...) {
    101101
    102102  static const char* StateString[] = {"Info", "Warn", "Error", "Fatal"};
    103   static char ErrorString[] = "vasprintf() failed in State()";
     103  static char ErrorString[] = "vasprintf() failed in Message()";
    104104  static char SBuf[STATUS_SIZE];
    105105  char TBuf[STATUS_SIZE];
     
    116116
    117117  // 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
    121121
    122122  if (Tmp != ErrorString) free(Tmp);
     
    174174  // Terminate if not successful
    175175  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());
    177177  }
    178178
    179179  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());
    181181        Result = (char *) Default;
    182182  }
     
    214214
    215215  // 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);
    217217  exit(EXIT_FAILURE);
    218218}
     
    253253  else snprintf(Msg, sizeof(Msg), "Terminate() called without an active exception");
    254254
    255   ThisServer->State(FATAL, Msg);
     255  ThisServer->Message(FATAL, Msg);
    256256}
    257257
    258258
    259259// Translates DIMInfo to string (memory has to be freed by caller)
     260// Static method: it cannot report memory allocation errors via Message()
    260261char *EvidenceServer::ToString(DimInfo *Item) {
    261262
     
    355356
    356357// Marker for history buffer
    357 const int EvidenceHistory::WrapMark[] = {0, -1};
    358 const int EvidenceHistory::EndMark[] = {0, 0};
     358const struct EvidenceHistory::Item EvidenceHistory::WrapMark = {0, -1, {}};
     359const struct EvidenceHistory::Item EvidenceHistory::EndMark = {0, 0, {}};
    359360
    360361// Constructor
     
    392393
    393394// Returns next item in history buffer
    394 bool EvidenceHistory::Next(int &Time, int &Size, void *&Data) {
    395 
    396   if (Buffer == NULL) return false;
     395const struct EvidenceHistory::Item *EvidenceHistory::Next() {
     396
     397  if (Buffer == NULL) return NULL;
    397398
    398399  // 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);
    400401 
    401402  // 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;
    411409}
    412410
     
    414412void EvidenceHistory::Rewind() {
    415413
    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.