Changeset 154 for Evidence/Evidence.cc
- Timestamp:
- 01/29/10 14:27:34 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Evidence.cc
r152 r154 25 25 #include "Evidence.h" 26 26 27 bool EvidenceServer::ExitRequest = false; 28 string __StatusName; 27 EvidenceServer *ThisServer; 29 28 30 29 // Constructor starts server with given name … … 33 32 // Initialize 34 33 Status = NULL; 35 ConfigList = NULL; 36 ConfigNum = 0; 37 __StatusName = string(Name) + "/Status"; 34 ExitRequest = false; 35 ThisServer = this; 38 36 39 37 // Catch some signals … … 47 45 48 46 // Start server 49 Status = new DimService(__StatusName.c_str(), (char *) "Server started"); 47 static char Init[] = "Server started"; 48 Status = new DimService((string(Name) + "/Status").c_str(), (char *) "C", Init, sizeof(Init)); 50 49 51 50 start(Name); 52 51 addExitHandler(this); 52 53 53 } 54 54 … … 56 56 EvidenceServer::~EvidenceServer() { 57 57 58 for (unsigned int i=0; i<Config Num; i++) {58 for (unsigned int i=0; i<ConfigList.size(); i++) { 59 59 delete[] ConfigList[i].Name; 60 60 delete[] ConfigList[i].Value; 61 61 } 62 free(ConfigList);63 62 } 64 63 … … 93 92 va_end(ArgumentPointer); 94 93 95 snprintf(TBuf, sizeof(TBuf), "%s (%s): %s", __StatusName.c_str(), StateString[Severity], Tmp); // Normal string 96 snprintf(SBuf, sizeof(SBuf), "%s*%c", Tmp, (char) Severity); 97 *(strrchr(SBuf, '*')) = '\0'; // String with severity encoding 94 // Create normal string 95 snprintf(TBuf, sizeof(TBuf), "%s (%s): %s", Status->getName(), StateString[Severity], Tmp); 96 97 // Create string with severity encoding 98 snprintf(SBuf, sizeof(SBuf), "%s**", Tmp); 99 SBuf[strlen(SBuf)-2] = '\0'; 100 SBuf[strlen(SBuf)+1] = Severity; 101 98 102 if (Tmp != ErrorString) free(Tmp); 99 103 … … 120 124 121 125 // Check if configuration request already in list 122 for (unsigned int i=0; i<Config Num; i++) {126 for (unsigned int i=0; i<ConfigList.size(); i++) { 123 127 if (strcmp(ConfigList[i].Name, Item) == 0) { 124 128 // Return original value if still up to date … … 144 148 } 145 149 146 // Enlarge memory to hold new pointerif necessary150 // Enlarge list if necessary 147 151 if (ItemNo == -1) { 148 void *N = realloc(ConfigList, sizeof(struct ConfigItem)*(++ConfigNum)); 149 if (N == NULL) { 150 State(WARN, "Could not realloc() memory for configuration, will lose memory (%s)", strerror(errno)); 151 ConfigNum--; 152 } 153 else ConfigList = (struct ConfigItem *) N; 154 155 ItemNo = ConfigNum-1; 156 } 157 158 // Allocate memory for strings, and copy data to this memory 152 struct ConfigItem New; 153 ConfigList.push_back(New); 154 ItemNo = ConfigList.size()-1; 155 } 156 157 // Create new entry in item list, allocate memory and copy data to this memory 159 158 ConfigList[ItemNo].Value = new char [strlen(Result)+1]; 160 159 ConfigList[ItemNo].Name = new char [strlen(Item)+1]; 161 160 strcpy(ConfigList[ItemNo].Name, Item); 162 161 strcpy(ConfigList[ItemNo].Value, Result); 163 164 162 ConfigList[ItemNo].Time = Time; 165 163 166 164 // Return address to configuration value 167 165 return ConfigList[ItemNo].Value; … … 174 172 void EvidenceServer::SignalHandler(int) { 175 173 176 EvidenceServer::ExitRequest = true;174 ThisServer->ExitRequest = true; 177 175 } 178 176 … … 180 178 void EvidenceServer::Terminate() { 181 179 182 string Msg = __StatusName + ": Caught unhandled exception"; 180 string Msg = string(ThisServer->Status->getName()) + ": Caught unhandled exception"; 181 183 182 printf("%s\n", Msg.c_str()); 184 183 DimClient::sendCommand("DColl/Log", Msg.c_str()); … … 187 186 } 188 187 188 189 189 // Translates DIMInfo to string (memory has to be freed by caller) 190 190 // No DIM structures are supported (only a single number or string is converted) 191 // For string conversion, a terminating \0 is enforced. 191 192 char *EvidenceServer::ToString(DimInfo *Item) { 192 193 … … 198 199 switch (*(Item->getFormat())) { 199 200 case 'I': R = asprintf(&Text, "%d", Item->getInt()); break; 200 case 'C': R = asprintf(&Text, "%s", Item->getString()); break;201 201 case 'S': R = asprintf(&Text, "%hd", Item->getShort()); break; 202 202 case 'F': R = asprintf(&Text, "%.5f", Item->getFloat()); break; 203 203 case 'D': R = asprintf(&Text, "%.5f", Item->getDouble()); break; 204 204 case 'X': R = asprintf(&Text, "%lld", Item->getLonglong()); break; 205 case 'C': *(Item->getString() + Item->getSize()) = '\0'; 206 R = asprintf(&Text, "%s", Item->getString()); 207 break; 205 208 default: return NULL; 206 209 }
Note:
See TracChangeset
for help on using the changeset viewer.