Changeset 178 for Evidence


Ignore:
Timestamp:
03/12/10 08:52:14 (15 years ago)
Author:
ogrimm
Message:
Server name added automatically to configuration request
Location:
Evidence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Evidence/Evidence.cc

    r174 r178  
    2020  class destructor.
    2121 
    22   Oliver Grimm, February 2009
     22  Oliver Grimm, March 2009
    2323 
    2424\********************************************************************/
    2525
    2626#include "Evidence.h"
    27 
    2827using namespace std;
    2928
     
    3332
    3433EvidenceServer *ThisServer;
    35 
    3634
    3735// Constructor starts server with given name
     
    4240  ExitRequest = false;
    4341  ThisServer = this;
    44  
     42  ServerName = Name;
     43
    4544  // Catch some signals
    4645  signal(SIGQUIT, &SignalHandler);  // CTRL-Backspace
     
    6059  if (asprintf(&InitMsg, "Server started (%s, compiled %s %s)", Rev.c_str(),__DATE__, __TIME__) == -1) InitMsg = NULL;
    6160 
    62   Status = new DimService((string(Name) + "/Status").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1);
     61  Status = new DimService((ServerName+"/Status").c_str(), (char *) "C", InitMsg, strlen(InitMsg)+1);
    6362
    6463  start(Name);
     
    7372 
    7473  for (unsigned int i=0; i<ConfigList.size(); i++) {
    75         delete[] ConfigList[i].Name;
    7674        delete[] ConfigList[i].Value;
    7775  }
     
    136134// The memory allocated by all calls to this function will be freed by
    137135// the destructor.
    138 char* EvidenceServer::GetConfig(const char *Item, const char *Default) {
     136char* EvidenceServer::GetConfig(string Item, const char *Default) {
    139137 
    140138  int ItemNo = -1;
    141139 
    142140  // Check if configuration request already in list
    143   for (unsigned int i=0; i<ConfigList.size(); i++) {
    144     if (strcmp(ConfigList[i].Name, Item) == 0) {
    145           // Return original value if still up to date
    146           if (ConfigList[i].Time >= ModifyInfo->LastModifyTime) return ConfigList[i].Value;
    147 
    148           // Otherwise, free memory of old value
    149           delete[] ConfigList[i].Name;
    150           delete[] ConfigList[i].Value;   
    151           ItemNo = i;
    152           break;
    153         }
     141  for (unsigned int i=0; i<ConfigList.size(); i++) if (ConfigList[i].Name == Item) {
     142        // Return original value if still up to date
     143        if (ConfigList[i].Time >= ModifyInfo->LastModifyTime) return ConfigList[i].Value;
     144
     145        // Otherwise, free memory of old value
     146        delete[] ConfigList[i].Value;
     147        ItemNo = i;
     148        break;
    154149  }
    155150 
    156151  // Make configuration request
    157152  DimRpcInfo Config((char *) "ConfigRequest", (char *) "");
    158   Config.setData((char *) Item);
     153  Config.setData((char *) (ServerName + " " + Item).c_str());
    159154  char *Result = Config.getString();
    160155 
    161156  // Terminate if not successful
    162157  if (strlen(Result) == 0) {
    163     if (Default == NULL) State(FATAL, "Missing configuration data '%s'", Item);
     158    if (Default == NULL) State(FATAL, "Missing configuration data '%s'", Item.c_str());
    164159        Result = (char *) Default;
    165160  }
     
    174169  // Create new entry in item list, allocate memory and copy data to this memory
    175170  ConfigList[ItemNo].Value = new char [strlen(Result)+1];
    176   ConfigList[ItemNo].Name = new char [strlen(Item)+1];
    177   strcpy(ConfigList[ItemNo].Name, Item);
     171  ConfigList[ItemNo].Name = Item;
    178172  strcpy(ConfigList[ItemNo].Value, Result);
    179173  ConfigList[ItemNo].Time = ModifyInfo->LastModifyTime;
  • Evidence/Evidence.h

    r174 r178  
    4141
    4242        struct ConfigItem {
    43           char *Name;
     43          std::string Name;
    4444          char *Value;
    4545          int Time;
     
    4747        std::vector<struct ConfigItem> ConfigList;
    4848
     49        std::string ServerName;
    4950    DimService *Status;
    5051        class ConfigUpdate *ModifyInfo;
     
    6566
    6667        void State(StateType, const char *, ...);
    67         char* GetConfig(const char *, const char * = NULL);
     68        char* GetConfig(std::string, const char * = NULL);
    6869        static char* ToString(DimInfo *);
    6970        static bool ServiceOK(DimInfo *);
Note: See TracChangeset for help on using the changeset viewer.