未验证 提交 5544c880 编写于 作者: O openharmony_ci 提交者: Gitee

!1405 fix: 解决模糊watcher时,name相同,但是value不同的问题

Merge pull request !1405 from cheng_jinsong/mutilwatch
......@@ -297,7 +297,7 @@ void WatcherManagerKits::ParamWatcher::OnParameterChange(const std::string &name
uint32_t index = 0;
ParameterChangeListener *listener = GetParameterListener(&index);
while (listener != nullptr) {
if (!listener->CheckValueChange(value)) {
if (!listener->CheckValueChange(name, value)) {
listener->OnParameterChange(name, value);
}
index++;
......
......@@ -53,14 +53,16 @@ private:
return (callback == callback_ && context == context_);
}
void OnParameterChange(const std::string &name, const std::string &value);
bool CheckValueChange(const std::string &value)
bool CheckValueChange(const std::string &name, const std::string &value)
{
bool ret = (value_ == value);
bool ret = (value_ == value && name_ == name);
value_ = value;
name_ = name;
return ret;
}
private:
std::string value_ {};
std::string name_ {};
ParameterChangePtr callback_ { nullptr };
void *context_ { nullptr };
};
......
......@@ -34,9 +34,11 @@ using namespace std;
using namespace OHOS;
using namespace OHOS::init_param;
int g_callbackCount = 0;
static void TestParameterChange(const char *key, const char *value, void *context)
{
printf("TestParameterChange key:%s %s", key, value);
printf("TestParameterChange key:%s %s \n", key, value);
g_callbackCount++;
}
static void TestWatcherCallBack(const char *key, ServiceStatus status)
......@@ -140,6 +142,7 @@ public:
data.WriteString(name);
data.WriteString(name);
data.WriteString("watcherId");
g_callbackCount = 0;
int ret = SystemWatchParameter(name.c_str(), TestParameterChange, nullptr);
EXPECT_EQ(ret, 0);
WatcherManagerKits &instance = OHOS::init_param::WatcherManagerKits::GetInstance();
......@@ -147,7 +150,13 @@ public:
instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option);
instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option);
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname", "testvalue");
EXPECT_EQ(g_callbackCount, 2);
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname.2", "testvalue");
EXPECT_EQ(g_callbackCount, 3);
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname.2", "testvalue");
EXPECT_EQ(g_callbackCount, 3);
}
EXPECT_EQ(g_callbackCount, 3);
return 0;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册