Changeset 9852 for fact/Evidence
- Timestamp:
- 08/12/10 13:11:58 (14 years ago)
- Location:
- fact/Evidence
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/Evidence/Alarm.cc
r262 r9852 10 10 The states are described in LevelStr[]. 11 11 - 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 13 14 A mutex is used because UpdateAlarmSummary() may be called from DIM handler thread and 14 15 from main thread. … … 32 33 class AlarmHandler: public DimClient, public EvidenceServer { 33 34 34 DimCommand *Command; 35 DimCommand *ResetCommand; 36 DimCommand *SwitchCommand; 35 37 DimService *Summary, *Master; 36 38 char *AlarmText; 37 39 int MasterAlarm; 40 bool Active; 38 41 39 42 void infoHandler(); … … 66 69 MasterAlarm = 0; 67 70 AlarmText = NULL; 68 71 Active = true; 72 69 73 // Handling of servies will only start after start() 70 74 autoStartOff(); … … 97 101 98 102 // 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); 100 105 101 106 // List set up, can start handling … … 107 112 AlarmHandler::~AlarmHandler() { 108 113 109 delete Command; 114 delete SwitchCommand; 115 delete ResetCommand; 110 116 111 117 for (int i=0; i<List.size(); i++) { … … 136 142 137 143 138 // Reset alarm level of given server144 // Handle commands 139 145 void AlarmHandler::commandHandler() { 140 146 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 145 149 // 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()); 151 165 } 152 166 … … 159 173 160 174 ostringstream Buf; 161 int Alarm = 0, Ret;175 int Alarm = -1, Ret; 162 176 163 177 Lock(); 164 178 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++) { 166 181 // Alarm level description 167 182 Buf << List[i].Server << ": " << (List[i].Level>=0 && List[i].Level<=4 ? LevelStr[List[i].Level] : "unknown"); … … 210 225 int main() { 211 226 212 DimBrowser B rowser;227 DimBrowser B; 213 228 char *Server, *Node; 214 229 bool Exist; 215 230 216 231 // 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 223 237 Exist = false; 224 B rowser.getServers();225 while (B rowser.getNextServer(Server, Node) == 1) {226 if (A larm.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; 227 241 } 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; 230 246 } 231 247 232 A larm.UpdateAlarmSummary();233 sleep(atoi(A larm.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 4 1 5 2 Version history … … 48 45 ConfigChanged() is called as separate thread when configuration file changes. Thread ID 49 46 is checked in GetConfig() and also from this thread it will make blocking requests. 47 12/8/2010 Added command to switch alarm server on/off (command 'Alarm/Switch').
Note:
See TracChangeset
for help on using the changeset viewer.