From: Youngjae Shin Date: Mon, 9 Mar 2020 02:57:48 +0000 (+0900) Subject: revise pkg actions(changedCB) X-Git-Tag: submit/tizen/20200406.072014~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f91eb649e2eb0b0b807ed9adeedcca0412064b11;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git revise pkg actions(changedCB) --- diff --git a/pkg/PkgAction.h b/pkg/PkgAction.h index b5cb7db..30eb892 100644 --- a/pkg/PkgAction.h +++ b/pkg/PkgAction.h @@ -27,16 +27,12 @@ public: : PluginAction(name) { } - virtual ~PkgAction() = default; + ~PkgAction() = default; virtual int set(int val) { return MODES_ERROR_NOT_SUPPORTED; } - virtual int get(int *val) - { - return MODES_ERROR_NOT_SUPPORTED; - } }; MODES_NAMESPACE_END diff --git a/pkg/PkgEnableSupportMode.cpp b/pkg/PkgEnableSupportMode.cpp index dae6ffa..bfcf38d 100644 --- a/pkg/PkgEnableSupportMode.cpp +++ b/pkg/PkgEnableSupportMode.cpp @@ -25,75 +25,50 @@ MODES_NAMESPACE_USE; -const std::string PkgStartSupportMode::NAME = "startSupportMode"; -int PkgStartSupportMode::appModeVal = 0; +const std::string PkgSupportMode::NAME = "supportMode"; -PkgStartSupportMode::PkgStartSupportMode() - : PkgAction(NAME) +PkgSupportMode::PkgSupportMode() + : PkgAction(NAME), requestVal(0) { } -int PkgStartSupportMode::app_list_cb(const pkgmgrinfo_appinfo_h handle, void *userData) -{ - std::list *appList = (std::list*)userData; - - int ret; - int appSupportMode = 0; - ret = pkgmgrinfo_appinfo_get_support_mode(handle, &appSupportMode); - if (PMINFO_R_OK != ret) - ERR("pkgmgrinfo_appinfo_get_support_mode() Fail"); - - - if (appSupportMode != appModeVal) { - char *appid = NULL; - ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (PMINFO_R_OK != ret) { - ERR("pkgmgrinfo_appinfo_get_appid() Fail"); - return 0; - } - - appList->push_back(appid); - } - return 0; -} - -int PkgStartSupportMode::set(int val) +int PkgSupportMode::set(int val) { int ret; pkgmgrinfo_appinfo_filter_h filter; ret = pkgmgrinfo_appinfo_filter_create(&filter); - if (ret != PMINFO_R_OK) - return ret; + if (ret != PMINFO_R_OK) { + ERR("pkgmgrinfo_appinfo_filter_create() Fail(%d)", ret); + return MODES_ERROR_SYSTEM; + } switch (val) { case ULTRA_POWER_SAVING: - appModeVal = APP_SUPPORT_MODE_ULTRA_POWER_SAVING_VAL; - break; case COOL_DOWN: - appModeVal = APP_SUPPORT_MODE_COOL_DOWN_VAL; - break; case SCREEN_READER: - appModeVal = APP_SUPPORT_MODE_SCREEN_READER_VAL; + requestVal = val; break; default: - ERR("invalid Mode(%d)", val); + ERR("Unknown Mode(%d)", val); return MODES_ERROR_INVALID_PARAMETER; } - pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, app_list_cb, &appList); + pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, appListCB, this); pkgmgrinfo_appinfo_filter_destroy(filter); int nApps = 0; - const char *appIDs[appList.size()]; - for (auto it = appList.begin(); it != appList.end(); it++, nApps++) { + const char *appIDs[inactiveApps.size()]; + for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) { appIDs[nApps] = it->c_str(); - DBG("Deactivate App(%s)", appIDs[nApps]); + INFO("Deactivate App(%s)", appIDs[nApps]); } pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST); int reqId = pkgmgr_client_deactivate_apps(pc, appIDs, nApps, NULL, NULL); + if (reqId < 0) + ERR("pkgmgr_client_deactivate_apps() Fail(%d)", reqId); DBG("Request id[%d] count[%d]", reqId, nApps); pkgmgr_client_free(pc); @@ -101,53 +76,79 @@ int PkgStartSupportMode::set(int val) return MODES_ERROR_NONE; } -int PkgStartSupportMode::get(int *val) -{ - if (val) - *val = appModeVal; - - return MODES_ERROR_NONE; -} - - -void PkgStartSupportMode::undo() +void PkgSupportMode::undo() { //If the appList is empty, it will be ignored at subroutines. - int nApps = 0; - const char *appIDs[appList.size()]; - for (auto it = appList.begin(); it != appList.end(); it++, nApps++) { + const char *appIDs[inactiveApps.size()]; + for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) { appIDs[nApps] = it->c_str(); - DBG("Activate App(%s)", appIDs[nApps]); + INFO("Activate App(%s)", appIDs[nApps]); } pkgmgr_client *pc = pkgmgr_client_new(PC_REQUEST); int reqId = pkgmgr_client_activate_apps(pc, appIDs, nApps, NULL, NULL); - WARN("Request id[%d] count[%d]", reqId, nApps); + if (reqId < 0) + ERR("pkgmgr_client_activate_apps() Fail(%d)", reqId); + 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 cleared by the destructor. + //Therefore, appList will be automatically cleared by the destructor. } -std::string PkgStartSupportMode::serialize() +std::string PkgSupportMode::serialize() { std::ostringstream ostr; - for (auto it = appList.begin(); it != appList.end(); it++) + for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++) ostr << *it << delimiter; return ostr.str(); } -int PkgStartSupportMode::parse(const std::string &data) +int PkgSupportMode::parse(const std::string &data) { size_t pos; size_t start = 0; while ((pos = data.find(delimiter, start)) != std::string::npos) { - appList.push_back(data.substr(start, pos - start)); + inactiveApps.push_back(data.substr(start, pos - start)); start = pos + 1; } return MODES_ERROR_NONE; } + +int PkgSupportMode::setChangedCallback(valueChangedCB callback, void *userData) +{ + ERR("Not Support Changed Callback"); + return MODES_ERROR_NOT_SUPPORTED; +} + +void PkgSupportMode::unSetChangedCallback(valueChangedCB callback, void *userData) +{ + ERR("Not Support Changed Callback"); +} + +int PkgSupportMode::appListCB(const pkgmgrinfo_appinfo_h handle, void *userData) +{ + PkgSupportMode *action = (PkgSupportMode*)userData; + + RETV_IF(nullptr == userData, 0); + + int appSupportMode = 0; + int ret = pkgmgrinfo_appinfo_get_support_mode(handle, &appSupportMode); + if (PMINFO_R_OK != ret) + ERR("pkgmgrinfo_appinfo_get_support_mode() Fail"); + + if (appSupportMode != action->requestVal) { + char *appid; + ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); + if (PMINFO_R_OK != ret) { + ERR("pkgmgrinfo_appinfo_get_appid() Fail"); + return 0; + } + action->inactiveApps.push_back(appid); + } + return 0; +} diff --git a/pkg/PkgEnableSupportMode.h b/pkg/PkgEnableSupportMode.h index a9a075b..c66fb17 100644 --- a/pkg/PkgEnableSupportMode.h +++ b/pkg/PkgEnableSupportMode.h @@ -23,27 +23,29 @@ MODES_NAMESPACE_BEGIN -class PkgStartSupportMode : public PkgAction { +class PkgSupportMode : public PkgAction { public: - static const std::string NAME; - PkgStartSupportMode(); + PkgSupportMode(); int set(int val) override; - int get(int *val) override; void undo() override; std::string serialize() override; int parse(const std::string &data) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback, void *userData) override; + + static const std::string NAME; private: - enum AppSupportMode { - ULTRA_POWER_SAVING = 1, - COOL_DOWN = 2, - SCREEN_READER = 4 + enum SupportModeType { + ULTRA_POWER_SAVING = APP_SUPPORT_MODE_ULTRA_POWER_SAVING_VAL, + COOL_DOWN = APP_SUPPORT_MODE_COOL_DOWN_VAL, + SCREEN_READER = APP_SUPPORT_MODE_SCREEN_READER_VAL }; - const char delimiter = '#'; + static int appListCB(const pkgmgrinfo_appinfo_h handle, void *userData); - static int app_list_cb(const pkgmgrinfo_appinfo_h handle, void *user_data); - static int appModeVal; - std::list appList; + const char delimiter = '#'; + int requestVal; + std::list inactiveApps; }; MODES_NAMESPACE_END diff --git a/pkg/PkgFactory.cpp b/pkg/PkgFactory.cpp index e279d5e..0183e3f 100644 --- a/pkg/PkgFactory.cpp +++ b/pkg/PkgFactory.cpp @@ -21,21 +21,21 @@ MODES_NAMESPACE_USE; PkgFactory::PkgFactory() { - actionMap[PkgStartSupportMode::NAME] = PKG_ACT_STARTSUPPORTMODE; + actionMap[PkgSupportMode::NAME] = PKG_ACT_SUPPORTMODE; } PkgAction* PkgFactory::createAction(const std::string &key) { auto search = actionMap.find(key); - if (search == actionMap.end()) { + if (actionMap.end() == search) { ERR("No PkgAction(%s)", key.c_str()); return nullptr; } PkgAction *action; switch (search->second) { - case PKG_ACT_STARTSUPPORTMODE: - action = new PkgStartSupportMode(); + case PKG_ACT_SUPPORTMODE: + action = new PkgSupportMode(); break; default: action = nullptr; diff --git a/pkg/PkgFactory.h b/pkg/PkgFactory.h index ecbc41d..4503735 100644 --- a/pkg/PkgFactory.h +++ b/pkg/PkgFactory.h @@ -30,7 +30,7 @@ public: void destroyAction(PkgAction *action); private: enum actionKey{ - PKG_ACT_STARTSUPPORTMODE + PKG_ACT_SUPPORTMODE }; std::map actionMap; diff --git a/pkg/PkgPlugin.cpp b/pkg/PkgPlugin.cpp index b833c64..fa80c89 100644 --- a/pkg/PkgPlugin.cpp +++ b/pkg/PkgPlugin.cpp @@ -26,7 +26,7 @@ MODES_NAMESPACE_USE; class PkgPlugin : public Plugin { public: PkgPlugin(); - ~PkgPlugin(); + ~PkgPlugin() = default; int set(const std::string &key, int val, PluginAction **piAction) override; void undo(PluginAction *piAction) override; @@ -50,17 +50,11 @@ PkgPlugin::PkgPlugin() setName("pkg"); } -PkgPlugin::~PkgPlugin() -{ -} - int PkgPlugin::set(const std::string &key, int val, PluginAction **piAction) { PkgAction *action = pkgFactory.createAction(key); RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str()); - DBG("Action(%s) set(%d)", key.c_str(), val); - int ret = action->set(val); if (piAction) *piAction = action; @@ -74,8 +68,6 @@ void PkgPlugin::undo(PluginAction *piAction) PkgAction *action = static_cast(piAction); RET_IF(nullptr == piAction); - DBG("Action(%s) undo", action->getName().c_str()); - action->undo(); pkgFactory.destroyAction(action); } diff --git a/pkg/tizen_pkg_rule.xml b/pkg/tizen_pkg_rule.xml index 58b6055..d4dc50a 100644 --- a/pkg/tizen_pkg_rule.xml +++ b/pkg/tizen_pkg_rule.xml @@ -1,7 +1,7 @@ - + 1 2 4 diff --git a/unittests/mdsp_test_pkg.cpp b/unittests/mdsp_test_pkg.cpp index 57fb3de..f8d441b 100644 --- a/unittests/mdsp_test_pkg.cpp +++ b/unittests/mdsp_test_pkg.cpp @@ -57,7 +57,7 @@ GMainLoop *PkgPluginTest::loop = NULL; TEST_F(PkgPluginTest, setUndoTest) { PluginAction *action; - int ret = plugin->set("startSupportMode", 1, &action); + int ret = plugin->set("supportMode", 1, &action); EXPECT_EQ(MODES_ERROR_NONE, ret); g_idle_add(pkgPluginIdler, plugin); diff --git a/unittests/mode/tizen_Power-Save_mode.xml b/unittests/mode/tizen_Power-Save_mode.xml index a113a2e..e8531ef 100644 --- a/unittests/mode/tizen_Power-Save_mode.xml +++ b/unittests/mode/tizen_Power-Save_mode.xml @@ -1,7 +1,7 @@ - ULTRA_POWER_SAVING + ULTRA_POWER_SAVING off off 30