Changeset 11088 for fact/Evidence/History.cc
- Timestamp:
- 06/21/11 12:52:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/Evidence/History.cc
r10996 r11088 31 31 const string DEFAULT_MAX_SIZE_KB = "2000"; 32 32 const string DEFAULT_NUM_ENTRIES = "1000"; // Number of entries in each history buffer 33 const double MIN_SAVE_PERDIOD = 0.5; // Minimum period between saving history buffers in hours 33 34 34 35 // … … 44 45 double MinAbsChange; 45 46 string Format; 47 time_t LastSave; 46 48 }; 47 49 map<string, struct Item> Map; … … 55 57 void AddService(string, const char *); 56 58 void RemoveService(string); 59 void SaveHistory(string); 57 60 off_t FileSize(FILE *); 58 61 FILE *OpenFile(string, const char *); … … 73 76 GetConfig("maxsize_kb", DEFAULT_MAX_SIZE_KB); 74 77 GetConfig("numentries", DEFAULT_NUM_ENTRIES); 78 GetConfig("saveperiod", "1"); 75 79 GetConfig("exclude", ""); 76 80 … … 95 99 // Check if service available 96 100 if (!ServiceOK(I)) return; 97 101 98 102 // ====== Part A: Handle service subscriptions === 99 103 … … 143 147 if (Map.count(Service) == 0 || I->getSize()==0 || I->getTimestamp()<=0) return; 144 148 149 // Save history buffers periodically (in case of program crash) 150 if (time(NULL)-Map[Service].LastSave > max(atof(GetConfig("saveperiod").c_str()),MIN_SAVE_PERDIOD)*3600) { 151 Map[Service].LastSave = time(NULL); 152 SaveHistory(Service); 153 } 154 145 155 // Resize buffer if necessary 146 156 int NEntries = atoi(GetConfig("numentries").c_str()); … … 266 276 Map[Name].Format = Format; 267 277 Map[Name].MinAbsChange = 0.0; 278 Map[Name].LastSave = 0.0; 268 279 269 280 // Set minimum required change if given in configuratrion … … 319 330 320 331 // Save history buffer 332 SaveHistory(Name); 333 334 Map.erase(Name); 335 } 336 337 338 // 339 // Save history buffer to file 340 // 341 void History::SaveHistory(string Name) { 342 321 343 FILE *File = OpenFile(Name, "wb"); 344 322 345 if (File != NULL) { 323 346 fwrite(&Map[Name].Next, sizeof(Map[Name].Next), 1, File); // Next pointer … … 327 350 // If error, try to delete (possibly erroneous) file 328 351 if (ferror(File) != 0) { 329 if (remove(Name.c_str()) == -1) Message(WARN, "Error writing history file '%s' in RemoveService(), could also not delete file", Name.c_str());330 else Message(WARN, "Error writing history file '%s' in RemoveService(), deleted file", Name.c_str());331 } 332 if (fclose(File) != 0) Message(WARN, "Error closing history file '%s' in RemoveService()", Name.c_str());;333 } 334 335 Map.erase(Name); 336 } 352 if (remove(Name.c_str()) == -1) Message(WARN, "Error writing history file '%s', could also not delete file", Name.c_str()); 353 else Message(WARN, "Error writing history file '%s', deleted file", Name.c_str()); 354 } 355 if (fclose(File) != 0) Message(WARN, "Error closing history file '%s'", Name.c_str()); 356 } 357 else Message(WARN, "Could not open history file '%s' for writing", Name.c_str());; 358 } 359 337 360 338 361 //
Note:
See TracChangeset
for help on using the changeset viewer.