- Timestamp:
- 03/12/10 08:52:14 (15 years ago)
- Location:
- Evidence
- Files:
-
- 2 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; -
Evidence/Evidence.h
r174 r178 41 41 42 42 struct ConfigItem { 43 char *Name;43 std::string Name; 44 44 char *Value; 45 45 int Time; … … 47 47 std::vector<struct ConfigItem> ConfigList; 48 48 49 std::string ServerName; 49 50 DimService *Status; 50 51 class ConfigUpdate *ModifyInfo; … … 65 66 66 67 void State(StateType, const char *, ...); 67 char* GetConfig( const char *, const char * = NULL);68 char* GetConfig(std::string, const char * = NULL); 68 69 static char* ToString(DimInfo *); 69 70 static bool ServiceOK(DimInfo *);
Note:
See TracChangeset
for help on using the changeset viewer.