- Timestamp:
- 05/28/10 09:01:45 (15 years ago)
- Location:
- Evidence
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Alarm.cc
r191 r216 71 71 } 72 72 73 // Subscribe with handler to ' Status' service of all servers73 // Subscribe with handler to 'Message' service of all servers 74 74 StatusService = new DimStampedInfo* [NumServers]; 75 75 State = new int [NumServers]; … … 79 79 char *Buffer = new char [strlen(Server[i])+10]; 80 80 strcpy(Buffer, Server[i]); 81 strcat(Buffer, "/ Status");81 strcat(Buffer, "/Message"); 82 82 StatusService[i] = new DimStampedInfo(Buffer, NO_LINK, this); 83 83 delete[] Buffer; … … 107 107 108 108 // 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; 110 110 111 111 // Update State: unavailable or current severity of status -
Evidence/Config.cc
r209 r216 67 67 // Initialise mutex (errno is not set by pthread_mutex_init()) 68 68 if (pthread_mutex_init(&Mutex, NULL) != 0) { 69 State(FATAL, "pthread_mutex_init() failed");69 Message(FATAL, "pthread_mutex_init() failed"); 70 70 } 71 71 72 72 // Open configuration file 73 73 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)); 75 75 } 76 76 77 77 // Disable buffering, so file modifications are immediately seen 78 78 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); 80 80 } 81 81 … … 87 87 EvidenceConfig::~EvidenceConfig() { 88 88 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)); 90 90 91 91 delete ConfigModified; … … 93 93 delete[] FileContent; 94 94 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"); 96 96 } 97 97 … … 103 103 104 104 // 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()"); 106 106 107 107 // Search for config data in list (default response is empty string) … … 111 111 112 112 // 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()"); 114 114 115 115 // Send data and update Status 116 116 setData((char *) Response.c_str()); 117 117 118 State(INFO, "Client '%s' (ID %d) requested '%s'. Send '%s'.",118 Message(INFO, "Client '%s' (ID %d) requested '%s'. Send '%s'.", 119 119 DimServer::getClientName(), 120 120 DimServer::getClientId(), … … 135 135 struct stat Stat; 136 136 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)); 138 138 delete ConfigModified; 139 139 delete ConfigContent; … … 152 152 rewind(File); 153 153 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"); 155 155 } 156 156 NewContent[Stat.st_size] = '\0'; … … 176 176 // Remove comments 177 177 if (Line.find('#') != string::npos) Line.erase(Line.find('#')); 178 // Rep ace all tabs by spaces178 // Replace all tabs by spaces 179 179 while (Line.find("\t") != string::npos) Line[Line.find("\t")] = ' '; 180 180 // Remove leading spaces … … 206 206 207 207 // 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()"); 209 209 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()"); 211 211 }; 212 212 } … … 224 224 225 225 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)); 227 227 } 228 228 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)); 230 230 close(Notify); 231 231 Notify = -1; … … 241 241 } 242 242 243 // Closing will also free all inotify watches 243 244 if (Notify != -1) close(Notify); 244 245 } -
Evidence/DColl.cc
r213 r216 13 13 - The history buffers are written to disk at program termination and 14 14 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 17 16 18 17 Oliver Grimm, May 2010 … … 23 22 24 23 #define MIN_HIST_SIZE 1024 // Minimum history buffer in bytes (> 3*sizeof(int) !) 24 #define LOG_FILENAME "Evidence.log" 25 25 26 26 #include "Evidence.h" … … 61 61 FILE *LogFile; 62 62 char *Filename; 63 float DataSize kB, LogSizekB;63 float DataSizeMB, LogSizeMB; 64 64 int DataSizeLastUpdate, LogSizeLastUpdate; 65 char * DataDir;65 char *BaseDir; 66 66 DimService *LogSizeService, *DataSizeService, *DataFilename; 67 string HistDir;68 67 int SizeUpdateDelay; 69 68 int TimeForNextFile; … … 106 105 107 106 // Request configuration data 108 DataDir = GetConfig("datadir");107 BaseDir = GetConfig("basedir"); 109 108 SizeUpdateDelay = atoi(GetConfig("sizeupdate")); 110 HistDir = GetConfig("histdir");111 109 RollOver = atoi(GetConfig("rollover")); 112 110 113 111 // 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)); 117 114 } 118 115 … … 121 118 122 119 // Create services for file sizes and data file name 123 DataSize kB = 0;124 DataSizeService = new DimService(SERVER_NAME "/DataSize kB", DataSizekB);125 126 LogSize kB = FileSize(LogFile)/1024.0;127 LogSizeService = new DimService(SERVER_NAME "/LogSizekB", LogSize kB);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); 128 125 129 126 DataFilename = new DimService(SERVER_NAME "/CurrentFile", (char *) ""); … … 155 152 RegExCount--; 156 153 i--; 157 State(ERROR, "Error compiling regular expression '%s' (%s)", Token, ErrMsg);154 Message(ERROR, "Error compiling regular expression '%s' (%s)", Token, ErrMsg); 158 155 } 159 156 else { … … 188 185 // Close files 189 186 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)); 191 188 } 192 189 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)); 194 191 } 195 192 … … 208 205 // no mutex is needed to serialize writing to the file 209 206 void DataHandler::infoHandler() { 210 211 static const int WrapMark[] = {0, -1};212 static const int EndMark[] = {0, 0};213 207 214 208 DimInfo *Info = getInfo(); … … 254 248 if (time(NULL) >= TimeForNextFile) { 255 249 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)); 257 251 } 258 252 DataFile = NULL; … … 266 260 // Get time structure with date rollover 267 261 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"); 269 263 270 264 // Create direcory if not existing (ignore error if already existing) 271 265 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"); 274 268 } 275 269 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)); 277 271 } 278 272 … … 280 274 free(Filename); 281 275 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"); 283 277 } 284 278 free(Dir); … … 286 280 // Open file 287 281 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); 291 285 DataFilename->updateService(Filename); 292 286 … … 337 331 fclose(DataFile); 338 332 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)); 340 334 } 341 335 … … 344 338 fflush(DataFile); // not continuously to reduce load 345 339 346 DataSize kB = FileSize(DataFile)/1024.0;340 DataSizeMB = FileSize(DataFile)/1024.0/1024.0; 347 341 DataSizeService->updateService(); 348 342 DataSizeLastUpdate = time(NULL); … … 354 348 // 355 349 356 if (Info->getSize() ==0) return;350 if (Info->getSize()==0 || Info->getTimestamp()==0) return; 357 351 358 352 // Check if data should be added to history buffer … … 373 367 374 368 // 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; 378 372 void *WrapPos = NULL; 379 373 char *Buffer = List[Service].Buffer; … … 390 384 (Oldest + *((int *) (Buffer + Oldest) + 1) + 2*sizeof(int) > Next)) { 391 385 // Check for wrap-around 392 if (memcmp(Buffer + Oldest, WrapMark, sizeof(WrapMark)) == 0) {386 if (memcmp(Buffer + Oldest, &EvidenceHistory::WrapMark, sizeof(EvidenceHistory::WrapMark)) == 0) { 393 387 Oldest = 4; 394 388 continue; 395 389 } 396 390 // 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) { 398 392 Oldest = Next; 399 393 break; … … 406 400 407 401 // 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)); 409 403 410 404 // Copy data into ring buffer … … 414 408 415 409 // 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)); 418 412 419 413 List[Service].Next = Next; … … 437 431 struct tm *TM = localtime(&RawTime); 438 432 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", 440 434 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); 442 436 443 437 fflush(LogFile); 444 438 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) 446 440 if(ferror(LogFile)) { 447 441 fclose(LogFile); 448 442 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)); 450 444 } 451 445 452 446 // Update logfile size service 453 447 if (time(NULL) - LogSizeLastUpdate > SizeUpdateDelay) { 454 LogSize kB = FileSize(LogFile)/1024.0;448 LogSizeMB = FileSize(LogFile)/1024.0/1024.0; 455 449 LogSizeService->updateService(); 456 450 LogSizeLastUpdate = time(NULL); … … 486 480 fread(Buffer, sizeof(char), Size-sizeof(int), File); 487 481 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()); 489 483 setData(NULL, 0); // Default response 490 484 } … … 493 487 } 494 488 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()); 496 490 } 497 491 … … 535 529 fread(&New.Next, sizeof(New.Next), 1, File); 536 530 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());; 539 533 } 540 534 } … … 564 558 fwrite(&(*E).Next, sizeof((*E).Next), 1, File); 565 559 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());; 568 562 } 569 563 … … 574 568 } 575 569 576 577 570 // 578 571 // Determine size of file in kB … … 583 576 584 577 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)); 586 579 return -1; 587 580 } … … 591 584 592 585 // 593 // Replace all '/' by '_' in string586 // Open file for service history 594 587 // 595 588 FILE *DataHandler::OpenHistFile(string Service, const char *Mode) { 596 589 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 597 596 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); 599 598 } 600 599 -
Evidence/Edd/Edd.cc
r212 r216 30 30 DimBrowser Browser; 31 31 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 32 36 Browser.getServices(Service); 33 37 if (Browser.getNextService(Name, Format) != DimSERVICE) return new EddPlot(Service, Index); 34 38 39 // Otherwise, determine from format if plot or text history 35 40 if (strlen(Format) == 1 && *Format != 'C') return new EddPlot(Service, Index); 36 41 else return new EddText(Service); … … 205 210 206 211 DimClient::sendCommand(Name.toAscii().data(), text().toAscii().data()); 212 clear(); 207 213 } 208 214 … … 276 282 for (ItemNo=0; ItemNo<List.size(); ItemNo++) if (List[ItemNo].Name == Name) { 277 283 278 // Service available?279 if (!SetStatus(this, Name, Time, Format)) return;280 281 284 // If size limit reached, clear buffer 282 285 if (List[ItemNo].Signal->dataSize() > SizeLimit) List[ItemNo].Signal->setData(QPolygonF()); … … 284 287 // If buffer empty, request new history buffer 285 288 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; 288 291 class EvidenceHistory *Hist; 289 292 290 293 if ((Hist = Handler->GetHistory(List[ItemNo].Name)) != NULL) { 291 294 double Number=0; 292 while ( Hist->Next(Time, Size, Data)) {295 while ((R=Hist->Next()) != NULL) { 293 296 switch (Format[0].toUpper().toAscii()) { 294 297 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; 300 303 default: break; 301 304 } 302 AddPoint(ItemNo, Time, Number);305 AddPoint(ItemNo, R->Time, Number); 303 306 Count++; 304 307 } … … 309 312 } 310 313 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 } 315 320 } 316 321 … … 721 726 if (!Pure) { 722 727 // Get history for this service 723 int Time, Size; 724 void *Data; 728 const struct EvidenceHistory::Item *R; 725 729 class EvidenceHistory *Hist; 726 730 727 731 if ((Hist = Handler->GetHistory(Name)) != NULL) { 728 while ( Hist->Next(Time, Size, Data)) {732 while ((R=Hist->Next()) != NULL) { 729 733 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"); 732 736 } 733 737 } … … 780 784 781 785 Mutex = new QMutex(QMutex::Recursive); 782 783 MinuteVolume = 0; 784 TotalVolume = 0; 786 Volume = 0; 785 787 786 788 // Timer to calculate data rates … … 815 817 YEP(Name, ServiceList[i].TimeStamp, ServiceList[i].ByteArray, ServiceList[i].Format, ServiceList[i].Text); 816 818 } 819 else YEP(Name, -1); 817 820 return; 818 821 } … … 878 881 QMutexLocker Locker(Mutex); 879 882 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; 886 887 } 887 888 … … 900 901 901 902 // 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(); 906 904 } 907 905 … … 1149 1147 1150 1148 // Status display 1151 EddLineDisplay *Line = new EddLineDisplay("ARDUINO/ Status");1149 EddLineDisplay *Line = new EddLineDisplay("ARDUINO/Message"); 1152 1150 Line->setMaximumWidth(200); 1153 1151 Layout->addWidget(Line, 0, 0, 1, 2); … … 1188 1186 1189 1187 Layout->addWidget(Plot, 0, 4, 12, 3); 1190 Line = new EddLineDisplay("Bias/ Status");1188 Line = new EddLineDisplay("Bias/Message"); 1191 1189 Line->setMaximumWidth(200); 1192 1190 Layout->addWidget(Line, 0, 0, 1, 3); … … 1195 1193 Layout->addWidget(Command, 10, 0, 1, 4); 1196 1194 1197 EddText *Text = new EddText("Bias/ StdOut", true);1195 EddText *Text = new EddText("Bias/Textout", true); 1198 1196 Text->setFixedWidth(400); 1199 1197 Layout->addWidget(Text, 11, 0, 4, 4); … … 1224 1222 //FeedbackLayout->addWidget(Graph, 10, 0, 10, 3); 1225 1223 1226 Line = new EddLineDisplay("drsdaq/ Status");1224 Line = new EddLineDisplay("drsdaq/Message"); 1227 1225 Line->setMaximumWidth(200); 1228 1226 Layout->addWidget(Line, 0, 0, 1, 2); … … 1409 1407 EddText *Text; 1410 1408 1411 Line = new EddLineDisplay("Alarm/ Status");1409 Line = new EddLineDisplay("Alarm/Message"); 1412 1410 Line->setMaximumWidth(200); 1413 1411 Layout->addWidget(Line, 0, 0, 1, 2); … … 1422 1420 Layout->addWidget(Text, 1, 0, 1, 2); 1423 1421 1424 Line = new EddLineDisplay("DColl/ Status");1422 Line = new EddLineDisplay("DColl/Message"); 1425 1423 Line->setMaximumWidth(200); 1426 1424 Layout->addWidget(Line, 3, 0, 1, 2); 1427 1425 1428 Line = new EddLineDisplay("DColl/DataSize kB");1426 Line = new EddLineDisplay("DColl/DataSizeMB"); 1429 1427 Layout->addWidget(Line, 4, 0, 1, 1); 1430 1428 1431 Line = new EddLineDisplay("DColl/LogSize kB");1429 Line = new EddLineDisplay("DColl/LogSizeMB"); 1432 1430 Layout->addWidget(Line, 4, 1, 1, 1); 1433 1431 … … 1436 1434 Layout->addWidget(Line, 5, 0, 1, 3); 1437 1435 1438 Line = new EddLineDisplay("Config/ Status");1436 Line = new EddLineDisplay("Config/Message"); 1439 1437 Line->setMaximumWidth(200); 1440 1438 Layout->addWidget(Line, 6, 0, 1, 2); … … 1450 1448 Layout->addWidget(Button, 7, 1, 1, 1); 1451 1449 1452 Line = new EddLineDisplay("Edd/Rate_kB Min");1450 Line = new EddLineDisplay("Edd/Rate_kBSec"); 1453 1451 Layout->addWidget(Line, 8, 0, 1, 1); 1454 Line = new EddLineDisplay("Edd/Total_MB");1455 Layout->addWidget(Line, 8, 1, 1, 1);1456 1452 } 1457 1453 -
Evidence/Edd/Edd.h
r212 r216 232 232 QList<HistItem> HistoryList; 233 233 234 long long TotalVolume; 235 long long MinuteVolume; 234 long long Volume; 236 235 237 236 void infoHandler(); -
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 } -
Evidence/Evidence.h
r212 r216 63 63 ~EvidenceServer(); 64 64 65 enum StateType {INFO=0, WARN=1, ERROR=2, FATAL=3};65 enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3}; 66 66 67 void State(StateType, const char *, ...);67 void Message(MessageType, const char *, ...); 68 68 void SetStdOut(char *); 69 69 char* GetConfig(std::string, const char * = NULL); … … 75 75 }; 76 76 77 class EvidenceHistory : public DimClient{77 class EvidenceHistory { 78 78 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)); 81 85 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 87 95 public: 88 96 EvidenceHistory(std::string); 89 ~EvidenceHistory(); 90 97 ~EvidenceHistory(); 98 91 99 bool GetHistory(); 92 bool Next(int &, int &, void *&);100 const struct Item *Next(); 93 101 void Rewind(); 94 102 }; -
Evidence/readme.txt
r213 r216 31 31 yet in memory, reading from history file is tried. Improved error handling of 32 32 history files. 33 33 28/5/2010 Changed name of 'State' service to 'Message' to better reflect its functionality. Added client information to log file entries. 34 34 35 35
Note:
See TracChangeset
for help on using the changeset viewer.