Changeset 229 for Evidence/Bridge.cc
- Timestamp:
- 06/24/10 07:51:15 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Evidence/Bridge.cc
r224 r229 24 24 using namespace std; 25 25 26 27 26 // Class declaration 28 27 class Bridge: public DimClient, public EvidenceServer { 29 28 30 29 struct Item { 31 string Name;32 30 DimCommand *Command; 33 31 DimStampedInfo *DataItem; … … 35 33 char *Data; 36 34 }; 37 vector<struct Item> List;35 map<string, struct Item> Map; 38 36 39 37 DimInfo *ServerList; … … 41 39 void infoHandler(); 42 40 void commandHandler(); 41 public: 43 42 void AddService(string, char *, int); 44 43 void RemoveService(string); 45 44 void BugFix(); 45 46 46 public: 47 47 Bridge(char *, int); … … 63 63 Bridge::~Bridge() { 64 64 65 while ( List.size() != 0) RemoveService(List[0].Name);65 while (Map.size() != 0) RemoveService((*Map.begin()).first); 66 66 delete ServerList; 67 67 } … … 77 77 78 78 // If service is DIS_DNS/SERVER_LIST, subscribe to all SERVICE_LIST services 79 if (strcmp(I->getName(), "DIS_DNS/SERVER_LIST") == 0) { 79 if (strcmp(I->getName(), "DIS_DNS/SERVER_LIST") == 0) { 80 printf("DIS_DNS/SERVER_LIST: '%s'\n", I->getString()); 80 81 char *Token = strtok(I->getString(), "+-!@"); 81 82 while (Token != NULL) { … … 94 95 // If service is SERVICE_LIST, scan and subscribe/unsubscribe to services 95 96 if (strstr(I->getName(), "/SERVICE_LIST") != NULL) { 97 98 // Bug fix for empty SERVICE_LIST 99 if (strlen(I->getString()) == 0) { 100 string Tmp(I->getName()); 101 RemoveService(I->getName()); 102 AddService(Tmp.c_str(), (char *) "C", DimSERVICE); 103 return; 104 } 105 96 106 char *Format, *Name = strtok(I->getString(), "+-!|"); 97 107 while (Name != NULL) { … … 131 141 } 132 142 133 // Identify service and repeat to secondary DNS 134 for (int Service=0; Service<List.size(); Service++) if (I == List[Service].DataItem) { 135 136 // Copy service data 137 delete[] List[Service].Data; 138 List[Service].Data = new char [I->getSize()]; 139 memcpy(List[Service].Data, I->getData(), I->getSize()); 140 141 // Set new service properties and update service 142 List[Service].Service->setQuality(I->getQuality()); 143 List[Service].Service->setTimestamp(I->getTimestamp(), I->getTimestampMillisecs()); 144 List[Service].Service->updateService(List[Service].Data, I->getSize()); 145 } 143 // Check if service known and repeat to secondary DNS 144 if (Map.count(I->getName()) == 0) return; 145 146 // Copy service data 147 delete[] Map[I->getName()].Data; 148 Map[I->getName()].Data = new char [I->getSize()]; 149 memcpy(Map[I->getName()].Data, I->getData(), I->getSize()); 150 151 // Set new service properties and update service 152 Map[I->getName()].Service->setQuality(I->getQuality()); 153 Map[I->getName()].Service->setTimestamp(I->getTimestamp(), I->getTimestampMillisecs()); 154 Map[I->getName()].Service->updateService(Map[I->getName()].Data, I->getSize()); 146 155 } 147 156 … … 161 170 162 171 // Check if already subscribed to this service 163 for (int i=0; i<List.size(); i++) { 164 if (Name == List[i].Name) return; 165 } 172 if (Map.count(Name) != 0) return; 166 173 167 174 // Create subscription and service to secondary DNS or new command 168 struct Item New = {Name, NULL, NULL, NULL, NULL}; 169 175 Map[Name].Command = NULL; 176 Map[Name].DataItem = NULL; 177 Map[Name].Service = NULL; 178 Map[Name].Data = NULL; 179 170 180 if (Type == DimSERVICE) { 171 New.Service = new DimService(Name.c_str(), (char *) Format, New.Data, 0); 172 New.DataItem = new DimStampedInfo(Name.c_str(), NO_LINK, this); 173 } 174 else if (Type == DimCOMMAND) New.Command = new DimCommand(Name.c_str(), Format, this); 175 176 List.push_back(New); 181 Map[Name].Service = new DimService(Name.c_str(), (char *) Format, Map[Name].Data, 0); 182 Map[Name].DataItem = new DimStampedInfo(Name.c_str(), NO_LINK, this); 183 } 184 else if (Type == DimCOMMAND) Map[Name].Command = new DimCommand(Name.c_str(), Format, this); 177 185 } 178 186 … … 181 189 void Bridge::RemoveService(string Name) { 182 190 183 vector<struct Item>::iterator E;184 for (E=List.begin(); E<List.end(); ++E) if (Name == (*E).Name) {185 delete (*E).DataItem; 186 delete (*E).Service;187 delete[] (*E).Data;188 delete (*E).Command;189 190 List.erase(E); 191 }191 // Check if actually subscribed to service 192 if (Map.count(Name) == 0) return; 193 194 delete Map[Name].DataItem; 195 delete Map[Name].Service; 196 delete[] Map[Name].Data; 197 delete Map[Name].Command; 198 199 Map.erase(Name); 192 200 } 193 201 … … 206 214 207 215 // Sleep until signal caught 208 pause();209 } 216 while (!Class.ExitRequest) pause(); 217 }
Note:
See TracChangeset
for help on using the changeset viewer.