Changeset 174 for Evidence/Evidence.cc
- Timestamp:
- 03/05/10 15:06:15 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r168 r174 34 34 EvidenceServer *ThisServer; 35 35 36 36 37 // Constructor starts server with given name 37 38 EvidenceServer::EvidenceServer(const char *Name) { … … 50 51 // Catch C++ unhandled exceptions 51 52 set_terminate(Terminate); 53 54 // Subscribe to modify service for keeping track of config file changes 55 ModifyInfo = new class ConfigUpdate(); 52 56 53 57 // Start server … … 72 76 delete[] ConfigList[i].Value; 73 77 } 78 delete ModifyInfo; 74 79 } 75 80 … … 125 130 } 126 131 127 // Get configuration data (program terminates if data is missing)132 // Get configuration data 128 133 // 134 // Program terminates if data is missing and no default given. Actual configuration 135 // request will be made only if config file has modification since last request. 129 136 // The memory allocated by all calls to this function will be freed by 130 137 // the destructor. 131 138 char* EvidenceServer::GetConfig(const char *Item, const char *Default) { 132 139 133 // Determine configuration file update time 134 DimCurrentInfo ModifyTime("Config/ModifyTime", 0); 135 int Time = ModifyTime.getInt(), ItemNo = -1; 140 int ItemNo = -1; 136 141 137 142 // Check if configuration request already in list … … 139 144 if (strcmp(ConfigList[i].Name, Item) == 0) { 140 145 // Return original value if still up to date 141 if (ConfigList[i].Time >= Time) return ConfigList[i].Value;146 if (ConfigList[i].Time >= ModifyInfo->LastModifyTime) return ConfigList[i].Value; 142 147 143 148 // Otherwise, free memory of old value … … 172 177 strcpy(ConfigList[ItemNo].Name, Item); 173 178 strcpy(ConfigList[ItemNo].Value, Result); 174 ConfigList[ItemNo].Time = Time;179 ConfigList[ItemNo].Time = ModifyInfo->LastModifyTime; 175 180 176 181 // Return address to configuration value … … 310 315 311 316 // Constructor 312 EvidenceHistory::EvidenceHistory() { 317 EvidenceHistory::EvidenceHistory(std::string Name, int Delay): 318 Name(Name+".hist"), 319 Delay(Delay) { 313 320 314 321 Buffer = NULL; 322 LastUpdate = 0; 315 323 } 316 324 … … 322 330 323 331 // Requests service history 324 bool EvidenceHistory::GetHistory(char *Name) { 325 326 DimCurrentInfo Info((string(Name)+".hist").c_str(), NO_LINK); 327 332 bool EvidenceHistory::GetHistory() { 333 334 // Check if last buffer update less than minimum delay in the past 335 if ((Buffer != NULL) && (time(NULL)-LastUpdate < Delay)) { 336 Offset = *(int *) Buffer; 337 return true; 338 } 339 LastUpdate = time(NULL); 340 328 341 // Check if service available 342 DimCurrentInfo Info(Name.c_str(), NO_LINK); 329 343 if (((Info.getSize() == strlen(NO_LINK)+1) && 330 344 (memcmp(Info.getData(), NO_LINK, Info.getSize()) == 0))) return false;
Note:
See TracChangeset
for help on using the changeset viewer.