std::map<std::string, VconfChangeAction*> VconfCbHandler::callbackMap;
-int VconfCbHandler::handleSubscription(const std::string &key)
+int VconfCbHandler::invokeChangedCB(const std::string &key)
{
auto found = callbackMap.find(key);
if (callbackMap.end() != found) {
- WARN("Acition(%s) already exist", key.c_str());
+ WARN("Action(%s) already exist", key.c_str());
found->second->vconfChangedCB();
-
- callbackMap.erase(found);
- int ret = vconf_ignore_key_changed(key.c_str(), vconfCallback);
- if (0 != ret) {
- ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
}
return MODES_ERROR_NONE;
}
{
requestVal = val;
- int ret = cbHandler.handleSubscription(KEY[keyType]);
+ int ret = cbHandler.invokeChangedCB(KEY[keyType]);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", KEY[keyType], ret);
return ret;
cb = nullptr;
}
+//This funcion handles changes made by the Modes
void DisplayActVconf::vconfChangedCB()
{
- //The value will be changed by Modes. That's why the callback is always called.
if (cb)
cb(cbData);
}
{
requestVal = val;
- int ret = cbHandler.handleSubscription(KEY);
+ int ret = cbHandler.invokeChangedCB(KEY);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", KEY, ret);
return ret;
return MODES_ERROR_NONE;
}
+
void DisplayBrightness::unSetChangedCallback(valueChangedCB callback, void *userData)
{
RET_IF(nullptr == callback);
cb = nullptr;
}
+//This funcion handles changes made by the Modes
void DisplayBrightness::vconfChangedCB()
{
- //The value will be changed by Modes. That's why the callback is always called.
if (cb)
cb(cbData);
}
*pluginAction = action;
else
displayFactory.destroyAction(action);
+
return ret;
}
*pluginAction = action;
else
displayFactory.destroyAction(action);
+
return ret;
}
class VconfCbHandler {
public:
- int handleSubscription(const std::string &key);
+ int invokeChangedCB(const std::string &key);
int setChangedCB(const std::string &key, VconfChangeAction *action);
void unSetChangedCB(const std::string &key);
private:
static void callback1(void *userData)
{
- DBG("%s changed callback called!", (char*)userData);
+ PluginAction *action = (PluginAction*)userData;
+ DBG("%s changed callback called!", action->getName().c_str());
+
+ //In practice, it is handled by Action. refer to Action.cpp
+ action->unSetChangedCallback(callback1, nullptr);
+
cb1Called = true;
}
ret = plugin->set(key, 4, &action1);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = action1->setChangedCallback(callback1, nullptr);
+ ret = action1->setChangedCallback(callback1, (void*)action1);
EXPECT_EQ(ret, MODES_ERROR_NONE);
PluginAction *action2;
ret = plugin->set(key, 2, &action2);
EXPECT_EQ(ret, MODES_ERROR_NONE);
EXPECT_TRUE(cb1Called);
- ret = action2->setChangedCallback(callback2, nullptr);
+ ret = action2->setChangedCallback(callback2, (void*)key);
EXPECT_EQ(ret, MODES_ERROR_NONE);
g_idle_add(changedCallbackidler, nullptr);
g_main_loop_run(loop);
{
requestVal = val;
- int ret = cbHandler.handleSubscription(key);
+ int ret = cbHandler.invokeChangedCB(key);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
return ret;
cb = nullptr;
}
+//This funcion handles changes made by the Modes
void VconfActionBool::vconfChangedCB()
{
- //The value will be changed by Modes. That's why the callback is always called.
if (cb)
cb(cbData);
}
{
requestVal = val;
- int ret = cbHandler.handleSubscription(key);
+ int ret = cbHandler.invokeChangedCB(key);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
return ret;
cb = nullptr;
}
+//This funcion handles changes made by the Modes
void VconfActionDbl::vconfChangedCB()
{
- //The value will be changed by Modes. That's why the callback is always called.
if (cb)
cb(cbData);
}
{
requestVal = val;
- int ret = cbHandler.handleSubscription(key);
+ int ret = cbHandler.invokeChangedCB(key);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
return ret;
cb = nullptr;
}
+//This funcion handles changes made by the Modes
void VconfActionInt::vconfChangedCB()
{
- //The value will be changed by Modes. That's why the callback is always called.
if (cb)
cb(cbData);
}
{
requestVal = val;
- int ret = cbHandler.handleSubscription(key);
+ int ret = cbHandler.invokeChangedCB(key);
if (MODES_ERROR_NONE != ret) {
ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
return ret;
cb = nullptr;
}
+//This funcion handles changes made by the Modes
void VconfActionStr::vconfChangedCB()
{
- //The value will be changed by Modes. That's why the callback is always called.
if (cb)
cb(cbData);
}