Changeset 9852 for fact/Evidence


Ignore:
Timestamp:
08/12/10 13:11:58 (14 years ago)
Author:
ogrimm
Message:
Alarm server can be switched off
Location:
fact/Evidence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • fact/Evidence/Alarm.cc

    r262 r9852  
    1010    The states are described in LevelStr[].
    1111  - A master alarm (indicating most severe of individual alarms) is published.
    12    
     12  - The server can be switched on/off with the command 'Alarm/Switch'.
     13     
    1314  A mutex is used because UpdateAlarmSummary() may be called from DIM handler thread and
    1415  from main thread.
     
    3233class AlarmHandler: public DimClient, public EvidenceServer {
    3334   
    34         DimCommand *Command;
     35        DimCommand *ResetCommand;
     36        DimCommand *SwitchCommand;
    3537        DimService *Summary, *Master;
    3638        char *AlarmText;
    3739        int MasterAlarm;
     40        bool Active;
    3841
    3942    void infoHandler();
     
    6669  MasterAlarm = 0;
    6770  AlarmText = NULL;
    68  
     71  Active = true;
     72
    6973  // Handling of servies will only start after start()
    7074  autoStartOff();
     
    97101
    98102  // Provide command to reset Level   
    99   Command = new DimCommand("ResetAlarm", (char *) "C", this);
     103  ResetCommand = new DimCommand(SERVER_NAME"/ResetAlarm", (char *) "C", this);
     104  SwitchCommand = new DimCommand(SERVER_NAME"/Switch", (char *) "C", this);
    100105 
    101106  // List set up, can start handling
     
    107112AlarmHandler::~AlarmHandler() {
    108113
    109   delete Command;
     114  delete SwitchCommand;
     115  delete ResetCommand;
    110116
    111117  for (int i=0; i<List.size(); i++) {
     
    136142
    137143
    138 // Reset alarm level of given server
     144// Handle commands
    139145void AlarmHandler::commandHandler() {
    140146
    141   // Safety check
    142   string Server = ToString((char *) "C", getCommand()->getData(), getCommand()->getSize());
    143   if (getCommand() != Command || Server.empty()) return;
    144  
     147  string Text = ToString((char *) "C", getCommand()->getData(), getCommand()->getSize());
     148
    145149  // Reset alarm level, publish/log action and reset server message severity
    146   for (int i=0; i<List.size(); i++) if (List[i].Server == Server) {
    147     Message(INFO, "Alarm level of server %s reset by %s (ID %d)", Server.c_str(), getClientName(), getClientId());
    148         List[i].Level = 0;
    149         List[i].WarnedLevel = 0;
    150         sendCommandNB((Server+"/ResetMessage").c_str(), (int) 0);
     150  if (getCommand() == ResetCommand) {
     151        for (int i=0; i<List.size(); i++) if (List[i].Server == Text) {
     152      Message(INFO, "Alarm level of server %s reset by %s (ID %d)", Text.c_str(), getClientName(), getClientId());
     153          List[i].Level = 0;
     154          List[i].WarnedLevel = 0;
     155          sendCommandNB((Text+"/ResetMessage").c_str(), (int) 0);
     156        }
     157  }
     158
     159  // Switch Alarm server on/off and publish/log action
     160  if (getCommand() == SwitchCommand) {
     161    if (Text == "off") Active = false;
     162        else Active = true;
     163
     164    Message(INFO, "Alarm server switched %s by %s (ID %d)", Active ? "ON":"OFF", getClientName(), getClientId());
    151165  }
    152166 
     
    159173
    160174  ostringstream Buf;
    161   int Alarm = 0, Ret; 
     175  int Alarm = -1, Ret; 
    162176
    163177  Lock();
    164178
    165   for (int i=0; i<List.size(); i++) {
     179  if (!Active) Buf << "Alarm server inactive";
     180  else for (int i=0; i<List.size(); i++) {
    166181        // Alarm level description
    167182        Buf << List[i].Server << ": " << (List[i].Level>=0 && List[i].Level<=4 ? LevelStr[List[i].Level] : "unknown");
     
    210225int main() {
    211226   
    212   DimBrowser Browser;
     227  DimBrowser B;
    213228  char *Server, *Node;
    214229  bool Exist;
    215230 
    216231  // Static declaration ensures calling of destructor by exit()
    217   static AlarmHandler Alarm;
    218  
    219   // Check periodically if servers are up
    220   while(!Alarm.ExitRequest) {
    221 
    222     for (int i=0; i<Alarm.List.size(); i++) {
     232  static AlarmHandler A;
     233 
     234  while(!A.ExitRequest) {
     235    for (int i=0; i<A.List.size(); i++) {
     236          // Check if server exists
    223237      Exist = false;
    224       Browser.getServers();
    225       while (Browser.getNextServer(Server, Node) == 1) {
    226         if (Alarm.List[i].Server == Server) Exist = true;
     238      B.getServers();
     239      while (B.getNextServer(Server, Node) == 1) {
     240        if (A.List[i].Server == Server) Exist = true;
    227241      }
    228           if (!Exist) Alarm.List[i].Level = 4;
    229           else if (Alarm.List[i].Level == -1) Alarm.List[i].Level = 0;
     242          if (!Exist) A.List[i].Level = 4;
     243
     244          // Check if standard service available in case server not yet chcked (Level is -1)
     245          if (B.getServices((A.List[i].Server+"/VERSION_NUMBER").c_str())>0 && A.List[i].Level==-1) A.List[i].Level = 0;
    230246    }
    231247   
    232     Alarm.UpdateAlarmSummary();
    233     sleep(atoi(Alarm.GetConfig("period").c_str()));
    234   }
    235 }
     248    A.UpdateAlarmSummary();
     249    sleep(atoi(A.GetConfig("period").c_str()));
     250  }
     251}
  • fact/Evidence/readme.txt

    r262 r9852  
    1 
    2 This directory contains the backbone of the control system. See directory Doc for documentation.
    3 
    41
    52Version history
     
    4845                        ConfigChanged() is called as separate thread when configuration file changes. Thread ID
    4946                        is checked in GetConfig() and also from this thread it will make blocking requests.
     4712/8/2010       Added command to switch alarm server on/off (command 'Alarm/Switch').
Note: See TracChangeset for help on using the changeset viewer.