Lines Matching refs:keyPrefix
90 int32_t WatcherManager::AddWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId)
94 WATCHER_CHECK(keyPrefix.size() < PARAM_NAME_LEN_MAX, return -1, "Failed to verify keyPrefix.");
99 auto group = AddWatcherGroup(keyPrefix);
100 WATCHER_CHECK(group != nullptr, return -1, "Failed to create group for %s", keyPrefix.c_str());
110 SendLocalChange(keyPrefix, remoteWatcherId);
112 keyPrefix.c_str(), remoteWatcherId, group->GetGroupId());
116 int32_t WatcherManager::DelWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId)
119 WATCHER_CHECK(keyPrefix.size() < PARAM_NAME_LEN_MAX, return -1, "Failed to verify keyPrefix.");
120 auto group = GetWatcherGroup(keyPrefix);
121 WATCHER_CHECK(group != nullptr, return 0, "Can not find group %s", keyPrefix.c_str());
123 WATCHER_CHECK(remoteWatcher != nullptr, return 0, "Can not find watcher %s %d", keyPrefix.c_str(), remoteWatcherId);
126 WATCHER_LOGI("Delete watcher prefix %s remoteWatcherId %u", keyPrefix.c_str(), remoteWatcherId);
138 int32_t WatcherManager::RefreshWatcher(const std::string &keyPrefix, uint32_t remoteWatcherId)
141 WATCHER_CHECK(keyPrefix.size() < PARAM_NAME_LEN_MAX, return -1, "Failed to verify keyPrefix.");
142 WATCHER_LOGV("Refresh watcher %s remoteWatcherId: %u", keyPrefix.c_str(), remoteWatcherId);
144 WATCHER_CHECK(remoteWatcher != nullptr, return 0, "Can not find watcher %s %d", keyPrefix.c_str(), remoteWatcherId);
148 auto group = GetWatcherGroup(keyPrefix);
149 WATCHER_CHECK(group != nullptr, return 0, "Can not find group %s", keyPrefix.c_str());
150 SendLocalChange(keyPrefix, remoteWatcherId);
195 static int FilterParam(const char *name, const std::string &keyPrefix)
197 if (keyPrefix.rfind("*") == keyPrefix.length() - 1) {
198 return strncmp(name, keyPrefix.c_str(), keyPrefix.length() - 1) == 0;
200 if (keyPrefix.rfind(".") == keyPrefix.length() - 1) {
201 return strncmp(name, keyPrefix.c_str(), keyPrefix.length() - 1) == 0;
203 return strcmp(name, keyPrefix.c_str()) == 0;
227 void WatcherManager::SendLocalChange(const std::string &keyPrefix, uint32_t remoteWatcherId)
232 std::string keyPrefix;
235 WATCHER_LOGI("SendLocalChange start keyPrefix '%s' remoteWatcherId %d", keyPrefix.c_str(), remoteWatcherId);
237 struct Context context = {buffer.data(), remoteWatcherId, keyPrefix, this};
245 if (!FilterParam(context->buffer, context->keyPrefix)) {
248 WATCHER_LOGV("SendLocalChange name '%s' prefix '%s'", context->buffer, context->keyPrefix.c_str());
256 context->keyPrefix, context->buffer, context->buffer + PARAM_NAME_LEN_MAX);
603 WatcherGroupPtr WatcherManager::AddWatcherGroup(const std::string &keyPrefix)
610 auto it = groupMap_.find(keyPrefix);
617 WATCHER_CHECK(ret == 0, return nullptr, "Failed to get group id for %s", keyPrefix.c_str());
618 WatcherGroupPtr group = new WatcherGroup(groupId, keyPrefix);
619 WATCHER_CHECK(group != nullptr, return nullptr, "Failed to create group for %s", keyPrefix.c_str());
621 groupMap_[keyPrefix] = group;
635 WatcherGroupPtr WatcherManager::GetWatcherGroup(const std::string &keyPrefix)
638 auto it = groupMap_.find(keyPrefix);