SET(MODES_PLUGIN_DEFAULT_DIR "/usr/lib/modes-plugins/")
ENDIF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR)
-SET(VCONF_COMMON_SRC ${CMAKE_SOURCE_DIR}/common/VconfCbHandler.cpp)
-
ADD_SUBDIRECTORY(wifi)
ADD_SUBDIRECTORY(vconf)
ADD_SUBDIRECTORY(app)
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <string>
-#include <PluginAction.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class AppAction : public PluginAction {
-public:
- AppAction(const std::string &name)
- : PluginAction(name)
- {
- }
- virtual ~AppAction() = default;
-
- virtual int set(const std::string &val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual int get(std::string *val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
-};
-
-MODES_NAMESPACE_END
-
#include <app_control.h>
#include <app_manager.h>
#include <app_manager_extension.h>
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
const std::string AppActionLaunch::NAME = "launch";
AppActionLaunch::AppActionLaunch()
- : AppAction(NAME), cb(nullptr), cbData(nullptr)
+ : PluginAction(NAME), cb(nullptr), cbData(nullptr)
{
aul_launch_init(NULL, NULL);
}
-int AppActionLaunch::set(const std::string &val)
+bool AppActionLaunch::IsCurrentValue(const std::string &val)
{
- requestVal = val;
-
bool running;
int ret = app_manager_is_running(val.c_str(), &running);
if (APP_MANAGER_ERROR_NONE != ret) {
ERR("app_manager_is_running(%s) Fail(%d)", val.c_str(), ret);
} else if (running) {
INFO("It's already running");
- return MODES_ERROR_NONE;
+ return true;
}
+ return false;
+}
+
+int AppActionLaunch::set(const std::string &val)
+{
+ requestVal = val;
app_control_h service;
app_control_create(&service);
app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_SINGLE);
- ret = app_control_send_launch_request(service, NULL, NULL);
+ int ret = app_control_send_launch_request(service, NULL, NULL);
if (APP_CONTROL_ERROR_NONE != ret) {
ERR("app_control_send_launch_request() Fail(%s)", get_error_message(ret));
return MODES_ERROR_SYSTEM;
ERR("app_manager_terminate_app() Fail(%s)", get_error_message(ret));
}
-std::string AppActionLaunch::serialize()
+std::string AppActionLaunch::getUndoInfo()
{
return requestVal;
}
-int AppActionLaunch::parse(const std::string &archive)
+int AppActionLaunch::setUndoInfo(const std::string &info)
{
- requestVal = archive;
+ requestVal = info;
return MODES_ERROR_NONE;
}
*/
#pragma once
-#include <list>
#include <string>
#include <app_manager.h>
#include <app_manager_extension.h>
-#include "AppAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
-class AppActionLaunch : public AppAction {
+class AppActionLaunch : public PluginAction {
public:
static const std::string NAME;
AppActionLaunch();
+ bool IsCurrentValue(const std::string &val) override;
int set(const std::string &val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &data) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
private:
actionMap[AppActionLaunch::NAME] = APP_ACT_LAUNCH;
}
-AppAction* AppFactory::createAction(const std::string &key)
+PluginAction* AppFactory::createAction(const std::string &key)
{
auto search = actionMap.find(key);
if (actionMap.end() == search) {
- ERR("No AppAction(%s)", key.c_str());
+ ERR("No App PluginAction(%s)", key.c_str());
return nullptr;
}
return nullptr;
}
-void AppFactory::destroyAction(AppAction *action)
+void AppFactory::destroyAction(PluginAction *action)
{
delete action;
}
#include <map>
#include <string>
-#include "AppAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
AppFactory();
~AppFactory() = default;
- AppAction* createAction(const std::string &key);
- void destroyAction(AppAction *action);
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
private:
enum actionKey{
APP_ACT_LAUNCH
* limitations under the License.
*/
#include <string>
-#include <modes_errors.h>
#include <Plugin.h>
#include "plugin-log.h"
#include "AppFactory.h"
class AppPlugin : public Plugin {
public:
AppPlugin();
- ~AppPlugin();
+ ~AppPlugin() override = default;
- int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
- void undo(PluginAction *piAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
private:
AppFactory appFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
- return new AppPlugin;
+ return new AppPlugin();
}
extern "C" API void objectDelete(Plugin *plugin)
setName("app");
}
-AppPlugin::~AppPlugin()
+PluginAction* AppPlugin::newAction(const std::string &key)
{
+ return appFactory.createAction(key);
}
-int AppPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
+void AppPlugin::deleteAction(PluginAction *piAction)
{
- AppAction *action = appFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- DBG("set [%s, %s]", key.c_str(), val.c_str());
-
- int ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- appFactory.destroyAction(action);
-
- return ret;
-}
-
-void AppPlugin::undo(PluginAction *piAction)
-{
- AppAction *action = static_cast<AppAction*>(piAction);
- RET_IF(nullptr == piAction);
-
- DBG("Action(%s) undo", action->getName().c_str());
-
- action->undo();
- appFactory.destroyAction(action);
-}
-
-PluginAction* AppPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
- AppAction *action = appFactory.createAction(key);
- RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
- int ret = action->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- appFactory.destroyAction(action);
- return nullptr;
- }
-
- return action;
+ appFactory.destroyAction(piAction);
}
#include "BtAction.h"
#include <bluetooth.h>
-#include <modes_errors.h>
MODES_NAMESPACE_USE;
else
return true;
}
-
-int BtAction::set(bool val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-int BtAction::set(const std::string &val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
class BtAction : public PluginAction {
public:
BtAction(const std::string &name);
- virtual ~BtAction();
-
- virtual int set(bool val);
- virtual int set(const std::string &val);
+ ~BtAction() override;
+protected:
bool getAdapterStatus();
};
*/
#include "BtActionAudioConnect.h"
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
bt_audio_deinitialize();
}
+bool BtActionAudioConnect::IsCurrentValue(const std::string &val)
+{
+ return false;
+}
+
int BtActionAudioConnect::set(const std::string &val)
{
if (!getAdapterStatus()) {
ERR("bt_audio_disconnect(%s) Fail(%s)", requestVal.c_str(), get_error_message(ret));
}
-std::string BtActionAudioConnect::serialize()
+std::string BtActionAudioConnect::getUndoInfo()
{
return requestVal;
}
-int BtActionAudioConnect::parse(const std::string &archive)
+int BtActionAudioConnect::setUndoInfo(const std::string &info)
{
- requestVal = archive;
+ requestVal = info;
return MODES_ERROR_NONE;
}
BtActionAudioConnect();
~BtActionAudioConnect();
+ bool IsCurrentValue(const std::string &val);
+
int set(const std::string &val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData);
void unSetChangedCallback(valueChangedCB callback, void *userData);
private:
#include "BtActionPower.h"
#include <sstream>
-#include <modes_errors.h>
#include <bluetooth.h>
#include <bluetooth_internal.h>
#include "plugin-log.h"
{
}
+bool BtActionPower::IsCurrentValue(bool val)
+{
+ return true;
+}
+
int BtActionPower::set(bool val)
{
requestVal = val;
set(oldVal);
}
-std::string BtActionPower::serialize()
+std::string BtActionPower::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int BtActionPower::parse(const std::string &archive)
+int BtActionPower::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
static const std::string NAME;
BtActionPower();
+ bool IsCurrentValue(bool val) override;
int set(bool val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string & archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData);
void unSetChangedCallback(valueChangedCB callback, void *userData);
private:
actionMap[BtActionAudioConnect::NAME] = AUDIO_CONNECT;
}
-BtAction* BtFactory::createAction(const std::string &key)
+PluginAction* BtFactory::createAction(const std::string &key)
{
auto search = actionMap.find(key);
if (actionMap.end() == search) {
return nullptr;
}
-void BtFactory::destroyAction(BtAction *action)
+void BtFactory::destroyAction(PluginAction *action)
{
delete action;
}
*/
#pragma once
-#include <string>
#include <map>
-#include "BtAction.h"
+#include <string>
+#include <PluginAction.h>
+#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
BtFactory();
~BtFactory() = default;
- BtAction *createAction(const std::string &key);
- void destroyAction(BtAction *action);
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
private:
enum actionKey {
POWER,
* limitations under the License.
*/
#include <string>
-#include <modes_errors.h>
#include <bluetooth.h>
#include <Plugin.h>
#include "plugin-log.h"
class BtPlugin : public Plugin {
public:
BtPlugin();
- ~BtPlugin();
+ ~BtPlugin() override = default;
- int set(const std::string &key, bool val, PluginAction **piAction) override;
- int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
- void undo(PluginAction *piAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
private:
BtFactory btFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
- return new BtPlugin;
+ return new BtPlugin();
}
extern "C" API void objectDelete(Plugin *plugin)
setName("bluetooth");
}
-BtPlugin::~BtPlugin()
+PluginAction* BtPlugin::newAction(const std::string &key)
{
+ return btFactory.createAction(key);
}
-//For BtActionPower
-int BtPlugin::set(const std::string &key, bool val, PluginAction **piAction)
+void BtPlugin::deleteAction(PluginAction *piAction)
{
- BtAction *action = btFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- DBG("set(%s, %d)", key.c_str(), val);
-
- int ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- btFactory.destroyAction(action);
-
- return ret;
-}
-
-//For BtActionAudioConnect
-int BtPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
-{
- BtAction *action = btFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- DBG("set(%s, %s)", key.c_str(), val.c_str());
-
- int ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- btFactory.destroyAction(action);
-
- return ret;
-}
-
-void BtPlugin::undo(PluginAction *piAction)
-{
- BtAction *action = static_cast<BtAction*>(piAction);
- RET_IF(nullptr == piAction);
-
- DBG("Action(%s) undo", action->getName().c_str());
-
- action->undo();
- btFactory.destroyAction(action);
-}
-
-PluginAction* BtPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
- BtAction *action = btFactory.createAction(key);
- RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
- int ret = action->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- btFactory.destroyAction(action);
- return nullptr;
- }
-
- return action;
+ btFactory.destroyAction(piAction);
}
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "VconfCbHandler.h"
-
-#include <string>
-#include <algorithm>
-#include <vconf.h>
-#include <modes_errors.h>
-#include "plugin-log.h"
-#include "VconfChangeAction.h"
-
-MODES_NAMESPACE_USE;
-
-std::map<std::string, VconfChangeAction*> VconfCbHandler::callbackMap;
-
-int VconfCbHandler::invokeChangedCB(const std::string &key)
-{
- auto found = callbackMap.find(key);
- if (callbackMap.end() != found) {
- WARN("Action(%s) already exist", key.c_str());
- found->second->vconfChangedCB();
- }
- return MODES_ERROR_NONE;
-}
-
-int VconfCbHandler::setChangedCB(const std::string &key, VconfChangeAction *action)
-{
- RETV_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER);
-
- int ret = vconf_notify_key_changed(key.c_str(), vconfCallback, NULL);
- if (0 != ret) {
- ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
-
- callbackMap[key] = action;
-
- return MODES_ERROR_NONE;
-}
-
-void VconfCbHandler::unSetChangedCB(const std::string &key)
-{
- auto found = callbackMap.find(key);
- if (callbackMap.end() == found) {
- ERR("No Changed Callback(%s)", key.c_str());
- return;
- }
-
- 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;
- }
-}
-
-void VconfCbHandler::vconfCallback(keynode_t *node, void *userData)
-{
- auto found = callbackMap.find(node->keyname);
- if (callbackMap.end() == found) {
- ERR("No VconfAction(%s)", node->keyname);
- return;
- }
-
- found->second->vconfChangedCB(node);
- DBG("Action(%s) is Changed", node->keyname);
-}
INCLUDE_DIRECTORIES(${DISPLAY_pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${DISPLAY_pkgs_LIBRARY_DIRS})
-ADD_LIBRARY(${DISPLAY_PLUGIN} SHARED ${DISPLAY_SRCS} ${VCONF_COMMON_SRC})
+ADD_LIBRARY(${DISPLAY_PLUGIN} SHARED ${DISPLAY_SRCS})
TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN} ${DISPLAY_pkgs_LIBRARIES})
SET_TARGET_PROPERTIES(${DISPLAY_PLUGIN} PROPERTIES NO_SONAME 1 )
INSTALL(TARGETS ${DISPLAY_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
#include <sstream>
#include <string>
#include <vconf.h>
-#include <modes_errors.h>
#include "plugin-log.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_USE;
};
DisplayActVconf::DisplayActVconf(int type)
- :DisplayAction(NAME[type]), keyType(type),
- requestVal(-1), oldVal(-1), cb(nullptr), cbData(nullptr)
+ : PluginAction(NAME[type]), keyType(type), requestVal(-1), oldVal(-1), cb(nullptr),
+ cbData(nullptr)
{
}
-int DisplayActVconf::set(int val)
+bool DisplayActVconf::IsCurrentValue(int val)
{
- requestVal = val;
-
- int ret = cbHandler.invokeChangedCB(KEY[keyType]);
- if (MODES_ERROR_NONE != ret) {
- ERR("handleChange(%s) Fail(%d)", KEY[keyType], ret);
- return ret;
- }
-
- ret = vconf_get_int(KEY[keyType], &oldVal);
+ int ret = vconf_get_int(KEY[keyType], &oldVal);
if (0 != ret) {
ERR("vconf_get_int(%s) Fail(%d)", KEY[keyType], ret);
- return MODES_ERROR_SYSTEM;
+ return false;
}
if (oldVal == val) {
INFO("%s already set(%d)", NAME[keyType].c_str(), val);
- } else {
- ret = vconf_set_int(KEY[keyType], val);
- if (0 != ret) {
- ERR("vconf_set_int(%s, %d) Fail(%d)", KEY[keyType], val, ret);
- return MODES_ERROR_SYSTEM;
- }
+ return true;
+ }
+
+ return false;
+}
+
+int DisplayActVconf::set(int val)
+{
+ requestVal = val;
+
+ int ret = vconf_set_int(KEY[keyType], val);
+ if (0 != ret) {
+ ERR("vconf_set_int(%s, %d) Fail(%d)", KEY[keyType], val, ret);
+ return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
void DisplayActVconf::undo()
{
- RET_IF(-1 == oldVal);
-
int ret = vconf_set_int(KEY[keyType], oldVal);
if (0 != ret)
ERR("vconf_set_int(%s, %d) Fail(%d)", KEY[keyType], oldVal, ret);
}
-std::string DisplayActVconf::serialize()
+std::string DisplayActVconf::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int DisplayActVconf::parse(const std::string &archive)
+int DisplayActVconf::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
{
RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
- int ret = cbHandler.setChangedCB(KEY[keyType], this);
- if (MODES_ERROR_NONE != ret) {
- ERR("setChangedCB(%s) Fail(%d)", KEY[keyType], ret);
- return ret;
+ int ret = vconf_notify_key_changed(KEY[keyType], vconfChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
cb = callback;
{
RET_IF(nullptr == callback);
- cbHandler.unSetChangedCB(KEY[keyType]);
+ int ret = vconf_ignore_key_changed(KEY[keyType], vconfChangedCB);
+ if (0 != ret) {
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return;
+ }
cbData = nullptr;
cb = nullptr;
}
-//This funcion handles changes made by the Modes
-void DisplayActVconf::vconfChangedCB()
-{
- if (cb)
- cb(cbData);
-}
-
-void DisplayActVconf::vconfChangedCB(keynode_t *node)
+void DisplayActVconf::changedCB(keynode_t *node)
{
const char *vconfKey = vconf_keynode_get_name(node);
- if (vconfKey != KEY[keyType]) {
- WARN("Unknown vconf(%s) notification", vconfKey);
+ if (nullptr == vconfKey || MDSP_EQUAL != strcmp(KEY[keyType], vconfKey)) {
+ WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
return;
}
int val = vconf_keynode_get_int(node);
-
if (cb && (val != requestVal))
cb(cbData);
}
+
+void DisplayActVconf::vconfChangedCB(keynode_t *node, void *userData)
+{
+ RET_IF(nullptr == userData);
+
+ DisplayActVconf *action = (DisplayActVconf*)userData;
+ action->changedCB(node);
+}
#pragma once
#include <string>
+#include <vconf.h>
+#include <PluginAction.h>
#include "plugin-def.h"
-#include "DisplayAction.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_BEGIN
-class DisplayActVconf : public DisplayAction, public VconfChangeAction {
+class DisplayActVconf : public PluginAction {
public:
DisplayActVconf(int type);
+ ~DisplayActVconf() override = default;
+ bool IsCurrentValue(int val) override;
int set(int val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
- void vconfChangedCB() override;
- void vconfChangedCB(keynode_t *node) override;
-
static const std::string NAME[2];
static const char* const KEY[2];
private:
+ void changedCB(keynode_t *node);
+ static void vconfChangedCB(keynode_t *node, void *userData);
+
int keyType;
int requestVal;
int oldVal;
- VconfCbHandler cbHandler;
valueChangedCB cb;
void *cbData;
};
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include "DisplayAction.h"
-
-#include <modes_errors.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_USE;
-
-DisplayAction::DisplayAction(const std::string &name)
- :PluginAction(name)
-{
-}
-
-int DisplayAction::set(int val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
-
-int DisplayAction::set(bool val)
-{
- return MODES_ERROR_NOT_SUPPORTED;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <PluginAction.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class DisplayAction : public PluginAction {
-public:
- DisplayAction(const std::string &name);
- ~DisplayAction() = default;
-
- virtual int set(int val);
- virtual int set(bool val);
-};
-
-MODES_NAMESPACE_END
-
#include <vconf.h>
#include <device/display.h>
#include <device/callback.h>
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
const char* const DisplayBrightness::KEY = VCONFKEY_SETAPPL_LCD_BRIGHTNESS;
DisplayBrightness::DisplayBrightness()
- :DisplayAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr)
+ :PluginAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr)
{
device_display_get_numbers(&numDisplay);
}
-int DisplayBrightness::set(int val)
+bool DisplayBrightness::IsCurrentValue(int val)
{
- requestVal = val;
+ int old;
+ int ret = vconf_get_int(KEY, &old);
+ if (0 != ret) {
+ ERR("vconf_get_int(%s) Fail(%d)", KEY, ret);
+ return false;
+ }
- int ret = cbHandler.invokeChangedCB(KEY);
- if (MODES_ERROR_NONE != ret) {
- ERR("handleChange(%s) Fail(%d)", KEY, ret);
- return ret;
+ if (old == val) {
+ INFO("%s already set(%d)", NAME.c_str(), val);
+ return true;
}
+ return false;
+}
+
+int DisplayBrightness::set(int val)
+{
+ int ret;
+ requestVal = val;
+
for (int i = 0; i < numDisplay ; i++) {
int oldVal = 0;
ret = device_display_get_brightness(i, &oldVal);
}
}
-std::string DisplayBrightness::serialize()
+std::string DisplayBrightness::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int DisplayBrightness::parse(const std::string &data)
+int DisplayBrightness::setUndoInfo(const std::string &data)
{
size_t pos;
size_t start = 0;
{
RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
- int ret = cbHandler.setChangedCB(KEY, this);
- if (MODES_ERROR_NONE != ret) {
- ERR("setChangedCB(%s) Fail(%d)", KEY, ret);
- return ret;
+ int ret = vconf_notify_key_changed(KEY, vconfChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", KEY, ret);
+ return MODES_ERROR_SYSTEM;
}
cb = callback;
{
RET_IF(nullptr == callback);
- cbHandler.unSetChangedCB(KEY);
+ int ret = vconf_ignore_key_changed(KEY, vconfChangedCB);
+ if (0 != ret) {
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", KEY, ret);
+ return;
+ }
cbData = nullptr;
cb = nullptr;
}
-//This funcion handles changes made by the Modes
-void DisplayBrightness::vconfChangedCB()
-{
- if (cb)
- cb(cbData);
-}
-
-void DisplayBrightness::vconfChangedCB(keynode_t *node)
+void DisplayBrightness::changedCB(keynode_t *node)
{
const char *vconfKey = vconf_keynode_get_name(node);
- if (vconfKey != KEY) {
- WARN("Unknown vconf(%s) notification", vconfKey);
+ if (nullptr == vconfKey || MDSP_EQUAL != strcmp(KEY, vconfKey)) {
+ WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
return;
}
}
int val = vconf_keynode_get_int(node);
- if (cb && (val != realVal))
+ if (cb && (val != requestVal))
cb(cbData);
}
+
+void DisplayBrightness::vconfChangedCB(keynode_t *node, void *userData)
+{
+ RET_IF(nullptr == userData);
+
+ DisplayBrightness *action = (DisplayBrightness*)userData;
+ action->changedCB(node);
+}
#include <list>
#include <string>
+#include <vconf.h>
+#include <PluginAction.h>
#include "plugin-def.h"
-#include "DisplayAction.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_BEGIN
-class DisplayBrightness : public DisplayAction, public VconfChangeAction {
+class DisplayBrightness : public PluginAction {
public:
DisplayBrightness();
- ~DisplayBrightness() = default;
+ ~DisplayBrightness() override = default;
+ bool IsCurrentValue(int val) override;
int set(int val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
- void vconfChangedCB() override;
- void vconfChangedCB(keynode_t *node) override;
-
static const std::string NAME;
static const char* const KEY;
private:
+ void changedCB(keynode_t *node);
+ static void vconfChangedCB(keynode_t *node, void *userData);
+
const char delimiter = '#';
int numDisplay;
int requestVal;
std::list<int> oldValList;
- VconfCbHandler cbHandler;
valueChangedCB cb;
void *cbData;
};
#include <Ecore_Wl2.h>
#include <efl_util.h>
#include <Ecore.h>
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
const std::string DisplayDenyPalmTouch::NAME = "denyPalmTouch";
DisplayDenyPalmTouch::DisplayDenyPalmTouch()
- :DisplayAction(NAME)
+ : PluginAction(NAME), oldVal(false)
{
}
set(false);
}
-std::string DisplayDenyPalmTouch::serialize()
+std::string DisplayDenyPalmTouch::getUndoInfo()
{
- //Not Support
+ WARN("Not Support getUndoInfo()");
return std::string();
}
-int DisplayDenyPalmTouch::parse(const std::string &archive)
+int DisplayDenyPalmTouch::setUndoInfo(const std::string &info)
{
WARN("Palm Touch setting is volatile");
return MODES_ERROR_NOT_SUPPORTED;
int DisplayDenyPalmTouch::setChangedCallback(valueChangedCB callback, void *userData)
{
- ERR("Not Support Changed Callback");
+ WARN("Not Support Changed Callback");
return MODES_ERROR_NOT_SUPPORTED;
}
void DisplayDenyPalmTouch::unSetChangedCallback(valueChangedCB callback, void *userData)
{
- ERR("Not Support Changed Callback");
+ WARN("Not Support Changed Callback");
}
#pragma once
#include <string>
+#include <PluginAction.h>
#include "plugin-def.h"
-#include "DisplayAction.h"
MODES_NAMESPACE_BEGIN
-class DisplayDenyPalmTouch : public DisplayAction {
+class DisplayDenyPalmTouch : public PluginAction {
public:
DisplayDenyPalmTouch();
- ~DisplayDenyPalmTouch() = default;
+ ~DisplayDenyPalmTouch() override = default;
int set(bool val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
actionMap[DisplayDenyPalmTouch::NAME] = DENY_PALM_TOUCH;
}
-DisplayAction* DisplayFactory::createAction(const std::string &key)
+PluginAction* DisplayFactory::createAction(const std::string &key)
{
auto search = actionMap.find(key);
if (actionMap.end() == search) {
- ERR("No DisplayAction(%s)", key.c_str());
+ ERR("No Display PluginAction(%s)", key.c_str());
return nullptr;
}
- DisplayAction *action;
+ PluginAction *action;
switch (search->second) {
case AUTO_BRIGHTNESS_VCONF:
action = new DisplayActVconf(AUTO_BRIGHTNESS_VCONF);
return action;
}
-void DisplayFactory::destroyAction(DisplayAction *action)
+void DisplayFactory::destroyAction(PluginAction *action)
{
delete action;
}
#include <map>
#include <string>
-#include "DisplayAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
DisplayFactory();
~DisplayFactory() = default;
- DisplayAction* createAction(const std::string &key);
- void destroyAction(DisplayAction *action);
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
private:
enum actionKey{
AUTO_BRIGHTNESS_VCONF,
* limitations under the License.
*/
#include <string>
-#include <modes_errors.h>
#include <Plugin.h>
#include "plugin-log.h"
#include "plugin-def.h"
#include "DisplayFactory.h"
-#include "DisplayAction.h"
MODES_NAMESPACE_USE;
class DisplayPlugin : public Plugin {
public:
DisplayPlugin();
- ~DisplayPlugin();
-
- int set(const std::string &key, int val, PluginAction **pluginAction) override;
- int set(const std::string &key, bool val, PluginAction **pluginAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
-
- void undo(PluginAction *pluginAction) override;
+ ~DisplayPlugin() override = default;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
private:
DisplayFactory displayFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
return new DisplayPlugin;
}
setName("display");
}
-DisplayPlugin::~DisplayPlugin()
-{
-}
-
-int DisplayPlugin::set(const std::string &key, int val, PluginAction **pluginAction)
-{
- DisplayAction *action = displayFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- int ret = action->set(val);
-
- DBG("Action(%s) set(%d)", key.c_str(), val);
-
- if ((ret == MODES_ERROR_NONE) && pluginAction)
- *pluginAction = action;
- else
- displayFactory.destroyAction(action);
-
- return ret;
-}
-
-int DisplayPlugin::set(const std::string &key, bool val, PluginAction **pluginAction)
+PluginAction* DisplayPlugin::newAction(const std::string &key)
{
- DisplayAction *action = displayFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- int ret = action->set(val);
-
- DBG("Action(%s) set(%d)", key.c_str(), val);
-
- if ((ret == MODES_ERROR_NONE) && pluginAction)
- *pluginAction = action;
- else
- displayFactory.destroyAction(action);
-
- return ret;
-}
-
-PluginAction* DisplayPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
- DisplayAction *action = displayFactory.createAction(key);
- RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
- int ret = action->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- displayFactory.destroyAction(action);
- return nullptr;
- }
-
- return action;
+ return displayFactory.createAction(key);
}
-void DisplayPlugin::undo(PluginAction *pluginAction)
+void DisplayPlugin::deleteAction(PluginAction *piAction)
{
- DisplayAction *action = static_cast<DisplayAction*>(pluginAction);
- RET_IF(nullptr == pluginAction);
-
- DBG("Action(%s) undo", action->getName().c_str());
-
- action->undo();
- displayFactory.destroyAction(action);
+ displayFactory.destroyAction(piAction);
}
-
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <map>
-#include <string>
-#include <vconf.h>
-#include "plugin-def.h"
-#include "VconfChangeAction.h"
-
-MODES_NAMESPACE_BEGIN
-
-class VconfCbHandler {
-public:
- int invokeChangedCB(const std::string &key);
- int setChangedCB(const std::string &key, VconfChangeAction *action);
- void unSetChangedCB(const std::string &key);
-private:
- static void vconfCallback(keynode_t *node, void *userData);
- static std::map<std::string, VconfChangeAction*> callbackMap;
-};
-
-MODES_NAMESPACE_END
-
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <vconf.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class VconfChangeAction {
-public:
- virtual void vconfChangedCB() = 0;
- virtual void vconfChangedCB(keynode_t *node) = 0;
-};
-
-MODES_NAMESPACE_END
#endif
#define API __attribute__((visibility("default")))
-#define MDS_EQUAL 0
+#define MDSP_EQUAL 0
#define MODES_NAMESPACE_BEGIN namespace ModeSupervisorNamespace {
#define MODES_NAMESPACE_END }
+++ /dev/null
-/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <string>
-#include <PluginAction.h>
-#include "plugin-def.h"
-
-MODES_NAMESPACE_BEGIN
-
-class MediaAction : public PluginAction {
-public:
- MediaAction(const std::string &name)
- : PluginAction(name)
- {
- }
- ~MediaAction() = default;
-
- virtual int set(const std::string &val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
- virtual int set(int val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
-};
-
-MODES_NAMESPACE_END
-
actionMap[MediaPlayer::NAME] = PLAYER;
}
-MediaAction* MediaFactory::createAction(const std::string &key)
+PluginAction* MediaFactory::createAction(const std::string &key)
{
auto search = actionMap.find(key);
if (actionMap.end() == search) {
- ERR("No MediaAction(%s)", key.c_str());
+ ERR("No Media PluginAction(%s)", key.c_str());
return nullptr;
}
- MediaAction *action;
+ PluginAction *action;
switch (search->second) {
case SYSTEM_VOL:
action = new SoundVolume(SYSTEM_VOL, SOUND_TYPE_SYSTEM);
return action;
}
-void MediaFactory::destroyAction(MediaAction *action)
+void MediaFactory::destroyAction(PluginAction *action)
{
delete action;
}
#include <map>
#include <string>
-#include "MediaAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
MediaFactory();
~MediaFactory() = default;
- MediaAction* createAction(const std::string &key);
- void destroyAction(MediaAction *action);
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
private:
enum actionKey{
SYSTEM_VOL,
#include <string>
#include <player.h>
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
const std::string MediaPlayer::NAME = "player";
MediaPlayer::MediaPlayer()
- : MediaAction(NAME), player(NULL), streamInfo(NULL), cb(nullptr), cbData(nullptr)
+ : PluginAction(NAME), player(NULL), streamInfo(NULL), cb(nullptr), cbData(nullptr)
{
int ret = player_create(&player);
if (PLAYER_ERROR_NONE != ret) {
player_stop(player);
}
-std::string MediaPlayer::serialize()
+std::string MediaPlayer::getUndoInfo()
{
//Not Support
return std::string();
}
-int MediaPlayer::parse(const std::string &archive)
+int MediaPlayer::setUndoInfo(const std::string &info)
{
WARN("MediaPlayer is volatile");
return MODES_ERROR_NOT_SUPPORTED;
#include <player.h>
#include <sound_manager.h>
+#include <PluginAction.h>
#include "plugin-def.h"
-#include "MediaAction.h"
MODES_NAMESPACE_BEGIN
-class MediaPlayer : public MediaAction {
+class MediaPlayer : public PluginAction {
public:
MediaPlayer();
- ~MediaPlayer();
+ ~MediaPlayer() override;
int set(const std::string &val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
* limitations under the License.
*/
#include <string>
-#include <modes_errors.h>
#include <Plugin.h>
#include "plugin-log.h"
#include "plugin-def.h"
#include "MediaFactory.h"
-#include "MediaAction.h"
MODES_NAMESPACE_USE;
class MediaPlugin : public Plugin {
public:
MediaPlugin();
- ~MediaPlugin();
+ ~MediaPlugin() override = default;
- int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
- int set(const std::string &key, int val, PluginAction **piAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
-
- void undo(PluginAction *piAction) override;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
private:
MediaFactory mediaFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
return new MediaPlugin;
}
setName("media");
}
-MediaPlugin::~MediaPlugin()
+PluginAction* MediaPlugin::newAction(const std::string &key)
{
+ return mediaFactory.createAction(key);
}
-int MediaPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
+void MediaPlugin::deleteAction(PluginAction *piAction)
{
- MediaAction *action = mediaFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- int ret = action->set(val);
- if (ret != MODES_ERROR_NONE) {
- ERR("Action(%s) set(%s) Fail(%d)", key.c_str(), val.c_str(), ret);
- mediaFactory.destroyAction(action);
- return ret;
- }
-
- if (piAction)
- *piAction = action;
- else
- mediaFactory.destroyAction(action);
- return ret;
-}
-
-int MediaPlugin::set(const std::string &key, int val, PluginAction **piAction)
-{
- MediaAction *action = mediaFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- int ret = action->set(val);
- if (ret != MODES_ERROR_NONE) {
- ERR("Action(%s) set(%d) Fail(%d)", key.c_str(), val, ret);
- mediaFactory.destroyAction(action);
- return ret;
- }
-
- if (piAction)
- *piAction = action;
- else
- mediaFactory.destroyAction(action);
- return ret;
-}
-
-PluginAction* MediaPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
- MediaAction *action = mediaFactory.createAction(key);
- RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
- int ret = action->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- mediaFactory.destroyAction(action);
- return nullptr;
- }
-
- return action;
-}
-
-void MediaPlugin::undo(PluginAction *piAction)
-{
- MediaAction *action = static_cast<MediaAction*>(piAction);
- RET_IF(nullptr == piAction);
-
- action->undo();
- mediaFactory.destroyAction(action);
+ mediaFactory.destroyAction(piAction);
}
#include <string>
#include <sstream>
-#include <modes_errors.h>
#include <player.h>
#include "plugin-log.h"
};
SoundVolume::SoundVolume(int key, sound_type_e soundType)
- : MediaAction(NAME[key]), type(soundType),
+ : PluginAction(NAME[key]), type(soundType),
requestVal(-1), oldVal(-1), callbackID(0), cb(nullptr), cbData(nullptr)
{
}
-int SoundVolume::set(int val)
+bool SoundVolume::IsCurrentValue(int val)
{
- requestVal = val;
-
- int ret = sound_manager_get_volume(type, &oldVal);
- if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_SYSTEM;
- }
+ int ret;
if (-1 == val) {
ret = sound_manager_get_max_volume(type, &val);
if (SOUND_MANAGER_ERROR_NONE != ret) {
ERR("sound_manager_get_max_volume() Fail(%s)", get_error_message(ret));
- return MODES_ERROR_SYSTEM;
+ return false;
}
- DBG("sound_manager_get_max_volume(%s) is (%d)", getName().c_str(), val);
+ INFO("sound_manager_get_max_volume(%s) is (%d)", getKey().c_str(), val);
}
+ ret = sound_manager_get_volume(type, &oldVal);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_get_volume() Fail(%s)", get_error_message(ret));
+ return false;
+ }
if (oldVal == val) {
- INFO("%s already set[%d]", getName().c_str(), val);
- } else {
- ret = sound_manager_set_volume(type, val);
+ INFO("%s already set[%d]", getKey().c_str(), val);
+ return true;
+ }
+
+ return false;
+}
+
+int SoundVolume::set(int val)
+{
+ int ret;
+ requestVal = val;
+
+ if (-1 == val) {
+ ret = sound_manager_get_max_volume(type, &val);
if (SOUND_MANAGER_ERROR_NONE != ret) {
- ERR("sound_manager_set_volume(%s) Fail(%s)", getName().c_str(), get_error_message(ret));
+ ERR("sound_manager_get_max_volume() Fail(%s)", get_error_message(ret));
return MODES_ERROR_SYSTEM;
}
+ INFO("sound_manager_get_max_volume(%s) is (%d)", getKey().c_str(), val);
}
+ ret = sound_manager_set_volume(type, val);
+ if (SOUND_MANAGER_ERROR_NONE != ret) {
+ ERR("sound_manager_set_volume(%s) Fail(%s)", getKey().c_str(), get_error_message(ret));
+ return MODES_ERROR_SYSTEM;
+ }
return MODES_ERROR_NONE;
}
ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret));
}
-std::string SoundVolume::serialize()
+std::string SoundVolume::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int SoundVolume::parse(const std::string &archive)
+int SoundVolume::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
#include <string>
#include <sound_manager.h>
+#include <PluginAction.h>
#include "plugin-def.h"
-#include "MediaAction.h"
MODES_NAMESPACE_BEGIN
-class SoundVolume : public MediaAction {
+class SoundVolume : public PluginAction {
public:
SoundVolume(int key, sound_type_e soundType);
- ~SoundVolume() = default;
+ ~SoundVolume() override = default;
+ bool IsCurrentValue(int val);
int set(int val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
* limitations under the License.
*/
#include "PkgEnableSupportMode.h"
+
#include <glib.h>
#include <list>
#include <string>
#include <sstream>
#include <pkgmgr-info.h>
#include <package-manager.h>
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
const std::string PkgSupportMode::NAME = "supportMode";
PkgSupportMode::PkgSupportMode()
- : PkgAction(NAME), requestVal(0)
+ : PluginAction(NAME), requestVal(0)
{
}
DBG("Request id[%d] count[%d]", reqId, nApps);
pkgmgr_client_free(pc);
-
- //The caller(Plugin undo function) includes destruction of this instance.
- //Therefore, appList will be automatically cleared by the destructor.
}
-std::string PkgSupportMode::serialize()
+std::string PkgSupportMode::getUndoInfo()
{
std::ostringstream ostr;
for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++)
return ostr.str();
}
-int PkgSupportMode::parse(const std::string &data)
+int PkgSupportMode::setUndoInfo(const std::string &info)
{
size_t pos;
size_t start = 0;
- while ((pos = data.find(delimiter, start)) != std::string::npos) {
- inactiveApps.push_back(data.substr(start, pos - start));
+ while ((pos = info.find(delimiter, start)) != std::string::npos) {
+ inactiveApps.push_back(info.substr(start, pos - start));
start = pos + 1;
}
return MODES_ERROR_NONE;
#include <list>
#include <string>
#include <pkgmgr-info.h>
+#include <PluginAction.h>
#include "plugin-def.h"
-#include "PkgAction.h"
MODES_NAMESPACE_BEGIN
-class PkgSupportMode : public PkgAction {
+class PkgSupportMode : public PluginAction {
public:
PkgSupportMode();
int set(int val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &data) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &data) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
actionMap[PkgSupportMode::NAME] = PKG_ACT_SUPPORTMODE;
}
-PkgAction* PkgFactory::createAction(const std::string &key)
+PluginAction* PkgFactory::createAction(const std::string &key)
{
auto search = actionMap.find(key);
if (actionMap.end() == search) {
- ERR("No PkgAction(%s)", key.c_str());
+ ERR("No Pkg PluginAction(%s)", key.c_str());
return nullptr;
}
- PkgAction *action;
+ PluginAction *action;
switch (search->second) {
case PKG_ACT_SUPPORTMODE:
action = new PkgSupportMode();
return action;
}
-void PkgFactory::destroyAction(PkgAction *action)
+void PkgFactory::destroyAction(PluginAction *action)
{
delete action;
}
#include <map>
#include <string>
-#include "PkgAction.h"
+#include <PluginAction.h>
+#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
PkgFactory();
~PkgFactory() = default;
- PkgAction* createAction(const std::string &key);
- void destroyAction(PkgAction *action);
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
private:
enum actionKey{
PKG_ACT_SUPPORTMODE
* limitations under the License.
*/
#include <string>
-#include <modes_errors.h>
#include <Plugin.h>
#include "plugin-log.h"
#include "plugin-def.h"
#include "PkgFactory.h"
-#include "PkgAction.h"
MODES_NAMESPACE_USE;
class PkgPlugin : public Plugin {
public:
PkgPlugin();
- ~PkgPlugin() = default;
+ ~PkgPlugin() override = default;
- int set(const std::string &key, int val, PluginAction **piAction) override;
- void undo(PluginAction *piAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
private:
PkgFactory pkgFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
- return new PkgPlugin;
+ return new PkgPlugin();
}
extern "C" API void objectDelete(Plugin *plugin)
setName("pkg");
}
-int PkgPlugin::set(const std::string &key, int val, PluginAction **piAction)
+PluginAction* PkgPlugin::newAction(const std::string &key)
{
- PkgAction *action = pkgFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- int ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- pkgFactory.destroyAction(action);
- return ret;
+ return pkgFactory.createAction(key);
}
-void PkgPlugin::undo(PluginAction *piAction)
+void PkgPlugin::deleteAction(PluginAction *piAction)
{
- PkgAction *action = static_cast<PkgAction*>(piAction);
- RET_IF(nullptr == piAction);
-
- action->undo();
- pkgFactory.destroyAction(action);
-}
-
-PluginAction* PkgPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
- PkgAction *action = pkgFactory.createAction(key);
- RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
- int ret = action->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- pkgFactory.destroyAction(action);
- return nullptr;
- }
-
- return action;
+ pkgFactory.destroyAction(piAction);
}
FILE(GLOB VCONF_SRCS ${VCONF_SRC_DIR}/*.cpp)
SET(VCONF_SRCS ${VCONF_SRCS} "mdsp_test_vconf.cpp")
-ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS} ${VCONF_COMMON_SRC})
+ADD_EXECUTABLE(${VCONF_PLUGIN_TEST} ${VCONF_SRCS})
TARGET_LINK_LIBRARIES(${VCONF_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
INSTALL(TARGETS ${VCONF_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
#===================================================================#
FILE(GLOB DISPLAY_SRCS ${DISPLAY_SRC_DIR}/*.cpp)
SET(DISPLAY_SRCS ${DISPLAY_SRCS} "mdsp_test_display.cpp")
-ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS} ${VCONF_COMMON_SRC})
+ADD_EXECUTABLE(${DISPLAY_PLUGIN_TEST} ${DISPLAY_SRCS})
TARGET_LINK_LIBRARIES(${DISPLAY_PLUGIN_TEST} ${test_pkgs_LIBRARIES})
INSTALL(TARGETS ${DISPLAY_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
#include <glib.h>
#include <aul.h>
#include <Plugin.h>
-#include <modes_errors.h>
#include <app_manager.h>
#include <app_manager_extension.h>
#include "plugin-def.h"
MODES_NAMESPACE_USE;
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
class AppPluginTest : public ::testing::Test {
protected:
static gboolean appUndoTimeout(gpointer data)
{
PluginAction *action = (PluginAction*)data;
- plugin->undo(action);
+ action->undo();
g_main_loop_quit(loop);
+ plugin->deleteAction(action);
return false;
}
static gboolean checkSetUndoIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("launch", std::string(testApp), &action);
+ PluginAction *action = plugin->newAction("launch");
+ EXPECT_FALSE(action->IsCurrentValue(std::string(testApp)));
+ result = action->set(std::string(testApp));
EXPECT_EQ(MODES_ERROR_NONE, result);
- if (MODES_ERROR_NONE == result)
+ if (MODES_ERROR_NONE == result) {
g_timeout_add(1000, appUndoTimeout, action);
- else
+ } else {
g_main_loop_quit(loop);
-
+ plugin->deleteAction(action);
+ }
return G_SOURCE_REMOVE;
}
static gboolean checkChangedCBIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("launch", std::string(testApp), &action);
+ PluginAction *action = plugin->newAction("launch");
+ EXPECT_FALSE(action->IsCurrentValue(std::string(testApp)));
+ result = action->set(std::string(testApp));
EXPECT_EQ(MODES_ERROR_NONE, result);
int ret = action->setChangedCallback(changedCB, (void*)testApp);
app_manager_get_app_context(testApp, &runAppContext);
app_manager_terminate_app(runAppContext);
- if (MODES_ERROR_NONE == result)
- g_timeout_add(3000, appUndoTimeout, action);
- else
+ if (MODES_ERROR_NONE == result) {
+ g_timeout_add(1000, appUndoTimeout, action);
+ } else {
g_main_loop_quit(loop);
+ plugin->deleteAction(action);
+ }
return G_SOURCE_REMOVE;
}
MODES_NAMESPACE_USE;
-extern "C" Plugin *objectCreate(void);
+extern "C" Plugin* objectCreate(void);
extern "C" void objectDelete(Plugin *plugin);
class BtPluginTest : public ::testing::Test {
ASSERT_TRUE(nullptr != plugin);
- ret = plugin->set("power", false, nullptr);
+ PluginAction *action = plugin->newAction("power");
+ ret = action->set(false);
EXPECT_EQ(ret, MODES_ERROR_NONE);
sleep(3);//for avoiding the NOW_IN_PROGRESS error
- ret = plugin->set("power", true, nullptr);
+ ret = action->set(true);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("power", std::string("on"), nullptr);
+ ret = action->set(std::string("on"));
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+ plugin->deleteAction(action);
- ret = plugin->set("abcdefg", true, nullptr);
- EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
+ action = plugin->newAction("abcdefg");
+ EXPECT_EQ(action, nullptr);
}
-
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
#include <glib.h>
#include <gtest/gtest.h>
#include <Plugin.h>
-#include <modes_errors.h>
#include "plugin-def.h"
MODES_NAMESPACE_USE;
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
class displayPluginTest : public ::testing::Test {
protected:
static gboolean displayPluginBrightnessIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("brightness", 100, &action);
+ PluginAction *action = plugin->newAction("brightness");
+ int value = 100;
+ if (action->IsCurrentValue(value))
+ value--;
+ result = action->set(value);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
g_main_loop_quit(loop);
-
return G_SOURCE_REMOVE;
}
static gboolean displayPluginDenyPalmTouchIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("denyPalmTouch", true, &action);
+ PluginAction *action = plugin->newAction("denyPalmTouch");
+ EXPECT_FALSE(action->IsCurrentValue(true));
+ result = action->set(true);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
g_main_loop_quit(loop);
-
return G_SOURCE_REMOVE;
}
static gboolean displayPluginAlwaysOnIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("timeout", 0, &action);
+ PluginAction *action = plugin->newAction("timeout");
+ EXPECT_FALSE(action->IsCurrentValue(0));
+ result = action->set(0);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
g_main_loop_quit(loop);
-
return G_SOURCE_REMOVE;
}
static gboolean displayPluginAutoBrightnessIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("autoBrightness", 1, &action);
+ PluginAction *action = plugin->newAction("autoBrightness");
+ EXPECT_FALSE(action->IsCurrentValue(1));
+ result = action->set(1);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
- result = plugin->set("autoBrightness", 2, &action);
+ result = action->set(2);
EXPECT_EQ(MODES_ERROR_NONE, result);
+ plugin->deleteAction(action);
g_main_loop_quit(loop);
-
return G_SOURCE_REMOVE;
}
static int result;
#include <string>
#include <gtest/gtest.h>
#include <Plugin.h>
-#include <modes_errors.h>
#include "plugin-def.h"
MODES_NAMESPACE_USE;
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
class MediaPluginTest : public ::testing::Test {
protected:
static gboolean mediaPlaySetUndoTimeout(gpointer data)
{
PluginAction *action = (PluginAction*)data;
- plugin->undo(action);
+ action->undo();
g_main_loop_quit(loop);
return false;
}
static gboolean mediaPlaySetUndoIdler(gpointer data)
{
- PluginAction *action;
- result = plugin->set("player", std::string("/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3"), &action);
- if (MODES_ERROR_NONE != result)
- result = plugin->set("player", std::string("/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg"), &action);
+ PluginAction *action = (PluginAction*)data;
+ const std::string file = "/opt/usr/data/settings/Ringtones/ringtone_sdk.mp3";
+ EXPECT_FALSE(action->IsCurrentValue(file));
+ result = action->set(file);
+ if (MODES_ERROR_NONE != result) {
+ const std::string wearableFile = "/opt/usr/data/settings/Previews/Media_preview_Over_the_horizon_B2.ogg";
+ EXPECT_FALSE(action->IsCurrentValue(wearableFile));
+ result = action->set(wearableFile);
+ }
EXPECT_EQ(MODES_ERROR_NONE, result);
static gboolean VolumeSetUndoIdler(gpointer data)
{
PluginAction *action;
- action = nullptr;
- result = plugin->set("mediaVolume", 5, &action);
+ action = plugin->newAction("mediaVolume");
+ EXPECT_FALSE(action->IsCurrentValue(5));
+ result = action->set(5);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("systemVolume", 2, &action);
+ action = plugin->newAction("systemVolume");
+ EXPECT_FALSE(action->IsCurrentValue(2));
+ result = action->set(2);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("ringtoneVolume", 9, &action);
+ action = plugin->newAction("ringtoneVolume");
+ EXPECT_FALSE(action->IsCurrentValue(9));
+ result = action->set(9);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("notificationVolume", 1, &action);
+ action = plugin->newAction("notificationVolume");
+ EXPECT_FALSE(action->IsCurrentValue(1));
+ result = action->set(1);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("mediaVolume", -1, &action);
+ action = plugin->newAction("mediaVolume");
+ EXPECT_FALSE(action->IsCurrentValue(-1));
+ result = action->set(-1);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("systemVolume", -1, &action);
+ action = plugin->newAction("systemVolume");
+ EXPECT_FALSE(action->IsCurrentValue(-1));
+ result = action->set(-1);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("ringtoneVolume", -1, &action);
+ action = plugin->newAction("ringtoneVolume");
+ EXPECT_FALSE(action->IsCurrentValue(-1));
+ result = action->set(-1);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
- action = nullptr;
- result = plugin->set("notificationVolume", -1, &action);
+ action = plugin->newAction("notificationVolume");
+ EXPECT_FALSE(action->IsCurrentValue(-1));
+ result = action->set(-1);
EXPECT_EQ(MODES_ERROR_NONE, result);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
g_main_loop_quit(loop);
int MediaPluginTest::result = 0;
Plugin *MediaPluginTest::plugin = nullptr;
-GMainLoop *MediaPluginTest::loop = NULL;
+GMainLoop *MediaPluginTest::loop = nullptr;
TEST_F(MediaPluginTest, setUndoMediaPlay)
{
- g_idle_add(mediaPlaySetUndoIdler, plugin);
+ PluginAction *action = plugin->newAction("player");
+ g_idle_add(mediaPlaySetUndoIdler, action);
g_main_loop_run(loop);
+ plugin->deleteAction(action);
}
TEST_F(MediaPluginTest, setUndoMediaVolume)
{
- g_idle_add(VolumeSetUndoIdler, plugin);
+ g_idle_add(VolumeSetUndoIdler, NULL);
g_main_loop_run(loop);
}
#include <string>
#include <gtest/gtest.h>
#include <Plugin.h>
-#include <modes_errors.h>
#include "plugin-def.h"
MODES_NAMESPACE_USE;
-extern "C" API Plugin *objectCreate(void);
-extern "C" API void objectDelete(Plugin *plugin);
+extern "C" Plugin* objectCreate(void);
+extern "C" void objectDelete(Plugin *plugin);
class PkgPluginTest : public ::testing::Test {
protected:
TEST_F(PkgPluginTest, setUndoTest)
{
- PluginAction *action;
- int ret = plugin->set("supportMode", 1, &action);
+ PluginAction *action = plugin->newAction("supportMode");
+ EXPECT_FALSE(action->IsCurrentValue(1));
+ int ret = action->set(1);
EXPECT_EQ(MODES_ERROR_NONE, ret);
g_idle_add(pkgPluginIdler, plugin);
g_main_loop_run(loop);
- plugin->undo(action);
+ action->undo();
g_idle_add(pkgPluginIdler, plugin);
g_main_loop_run(loop);
+ plugin->deleteAction(action);
}
int main(int argc, char **argv) {
#include <vconf.h>
#include <gtest/gtest.h>
#include <Plugin.h>
-#include <modes_errors.h>
#include "plugin-log.h"
#include "plugin-def.h"
MODES_NAMESPACE_USE;
-extern "C" Plugin *objectCreate(void);
+extern "C" Plugin* objectCreate(void);
extern "C" void objectDelete(Plugin *plugin);
class VconfPluginTest : public ::testing::Test {
static void callback1(void *userData)
{
PluginAction *action = (PluginAction*)userData;
- DBG("%s changed callback called!", action->getName().c_str());
+ DBG("%s changed callback called!", action->getKey().c_str());
//In practice, it is handled by Action. refer to Action.cpp
action->unSetChangedCallback(callback1, nullptr);
int ret;
const char *key = "db.setting.psmode";
- ret = plugin->set(key, 0, nullptr);
+ PluginAction *action = plugin->newAction(key);;
+ ret = action->set(0);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- PluginAction *action;
- ret = plugin->set(key, 1, &action);
+ EXPECT_FALSE(action->IsCurrentValue(1));
+ ret = action->set(1);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
}
TEST_F(VconfPluginTest, VconfDouble)
int ret;
const char *key = "db.system.timechange_external";
- ret = plugin->set(key, 0.0, nullptr);
+ PluginAction *action = plugin->newAction(key);;
+ ret = action->set(0.0);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- PluginAction *action;
- ret = plugin->set(key, 1.0, &action);
+ EXPECT_FALSE(action->IsCurrentValue(1.0));
+ ret = action->set(1.0);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
}
TEST_F(VconfPluginTest, VconfBool)
int ret;
const char *key = "db.setting.sound.button_sounds";
- ret = plugin->set(key, true, nullptr);
+ PluginAction *action = plugin->newAction(key);;
+ ret = action->set(true);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- PluginAction *action;
- ret = plugin->set(key, false, &action);
+ EXPECT_FALSE(action->IsCurrentValue(false));
+ ret = action->set(false);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
}
TEST_F(VconfPluginTest, VconfStr)
const std::string devName = "Tizen";
const std::string tmpName = "ModesTest";
- ret = plugin->set(key, devName, nullptr);
+ PluginAction *action = plugin->newAction(key);
+ ret = action->set(devName);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- PluginAction *action;
- ret = plugin->set(key, tmpName, &action);
+ EXPECT_FALSE(action->IsCurrentValue(tmpName));
+ ret = action->set(tmpName);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- plugin->undo(action);
+ action->undo();
+ plugin->deleteAction(action);
}
TEST_F(VconfPluginTest, callbackPluginVconf)
int ret = vconf_get_int("db/setting/psmode", &oldVal);
EXPECT_EQ(ret, 0);
- PluginAction *action;
- ret = plugin->set(key, 0, &action);
+ PluginAction *action = plugin->newAction(key);
+ ret = action->set(0);
EXPECT_EQ(ret, MODES_ERROR_NONE);
ret = action->setChangedCallback(valChangedCb, (void*)key);
ret = action->setChangedCallback(shoudNotBeCalled, (void*)key);
EXPECT_EQ(ret, MODES_ERROR_NONE);
action->unSetChangedCallback(shoudNotBeCalled, (void*)key);
+ plugin->deleteAction(action);
vconf_set_int("db/setting/psmode", oldVal);
}
-TEST_F(VconfPluginTest, callbackPluginVconfReset)
-{
- int ret;
- const char *key = "db.setting.psmode";
-
- PluginAction *action1;
- ret = plugin->set(key, 4, &action1);
- EXPECT_EQ(ret, MODES_ERROR_NONE);
-
- 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, (void*)key);
- EXPECT_EQ(ret, MODES_ERROR_NONE);
- g_idle_add(changedCallbackidler, nullptr);
- g_main_loop_run(loop);
- EXPECT_TRUE(cb2Called);
-
- action2->unSetChangedCallback(callback2, nullptr);
- vconf_set_int("db/setting/psmode", 0);
-}
-
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
MODES_NAMESPACE_USE;
-extern "C" Plugin *objectCreate(void);
+extern "C" Plugin* objectCreate(void);
extern "C" void objectDelete(Plugin *plugin);
class WifiPluginTest : public ::testing::Test {
plugin = nullptr;
}
+ static gboolean timer(gpointer data)
+ {
+ GMainLoop *loop = (GMainLoop*)data;
+ g_main_loop_quit(loop);
+ return G_SOURCE_REMOVE;
+ }
+
Plugin *plugin;
};
ASSERT_TRUE(nullptr != plugin);
- ret = plugin->set("power", false, nullptr);
+ bool val;
+ PluginAction *action = plugin->newAction("power");
+ val = action->IsCurrentValue(false);
+ ret = action->set(val);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("power", true, nullptr);
+ GMainLoop *loop = g_main_loop_new(NULL, FALSE);
+ g_timeout_add(1000, timer, (gpointer)loop);
+ g_main_loop_run(loop);
+
+ ret = action->set(!val);
EXPECT_EQ(ret, MODES_ERROR_NONE);
- ret = plugin->set("power", 0, nullptr);
+ ret = action->set(0);
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
- ret = plugin->set("power", 1, nullptr);
+ ret = action->set(1);
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
- ret = plugin->set("power", 0.0, nullptr);
+ ret = action->set(0.0);
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
- ret = plugin->set("power", 1.0, nullptr);
+ ret = action->set(1.0);
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
- ret = plugin->set("power", std::string("off"), nullptr);
+ ret = action->set(std::string("off"));
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
- ret = plugin->set("power", std::string("on"), nullptr);
+ ret = action->set(std::string("on"));
EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED);
+ plugin->deleteAction(action);
- ret = plugin->set("abcdefg", true, nullptr);
- EXPECT_EQ(ret, MODES_ERROR_INVALID_PARAMETER);
+ action = plugin->newAction("abcdefg");
+ EXPECT_EQ(action, nullptr);
}
int main(int argc, char **argv) {
INCLUDE_DIRECTORIES(${vconf_pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${vconf_pkgs_LIBRARY_DIRS})
-ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS} ${VCONF_COMMON_SRC})
+ADD_LIBRARY(${VCONF_PLUGIN} SHARED ${VCONF_SRCS})
TARGET_LINK_LIBRARIES(${VCONF_PLUGIN} ${vconf_pkgs_LIBRARIES})
SET_TARGET_PROPERTIES(${VCONF_PLUGIN} PROPERTIES NO_SONAME 1 )
INSTALL(TARGETS ${VCONF_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "VconfActionBool.h"
+#include "VconfBool.h"
#include <string>
#include <sstream>
MODES_NAMESPACE_USE;
-VconfActionBool::VconfActionBool(const std::string &vconfKey)
+VconfBool::VconfBool(const std::string &vconfKey)
: PluginAction("boolVconf"), key(vconfKey), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr)
{
}
-int VconfActionBool::set(bool val)
+bool VconfBool::IsCurrentValue(bool val)
{
- requestVal = val;
-
- int ret = cbHandler.invokeChangedCB(key);
- if (MODES_ERROR_NONE != ret) {
- ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
- return ret;
- }
-
- int prev;
- ret = vconf_get_bool(key.c_str(), &prev);
+ int tmp;
+ int ret = vconf_get_bool(key.c_str(), &tmp);
if (0 != ret) {
ERR("vconf_get_bool(%s) Fail(%d)", key.c_str(), ret);
- return MODES_ERROR_SYSTEM;
+ return false;
}
- oldVal = prev;
+ oldVal = tmp;
if (oldVal == val) {
INFO("vconf(%s) already set(%d)", key.c_str(), val);
- } else {
- ret = vconf_set_bool(key.c_str(), val);
- if (0 != ret) {
- ERR("vconf_set_bool(%s, %d) Fail(%d)", key.c_str(), val, ret);
- return MODES_ERROR_SYSTEM;
- }
+ return true;
+ }
+
+ return false;
+}
+
+int VconfBool::set(bool val)
+{
+ requestVal = val;
+
+ int ret = vconf_set_bool(key.c_str(), val);
+ if (0 != ret) {
+ ERR("vconf_set_bool(%s, %d) Fail(%d)", key.c_str(), val, ret);
+ return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
-void VconfActionBool::undo()
+void VconfBool::undo()
{
int ret = vconf_set_bool(key.c_str(), oldVal ? 1 : 0);
if (0 != ret)
ERR("vconf_set_bool(%s, %d) Fail(%d)", key.c_str(), oldVal, ret);
}
-std::string VconfActionBool::serialize()
+std::string VconfBool::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int VconfActionBool::parse(const std::string &archive)
+int VconfBool::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
}
-int VconfActionBool::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfBool::setChangedCallback(valueChangedCB callback, void *userData)
{
RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
- int ret = cbHandler.setChangedCB(key, this);
- if (MODES_ERROR_NONE != ret) {
- ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
- return ret;
+ int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
cb = callback;
return MODES_ERROR_NONE;
}
-void VconfActionBool::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfBool::unSetChangedCallback(valueChangedCB callback, void *userData)
{
RET_IF(nullptr == callback);
- cbHandler.unSetChangedCB(key);
+ int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+ if (0 != ret) {
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return;
+ }
cbData = nullptr;
cb = nullptr;
}
-//This funcion handles changes made by the Modes
-void VconfActionBool::vconfChangedCB()
-{
- if (cb)
- cb(cbData);
-}
-
-void VconfActionBool::vconfChangedCB(keynode_t *node)
+void VconfBool::changedCB(keynode_t *node)
{
const char *vconfKey = vconf_keynode_get_name(node);
- if (vconfKey != key) {
- WARN("Unknown vconf(%s) notification", vconfKey);
+ if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+ WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
return;
}
- bool val = vconf_keynode_get_bool(node);
+ int val = vconf_keynode_get_bool(node);
if (cb && (val != requestVal))
cb(cbData);
}
+
+void VconfBool::vconfChangedCB(keynode_t *node, void *userData)
+{
+ RET_IF(nullptr == userData);
+
+ VconfBool *action = (VconfBool*)userData;
+ action->changedCB(node);
+}
#pragma once
#include <string>
+#include <vconf.h>
#include <PluginAction.h>
#include "plugin-def.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_BEGIN
-class VconfActionBool : public PluginAction, public VconfChangeAction {
+class VconfBool : public PluginAction {
public:
- VconfActionBool(const std::string &vconfKey);
+ VconfBool(const std::string &vconfKey);
- int set(bool val);
+ bool IsCurrentValue(bool val) override;
+ int set(bool val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
-
- void vconfChangedCB() override;
- void vconfChangedCB(keynode_t *node) override;
private:
+ void changedCB(keynode_t *node);
+ static void vconfChangedCB(keynode_t *node, void *userData);
+
std::string key;
bool requestVal;
bool oldVal;
- VconfCbHandler cbHandler;
valueChangedCB cb;
void *cbData;
};
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "VconfActionDbl.h"
+#include "VconfDbl.h"
#include <string>
#include <sstream>
MODES_NAMESPACE_USE;
-VconfActionDbl::VconfActionDbl(const std::string &vconfKey)
+VconfDbl::VconfDbl(const std::string &vconfKey)
: PluginAction("dblVconf"), key(vconfKey), requestVal(0.0), oldVal(0.0), cb(nullptr), cbData(nullptr)
{
}
-int VconfActionDbl::set(double val)
+bool VconfDbl::IsCurrentValue(double val)
{
- requestVal = val;
-
- int ret = cbHandler.invokeChangedCB(key);
- if (MODES_ERROR_NONE != ret) {
- ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
- return ret;
- }
-
- ret = vconf_get_dbl(key.c_str(), &oldVal);
+ int ret = vconf_get_dbl(key.c_str(), &oldVal);
if (0 != ret) {
ERR("vconf_get_dbl(%s) Fail(%d)", key.c_str(), ret);
- return MODES_ERROR_SYSTEM;
+ return false;
}
if (oldVal == val) {
INFO("vconf(%s) already set(%f)", key.c_str(), val);
- } else {
- ret = vconf_set_dbl(key.c_str(), val);
- if (0 != ret) {
- ERR("vconf_set_dbl(%s, %f) Fail(%d)", key.c_str(), val, ret);
- return MODES_ERROR_SYSTEM;
- }
+ return true;
+ }
+
+ return false;
+}
+
+int VconfDbl::set(double val)
+{
+ requestVal = val;
+
+ int ret = vconf_set_dbl(key.c_str(), val);
+ if (0 != ret) {
+ ERR("vconf_set_dbl(%s, %f) Fail(%d)", key.c_str(), val, ret);
+ return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
-void VconfActionDbl::undo()
+void VconfDbl::undo()
{
int ret = vconf_set_dbl(key.c_str(), oldVal);
if (0 != ret)
ERR("vconf_set_dbl(%s, %f) Fail(%d)", key.c_str(), oldVal, ret);
}
-std::string VconfActionDbl::serialize()
+std::string VconfDbl::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int VconfActionDbl::parse(const std::string &archive)
+int VconfDbl::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
}
-int VconfActionDbl::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfDbl::setChangedCallback(valueChangedCB callback, void *userData)
{
RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
- int ret = cbHandler.setChangedCB(key, this);
- if (MODES_ERROR_NONE != ret) {
- ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
- return ret;
+ int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
cb = callback;
return MODES_ERROR_NONE;
}
-void VconfActionDbl::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfDbl::unSetChangedCallback(valueChangedCB callback, void *userData)
{
RET_IF(nullptr == callback);
- cbHandler.unSetChangedCB(key);
+ int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+ if (0 != ret) {
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return;
+ }
cbData = nullptr;
cb = nullptr;
}
-//This funcion handles changes made by the Modes
-void VconfActionDbl::vconfChangedCB()
-{
- if (cb)
- cb(cbData);
-}
-
-void VconfActionDbl::vconfChangedCB(keynode_t *node)
+void VconfDbl::changedCB(keynode_t *node)
{
const char *vconfKey = vconf_keynode_get_name(node);
- if (vconfKey != key) {
- WARN("Unknown vconf(%s) notification", vconfKey);
+ if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+ WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
return;
}
if (cb && (val != requestVal))
cb(cbData);
}
+
+void VconfDbl::vconfChangedCB(keynode_t *node, void *userData)
+{
+ RET_IF(nullptr == userData);
+
+ VconfDbl *action = (VconfDbl*)userData;
+ action->changedCB(node);
+}
#pragma once
#include <string>
+#include <vconf.h>
#include <PluginAction.h>
#include "plugin-def.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_BEGIN
-class VconfActionDbl : public PluginAction, public VconfChangeAction {
+class VconfDbl : public PluginAction {
public:
- VconfActionDbl(const std::string &vconfKey);
+ VconfDbl(const std::string &vconfKey);
- int set(double val);
+ bool IsCurrentValue(double val) override;
+ int set(double val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
-
- void vconfChangedCB() override;
- void vconfChangedCB(keynode_t *node) override;
private:
+ void changedCB(keynode_t *node);
+ static void vconfChangedCB(keynode_t *node, void *userData);
+
std::string key;
double requestVal;
double oldVal;
- VconfCbHandler cbHandler;
valueChangedCB cb;
void *cbData;
};
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "VconfFactory.h"
+
+#include <algorithm>
+#include "plugin-log.h"
+#include "VconfBool.h"
+#include "VconfDbl.h"
+#include "VconfInt.h"
+#include "VconfStr.h"
+
+MODES_NAMESPACE_USE;
+
+template<typename T> PluginAction* newVconf(const std::string &key)
+{
+ return new T(key);
+}
+
+VconfFactory::VconfFactory()
+{
+ actionMap["db.setting.psmode"] = &newVconf<VconfInt>;
+ actionMap["db.setting.sound.sound_on"] = &newVconf<VconfBool>;
+ actionMap["db.setting.sound.vibration_on"] = &newVconf<VconfBool>;
+ actionMap["db.location.setting.Usemylocation"] = &newVconf<VconfInt>;
+ actionMap["db.setting.auto_rotate_screen"] = &newVconf<VconfBool>;
+ actionMap["db.setting.menuscreen.package_name"] = &newVconf<VconfStr>;
+#ifdef MDS_TEST
+ actionMap["db.system.timechange_external"] = &newVconf<VconfDbl>;
+ actionMap["db.setting.sound.button_sounds"] = &newVconf<VconfBool>;
+ actionMap["db.setting.device_name"] = &newVconf<VconfStr>;
+#endif
+}
+
+PluginAction* VconfFactory::createAction(const std::string &key)
+{
+ auto found = actionMap.find(key);
+ if (actionMap.end() == found) {
+ ERR("No PluginAction(%s)", key.c_str());
+ return nullptr;
+ }
+
+ std::string newKey(key);
+ std::replace(newKey.begin(), newKey.end(), '.', '/');
+
+ return found->second(newKey);;
+}
+
+void VconfFactory::destroyAction(PluginAction *action)
+{
+ delete action;
+}
*/
#pragma once
+#include <map>
#include <string>
#include <PluginAction.h>
#include "plugin-def.h"
MODES_NAMESPACE_BEGIN
-class PkgAction : public PluginAction {
+class VconfFactory {
public:
- PkgAction(const std::string &name)
- : PluginAction(name)
- {
- }
- ~PkgAction() = default;
+ VconfFactory();
+ ~VconfFactory() = default;
- virtual int set(int val)
- {
- return MODES_ERROR_NOT_SUPPORTED;
- }
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
+private:
+ std::map<std::string, PluginAction*(*)(const std::string&)> actionMap;
};
MODES_NAMESPACE_END
-
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "VconfActionInt.h"
+#include "VconfInt.h"
#include <string>
#include <sstream>
MODES_NAMESPACE_USE;
-VconfActionInt::VconfActionInt(const std::string &vconfKey)
+VconfInt::VconfInt(const std::string &vconfKey)
: PluginAction("intVconf"), key(vconfKey), requestVal(0), oldVal(0), cb(nullptr), cbData(nullptr)
{
}
-int VconfActionInt::set(int val)
+bool VconfInt::IsCurrentValue(int val)
{
- requestVal = val;
-
- int ret = cbHandler.invokeChangedCB(key);
- if (MODES_ERROR_NONE != ret) {
- ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
- return ret;
- }
-
- ret = vconf_get_int(key.c_str(), &oldVal);
+ int ret = vconf_get_int(key.c_str(), &oldVal);
if (0 != ret) {
ERR("vconf_get_int(%s) Fail(%d)", key.c_str(), ret);
- return MODES_ERROR_SYSTEM;
+ return false;
}
if (oldVal == val) {
INFO("vconf(%s) already set(%d)", key.c_str(), val);
- } else {
- ret = vconf_set_int(key.c_str(), val);
- if (0 != ret) {
- ERR("vconf_set_int(%s, %d) Fail(%d)", key.c_str(), val, ret);
- return MODES_ERROR_SYSTEM;
- }
+ return true;
+ }
+
+ return false;
+}
+
+int VconfInt::set(int val)
+{
+ requestVal = val;
+
+ int ret = vconf_set_int(key.c_str(), val);
+ if (0 != ret) {
+ ERR("vconf_set_int(%s, %d) Fail(%d)", key.c_str(), val, ret);
+ return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
-void VconfActionInt::undo()
+void VconfInt::undo()
{
int ret = vconf_set_int(key.c_str(), oldVal);
if (0 != ret)
ERR("vconf_set_int(%s, %d) Fail(%d)", key.c_str(), oldVal, ret);
}
-std::string VconfActionInt::serialize()
+std::string VconfInt::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int VconfActionInt::parse(const std::string &archive)
+int VconfInt::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
}
-int VconfActionInt::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfInt::setChangedCallback(valueChangedCB callback, void *userData)
{
RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
- int ret = cbHandler.setChangedCB(key, this);
- if (MODES_ERROR_NONE != ret) {
- ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
- return ret;
+ int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
cb = callback;
return MODES_ERROR_NONE;
}
-void VconfActionInt::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfInt::unSetChangedCallback(valueChangedCB callback, void *userData)
{
RET_IF(nullptr == callback);
- cbHandler.unSetChangedCB(key);
+ int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+ if (0 != ret) {
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return;
+ }
cbData = nullptr;
cb = nullptr;
}
-//This funcion handles changes made by the Modes
-void VconfActionInt::vconfChangedCB()
-{
- if (cb)
- cb(cbData);
-}
-
-void VconfActionInt::vconfChangedCB(keynode_t *node)
+void VconfInt::changedCB(keynode_t *node)
{
const char *vconfKey = vconf_keynode_get_name(node);
- if (vconfKey != key) {
- WARN("Unknown vconf(%s) notification", vconfKey);
+ if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+ WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
return;
}
if (cb && (val != requestVal))
cb(cbData);
}
+
+void VconfInt::vconfChangedCB(keynode_t *node, void *userData)
+{
+ RET_IF(nullptr == userData);
+
+ VconfInt *action = (VconfInt*)userData;
+ action->changedCB(node);
+}
#pragma once
#include <string>
+#include <vconf.h>
#include <PluginAction.h>
#include "plugin-def.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_BEGIN
-class VconfActionInt : public PluginAction, public VconfChangeAction {
+class VconfInt : public PluginAction {
public:
- VconfActionInt(const std::string &vconfKey);
+ VconfInt(const std::string &vconfKey);
- int set(int val);
+ bool IsCurrentValue(int val) override;
+ int set(int val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
-
- void vconfChangedCB() override;
- void vconfChangedCB(keynode_t *node) override;
private:
+ void changedCB(keynode_t *node);
+ static void vconfChangedCB(keynode_t *node, void *userData);
+
std::string key;
int requestVal;
int oldVal;
- VconfCbHandler cbHandler;
valueChangedCB cb;
void *cbData;
};
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <string>
-#include <algorithm>
#include <vconf.h>
-#include <modes_errors.h>
#include <Plugin.h>
#include "plugin-log.h"
#include "plugin-def.h"
-#include "VconfActionInt.h"
-#include "VconfActionDbl.h"
-#include "VconfActionBool.h"
-#include "VconfActionStr.h"
+#include "VconfFactory.h"
MODES_NAMESPACE_USE;
class VconfPlugin : public Plugin {
public:
VconfPlugin();
+ ~VconfPlugin() override = default;
- int set(const std::string &key, int val, PluginAction **piAction) override;
- int set(const std::string &key, double val, PluginAction **piAction) override;
- int set(const std::string &key, bool val, PluginAction **piAction) override;
- int set(const std::string &key, const std::string &val, PluginAction **piAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
- std::string serializeAction(PluginAction *piAction) override;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
+private:
+ VconfFactory vconfFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
- return new VconfPlugin;
+ return new VconfPlugin();
}
extern "C" API void objectDelete(Plugin *plugin)
setName("vconf");
}
-int VconfPlugin::set(const std::string &key, int val, PluginAction **piAction)
+PluginAction* VconfPlugin::newAction(const std::string &key)
{
- int ret;
- DBG("set<int>(%s, %d)", key.c_str(), val);
-
- std::string newKey(key);
- std::replace(newKey.begin(), newKey.end(), '.', '/');
-
- VconfActionInt *action = new VconfActionInt(newKey);
- ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- delete action;
- return ret;
-}
-
-int VconfPlugin::set(const std::string &key, double val, PluginAction **piAction)
-{
- int ret;
- DBG("set<double>(%s, %lf)", key.c_str(), val);
-
- std::string newKey(key);
- std::replace(newKey.begin(), newKey.end(), '.', '/');
-
- VconfActionDbl *action = new VconfActionDbl(newKey);
- ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- delete action;
- return ret;
-}
-
-int VconfPlugin::set(const std::string &key, bool val, PluginAction **piAction)
-{
- int ret;
- DBG("set<bool>(%s, %d)", key.c_str(), val);
-
- std::string newKey(key);
- std::replace(newKey.begin(), newKey.end(), '.', '/');
-
- VconfActionBool *action = new VconfActionBool(newKey);
- ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- delete action;
- return ret;
+ return vconfFactory.createAction(key);
}
-int VconfPlugin::set(const std::string &key, const std::string &val, PluginAction **piAction)
+void VconfPlugin::deleteAction(PluginAction *piAction)
{
- DBG("set<string>(%s, %s)", key.c_str(), val.c_str());
-
- std::string newKey(key);
- std::replace(newKey.begin(), newKey.end(), '.', '/');
-
- VconfActionStr *action = new VconfActionStr(newKey);
- int ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- delete action;
- return ret;
-}
-
-PluginAction* VconfPlugin::getUndoAction(const std::string &key, const std::string &info)
-{
- std::string newKey(key);
- std::replace(newKey.begin(), newKey.end(), '.', '/');
-
- PluginAction *piAction;
- switch (info.front()) {
- case 's':
- piAction = new VconfActionStr(newKey);
- break;
- case 'i':
- piAction = new VconfActionInt(newKey);
- break;
- case 'd':
- piAction = new VconfActionDbl(newKey);
- break;
- case 'b':
- piAction = new VconfActionBool(newKey);
- break;
- default:
- ERR("Unknown Undo Information(%s)", info.c_str());
- return nullptr;
- }
- int ret = piAction->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- delete piAction;
- return nullptr;
- }
-
- return piAction;
-}
-
-std::string VconfPlugin::serializeAction(PluginAction *piAction)
-{
- RETV_IF(nullptr == piAction, std::string());
-
- std::string rawStr = piAction->serialize();
- return piAction->getName().front() + rawStr;
+ vconfFactory.destroyAction(piAction);
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "VconfActionStr.h"
+#include "VconfStr.h"
#include <string>
#include <vconf.h>
MODES_NAMESPACE_USE;
-VconfActionStr::VconfActionStr(const std::string &vconfKey)
+VconfStr::VconfStr(const std::string &vconfKey)
: PluginAction("strVconf"), key(vconfKey), cb(nullptr), cbData(nullptr)
{
}
-int VconfActionStr::set(const std::string &val)
+bool VconfStr::IsCurrentValue(const std::string &val)
{
- requestVal = val;
-
- int ret = cbHandler.invokeChangedCB(key);
- if (MODES_ERROR_NONE != ret) {
- ERR("handleChange(%s) Fail(%d)", key.c_str(), ret);
- return ret;
- }
-
char *prev = vconf_get_str(key.c_str());
if (nullptr == prev) {
ERR("vconf_get_str(%s) Fail()", key.c_str());
- return MODES_ERROR_SYSTEM;
+ return false;
}
oldVal = prev;
free(prev);
if (oldVal == val) {
INFO("vconf(%s) already set(%s)", key.c_str(), val.c_str());
- } else {
- ret = vconf_set_str(key.c_str(), val.c_str());
- if (0 != ret) {
- ERR("vconf_set_str(%s, %s) Fail(%d)", key.c_str(), val.c_str(), ret);
- return MODES_ERROR_SYSTEM;
- }
+ return true;
+ }
+ return false;
+}
+
+int VconfStr::set(const std::string &val)
+{
+ requestVal = val;
+
+ int ret = vconf_set_str(key.c_str(), val.c_str());
+ if (0 != ret) {
+ ERR("vconf_set_str(%s, %s) Fail(%d)", key.c_str(), val.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
return MODES_ERROR_NONE;
}
-void VconfActionStr::undo()
+void VconfStr::undo()
{
int ret = vconf_set_str(key.c_str(), oldVal.c_str());
if (0 != ret)
ERR("vconf_set_str(%s, %s) Fail(%d)", key.c_str(), oldVal.c_str(), ret);
}
-std::string VconfActionStr::serialize()
+std::string VconfStr::getUndoInfo()
{
return oldVal;
}
-int VconfActionStr::parse(const std::string &archive)
+int VconfStr::setUndoInfo(const std::string &info)
{
- oldVal = archive;
+ oldVal = info;
return MODES_ERROR_NONE;
}
-int VconfActionStr::setChangedCallback(valueChangedCB callback, void *userData)
+int VconfStr::setChangedCallback(valueChangedCB callback, void *userData)
{
RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER);
- int ret = cbHandler.setChangedCB(key, this);
- if (MODES_ERROR_NONE != ret) {
- ERR("setChangedCB(%s) Fail(%d)", key.c_str(), ret);
- return ret;
+ int ret = vconf_notify_key_changed(key.c_str(), vconfChangedCB, this);
+ if (0 != ret) {
+ ERR("vconf_notify_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return MODES_ERROR_SYSTEM;
}
cb = callback;
return MODES_ERROR_NONE;
}
-void VconfActionStr::unSetChangedCallback(valueChangedCB callback, void *userData)
+void VconfStr::unSetChangedCallback(valueChangedCB callback, void *userData)
{
RET_IF(nullptr == callback);
- cbHandler.unSetChangedCB(key);
+ int ret = vconf_ignore_key_changed(key.c_str(), vconfChangedCB);
+ if (0 != ret) {
+ ERR("vconf_ignore_key_changed(%s) Fail(%d)", key.c_str(), ret);
+ return;
+ }
cbData = nullptr;
cb = nullptr;
}
-//This funcion handles changes made by the Modes
-void VconfActionStr::vconfChangedCB()
-{
- if (cb)
- cb(cbData);
-}
-
-void VconfActionStr::vconfChangedCB(keynode_t *node)
+void VconfStr::changedCB(keynode_t * node)
{
const char *vconfKey = vconf_keynode_get_name(node);
- if (vconfKey != key) {
- WARN("Unknown vconf(%s) notification", vconfKey);
+ if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) {
+ WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL");
return;
}
if (cb && (val != requestVal))
cb(cbData);
}
+
+void VconfStr::vconfChangedCB(keynode_t *node, void *userData)
+{
+ RET_IF(nullptr == userData);
+
+ VconfStr *action = (VconfStr*)userData;
+ action->changedCB(node);
+}
#pragma once
#include <string>
+#include <vconf.h>
#include <PluginAction.h>
#include "plugin-def.h"
-#include "VconfCbHandler.h"
MODES_NAMESPACE_BEGIN
-class VconfActionStr : public PluginAction, public VconfChangeAction {
+class VconfStr : public PluginAction {
public:
- VconfActionStr(const std::string &vconfKey);
+ VconfStr(const std::string &vconfKey);
- int set(const std::string &val);
+ bool IsCurrentValue(const std::string &val) override;
+ int set(const std::string &val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
-
- void vconfChangedCB() override;
- void vconfChangedCB(keynode_t *node) override;
private:
+ void changedCB(keynode_t *node);
+ static void vconfChangedCB(keynode_t *node, void *userData);
+
std::string key;
std::string requestVal;
std::string oldVal;
- VconfCbHandler cbHandler;
valueChangedCB cb;
void *cbData;
};
*/
#include "WifiAction.h"
-#include <modes_errors.h>
#include "plugin-log.h"
#include "plugin-def.h"
WifiAction(const std::string &name);
~WifiAction();
- virtual int set(bool val) = 0;
protected:
wifi_manager_h handle;
};
#include "WifiActionPower.h"
#include <sstream>
-#include <modes_errors.h>
#include "plugin-log.h"
MODES_NAMESPACE_USE;
{
}
-int WifiActionPower::set(bool val)
+bool WifiActionPower::IsCurrentValue(bool val)
{
- requestVal = val;
wifi_manager_is_activated(handle, &oldVal);
if (oldVal == val) {
INFO("Already wifi is [%s]", val ? "On" : "Off");
- return MODES_ERROR_NONE;
+ return true;
}
+ return false;
+}
+
+int WifiActionPower::set(bool val)
+{
+ requestVal = val;
+
if (val) {
int ret = wifi_manager_activate(handle, activateCB, this);
if (WIFI_MANAGER_ERROR_NONE != ret) {
set(oldVal);
}
-std::string WifiActionPower::serialize()
+std::string WifiActionPower::getUndoInfo()
{
std::ostringstream ostr;
return ostr.str();
}
-int WifiActionPower::parse(const std::string &archive)
+int WifiActionPower::setUndoInfo(const std::string &info)
{
- std::istringstream iss(archive);
+ std::istringstream iss(info);
iss >> oldVal;
return MODES_ERROR_NONE;
public:
WifiActionPower();
+ bool IsCurrentValue(bool val) override;
int set(bool val) override;
void undo() override;
- std::string serialize() override;
- int parse(const std::string &archive) override;
+ std::string getUndoInfo() override;
+ int setUndoInfo(const std::string &info) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
MODES_NAMESPACE_USE;
+template<typename T> PluginAction* newWifiAction() { return new T(); }
+
WifiFactory::WifiFactory()
{
- actionMap[WifiActionPower::NAME] = POWER;
+ actionMap[WifiActionPower::NAME] = &newWifiAction<WifiActionPower>;
}
-WifiAction* WifiFactory::createAction(const std::string &key)
+PluginAction* WifiFactory::createAction(const std::string &key)
{
- auto search = actionMap.find(key);
- if (actionMap.end() == search) {
+ auto found = actionMap.find(key);
+ if (actionMap.end() == found) {
ERR("No WifiAction(%s)", key.c_str());
return nullptr;
}
- switch (search->second) {
- case POWER:
- WifiActionPower *wifiActionPower = new WifiActionPower();
- return wifiActionPower;
- break;
- }
-
- return nullptr;
+ return found->second();
}
-void WifiFactory::destroyAction(WifiAction *action)
+void WifiFactory::destroyAction(PluginAction *action)
{
delete action;
}
WifiFactory();
~WifiFactory() = default;
- WifiAction *createAction(const std::string &key);
- void destroyAction(WifiAction *action);
+ PluginAction* createAction(const std::string &key);
+ void destroyAction(PluginAction *action);
private:
enum actionKey {
POWER
};
- std::map<std::string, actionKey> actionMap;
+ std::map<std::string, PluginAction*(*)()> actionMap;
};
MODES_NAMESPACE_END
* limitations under the License.
*/
#include <string>
-#include <modes_errors.h>
-#include <wifi-manager.h>
#include <Plugin.h>
#include "plugin-log.h"
#include "WifiFactory.h"
class WifiPlugin : public Plugin {
public:
WifiPlugin();
+ ~WifiPlugin() override = default;
- int set(const std::string &key, bool val, PluginAction **piAction) override;
- void undo(PluginAction *piAction) override;
- PluginAction* getUndoAction(const std::string &key, const std::string &info) override;
+ PluginAction* newAction(const std::string &key) override;
+ void deleteAction(PluginAction *piAction) override;
private:
WifiFactory wifiFactory;
};
-extern "C" API Plugin *objectCreate(void)
+extern "C" API Plugin* objectCreate(void)
{
- return new WifiPlugin;
+ return new WifiPlugin();
}
extern "C" API void objectDelete(Plugin *plugin)
setName("wifi");
}
-int WifiPlugin::set(const std::string &key, bool val, PluginAction **piAction)
+PluginAction* WifiPlugin::newAction(const std::string &key)
{
- WifiAction *action = wifiFactory.createAction(key);
- RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
-
- DBG("set [%s, %s]", key.c_str(), (val ? "on" : "off"));
-
- int ret = action->set(val);
- if (piAction)
- *piAction = action;
- else
- wifiFactory.destroyAction(action);
-
- return ret;
-}
-
-void WifiPlugin::undo(PluginAction *piAction)
-{
- WifiAction *action = static_cast<WifiAction*>(piAction);
- RET_IF(nullptr == piAction);
-
- DBG("Action(%s) undo", action->getName().c_str());
-
- action->undo();
- wifiFactory.destroyAction(action);
+ return wifiFactory.createAction(key);
}
-PluginAction* WifiPlugin::getUndoAction(const std::string &key, const std::string &info)
+void WifiPlugin::deleteAction(PluginAction *piAction)
{
- WifiAction *action = wifiFactory.createAction(key);
- RETVM_IF(nullptr == action, nullptr, "action(%s) is null", key.c_str());
-
- int ret = action->parse(info);
- if (MODES_ERROR_NONE != ret) {
- ERR("Action(%s) parse(%s) Fail(%d)", key.c_str(), info.c_str(), ret);
- wifiFactory.destroyAction(action);
- return nullptr;
- }
-
- return action;
+ wifiFactory.destroyAction(piAction);
}