Changeset 216


Ignore:
Timestamp:
May 28, 2010, 9:01:45 AM (11 years ago)
Author:
ogrimm
Message:
Changed service 'Status' to 'Message' for clarity, added client information in log file entries
Location:
Evidence
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Alarm.cc

    r191 r216  
    7171  }
    7272
    73   // Subscribe with handler to 'Status' service of all servers
     73  // Subscribe with handler to 'Message' service of all servers
    7474  StatusService = new DimStampedInfo* [NumServers];
    7575  State = new int [NumServers];
     
    7979    char *Buffer = new char [strlen(Server[i])+10];
    8080    strcpy(Buffer, Server[i]);
    81     strcat(Buffer, "/Status");
     81    strcat(Buffer, "/Message");
    8282    StatusService[i] = new DimStampedInfo(Buffer, NO_LINK, this);
    8383    delete[] Buffer;
     
    107107
    108108        // Ignore DIS_DNS (has no status service)
    109         if (strcmp(getInfo()->getName(),"DIS_DNS/Status") == 0) return;
     109        if (strcmp(getInfo()->getName(),"DIS_DNS/Message") == 0) return;
    110110       
    111111        // Update State: unavailable or current severity of status 
  • Evidence/Config.cc

    r209 r216  
    6767  // Initialise mutex (errno is not set by pthread_mutex_init())
    6868  if (pthread_mutex_init(&Mutex, NULL) != 0) {
    69     State(FATAL, "pthread_mutex_init() failed");
     69    Message(FATAL, "pthread_mutex_init() failed");
    7070  }
    7171
    7272  // Open configuration file
    7373  if ((File = fopen(Filename, "r")) == NULL) {
    74     State(FATAL, "Could not open configuration file '%s' (%s)\n", Filename, strerror(errno));
     74    Message(FATAL, "Could not open configuration file '%s' (%s)\n", Filename, strerror(errno));
    7575  }
    7676
    7777  // Disable buffering, so file modifications are immediately seen
    7878  if (setvbuf(File, NULL, _IONBF, 0) != 0) {
    79     State(WARN, "Error setting configuration file '%s' to unbuffered mode", Filename);
     79    Message(WARN, "Error setting configuration file '%s' to unbuffered mode", Filename);
    8080  }
    8181 
     
    8787EvidenceConfig::~EvidenceConfig() {
    8888
    89   if (File != NULL && fclose(File) != 0) State(ERROR, "Error closing configuration file (%s)", strerror(errno));
     89  if (File != NULL && fclose(File) != 0) Message(ERROR, "Error closing configuration file (%s)", strerror(errno));
    9090
    9191  delete ConfigModified;
     
    9393  delete[] FileContent;
    9494
    95   if (pthread_mutex_destroy(&Mutex) != 0) State(ERROR, "pthread_mutex_destroy() failed");
     95  if (pthread_mutex_destroy(&Mutex) != 0) Message(ERROR, "pthread_mutex_destroy() failed");
    9696}
    9797
     
    103103 
    104104  // Lock because ConfigChange() might access concurrently
    105   if (pthread_mutex_lock(&Mutex) != 0) State(ERROR, "pthread_mutex_lock() failed in rpcHandler()");
     105  if (pthread_mutex_lock(&Mutex) != 0) Message(ERROR, "pthread_mutex_lock() failed in rpcHandler()");
    106106
    107107  // Search for config data in list (default response is empty string)
     
    111111 
    112112  // Unlock
    113   if (pthread_mutex_unlock(&Mutex) != 0) State(ERROR, "pthread_mutex_unlock() failed in rpcHandler()");
     113  if (pthread_mutex_unlock(&Mutex) != 0) Message(ERROR, "pthread_mutex_unlock() failed in rpcHandler()");
    114114
    115115  // Send data and update Status
    116116  setData((char *) Response.c_str());
    117117   
    118   State(INFO, "Client '%s' (ID %d) requested '%s'. Send '%s'.",
     118  Message(INFO, "Client '%s' (ID %d) requested '%s'. Send '%s'.",
    119119                DimServer::getClientName(),
    120120                DimServer::getClientId(),
     
    135135  struct stat Stat;
    136136  if (fstat(fileno(File), &Stat) == -1) {
    137     State(ERROR, "Error with stat() system call for configuration file, cannot update configuration file information (%s)", strerror(errno));
     137    Message(ERROR, "Error with stat() system call for configuration file, cannot update configuration file information (%s)", strerror(errno));
    138138        delete ConfigModified;
    139139        delete ConfigContent;
     
    152152  rewind(File);
    153153  if (fread(NewContent, sizeof(char), Stat.st_size, File) != Stat.st_size) {
    154     State(FATAL, "Could not read configuration file");
     154    Message(FATAL, "Could not read configuration file");
    155155  }
    156156  NewContent[Stat.st_size] = '\0';
     
    176176    // Remove comments
    177177        if (Line.find('#') != string::npos) Line.erase(Line.find('#'));
    178     // Repace all tabs by spaces
     178    // Replace all tabs by spaces
    179179    while (Line.find("\t") != string::npos) Line[Line.find("\t")] = ' ';
    180180        // Remove leading spaces
     
    206206
    207207        // Add to configuration list
    208         if (pthread_mutex_lock(&Mutex) != 0) State(ERROR, "pthread_mutex_lock() failed in ConfigChanged()");
     208        if (pthread_mutex_lock(&Mutex) != 0) Message(ERROR, "pthread_mutex_lock() failed in ConfigChanged()");
    209209        List.push_back(New);
    210         if (pthread_mutex_unlock(&Mutex) != 0) State(ERROR, "pthread_mutex_unlock() failed in ConfigChanged()");
     210        if (pthread_mutex_unlock(&Mutex) != 0) Message(ERROR, "pthread_mutex_unlock() failed in ConfigChanged()");
    211211  };
    212212}
     
    224224 
    225225  if ((Notify = inotify_init()) == -1) {
    226     Config.State(EvidenceConfig::WARN, "inotify_init() failed, cannot monitor changes of configuration file (%s)\n", strerror(errno));
     226    Config.Message(EvidenceConfig::WARN, "inotify_init() failed, cannot monitor changes of configuration file (%s)\n", strerror(errno));
    227227  }
    228228  else if (inotify_add_watch(Notify, argc<2 ? DEFAULT_CONFIG : argv[1], IN_MODIFY) == -1) {
    229       Config.State(EvidenceConfig::WARN, "Could not set inotify watch on configuration file (%s)\n", strerror(errno));
     229      Config.Message(EvidenceConfig::WARN, "Could not set inotify watch on configuration file (%s)\n", strerror(errno));
    230230          close(Notify);
    231231          Notify = -1;
     
    241241  }
    242242 
     243  // Closing will also free all inotify watches
    243244  if (Notify != -1) close(Notify);
    244245}
  • Evidence/DColl.cc

    r213 r216  
    1313  - The history buffers are written to disk at program termination and
    1414    are tired to be read when adding a service.
    15   - The command 'DColl/Log' writes the associated string to the log
    16     file specified in the configuration.
     15  - The command 'DColl/Log' writes the associated string to the log file
    1716 
    1817  Oliver Grimm, May 2010
     
    2322
    2423#define MIN_HIST_SIZE 1024      // Minimum history buffer in bytes (> 3*sizeof(int) !)
     24#define LOG_FILENAME "Evidence.log"
    2525
    2626#include "Evidence.h"
     
    6161    FILE *LogFile;
    6262        char *Filename;
    63         float DataSizekB, LogSizekB;
     63        float DataSizeMB, LogSizeMB;
    6464        int DataSizeLastUpdate, LogSizeLastUpdate;
    65         char *DataDir;
     65        char *BaseDir;
    6666    DimService *LogSizeService, *DataSizeService, *DataFilename;
    67         string HistDir;
    6867        int SizeUpdateDelay;
    6968        int TimeForNextFile;
     
    106105
    107106  // Request configuration data
    108   DataDir = GetConfig("datadir");
     107  BaseDir = GetConfig("basedir");
    109108  SizeUpdateDelay = atoi(GetConfig("sizeupdate"));
    110   HistDir = GetConfig("histdir");
    111109  RollOver = atoi(GetConfig("rollover"));
    112110
    113111  // Open log file
    114   char *Logname = GetConfig("logfile");
    115   if ((LogFile = fopen(Logname, "a")) == NULL) {
    116     State(FATAL, "Could not open log file '%s' (%s)", Logname, strerror(errno));
     112  if ((LogFile = fopen((string(BaseDir)+"/"+LOG_FILENAME).c_str(), "a")) == NULL) {
     113    Message(FATAL, "Could not open log file (%s)", strerror(errno));
    117114  }
    118115
     
    121118             
    122119  // Create services for file sizes and data file name
    123   DataSizekB = 0;
    124   DataSizeService = new DimService(SERVER_NAME "/DataSizekB", DataSizekB);
    125  
    126   LogSizekB = FileSize(LogFile)/1024.0;
    127   LogSizeService = new DimService(SERVER_NAME "/LogSizekB", LogSizekB);
     120  DataSizeMB = 0;
     121  DataSizeService = new DimService(SERVER_NAME "/DataSizeMB", DataSizeMB);
     122 
     123  LogSizeMB = FileSize(LogFile)/1024.0/1024.0;
     124  LogSizeService = new DimService(SERVER_NAME "/LogSizekB", LogSizeMB);
    128125
    129126  DataFilename = new DimService(SERVER_NAME "/CurrentFile", (char *) "");
     
    155152          RegExCount--;
    156153          i--;
    157           State(ERROR, "Error compiling regular expression '%s' (%s)", Token, ErrMsg);
     154          Message(ERROR, "Error compiling regular expression '%s' (%s)", Token, ErrMsg);
    158155        }
    159156        else {
     
    188185  // Close files
    189186  if (LogFile != NULL) if (fclose(LogFile) != 0) {
    190         State(ERROR, "Could not close log file (%s)", strerror(errno));
     187        Message(ERROR, "Could not close log file (%s)", strerror(errno));
    191188  }
    192189  if (DataFile != NULL && fclose(DataFile) != 0) {
    193         State(ERROR, "Error: Could not close data file (%s)", strerror(errno));
     190        Message(ERROR, "Error: Could not close data file (%s)", strerror(errno));
    194191  }
    195192
     
    208205// no mutex is needed to serialize writing to the file
    209206void DataHandler::infoHandler() {
    210 
    211   static const int WrapMark[] = {0, -1};
    212   static const int EndMark[] = {0, 0};
    213207
    214208  DimInfo *Info = getInfo();
     
    254248  if (time(NULL) >= TimeForNextFile) {
    255249        if (DataFile != NULL && fclose(DataFile) != 0) {
    256           State(ERROR, "Error: Could not close data file (%s)", strerror(errno));
     250          Message(ERROR, "Error: Could not close data file (%s)", strerror(errno));
    257251        }
    258252        DataFile = NULL;
     
    266260        // Get time structure with date rollover
    267261        if (T->tm_hour >= RollOver) T->tm_mday++;
    268         if (mktime(T) == -1) State(ERROR, "mktime() failed, check filename");
     262        if (mktime(T) == -1) Message(ERROR, "mktime() failed, check filename");
    269263
    270264        // Create direcory if not existing (ignore error if already existing)
    271265        char *Dir;
    272         if (asprintf(&Dir, "%s/%d%02d",DataDir, T->tm_year+1900, T->tm_mon + 1) == -1) {
    273           State(FATAL, "asprintf() failed, could not create direcory name");   
     266        if (asprintf(&Dir, "%s/%d%02d", BaseDir, T->tm_year+1900, T->tm_mon + 1) == -1) {
     267          Message(FATAL, "asprintf() failed, could not create direcory name"); 
    274268        }
    275269        if(mkdir(Dir, S_IRWXU|S_IRWXG)==-1 && errno!=EEXIST) {
    276           State(FATAL, "Could not create directory '%s' (%s)", Dir, strerror(errno));
     270          Message(FATAL, "Could not create directory '%s' (%s)", Dir, strerror(errno));
    277271        }
    278272
     
    280274        free(Filename);
    281275        if (asprintf(&Filename, "%s/%d%02d%02d.slow", Dir, T->tm_year+1900, T->tm_mon+1, T->tm_mday) == 1) {
    282           State(FATAL, "asprintf() failed, could not create filename");           
     276          Message(FATAL, "asprintf() failed, could not create filename");                 
    283277        }
    284278        free(Dir);
     
    286280        // Open file
    287281        if ((DataFile = fopen(Filename, "a")) == NULL) {
    288       State(FATAL, "Could not open data file '%s' (%s)", Filename, strerror(errno));
    289         }
    290         else State(INFO, "Opened data file '%s'", Filename);
     282      Message(FATAL, "Could not open data file '%s' (%s)", Filename, strerror(errno));
     283        }
     284        else Message(INFO, "Opened data file '%s'", Filename);
    291285        DataFilename->updateService(Filename);
    292286       
     
    337331      fclose(DataFile);
    338332          DataFile = NULL;
    339           State(FATAL, "Error writing to data file, closed file (%s)", strerror(errno));
     333          Message(FATAL, "Error writing to data file, closed file (%s)", strerror(errno));
    340334        }
    341335
     
    344338      fflush(DataFile); // not continuously to reduce load
    345339
    346           DataSizekB = FileSize(DataFile)/1024.0;
     340          DataSizeMB = FileSize(DataFile)/1024.0/1024.0;
    347341          DataSizeService->updateService();
    348342          DataSizeLastUpdate = time(NULL);
     
    354348  //
    355349
    356   if (Info->getSize() == 0) return;
     350  if (Info->getSize()==0 || Info->getTimestamp()==0) return;
    357351
    358352  // Check if data should be added to history buffer
     
    373367 
    374368  // Check if data fits into buffer
    375   if (List[Service].HistSize < Info->getSize() + 5*sizeof(int)) return;
    376 
    377   int Size = Info->getSize() + 4*sizeof(int), Next = List[Service].Next;
     369  if (List[Service].HistSize < Info->getSize() + sizeof(int)+ 2*sizeof(EvidenceHistory::Item)) return;
     370
     371  int Size = Info->getSize() + 2*sizeof(EvidenceHistory::Item), Next = List[Service].Next;
    378372  void *WrapPos = NULL;
    379373  char *Buffer = List[Service].Buffer;
     
    390384                 (Oldest + *((int *) (Buffer + Oldest) + 1) + 2*sizeof(int) > Next)) {
    391385        // Check for wrap-around
    392         if (memcmp(Buffer + Oldest, WrapMark, sizeof(WrapMark)) == 0) {
     386        if (memcmp(Buffer + Oldest, &EvidenceHistory::WrapMark, sizeof(EvidenceHistory::WrapMark)) == 0) {
    393387          Oldest = 4;
    394388          continue;
    395389        }
    396390        // Check if end marker reached, then only one event fits buffer
    397         if (memcmp(Buffer + Oldest, EndMark, sizeof(EndMark)) == 0) {
     391        if (memcmp(Buffer + Oldest, &EvidenceHistory::EndMark, sizeof(EvidenceHistory::EndMark)) == 0) {
    398392          Oldest = Next;
    399393          break;
     
    406400
    407401  // Write wrap mark if necessary
    408   if (WrapPos != NULL) memcpy(WrapPos, WrapMark, sizeof(WrapMark));
     402  if (WrapPos != NULL) memcpy(WrapPos, &EvidenceHistory::WrapMark, sizeof(EvidenceHistory::WrapMark));
    409403
    410404  // Copy data into ring buffer
     
    414408
    415409  // Adjust pointer for next entry and write end marker to buffer
    416   Next += Info->getSize() + 2*sizeof(int);
    417   memcpy(Buffer + Next, EndMark, sizeof(EndMark));
     410  Next += Info->getSize() + sizeof(EvidenceHistory::Item);
     411  memcpy(Buffer + Next, &EvidenceHistory::EndMark, sizeof(EvidenceHistory::EndMark));
    418412 
    419413  List[Service].Next = Next;
     
    437431  struct tm *TM = localtime(&RawTime);
    438432
    439   fprintf(LogFile, "%d/%d/%d %d:%d:%d: %s\n",
     433  fprintf(LogFile, "%2d/%2d/%4d %2d:%2d:%2d %s (ID %d): %s\n",
    440434                TM->tm_mday, TM->tm_mon+1, TM->tm_year+1900,
    441                 TM->tm_hour, TM->tm_min, TM->tm_sec, Text);
     435                TM->tm_hour, TM->tm_min, TM->tm_sec, getClientName(), getClientId(), Text);
    442436
    443437  fflush(LogFile);
    444438 
    445   // If error close file (otherwise infinite loop because State() also writes to log)
     439  // If error close file (otherwise infinite loop because Message() also writes to log)
    446440  if(ferror(LogFile)) {
    447441    fclose(LogFile);
    448442        LogFile = NULL;
    449     State(ERROR, "Error writing to log file, closing file (%s)", strerror(errno));
     443    Message(ERROR, "Error writing to log file, closing file (%s)", strerror(errno));
    450444  }
    451445   
    452446  // Update logfile size service
    453447  if (time(NULL) - LogSizeLastUpdate > SizeUpdateDelay) {
    454         LogSizekB = FileSize(LogFile)/1024.0;
     448        LogSizeMB = FileSize(LogFile)/1024.0/1024.0;
    455449        LogSizeService->updateService();
    456450        LogSizeLastUpdate = time(NULL);
     
    486480        fread(Buffer, sizeof(char), Size-sizeof(int), File);
    487481        if (ferror(File) != 0) {
    488           State(WARN, "Error reading history file '%s' in rpcHandler()", getString());
     482          Message(WARN, "Error reading history file '%s' in rpcHandler()", getString());
    489483          setData(NULL, 0);             // Default response
    490484        }
     
    493487  }
    494488 
    495   if (fclose(File) != 0) State(WARN, "Error closing history file '%s' in rpcHandler()", getString());
     489  if (fclose(File) != 0) Message(WARN, "Error closing history file '%s' in rpcHandler()", getString());
    496490}
    497491
     
    535529      fread(&New.Next, sizeof(New.Next), 1, File);
    536530      fread(New.Buffer, sizeof(char), New.HistSize, File);
    537           if (ferror(File) != 0) State(WARN, "Error reading history file '%s' in AddService()", Name.c_str());
    538       if (fclose(File) != 0) State(WARN, "Error closing history file '%s' in AddService()", Name.c_str());;
     531          if (ferror(File) != 0) Message(WARN, "Error reading history file '%s' in AddService()", Name.c_str());
     532      if (fclose(File) != 0) Message(WARN, "Error closing history file '%s' in AddService()", Name.c_str());;
    539533        }
    540534  }
     
    564558      fwrite(&(*E).Next, sizeof((*E).Next), 1, File);
    565559      fwrite((*E).Buffer, sizeof(char), (*E).HistSize, File);
    566           if (ferror(File) != 0) State(WARN, "Error writing history file '%s' in RemoveService()", Name.c_str());
    567       if (fclose(File) != 0) State(WARN, "Error closing history file '%s' in RemoveService()", Name.c_str());;
     560          if (ferror(File) != 0) Message(WARN, "Error writing history file '%s' in RemoveService()", Name.c_str());
     561      if (fclose(File) != 0) Message(WARN, "Error closing history file '%s' in RemoveService()", Name.c_str());;
    568562        }
    569563       
     
    574568}
    575569
    576 
    577570//
    578571// Determine size of file in kB
     
    583576
    584577  if (fstat(fileno(File), &FileStatus) == -1) {
    585      State(WARN, "Could not determine size of file (%s)", strerror(errno));
     578     Message(WARN, "Could not determine size of file (%s)", strerror(errno));
    586579         return -1;
    587580  }
     
    591584
    592585//
    593 // Replace all '/' by '_' in string
     586// Open file for service history
    594587//
    595588FILE *DataHandler::OpenHistFile(string Service, const char *Mode) {
    596589
     590  string Dir = string(BaseDir) + "/Histories/";
     591
     592  // Create directory if not yet existing
     593  if(mkdir(Dir.c_str(), S_IRWXU|S_IRWXG)==-1 && errno!=EEXIST) return NULL;
     594
     595  // Replace all '/' by '_' in string and open file
    597596  for (int i=0; i<Service.size(); i++) if (Service[i] == '/') Service[i] = '_';
    598   return fopen((HistDir + "/" + Service).c_str(), Mode);
     597  return fopen((Dir + Service).c_str(), Mode);
    599598}
    600599
  • Evidence/Edd/Edd.cc

    r212 r216  
    3030  DimBrowser Browser;
    3131
     32  // If status service displayed as text history
     33  if (strstr(Service, "/Message") != NULL) return new EddText(Service);
     34
     35  // If service currently not available, default open as plot
    3236  Browser.getServices(Service);
    3337  if (Browser.getNextService(Name, Format) != DimSERVICE) return new EddPlot(Service, Index);
    3438 
     39  // Otherwise, determine from format if plot or text history
    3540  if (strlen(Format) == 1 && *Format != 'C') return new EddPlot(Service, Index);
    3641  else return new EddText(Service);
     
    205210
    206211  DimClient::sendCommand(Name.toAscii().data(), text().toAscii().data());
     212  clear();
    207213}
    208214
     
    276282  for (ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) {
    277283
    278         // Service available?
    279         if (!SetStatus(this, Name, Time, Format)) return;
    280  
    281284        // If size limit reached, clear buffer
    282285    if (List[ItemNo].Signal->dataSize() > SizeLimit) List[ItemNo].Signal->setData(QPolygonF());
     
    284287        // If buffer empty, request new history buffer
    285288    if (List[ItemNo].Signal->dataSize() == 0) {
    286           int Time, Size, Count=0;
    287           void *Data;
     289          int Count=0;
     290          const struct EvidenceHistory::Item *R;
    288291          class EvidenceHistory *Hist;
    289292
    290293          if ((Hist = Handler->GetHistory(List[ItemNo].Name)) != NULL) {
    291294                double Number=0;
    292                 while (Hist->Next(Time, Size, Data)) {
     295                while ((R=Hist->Next()) != NULL) {
    293296                  switch (Format[0].toUpper().toAscii()) {
    294297                case 'I':
    295                         case 'L':  Number = *((int *) Data + List[ItemNo].Index);   break;
    296                 case 'S':  Number = *((short *) Data + List[ItemNo].Index);   break;
    297                 case 'F':  Number = *((float *) Data + List[ItemNo].Index);   break;
    298                 case 'D':  Number = *((double *) Data + List[ItemNo].Index);   break;
    299                 case 'X':  Number = *((long long *) Data + List[ItemNo].Index);   break;
     298                        case 'L':  Number = *((int *) R->Data + List[ItemNo].Index);   break;
     299                case 'S':  Number = *((short *) R->Data + List[ItemNo].Index);   break;
     300                case 'F':  Number = *((float *) R->Data + List[ItemNo].Index);   break;
     301                case 'D':  Number = *((double *) R->Data + List[ItemNo].Index);   break;
     302                case 'X':  Number = *((long long *) R->Data + List[ItemNo].Index);   break;
    300303                default: break;
    301304                  }
    302                   AddPoint(ItemNo, Time, Number);
     305                  AddPoint(ItemNo, R->Time, Number);
    303306                  Count++;
    304307                }
     
    309312        }
    310313
    311     // Append data
    312         QString Txt = Text;
    313         Txt = Txt.section(' ', List[ItemNo].Index, List[ItemNo].Index);
    314     AddPoint(ItemNo, Time, atof(Txt.toAscii().data()));
     314        // Appen data only if service available
     315        if (SetStatus(this, Name, Time, Format)) {
     316          QString Txt = Text;
     317          Txt = Txt.section(' ', List[ItemNo].Index, List[ItemNo].Index);
     318      AddPoint(ItemNo, Time, atof(Txt.toAscii().data()));
     319        }
    315320  }
    316321
     
    721726  if (!Pure) {
    722727        // Get history for this service
    723         int Time, Size;
    724         void *Data;
     728        const struct EvidenceHistory::Item *R;
    725729        class EvidenceHistory *Hist;
    726730
    727731        if ((Hist = Handler->GetHistory(Name)) != NULL) {
    728           while (Hist->Next(Time, Size, Data)) {
     732          while ((R=Hist->Next()) != NULL) {
    729733                moveCursor (QTextCursor::Start);
    730                 insertPlainText(QString("(")+QDateTime::fromTime_t(Time).toString()+") ");       
    731                 insertPlainText(QString((char *) Data) + "\n");   
     734                insertPlainText(QString("(")+QDateTime::fromTime_t(R->Time).toString()+") ");     
     735                insertPlainText(QString((char *) R->Data) + "\n");       
    732736          }
    733737        }
     
    780784
    781785  Mutex = new QMutex(QMutex::Recursive);
    782 
    783   MinuteVolume = 0;
    784   TotalVolume = 0;
     786  Volume = 0;
    785787
    786788  // Timer to calculate data rates
     
    815817          YEP(Name, ServiceList[i].TimeStamp, ServiceList[i].ByteArray, ServiceList[i].Format, ServiceList[i].Text);
    816818        }
     819        else YEP(Name, -1);
    817820        return;
    818821  }
     
    878881  QMutexLocker Locker(Mutex);
    879882
    880   float Rate = MinuteVolume/1024.0 * 6;
    881   float Total = TotalVolume/1024.0/1024.0;
    882 
    883   YEP("Edd/Rate_kBMin", time(NULL), QByteArray::number(Rate), "F", QString::number(Rate));
    884   YEP("Edd/Total_MB", time(NULL), QByteArray::number(Total), "F", QString::number(Total));
    885   MinuteVolume = 0;
     883  float Rate = Volume/1024.0/10;
     884
     885  YEP("Edd/Rate_kBSec", time(NULL), QByteArray::number(Rate), "F", QString::number(Rate));
     886  Volume = 0;
    886887}
    887888
     
    900901
    901902  // Update statistics only for Dim services
    902   if (!Name.startsWith("Edd/")) { 
    903         TotalVolume += Data.size();
    904         MinuteVolume += Data.size();
    905   }
     903  if (!Name.startsWith("Edd/")) Volume += Data.size();
    906904}
    907905
     
    11491147
    11501148  // Status display
    1151   EddLineDisplay *Line = new EddLineDisplay("ARDUINO/Status");
     1149  EddLineDisplay *Line = new EddLineDisplay("ARDUINO/Message");
    11521150  Line->setMaximumWidth(200);
    11531151  Layout->addWidget(Line, 0, 0, 1, 2);     
     
    11881186
    11891187  Layout->addWidget(Plot, 0, 4, 12, 3);
    1190   Line = new EddLineDisplay("Bias/Status");
     1188  Line = new EddLineDisplay("Bias/Message");
    11911189  Line->setMaximumWidth(200);
    11921190  Layout->addWidget(Line, 0, 0, 1, 3);     
     
    11951193  Layout->addWidget(Command, 10, 0, 1, 4);   
    11961194
    1197   EddText *Text = new EddText("Bias/StdOut", true);
     1195  EddText *Text = new EddText("Bias/Textout", true);
    11981196  Text->setFixedWidth(400);
    11991197  Layout->addWidget(Text, 11, 0, 4, 4);     
     
    12241222  //FeedbackLayout->addWidget(Graph, 10, 0, 10, 3);
    12251223
    1226   Line = new EddLineDisplay("drsdaq/Status");
     1224  Line = new EddLineDisplay("drsdaq/Message");
    12271225  Line->setMaximumWidth(200);
    12281226  Layout->addWidget(Line, 0, 0, 1, 2);     
     
    14091407  EddText *Text;
    14101408 
    1411   Line = new EddLineDisplay("Alarm/Status");
     1409  Line = new EddLineDisplay("Alarm/Message");
    14121410  Line->setMaximumWidth(200);
    14131411  Layout->addWidget(Line, 0, 0, 1, 2);     
     
    14221420  Layout->addWidget(Text, 1, 0, 1, 2);
    14231421
    1424   Line = new EddLineDisplay("DColl/Status");
     1422  Line = new EddLineDisplay("DColl/Message");
    14251423  Line->setMaximumWidth(200);
    14261424  Layout->addWidget(Line, 3, 0, 1, 2);     
    14271425
    1428   Line = new EddLineDisplay("DColl/DataSizekB");
     1426  Line = new EddLineDisplay("DColl/DataSizeMB");
    14291427  Layout->addWidget(Line, 4, 0, 1, 1);
    14301428
    1431   Line = new EddLineDisplay("DColl/LogSizekB");
     1429  Line = new EddLineDisplay("DColl/LogSizeMB");
    14321430  Layout->addWidget(Line, 4, 1, 1, 1);
    14331431
     
    14361434  Layout->addWidget(Line, 5, 0, 1, 3);
    14371435
    1438   Line = new EddLineDisplay("Config/Status");
     1436  Line = new EddLineDisplay("Config/Message");
    14391437  Line->setMaximumWidth(200);
    14401438  Layout->addWidget(Line, 6, 0, 1, 2);     
     
    14501448  Layout->addWidget(Button, 7, 1, 1, 1);
    14511449
    1452   Line = new EddLineDisplay("Edd/Rate_kBMin");
     1450  Line = new EddLineDisplay("Edd/Rate_kBSec");
    14531451  Layout->addWidget(Line, 8, 0, 1, 1);
    1454   Line = new EddLineDisplay("Edd/Total_MB");
    1455   Layout->addWidget(Line, 8, 1, 1, 1);
    14561452}
    14571453 
  • Evidence/Edd/Edd.h

    r212 r216  
    232232    QList<HistItem> HistoryList;
    233233
    234         long long TotalVolume;
    235         long long MinuteVolume;
     234        long long Volume;
    236235
    237236        void infoHandler();
  • 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}
  • Evidence/Evidence.h

    r212 r216  
    6363        ~EvidenceServer();
    6464
    65         enum StateType {INFO=0, WARN=1, ERROR=2, FATAL=3};
     65        enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3};
    6666
    67         void State(StateType, const char *, ...);
     67        void Message(MessageType, const char *, ...);
    6868        void SetStdOut(char *);
    6969        char* GetConfig(std::string, const char * = NULL);
     
    7575};
    7676
    77 class EvidenceHistory: public DimClient {
     77class EvidenceHistory {
    7878
    79   static const int WrapMark[];
    80   static const int EndMark[];
     79  public: 
     80        struct Item {
     81          int Time;
     82          int Size;
     83          char Data[]; // Size bytes
     84        } __attribute__((packed));
    8185
    82   std::string Name;
    83   char *Buffer;
    84   int BufferSize;
    85   int Offset;
    86  
     86        static const struct Item WrapMark;
     87        static const struct Item EndMark;
     88
     89  private:
     90        std::string Name;
     91        char *Buffer;
     92        int BufferSize;
     93        struct Item *Pointer;
     94       
    8795  public:
    8896        EvidenceHistory(std::string);
    89         ~EvidenceHistory();
    90        
     97        ~EvidenceHistory();     
     98
    9199        bool GetHistory();
    92         bool Next(int &, int &, void *&);
     100        const struct Item *Next();
    93101        void Rewind();
    94102};
  • Evidence/readme.txt

    r213 r216  
    3131                        yet in memory, reading from history file is tried. Improved error handling of
    3232                        history files.
    33                        
     3328/5/2010       Changed name of 'State' service to 'Message' to better reflect its functionality. Added client information to log file entries.                 
    3434
    3535
Note: See TracChangeset for help on using the changeset viewer.