提交 4da97c1e 编写于 作者: C cheng_jinsong

name different for same value

Signed-off-by: Ncheng_jinsong <chengjinsong2@huawei.com>
上级 0752e93b
...@@ -297,7 +297,7 @@ void WatcherManagerKits::ParamWatcher::OnParameterChange(const std::string &name ...@@ -297,7 +297,7 @@ void WatcherManagerKits::ParamWatcher::OnParameterChange(const std::string &name
uint32_t index = 0; uint32_t index = 0;
ParameterChangeListener *listener = GetParameterListener(&index); ParameterChangeListener *listener = GetParameterListener(&index);
while (listener != nullptr) { while (listener != nullptr) {
if (!listener->CheckValueChange(value)) { if (!listener->CheckValueChange(name, value)) {
listener->OnParameterChange(name, value); listener->OnParameterChange(name, value);
} }
index++; index++;
......
...@@ -53,14 +53,16 @@ private: ...@@ -53,14 +53,16 @@ private:
return (callback == callback_ && context == context_); return (callback == callback_ && context == context_);
} }
void OnParameterChange(const std::string &name, const std::string &value); 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; value_ = value;
name_ = name;
return ret; return ret;
} }
private: private:
std::string value_ {}; std::string value_ {};
std::string name_ {};
ParameterChangePtr callback_ { nullptr }; ParameterChangePtr callback_ { nullptr };
void *context_ { nullptr }; void *context_ { nullptr };
}; };
......
...@@ -34,9 +34,11 @@ using namespace std; ...@@ -34,9 +34,11 @@ using namespace std;
using namespace OHOS; using namespace OHOS;
using namespace OHOS::init_param; using namespace OHOS::init_param;
int g_callbackCount = 0;
static void TestParameterChange(const char *key, const char *value, void *context) 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) static void TestWatcherCallBack(const char *key, ServiceStatus status)
...@@ -140,6 +142,7 @@ public: ...@@ -140,6 +142,7 @@ public:
data.WriteString(name); data.WriteString(name);
data.WriteString(name); data.WriteString(name);
data.WriteString("watcherId"); data.WriteString("watcherId");
g_callbackCount = 0;
int ret = SystemWatchParameter(name.c_str(), TestParameterChange, nullptr); int ret = SystemWatchParameter(name.c_str(), TestParameterChange, nullptr);
EXPECT_EQ(ret, 0); EXPECT_EQ(ret, 0);
WatcherManagerKits &instance = OHOS::init_param::WatcherManagerKits::GetInstance(); WatcherManagerKits &instance = OHOS::init_param::WatcherManagerKits::GetInstance();
...@@ -147,7 +150,13 @@ public: ...@@ -147,7 +150,13 @@ public:
instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option); instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE, data, reply, option);
instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option); instance.remoteWatcher_->OnRemoteRequest(IWatcher::PARAM_CHANGE + 1, data, reply, option);
instance.remoteWatcher_->OnParameterChange(name.c_str(), "testname", "testvalue"); 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; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册