| 336 | } |
| 337 | |
| 338 | int NamingServiceThread::AddWatcher(NamingServiceWatcher* watcher, |
| 339 | const NamingServiceFilter* filter) { |
| 340 | if (watcher == NULL) { |
| 341 | LOG(ERROR) << "Param[watcher] is NULL"; |
| 342 | return -1; |
| 343 | } |
| 344 | BAIDU_SCOPED_LOCK(_mutex); |
| 345 | if (_watchers.emplace(watcher, filter).second) { |
| 346 | if (!_last_sockets.empty()) { |
| 347 | std::vector<ServerId> added_ids; |
| 348 | ServerNodeWithId2ServerId(_last_sockets, &added_ids, filter); |
| 349 | watcher->OnAddedServers(added_ids); |
| 350 | } |
| 351 | return 0; |
| 352 | } |
| 353 | return -1; |
| 354 | } |
| 355 | |
| 356 | int NamingServiceThread::RemoveWatcher(NamingServiceWatcher* watcher) { |
| 357 | if (watcher == NULL) { |
no test coverage detected