Changeset 174 for Evidence/Evidence.cc


Ignore:
Timestamp:
03/05/10 15:06:15 (15 years ago)
Author:
ogrimm
Message:
Update to configuration handling: Dim request only made if configuration file was modified since last request
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Evidence.cc

    r168 r174  
    3434EvidenceServer *ThisServer;
    3535
     36
    3637// Constructor starts server with given name
    3738EvidenceServer::EvidenceServer(const char *Name) {
     
    5051  // Catch C++ unhandled exceptions
    5152  set_terminate(Terminate);
     53
     54  // Subscribe to modify service for keeping track of config file changes
     55  ModifyInfo = new class ConfigUpdate();
    5256 
    5357  // Start server
     
    7276        delete[] ConfigList[i].Value;
    7377  }
     78  delete ModifyInfo;
    7479}
    7580
     
    125130}
    126131
    127 // Get configuration data (program terminates if data is missing)
     132// Get configuration data
    128133//
     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.
    129136// The memory allocated by all calls to this function will be freed by
    130137// the destructor.
    131138char* EvidenceServer::GetConfig(const char *Item, const char *Default) {
    132139 
    133   // Determine configuration file update time
    134   DimCurrentInfo ModifyTime("Config/ModifyTime", 0);
    135   int Time = ModifyTime.getInt(), ItemNo = -1;
     140  int ItemNo = -1;
    136141 
    137142  // Check if configuration request already in list
     
    139144    if (strcmp(ConfigList[i].Name, Item) == 0) {
    140145          // 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;
    142147
    143148          // Otherwise, free memory of old value
     
    172177  strcpy(ConfigList[ItemNo].Name, Item);
    173178  strcpy(ConfigList[ItemNo].Value, Result);
    174   ConfigList[ItemNo].Time = Time;
     179  ConfigList[ItemNo].Time = ModifyInfo->LastModifyTime;
    175180   
    176181  // Return address to configuration value 
     
    310315
    311316// Constructor
    312 EvidenceHistory::EvidenceHistory() {
     317EvidenceHistory::EvidenceHistory(std::string Name, int Delay):
     318        Name(Name+".hist"),
     319        Delay(Delay) {
    313320
    314321  Buffer = NULL;
     322  LastUpdate = 0;
    315323}
    316324
     
    322330
    323331// Requests service history
    324 bool EvidenceHistory::GetHistory(char *Name) {
    325 
    326   DimCurrentInfo Info((string(Name)+".hist").c_str(), NO_LINK);
    327 
     332bool 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 
    328341  // Check if service available
     342  DimCurrentInfo Info(Name.c_str(), NO_LINK);
    329343  if (((Info.getSize() == strlen(NO_LINK)+1) && 
    330344          (memcmp(Info.getData(), NO_LINK, Info.getSize()) == 0))) return false;
Note: See TracChangeset for help on using the changeset viewer.