Changeset 178 for Evidence/Evidence.cc
- Timestamp:
- 03/12/10 08:52:14 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r174 r178 20 20 class destructor. 21 21 22 Oliver Grimm, February200922 Oliver Grimm, March 2009 23 23 24 24 \********************************************************************/ 25 25 26 26 #include "Evidence.h" 27 28 27 using namespace std; 29 28 … … 33 32 34 33 EvidenceServer *ThisServer; 35 36 34 37 35 // Constructor starts server with given name … … 42 40 ExitRequest = false; 43 41 ThisServer = this; 44 42 ServerName = Name; 43 45 44 // Catch some signals 46 45 signal(SIGQUIT, &SignalHandler); // CTRL-Backspace … … 60 59 if (asprintf(&InitMsg, "Server started (%s, compiled %s %s)", Rev.c_str(),__DATE__, __TIME__) == -1) InitMsg = NULL; 61 60 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); 63 62 64 63 start(Name); … … 73 72 74 73 for (unsigned int i=0; i<ConfigList.size(); i++) { 75 delete[] ConfigList[i].Name;76 74 delete[] ConfigList[i].Value; 77 75 } … … 136 134 // The memory allocated by all calls to this function will be freed by 137 135 // the destructor. 138 char* EvidenceServer::GetConfig( const char *Item, const char *Default) {136 char* EvidenceServer::GetConfig(string Item, const char *Default) { 139 137 140 138 int ItemNo = -1; 141 139 142 140 // 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; 154 149 } 155 150 156 151 // Make configuration request 157 152 DimRpcInfo Config((char *) "ConfigRequest", (char *) ""); 158 Config.setData((char *) Item);153 Config.setData((char *) (ServerName + " " + Item).c_str()); 159 154 char *Result = Config.getString(); 160 155 161 156 // Terminate if not successful 162 157 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()); 164 159 Result = (char *) Default; 165 160 } … … 174 169 // Create new entry in item list, allocate memory and copy data to this memory 175 170 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; 178 172 strcpy(ConfigList[ItemNo].Value, Result); 179 173 ConfigList[ItemNo].Time = ModifyInfo->LastModifyTime;
Note:
See TracChangeset
for help on using the changeset viewer.