Changeset 10143
- Timestamp:
- 02/08/11 16:13:12 (14 years ago)
- Location:
- fact/Evidence
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/Evidence/Alarm.cc
r10068 r10143 8 8 - Maximum severity may be reset by a command 'Alarm/ResetAlarm' for a server. 9 9 - A text describing the current state of all servers is published as DIM service. 10 The states are described in LevelStr[].11 10 - A master alarm (indicating most severe of individual alarms) is published. 12 11 - The server can be switched on/off with the command 'Alarm/Switch'. … … 15 14 from main thread. 16 15 17 Oliver Grimm, June 201016 Oliver Grimm, February 2011 18 17 19 18 \********************************************************************/ … … 26 25 using namespace std; 27 26 28 const char* LevelStr[] = {"OK", "WARN", "ERROR", "FATAL", "UNAVAILABLE"};29 const int MIN_PERIOD = 5; // Minimum period in seconds for checking servers are alive27 const int MIN_PERIOD = 5; // Minimum period in seconds for checking servers are alive 28 const int UNAVA = 255; // Alarm level to use if server unavailable 30 29 31 30 // … … 135 134 for (int i=0; i<List.size(); i++) if (getInfo() == List[i].Subscription) { 136 135 // Update level: unavailable or current severity of status (safely extracted) 137 if (!ServiceOK(getInfo())) List[i].Level = 4;136 if (!ServiceOK(getInfo())) List[i].Level = UNAVA; 138 137 else { 139 138 int Severity = atoi(ToString(getInfo()->getFormat(), getInfo()->getData(), getInfo()->getSize()).c_str()); 140 if ((Severity>List[i].Level) || (List[i].Level== 4&& Severity==0)) List[i].Level = Severity;139 if ((Severity>List[i].Level) || (List[i].Level==UNAVA && Severity==0)) List[i].Level = Severity; 141 140 } 142 141 } … … 177 176 178 177 ostringstream Buf; 178 string Desc; 179 179 int Alarm = -1, Ret; 180 180 … … 184 184 else for (int i=0; i<List.size(); i++) { 185 185 // Alarm level description 186 Buf << List[i].Server << ": " << (List[i].Level>=0 && List[i].Level<=4 ? LevelStr[List[i].Level] : "unknown"); 187 Buf << " (" << List[i].Level << ")" << endl; 186 Buf << List[i].Server << ": "; 187 switch (List[i].Level) { 188 case INFO: Desc = "OK"; break; 189 case WARN: Desc = "WARN"; break; 190 case ERROR: Desc = "ERROR"; break; 191 case FATAL: Desc = "FATAL"; break; 192 case UNAVA: Desc = "UNAVAILABLE"; break; 193 default: Desc = "?"; break; 194 } 195 Buf << Desc << " (" << List[i].Level << ")" << endl; 188 196 189 197 // Adjust master alarm and update server alarm level … … 198 206 char *Text; 199 207 time_t Time = time(NULL); 200 if (asprintf(&Text, "echo \"Server alarm level '%s' at %s\"|"208 if (asprintf(&Text, "echo \"Server alarm level '%s' (%d) at %s\"|" 201 209 "mail -s \"Evidence Alarm for '%s'\" %s", 202 List[i].Level>=0 && List[i].Level<=4 ? LevelStr[List[i].Level] : "unknown", 203 ctime(&Time), List[i].Server.c_str(), List[i].Email.c_str()) != -1) { 210 Desc.c_str(), List[i].Level, ctime(&Time), List[i].Server.c_str(), List[i].Email.c_str()) != -1) { 204 211 system(Text); // Return value depending on OS 205 212 free(Text); … … 245 252 if (A.List[i].Server == Server) Exist = true; 246 253 } 247 if (!Exist) A.List[i].Level = 4;254 if (!Exist) A.List[i].Level = UNAVA; 248 255 249 256 // Check if standard service available in case server not yet checked (Level is -1) -
fact/Evidence/Edd/Edd.cc
r10125 r10143 1439 1439 1440 1440 // 1441 // FADctrl page 1442 // 1443 TP_FADctrl::TP_FADctrl() { 1444 1445 QString Board; 1446 1447 QGridLayout *Layout = new QGridLayout(this); 1448 setAttribute(Qt::WA_DeleteOnClose); 1449 EddLineDisplay *Line; 1450 1451 Line = new EddLineDisplay("FADctrl/Message"); 1452 Line->setMaximumWidth(200); 1453 Layout->addWidget(Line, 0, 0, 1, 3); 1454 1455 EddCommand *Command = new EddCommand("FADctrl/Command"); 1456 Layout->addWidget(Command, 1, 0, 1, 4); 1457 1458 EddText *Text = new EddText("FADctrl/ConsoleOut", true); 1459 Text->setFixedWidth(400); 1460 Layout->addWidget(Text, 2, 0, 4, 4); 1461 1462 for (int i=0; i<10; i++) { 1463 Board = Board.sprintf("FADctrl/Board%.2d/", i); 1464 Line = new EddLineDisplay(Board+"Server"); 1465 Layout->addWidget(Line, i+7, 0, 1, 1); 1466 Line = new EddLineDisplay(Board+"BoardID"); 1467 Layout->addWidget(Line, i+7, 1, 1, 1); 1468 Line = new EddLineDisplay(Board+"Temperature", 0); 1469 Layout->addWidget(Line, i+7, 2, 1, 1); 1470 Line = new EddLineDisplay(Board+"Temperature", 1); 1471 Layout->addWidget(Line, i+7, 3, 1, 1); 1472 Line = new EddLineDisplay(Board+"Temperature", 2); 1473 Layout->addWidget(Line, i+7, 4, 1, 1); 1474 Line = new EddLineDisplay(Board+"Temperature", 3); 1475 Layout->addWidget(Line, i+7, 5, 1, 1); 1476 } 1477 } 1478 1479 // 1441 1480 // Event scope page 1442 1481 // … … 1750 1789 connect(TabWidget, SIGNAL(tabCloseRequested(int)), SLOT(DetachTab(int))); 1751 1790 TabWidget->addTab(new TP_DAQ, "Event scope " + DRSBoard); 1791 TabWidget->addTab(new TP_FADctrl, "FADctrl"); 1752 1792 TabWidget->addTab(new TP_Bias, "Bias"); 1753 1793 TabWidget->addTab(new TP_Feedback, "Feedback"); -
fact/Evidence/Edd/Edd.h
r10118 r10143 322 322 }; 323 323 324 class TP_FADctrl: public QWidget { 325 Q_OBJECT 326 327 public: 328 TP_FADctrl(); 329 }; 330 324 331 class TP_Feedback: public QWidget { 325 332 Q_OBJECT -
fact/Evidence/Evidence.cc
r264 r10143 20 20 - A terminate-handler is installed for catching unhandled C++ exceptions. 21 21 22 Oliver Grimm , June 201022 Oliver Grimm 23 23 24 24 \********************************************************************/ … … 59 59 60 60 if (!ServiceOK(DimInfo::getInfo())) return; 61 return; 61 62 62 This->Lock(); 63 63 ConfigTimeStamp = getInfo()->getInt(); … … 82 82 // Clear to allow new rpc call 83 83 CurrentItem.clear(); 84 This->Unlock();85 }86 87 // Request configuration data possible only when answer to previous request received88 void EvidenceServer::Config::RequestNB(string Item) {89 90 This->Lock();91 if (CurrentItem.empty()) {92 CurrentItem = Item;93 setData(((char *) Item.c_str()));94 }95 84 This->Unlock(); 96 85 } … … 163 152 Message(ERROR, "pthread_mutex_destroy() failed (%s)", strerror(Ret)); 164 153 } 165 154 166 155 delete MessageService; 167 156 delete[] MessageData; … … 170 159 171 160 // DIM exit handler 161 // Note handler runs in DIM thread, thus exit() will call destructors of static objects in this thread 172 162 void EvidenceServer::exitHandler(int Code) { 173 163 … … 184 174 185 175 // Set server message (if Severity is FATAL, exit() will be invoked) 186 void EvidenceServer::Message(MessageType Severity, const char *Format, ...) { 187 188 static const char* StateString[] = {"Info", "Warn", "Error", "Fatal"}; 176 void EvidenceServer::Message(int Severity, const char *Format, ...) { 177 189 178 static char ErrorString[] = "vasprintf() failed in Message()"; 179 char Buffer[10]; 190 180 char *Text; 191 181 … … 206 196 207 197 // Send message to console and log file 208 printf("%s (%s): %s\n", MessageService->getName(), StateString[Severity], NewMsg->Text); 209 SendToLog("%s (%s): %s", MessageService->getName(), StateString[Severity], NewMsg->Text); 198 const char *Desc; 199 switch (Severity) { 200 case INFO: Desc = "Info"; break; 201 case WARN: Desc = "Warn"; break; 202 case ERROR: Desc = "Error"; break; 203 case FATAL: Desc = "Fatal"; break; 204 default: snprintf(Buffer, sizeof(Buffer), "%d", Severity); 205 Desc = Buffer; 206 } 207 208 printf("%s (%s): %s\n", MessageService->getName(), Desc, NewMsg->Text); 209 SendToLog("%s (%s): %s", MessageService->getName(), Desc, NewMsg->Text); 210 210 211 211 // Update DIM message service … … 293 293 if (!Blocking) { 294 294 Lock(); 295 if (List.count(Item) > 0) { 296 ConfClass->RequestNB(Name + " " + Item); 297 Result = List[Item].Value; 295 296 // Make request if currently non is processed 297 if (ConfClass->CurrentItem.empty()) { 298 ConfClass->CurrentItem = Item; 299 ConfClass->setData(((char *) (Name + " " + Item).c_str())); 298 300 } 301 302 if (List.count(Item) > 0) Result = List[Item].Value; 303 else Result = Default; 299 304 Unlock(); 300 305 } … … 353 358 void EvidenceServer::SignalHandler(int Signal) { 354 359 355 static bool Called = false;360 static int Count = 0; 356 361 357 362 // At first invocation just request exit 358 if (!Called) { 359 Called = true; 363 if (++Count == 1) { 360 364 This->ExitRequest = true; 361 365 return; … … 363 367 364 368 // If invoked twice, call exit() 365 This->Message(WARN, "Signal handler called again, invoking exit() (signal %d)", Signal); 366 exit(EXIT_FAILURE); 369 if (Count == 2) { 370 This->Message(WARN, "Signal handler called twice, invoking exit() (signal %d)", Signal); 371 exit(EXIT_FAILURE); 372 } 373 374 // If invoked more than twice, call abort() 375 This->Message(WARN, "Signal handler called %d times, invoking abort(). Good bye. (signal %d)", Count, Signal); 376 abort(); 367 377 } 368 378 -
fact/Evidence/Evidence.h
r263 r10143 30 30 31 31 DimInfo *Service; 32 std::string CurrentItem;33 32 34 33 void rpcInfoHandler(); … … 41 40 42 41 int ConfigTimeStamp; 43 void RequestNB(std::string);42 std::string CurrentItem; 44 43 }; 45 44 … … 73 72 ~EvidenceServer(); 74 73 75 enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3};74 enum {INFO=0, WARN=10, ERROR=20, FATAL=30}; 76 75 77 void Message( MessageType, const char *, ...);76 void Message(int, const char *, ...); 78 77 static void SendToLog(const char *, ...); 79 78 std::string GetConfig(std::string, std::string = std::string()); -
fact/Evidence/readme.txt
r10068 r10143 47 47 12/8/2010 Added command to switch alarm server on/off (command 'Alarm/Switch'). 48 48 9/12/2010 Minimum period for checking server status in Alarm set to 5 seconds. 49 2/2/2011 Changed encoding of WARN, ERROR and FATAL to 10,20,30 to allow intermediate values. 50 Non-blocking configuration request with default value was not working. 51 Signal handler calls abort() if invoked three times or more.
Note:
See TracChangeset
for help on using the changeset viewer.