Changeset 10143 for fact/Evidence


Ignore:
Timestamp:
02/08/11 16:13:12 (14 years ago)
Author:
ogrimm
Message:
Non-blocking configuration request did not recognize default value
Location:
fact/Evidence
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • fact/Evidence/Alarm.cc

    r10068 r10143  
    88  - Maximum severity may be reset by a command 'Alarm/ResetAlarm' for a server.
    99  - A text describing the current state of all servers is published as DIM service.
    10     The states are described in LevelStr[].
    1110  - A master alarm (indicating most severe of individual alarms) is published.
    1211  - The server can be switched on/off with the command 'Alarm/Switch'.
     
    1514  from main thread.
    1615
    17   Oliver Grimm, June 2010
     16  Oliver Grimm, February 2011
    1817
    1918\********************************************************************/
     
    2625using namespace std;
    2726
    28 const char* LevelStr[] = {"OK", "WARN", "ERROR", "FATAL", "UNAVAILABLE"};
    29 const int MIN_PERIOD = 5;  // Minimum period in seconds for checking servers are alive
     27const int MIN_PERIOD = 5;       // Minimum period in seconds for checking servers are alive
     28const int UNAVA = 255;          // Alarm level to use if server unavailable
    3029
    3130//
     
    135134  for (int i=0; i<List.size(); i++) if (getInfo() == List[i].Subscription) {
    136135        // 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;
    138137        else {
    139138          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;
    141140        }
    142141  }
     
    177176
    178177  ostringstream Buf;
     178  string Desc;
    179179  int Alarm = -1, Ret; 
    180180
     
    184184  else for (int i=0; i<List.size(); i++) {
    185185        // 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;
    188196
    189197        // Adjust master alarm and update server alarm level
     
    198206          char *Text;
    199207          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\"|"
    201209                        "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) {
    204211                system(Text); // Return value depending on OS
    205212                free(Text);
     
    245252        if (A.List[i].Server == Server) Exist = true;
    246253      }
    247           if (!Exist) A.List[i].Level = 4;
     254          if (!Exist) A.List[i].Level = UNAVA;
    248255
    249256          // Check if standard service available in case server not yet checked (Level is -1)
  • fact/Evidence/Edd/Edd.cc

    r10125 r10143  
    14391439
    14401440//
     1441// FADctrl page
     1442//
     1443TP_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//
    14411480// Event scope page
    14421481//
     
    17501789  connect(TabWidget, SIGNAL(tabCloseRequested(int)), SLOT(DetachTab(int)));
    17511790  TabWidget->addTab(new TP_DAQ, "Event scope " + DRSBoard);
     1791  TabWidget->addTab(new TP_FADctrl, "FADctrl");
    17521792  TabWidget->addTab(new TP_Bias, "Bias");
    17531793  TabWidget->addTab(new TP_Feedback, "Feedback");
  • fact/Evidence/Edd/Edd.h

    r10118 r10143  
    322322};
    323323
     324class TP_FADctrl: public QWidget {
     325  Q_OBJECT
     326
     327  public:
     328    TP_FADctrl();
     329};
     330
    324331class TP_Feedback: public QWidget {
    325332  Q_OBJECT
  • fact/Evidence/Evidence.cc

    r264 r10143  
    2020  - A terminate-handler is installed for catching unhandled C++ exceptions.
    2121
    22   Oliver Grimm, June 2010
     22  Oliver Grimm
    2323 
    2424\********************************************************************/
     
    5959
    6060  if (!ServiceOK(DimInfo::getInfo())) return;
    61 return;
     61
    6262  This->Lock();
    6363  ConfigTimeStamp = getInfo()->getInt();
     
    8282  // Clear to allow new rpc call
    8383  CurrentItem.clear();
    84   This->Unlock();
    85 }
    86 
    87 // Request configuration data possible only when answer to previous request received
    88 void EvidenceServer::Config::RequestNB(string Item) {
    89 
    90   This->Lock();
    91   if (CurrentItem.empty()) {
    92         CurrentItem = Item;
    93         setData(((char *) Item.c_str()));
    94   }
    9584  This->Unlock();
    9685}
     
    163152        Message(ERROR, "pthread_mutex_destroy() failed (%s)", strerror(Ret));
    164153  }
    165  
     154
    166155  delete MessageService;
    167156  delete[] MessageData;
     
    170159
    171160// DIM exit handler
     161// Note handler runs in DIM thread, thus exit() will call destructors of static objects in this thread
    172162void EvidenceServer::exitHandler(int Code) {
    173163
     
    184174
    185175// 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"};
     176void EvidenceServer::Message(int Severity, const char *Format, ...) {
     177
    189178  static char ErrorString[] = "vasprintf() failed in Message()";
     179  char Buffer[10];
    190180  char *Text;
    191181 
     
    206196 
    207197  // 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);
    210210
    211211  // Update DIM message service
     
    293293  if (!Blocking) {
    294294        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()));
    298300        }
     301
     302        if (List.count(Item) > 0) Result = List[Item].Value;
     303        else Result = Default;
    299304        Unlock();
    300305  }
     
    353358void EvidenceServer::SignalHandler(int Signal) {
    354359
    355   static bool Called = false;
     360  static int Count = 0;
    356361
    357362  // At first invocation just request exit
    358   if (!Called) {
    359         Called = true;
     363  if (++Count == 1) {
    360364        This->ExitRequest = true;
    361365        return;
     
    363367
    364368  // 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();
    367377}
    368378
  • fact/Evidence/Evidence.h

    r263 r10143  
    3030
    3131                DimInfo *Service;
    32                 std::string CurrentItem;
    3332
    3433                void rpcInfoHandler();
     
    4140
    4241                int ConfigTimeStamp;
    43                 void RequestNB(std::string);
     42                std::string CurrentItem;
    4443        };
    4544
     
    7372        ~EvidenceServer();
    7473
    75         enum MessageType {INFO=0, WARN=1, ERROR=2, FATAL=3};
     74        enum {INFO=0, WARN=10, ERROR=20, FATAL=30};
    7675
    77         void Message(MessageType, const char *, ...);
     76        void Message(int, const char *, ...);
    7877        static void SendToLog(const char *, ...);
    7978        std::string GetConfig(std::string, std::string = std::string());
  • fact/Evidence/readme.txt

    r10068 r10143  
    474712/8/2010       Added command to switch alarm server on/off (command 'Alarm/Switch').
    48489/12/2010       Minimum period for checking server status in Alarm set to 5 seconds.
     492/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.