From: Youngjae Shin Date: Thu, 10 Mar 2022 06:42:08 +0000 (+0900) Subject: add clang format for applying style automatically X-Git-Tag: submit/tizen/20220615.002146~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=553b3cc017d7bb3d5056624d4d2072d56ba6dfa0;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git add clang format for applying style automatically Change-Id: I9bdf23e2c2be26f523426313b1936ba0064378e6 --- diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..90419d3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,167 @@ +--- +Language: Cpp +# BasedOnStyle: Google +AccessModifierOffset: -2 +AlignAfterOpenBracket: DontAlign +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 100 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 6 +ContinuationIndentWidth: 6 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Regroup +IncludeCategories: + - Regex: '^' + Priority: 2 + SortPriority: 0 + - Regex: '^<.*\.h>' + Priority: 1 + SortPriority: 0 + - Regex: '^<.*' + Priority: 2 + SortPriority: 0 + - Regex: '.*' + Priority: 3 + SortPriority: 0 +IncludeIsMainRegex: '([-_](test|unittest))?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentWidth: 4 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Never +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +RawStringFormats: + - Language: Cpp + Delimiters: + - cc + - CC + - cpp + - Cpp + - CPP + - 'c++' + - 'C++' + CanonicalDelimiter: '' + BasedOnStyle: google + - Language: TextProto + Delimiters: + - pb + - PB + - proto + - PROTO + EnclosingFunctions: + - EqualsProto + - EquivToProto + - PARSE_PARTIAL_TEXT_PROTO + - PARSE_TEST_PROTO + - PARSE_TEXT_PROTO + - ParseTextOrDie + - ParseTextProtoOrDie + CanonicalDelimiter: '' + BasedOnStyle: google +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 4 +UseCRLF: false +UseTab: Never +... diff --git a/app/AppActionLaunch.cpp b/app/AppActionLaunch.cpp index fdbb1a2..fff0781 100644 --- a/app/AppActionLaunch.cpp +++ b/app/AppActionLaunch.cpp @@ -15,132 +15,134 @@ */ #include "AppActionLaunch.h" -#include -#include #include #include #include +#include + +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; const std::string AppActionLaunch::NAME = "launch"; -AppActionLaunch::AppActionLaunch() - : PluginAction(NAME), cb(nullptr), cbData(nullptr) +AppActionLaunch::AppActionLaunch() : PluginAction(NAME), cb(nullptr), cbData(nullptr) { - aul_launch_init(NULL, NULL); + aul_launch_init(NULL, NULL); } bool AppActionLaunch::IsCurrentValue(const std::string &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 true; - } - return false; + 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 true; + } + return false; } int AppActionLaunch::set(const std::string &val) { - requestVal = val; - - app_control_h service; - app_control_create(&service); - app_control_set_app_id(service, val.c_str()); - app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT); - app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_SINGLE); - - 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; - } - app_control_destroy(service); - - return MODES_ERROR_NONE; + requestVal = val; + + app_control_h service; + app_control_create(&service); + app_control_set_app_id(service, val.c_str()); + app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT); + app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_SINGLE); + + 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; + } + app_control_destroy(service); + + return MODES_ERROR_NONE; } void AppActionLaunch::undo() { - bool running; - app_context_h runAppContext; - - int ret = app_manager_is_running(requestVal.c_str(), &running); - if (APP_MANAGER_ERROR_NONE != ret) { - ERR("app_manager_is_running(%s) Fail(%d)", requestVal.c_str(), ret); - } else if (false == running) { - WARN("It's NOT running"); - return; - } - - ret = app_manager_get_app_context(requestVal.c_str(), &runAppContext); - if (APP_MANAGER_ERROR_NONE != ret) { - ERR("app_manager_get_app_context(%s) Fail(%s)", requestVal.c_str(), get_error_message(ret)); - return; - } - ret = app_manager_terminate_app(runAppContext); - if (APP_MANAGER_ERROR_NONE != ret) - ERR("app_manager_terminate_app() Fail(%s)", get_error_message(ret)); + bool running; + app_context_h runAppContext; + + int ret = app_manager_is_running(requestVal.c_str(), &running); + if (APP_MANAGER_ERROR_NONE != ret) { + ERR("app_manager_is_running(%s) Fail(%d)", requestVal.c_str(), ret); + } else if (false == running) { + WARN("It's NOT running"); + return; + } + + ret = app_manager_get_app_context(requestVal.c_str(), &runAppContext); + if (APP_MANAGER_ERROR_NONE != ret) { + ERR("app_manager_get_app_context(%s) Fail(%s)", requestVal.c_str(), get_error_message(ret)); + return; + } + ret = app_manager_terminate_app(runAppContext); + if (APP_MANAGER_ERROR_NONE != ret) + ERR("app_manager_terminate_app() Fail(%s)", get_error_message(ret)); } std::string AppActionLaunch::getUndoInfo() { - return requestVal; + return requestVal; } int AppActionLaunch::setUndoInfo(const std::string &info) { - requestVal = info; - return MODES_ERROR_NONE; + requestVal = info; + return MODES_ERROR_NONE; } int AppActionLaunch::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - int err = app_manager_set_app_context_status_cb(appContextStatusCB, requestVal.c_str(), this); - if (APP_MANAGER_ERROR_NONE != err) { - ERR("app_manager_set_app_context_status_cb() Fail(%s)", get_error_message(err)); - return MODES_ERROR_SYSTEM; - } + int err = app_manager_set_app_context_status_cb(appContextStatusCB, requestVal.c_str(), this); + if (APP_MANAGER_ERROR_NONE != err) { + ERR("app_manager_set_app_context_status_cb() Fail(%s)", get_error_message(err)); + return MODES_ERROR_SYSTEM; + } - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void AppActionLaunch::unSetChangedCallback(valueChangedCB callback) { - int ret = app_manager_unset_app_context_status_cb(appContextStatusCB, requestVal.c_str()); - if (APP_MANAGER_ERROR_NONE != ret) - ERR("app_manager_unset_app_context_status_cb() Fail(%s)", get_error_message(ret)); + int ret = app_manager_unset_app_context_status_cb(appContextStatusCB, requestVal.c_str()); + if (APP_MANAGER_ERROR_NONE != ret) + ERR("app_manager_unset_app_context_status_cb() Fail(%s)", get_error_message(ret)); - cb = nullptr; - cbData = nullptr; + cb = nullptr; + cbData = nullptr; } -void AppActionLaunch::appContextStatusCB(app_context_h app_context, app_context_status_e status, void *userData) +void AppActionLaunch::appContextStatusCB(app_context_h app_context, app_context_status_e status, + void *userData) { - AppActionLaunch *action = (AppActionLaunch*)userData; + AppActionLaunch *action = (AppActionLaunch *)userData; - RET_IF(nullptr == userData); - RET_IF(APP_CONTEXT_STATUS_TERMINATED != status); + RET_IF(nullptr == userData); + RET_IF(APP_CONTEXT_STATUS_TERMINATED != status); - char *appid = nullptr; - int ret = app_context_get_app_id(app_context, &appid); - if (APP_MANAGER_ERROR_NONE != ret) { - ERR("app_context_get_app_id() Fail(%d)", ret); - return; - } + char *appid = nullptr; + int ret = app_context_get_app_id(app_context, &appid); + if (APP_MANAGER_ERROR_NONE != ret) { + ERR("app_context_get_app_id() Fail(%d)", ret); + return; + } - if (action->cb && appid == action->requestVal) - action->cb(action->cbData); + if (action->cb && appid == action->requestVal) + action->cb(action->cbData); - free(appid); + free(appid); } diff --git a/app/AppActionLaunch.h b/app/AppActionLaunch.h index ca36240..5c89246 100644 --- a/app/AppActionLaunch.h +++ b/app/AppActionLaunch.h @@ -15,31 +15,35 @@ */ #pragma once -#include +#include #include #include -#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN 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 getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; -private: - static void appContextStatusCB(app_context_h app_context, app_context_status_e status, void *user_data); - std::string requestVal; - valueChangedCB cb; - void *cbData; + 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 getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + private: + static void appContextStatusCB(app_context_h app_context, app_context_status_e status, + void *user_data); + std::string requestVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/app/AppFactory.cpp b/app/AppFactory.cpp index 31ad3b4..091b8ee 100644 --- a/app/AppFactory.cpp +++ b/app/AppFactory.cpp @@ -14,35 +14,36 @@ * limitations under the License. */ #include "AppFactory.h" -#include "plugin-log.h" + #include "AppActionLaunch.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; AppFactory::AppFactory() { - actionMap[AppActionLaunch::NAME] = APP_ACT_LAUNCH; + actionMap[AppActionLaunch::NAME] = APP_ACT_LAUNCH; } -PluginAction* AppFactory::createAction(const std::string &key) +PluginAction *AppFactory::createAction(const std::string &key) { - auto search = actionMap.find(key); - if (actionMap.end() == search) { - ERR("No App PluginAction(%s)", key.c_str()); - return nullptr; - } + auto search = actionMap.find(key); + if (actionMap.end() == search) { + ERR("No App PluginAction(%s)", key.c_str()); + return nullptr; + } - switch (search->second) { - case APP_ACT_LAUNCH: - AppActionLaunch *appActionLaunch = new AppActionLaunch(); - return appActionLaunch; - break; - } + switch (search->second) { + case APP_ACT_LAUNCH: + AppActionLaunch *appActionLaunch = new AppActionLaunch(); + return appActionLaunch; + break; + } - return nullptr; + return nullptr; } void AppFactory::destroyAction(PluginAction *action) { - delete action; + delete action; } diff --git a/app/AppFactory.h b/app/AppFactory.h index 8c314d3..904a4d5 100644 --- a/app/AppFactory.h +++ b/app/AppFactory.h @@ -15,26 +15,27 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class AppFactory { -public: - AppFactory(); - ~AppFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey{ - APP_ACT_LAUNCH - }; - - std::map actionMap; + public: + AppFactory(); + ~AppFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { APP_ACT_LAUNCH }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/app/AppPlugin.cpp b/app/AppPlugin.cpp index 9164798..d1dec9d 100644 --- a/app/AppPlugin.cpp +++ b/app/AppPlugin.cpp @@ -13,45 +13,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include "plugin-log.h" + +#include + #include "AppFactory.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class AppPlugin : public Plugin { -public: - AppPlugin(); - ~AppPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - AppFactory appFactory; + public: + AppPlugin(); + ~AppPlugin() override = default; + + 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) { - delete plugin; + delete plugin; } AppPlugin::AppPlugin() { - setName("app"); + setName("app"); } -PluginAction* AppPlugin::newAction(const std::string &key) +PluginAction *AppPlugin::newAction(const std::string &key) { - return appFactory.createAction(key); + return appFactory.createAction(key); } void AppPlugin::deleteAction(PluginAction *piAction) { - appFactory.destroyAction(piAction); + appFactory.destroyAction(piAction); } diff --git a/bluetooth/BtAction.cpp b/bluetooth/BtAction.cpp index 1d938a8..e7aeec8 100644 --- a/bluetooth/BtAction.cpp +++ b/bluetooth/BtAction.cpp @@ -19,29 +19,28 @@ MODES_NAMESPACE_USE; -BtAction::BtAction(const std::string &name) - : PluginAction(name) +BtAction::BtAction(const std::string &name) : PluginAction(name) { - int btRet = bt_initialize(); - if (BT_ERROR_NONE != btRet) - ERR("bt_initialize() Fail(%d)", btRet); + int btRet = bt_initialize(); + if (BT_ERROR_NONE != btRet) + ERR("bt_initialize() Fail(%d)", btRet); } BtAction::~BtAction() { - bt_deinitialize(); + bt_deinitialize(); } bool BtAction::getAdapterStatus() { - bt_adapter_state_e state; - int btRet = bt_adapter_get_state(&state); - if (BT_ERROR_NONE != btRet) { - ERR("bt_adapter_get_state() Fail(%d)", btRet); - } + bt_adapter_state_e state; + int btRet = bt_adapter_get_state(&state); + if (BT_ERROR_NONE != btRet) { + ERR("bt_adapter_get_state() Fail(%d)", btRet); + } - if (state != BT_ADAPTER_ENABLED) - return false; - else - return true; + if (state != BT_ADAPTER_ENABLED) + return false; + else + return true; } diff --git a/bluetooth/BtAction.h b/bluetooth/BtAction.h index 94e6d4d..7bcd725 100644 --- a/bluetooth/BtAction.h +++ b/bluetooth/BtAction.h @@ -15,20 +15,22 @@ */ #pragma once -#include #include -#include "plugin-log.h" + +#include + #include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_BEGIN class BtAction : public PluginAction { -public: - BtAction(const std::string &name); - ~BtAction() override; -protected: - bool getAdapterStatus(); + public: + BtAction(const std::string &name); + ~BtAction() override; + + protected: + bool getAdapterStatus(); }; MODES_NAMESPACE_END - diff --git a/bluetooth/BtActionAudioConnect.cpp b/bluetooth/BtActionAudioConnect.cpp index d5b87cc..9588948 100644 --- a/bluetooth/BtActionAudioConnect.cpp +++ b/bluetooth/BtActionAudioConnect.cpp @@ -21,178 +21,177 @@ MODES_NAMESPACE_USE; const std::string BtActionAudioConnect::NAME = "audioConnect"; -BtActionAudioConnect::BtActionAudioConnect() - : BtAction(NAME), cb(nullptr), cbData(nullptr) +BtActionAudioConnect::BtActionAudioConnect() : BtAction(NAME), cb(nullptr), cbData(nullptr) { - bt_audio_initialize(); + bt_audio_initialize(); } BtActionAudioConnect::~BtActionAudioConnect() { - bt_audio_deinitialize(); + bt_audio_deinitialize(); } bool BtActionAudioConnect::IsCurrentValue(const std::string &val) { - return false; + return false; } int BtActionAudioConnect::set(const std::string &val) { - if (!getAdapterStatus()) { - ERR("BT is disabled"); - return MODES_ERROR_SYSTEM; - } - - requestVal = val; - - bt_device_info_s *devInfo; - int ret = bt_adapter_get_bonded_device_info(val.c_str(), &devInfo); - if (BT_ERROR_NONE == ret) { - printBtDeviceInfo(devInfo); - bt_major_device_class_e devClass = devInfo->bt_class.major_device_class; - bt_adapter_free_device_info(devInfo); - - return connectAudio(devClass, val.c_str()); - } else if (BT_ERROR_REMOTE_DEVICE_NOT_BONDED == ret) { - DBG("BT device(%s) is not bonded", val.c_str()); - } else { - ERR("bt_adapter_get_bonded_device_info() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - ret = bt_device_set_bond_created_cb(bondCreatedCB, this); - if (ret != BT_ERROR_NONE) { - ERR("bt_device_set_bond_created_cb(%s) Fail(%s)", val.c_str(), get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - ret = bt_device_create_bond(val.c_str()); - if (ret != BT_ERROR_NONE) { - ERR("bt_device_create_bond(%s) Fail(%s)", val.c_str(), get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - return MODES_ERROR_NONE; + if (!getAdapterStatus()) { + ERR("BT is disabled"); + return MODES_ERROR_SYSTEM; + } + + requestVal = val; + + bt_device_info_s *devInfo; + int ret = bt_adapter_get_bonded_device_info(val.c_str(), &devInfo); + if (BT_ERROR_NONE == ret) { + printBtDeviceInfo(devInfo); + bt_major_device_class_e devClass = devInfo->bt_class.major_device_class; + bt_adapter_free_device_info(devInfo); + + return connectAudio(devClass, val.c_str()); + } else if (BT_ERROR_REMOTE_DEVICE_NOT_BONDED == ret) { + DBG("BT device(%s) is not bonded", val.c_str()); + } else { + ERR("bt_adapter_get_bonded_device_info() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + ret = bt_device_set_bond_created_cb(bondCreatedCB, this); + if (ret != BT_ERROR_NONE) { + ERR("bt_device_set_bond_created_cb(%s) Fail(%s)", val.c_str(), get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + ret = bt_device_create_bond(val.c_str()); + if (ret != BT_ERROR_NONE) { + ERR("bt_device_create_bond(%s) Fail(%s)", val.c_str(), get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + return MODES_ERROR_NONE; } void BtActionAudioConnect::undo() { - int ret = bt_audio_disconnect(requestVal.c_str(), BT_AUDIO_PROFILE_TYPE_ALL); - if (BT_ERROR_NONE != ret) - ERR("bt_audio_disconnect(%s) Fail(%s)", requestVal.c_str(), get_error_message(ret)); + int ret = bt_audio_disconnect(requestVal.c_str(), BT_AUDIO_PROFILE_TYPE_ALL); + if (BT_ERROR_NONE != ret) + ERR("bt_audio_disconnect(%s) Fail(%s)", requestVal.c_str(), get_error_message(ret)); } std::string BtActionAudioConnect::getUndoInfo() { - return requestVal; + return requestVal; } int BtActionAudioConnect::setUndoInfo(const std::string &info) { - requestVal = info; - return MODES_ERROR_NONE; + requestVal = info; + return MODES_ERROR_NONE; } int BtActionAudioConnect::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - int ret = bt_audio_set_connection_state_changed_cb(connStateChangedCb, this); - if (BT_ERROR_NONE != ret) { - ERR("bt_audio_set_connection_state_changed_cb() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } + int ret = bt_audio_set_connection_state_changed_cb(connStateChangedCb, this); + if (BT_ERROR_NONE != ret) { + ERR("bt_audio_set_connection_state_changed_cb() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void BtActionAudioConnect::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - int ret = bt_audio_unset_connection_state_changed_cb(); - if (BT_ERROR_NONE != ret) - ERR("bt_audio_unset_connection_state_changed_cb() Fail(%s)", get_error_message(ret)); + int ret = bt_audio_unset_connection_state_changed_cb(); + if (BT_ERROR_NONE != ret) + ERR("bt_audio_unset_connection_state_changed_cb() Fail(%s)", get_error_message(ret)); - cb = nullptr; - cbData = nullptr; + cb = nullptr; + cbData = nullptr; } void BtActionAudioConnect::connStateChangedCb(int result, bool connected, const char *address, - bt_audio_profile_type_e type, void *userData) + bt_audio_profile_type_e type, void *userData) { - BtActionAudioConnect *action = (BtActionAudioConnect*)userData; + BtActionAudioConnect *action = (BtActionAudioConnect *)userData; - RET_IF(nullptr == userData); - RETM_IF(true == connected, "BT Device(%s) is Connected", address); + RET_IF(nullptr == userData); + RETM_IF(true == connected, "BT Device(%s) is Connected", address); - INFO("BT device(%s) connection(%d)", address, connected); - if (BT_ERROR_NONE != result) { - ERR("connectionStateChangedCb() Fail(%d)", result); - return; - } + INFO("BT device(%s) connection(%d)", address, connected); + if (BT_ERROR_NONE != result) { + ERR("connectionStateChangedCb() Fail(%d)", result); + return; + } - if (action->cb && address == action->requestVal) - action->cb(action->cbData); + if (action->cb && address == action->requestVal) + action->cb(action->cbData); } void BtActionAudioConnect::bondCreatedCB(int result, bt_device_info_s *devInfo, void *userData) { - if (BT_ERROR_NONE != result) { - ERR("btDeviceBondCreatedCb Fail(%s)", get_error_message(result)); - return; - } - - BtActionAudioConnect *action = (BtActionAudioConnect*)userData; - if (action->requestVal != devInfo->remote_address) { - ERR("Unknown BT device(%s)", devInfo->remote_address); - return; - } else { - bt_device_unset_bond_created_cb(); - } - action->printBtDeviceInfo(devInfo); - - int ret = action->connectAudio(devInfo->bt_class.major_device_class, devInfo->remote_address); - if (MODES_ERROR_NONE != ret) { - ERR("connectAudio(%s) Fail(%d)", devInfo->remote_address, ret); - return; - } + if (BT_ERROR_NONE != result) { + ERR("btDeviceBondCreatedCb Fail(%s)", get_error_message(result)); + return; + } + + BtActionAudioConnect *action = (BtActionAudioConnect *)userData; + if (action->requestVal != devInfo->remote_address) { + ERR("Unknown BT device(%s)", devInfo->remote_address); + return; + } else { + bt_device_unset_bond_created_cb(); + } + action->printBtDeviceInfo(devInfo); + + int ret = action->connectAudio(devInfo->bt_class.major_device_class, devInfo->remote_address); + if (MODES_ERROR_NONE != ret) { + ERR("connectAudio(%s) Fail(%d)", devInfo->remote_address, ret); + return; + } } int BtActionAudioConnect::connectAudio(bt_major_device_class_e devClass, const char *address) { - if (BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO != devClass) { - ERR("BT device(%s) is not AUDIO MAJOR Class", address); - return MODES_ERROR_SYSTEM; - } - - int ret = bt_audio_connect(address, BT_AUDIO_PROFILE_TYPE_ALL); - if (BT_ERROR_NONE != ret) { - ERR("bt_audio_connect(%s) Fail(%s)", address, get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - return MODES_ERROR_NONE; + if (BT_MAJOR_DEVICE_CLASS_AUDIO_VIDEO != devClass) { + ERR("BT device(%s) is not AUDIO MAJOR Class", address); + return MODES_ERROR_SYSTEM; + } + + int ret = bt_audio_connect(address, BT_AUDIO_PROFILE_TYPE_ALL); + if (BT_ERROR_NONE != ret) { + ERR("bt_audio_connect(%s) Fail(%s)", address, get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + return MODES_ERROR_NONE; } void BtActionAudioConnect::printBtDeviceInfo(bt_device_info_s *devInfo) { - RET_IF(nullptr == devInfo); - - DBG("BT Bonded Device Info ========================================"); - DBG("remote_address : [%s]", devInfo->remote_address); - DBG("remote_name : [%s]", devInfo->remote_name); - DBG("major_class : [%x]", devInfo->bt_class.major_device_class); - DBG("major_class : [%x]", devInfo->bt_class.minor_device_class); - DBG("service_uuid : [%s]", *(devInfo->service_uuid)); - DBG("service_count : [%d]", devInfo->service_count); - DBG("is_bonded : [%d]", devInfo->is_bonded); - DBG("is_connected : [%d]", devInfo->is_connected); - DBG("is_authorized : [%d]", devInfo->is_authorized); - DBG("manufacturer_data : [%s]", devInfo->manufacturer_data); - DBG("=============================================================="); + RET_IF(nullptr == devInfo); + + DBG("BT Bonded Device Info ========================================"); + DBG("remote_address : [%s]", devInfo->remote_address); + DBG("remote_name : [%s]", devInfo->remote_name); + DBG("major_class : [%x]", devInfo->bt_class.major_device_class); + DBG("major_class : [%x]", devInfo->bt_class.minor_device_class); + DBG("service_uuid : [%s]", *(devInfo->service_uuid)); + DBG("service_count : [%d]", devInfo->service_count); + DBG("is_bonded : [%d]", devInfo->is_bonded); + DBG("is_connected : [%d]", devInfo->is_connected); + DBG("is_authorized : [%d]", devInfo->is_authorized); + DBG("manufacturer_data : [%s]", devInfo->manufacturer_data); + DBG("=============================================================="); } diff --git a/bluetooth/BtActionAudioConnect.h b/bluetooth/BtActionAudioConnect.h index 0989b94..b364354 100644 --- a/bluetooth/BtActionAudioConnect.h +++ b/bluetooth/BtActionAudioConnect.h @@ -15,34 +15,38 @@ */ #pragma once -#include #include + +#include + #include "BtAction.h" MODES_NAMESPACE_BEGIN class BtActionAudioConnect : public BtAction { -public: - static const std::string NAME; - BtActionAudioConnect(); - ~BtActionAudioConnect(); - - bool IsCurrentValue(const std::string &val); - - int set(const std::string &val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData); - void unSetChangedCallback(valueChangedCB callback); -private: - static void connStateChangedCb(int result, bool connected, const char *address, bt_audio_profile_type_e type, void *userData); - static void bondCreatedCB(int result, bt_device_info_s *devInfo, void *userData); - int connectAudio(bt_major_device_class_e devClass, const char *address); - void printBtDeviceInfo(bt_device_info_s *devInfo); - valueChangedCB cb; - void *cbData; - std::string requestVal; + public: + static const std::string NAME; + BtActionAudioConnect(); + ~BtActionAudioConnect(); + + bool IsCurrentValue(const std::string &val); + + int set(const std::string &val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData); + void unSetChangedCallback(valueChangedCB callback); + + private: + static void connStateChangedCb(int result, bool connected, const char *address, + bt_audio_profile_type_e type, void *userData); + static void bondCreatedCB(int result, bt_device_info_s *devInfo, void *userData); + int connectAudio(bt_major_device_class_e devClass, const char *address); + void printBtDeviceInfo(bt_device_info_s *devInfo); + valueChangedCB cb; + void *cbData; + std::string requestVal; }; MODES_NAMESPACE_END diff --git a/bluetooth/BtActionPower.cpp b/bluetooth/BtActionPower.cpp index 232ce6e..cfcee0c 100644 --- a/bluetooth/BtActionPower.cpp +++ b/bluetooth/BtActionPower.cpp @@ -15,9 +15,11 @@ */ #include "BtActionPower.h" -#include #include #include + +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; @@ -25,111 +27,111 @@ MODES_NAMESPACE_USE; const std::string BtActionPower::NAME = "power"; BtActionPower::BtActionPower() - : BtAction(NAME), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr) + : BtAction(NAME), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr) { } bool BtActionPower::IsCurrentValue(bool val) { - return true; + return true; } int BtActionPower::set(bool val) { - requestVal = val; - if (val) { - oldVal = false; - int ret = bt_adapter_enable(); - if (BT_ERROR_NONE != ret) { - if (BT_ERROR_ALREADY_DONE == ret) { - oldVal = true; - } else { - ERR("bt_adapter_enable() Fail(%d)", ret); - return MODES_ERROR_SYSTEM; - } - } - } else { - oldVal = true; - int ret = bt_adapter_disable(); - if (BT_ERROR_NONE != ret) { - if (BT_ERROR_NOT_ENABLED == ret) { - oldVal = false; - } else { - ERR("bt_adapter_disable() Fail(%d)", ret); - return MODES_ERROR_SYSTEM; - } - } - } - - INFO("BT power (%s -> %s)", val ? "On" : "Off", oldVal ? "On" : "Off"); - return MODES_ERROR_NONE; + requestVal = val; + if (val) { + oldVal = false; + int ret = bt_adapter_enable(); + if (BT_ERROR_NONE != ret) { + if (BT_ERROR_ALREADY_DONE == ret) { + oldVal = true; + } else { + ERR("bt_adapter_enable() Fail(%d)", ret); + return MODES_ERROR_SYSTEM; + } + } + } else { + oldVal = true; + int ret = bt_adapter_disable(); + if (BT_ERROR_NONE != ret) { + if (BT_ERROR_NOT_ENABLED == ret) { + oldVal = false; + } else { + ERR("bt_adapter_disable() Fail(%d)", ret); + return MODES_ERROR_SYSTEM; + } + } + } + + INFO("BT power (%s -> %s)", val ? "On" : "Off", oldVal ? "On" : "Off"); + return MODES_ERROR_NONE; } void BtActionPower::undo() { - set(oldVal); + set(oldVal); } std::string BtActionPower::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int BtActionPower::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int BtActionPower::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - int ret = bt_adapter_set_state_changed_cb(stateChangedCB, this); - if (BT_ERROR_NONE != ret) { - ERR("bt_adapter_set_state_changed_cb() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } + int ret = bt_adapter_set_state_changed_cb(stateChangedCB, this); + if (BT_ERROR_NONE != ret) { + ERR("bt_adapter_set_state_changed_cb() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void BtActionPower::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - int ret = bt_adapter_unset_state_changed_cb(); - if (BT_ERROR_NONE != ret) - ERR("bt_adapter_unset_state_changed_cb() Fail(%s)", get_error_message(ret)); + int ret = bt_adapter_unset_state_changed_cb(); + if (BT_ERROR_NONE != ret) + ERR("bt_adapter_unset_state_changed_cb() Fail(%s)", get_error_message(ret)); - cb = nullptr; - cbData = nullptr; + cb = nullptr; + cbData = nullptr; } void BtActionPower::stateChangedCB(int result, bt_adapter_state_e state, void *userData) { - BtActionPower *action = (BtActionPower*)userData; + BtActionPower *action = (BtActionPower *)userData; - RET_IF(nullptr == userData); + RET_IF(nullptr == userData); - bool changedVal = action->requestVal; - if (state == BT_ADAPTER_ENABLED) - changedVal = true; - else if (state == BT_ADAPTER_DISABLED) - changedVal = false; - else - ERR("Unknown state(%d)", state); + bool changedVal = action->requestVal; + if (state == BT_ADAPTER_ENABLED) + changedVal = true; + else if (state == BT_ADAPTER_DISABLED) + changedVal = false; + else + ERR("Unknown state(%d)", state); - INFO("state:%d", state); + INFO("state:%d", state); - if (action->cb && changedVal != action->requestVal) - action->cb(action->cbData); + if (action->cb && changedVal != action->requestVal) + action->cb(action->cbData); } diff --git a/bluetooth/BtActionPower.h b/bluetooth/BtActionPower.h index 22022b8..c759759 100644 --- a/bluetooth/BtActionPower.h +++ b/bluetooth/BtActionPower.h @@ -15,30 +15,33 @@ */ #pragma once -#include #include + +#include + #include "BtAction.h" MODES_NAMESPACE_BEGIN class BtActionPower : public BtAction { -public: - static const std::string NAME; - BtActionPower(); - - bool IsCurrentValue(bool val) override; - int set(bool val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData); - void unSetChangedCallback(valueChangedCB callback); -private: - static void stateChangedCB(int result, bt_adapter_state_e state, void *user_data); - bool requestVal; - bool oldVal; - valueChangedCB cb; - void *cbData; + public: + static const std::string NAME; + BtActionPower(); + + bool IsCurrentValue(bool val) override; + int set(bool val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData); + void unSetChangedCallback(valueChangedCB callback); + + private: + static void stateChangedCB(int result, bt_adapter_state_e state, void *user_data); + bool requestVal; + bool oldVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/bluetooth/BtFactory.cpp b/bluetooth/BtFactory.cpp index a0f6a0d..f5895b2 100644 --- a/bluetooth/BtFactory.cpp +++ b/bluetooth/BtFactory.cpp @@ -15,40 +15,39 @@ */ #include "BtFactory.h" +#include "BtActionAudioConnect.h" +#include "BtActionPower.h" #include "modes_errors.h" #include "plugin-log.h" -#include "BtActionPower.h" -#include "BtActionAudioConnect.h" - MODES_NAMESPACE_USE; BtFactory::BtFactory() { - actionMap[BtActionPower::NAME] = POWER; - actionMap[BtActionAudioConnect::NAME] = AUDIO_CONNECT; + actionMap[BtActionPower::NAME] = POWER; + actionMap[BtActionAudioConnect::NAME] = AUDIO_CONNECT; } -PluginAction* BtFactory::createAction(const std::string &key) +PluginAction *BtFactory::createAction(const std::string &key) { - auto search = actionMap.find(key); - if (actionMap.end() == search) { - ERR("No BtAction(%s)", key.c_str()); - return nullptr; - } + auto search = actionMap.find(key); + if (actionMap.end() == search) { + ERR("No BtAction(%s)", key.c_str()); + return nullptr; + } - switch (search->second) { - case POWER: - return (new BtActionPower()); + switch (search->second) { + case POWER: + return (new BtActionPower()); - case AUDIO_CONNECT: - return (new BtActionAudioConnect()); - } + case AUDIO_CONNECT: + return (new BtActionAudioConnect()); + } - return nullptr; + return nullptr; } void BtFactory::destroyAction(PluginAction *action) { - delete action; + delete action; } diff --git a/bluetooth/BtFactory.h b/bluetooth/BtFactory.h index 6414e1e..a779584 100644 --- a/bluetooth/BtFactory.h +++ b/bluetooth/BtFactory.h @@ -15,27 +15,27 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class BtFactory { -public: - BtFactory(); - ~BtFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey { - POWER, - AUDIO_CONNECT - }; - - std::map actionMap; + public: + BtFactory(); + ~BtFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { POWER, AUDIO_CONNECT }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/bluetooth/BtPlugin.cpp b/bluetooth/BtPlugin.cpp index 0b79c31..8003c25 100644 --- a/bluetooth/BtPlugin.cpp +++ b/bluetooth/BtPlugin.cpp @@ -13,46 +13,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include #include -#include "plugin-log.h" +#include + +#include + #include "BtFactory.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class BtPlugin : public Plugin { -public: - BtPlugin(); - ~BtPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - BtFactory btFactory; + public: + BtPlugin(); + ~BtPlugin() override = default; + + 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) { - delete plugin; + delete plugin; } BtPlugin::BtPlugin() { - setName("bluetooth"); + setName("bluetooth"); } -PluginAction* BtPlugin::newAction(const std::string &key) +PluginAction *BtPlugin::newAction(const std::string &key) { - return btFactory.createAction(key); + return btFactory.createAction(key); } void BtPlugin::deleteAction(PluginAction *piAction) { - btFactory.destroyAction(piAction); + btFactory.destroyAction(piAction); } diff --git a/display/DisplayActVconf.cpp b/display/DisplayActVconf.cpp index 11f25e0..ac15256 100644 --- a/display/DisplayActVconf.cpp +++ b/display/DisplayActVconf.cpp @@ -15,128 +15,134 @@ */ #include "DisplayActVconf.h" +#include + #include #include -#include + #include "plugin-log.h" MODES_NAMESPACE_USE; // It should align with actionKey in DisplayFactory const std::string DisplayActVconf::NAME[2] = { - "autoBrightness", - "timeout", + "autoBrightness", + "timeout", }; -const char* const DisplayActVconf::KEY[2] = { - VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, - VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, +const char *const DisplayActVconf::KEY[2] = { + VCONFKEY_SETAPPL_BRIGHTNESS_AUTOMATIC_INT, + VCONFKEY_SETAPPL_LCD_TIMEOUT_NORMAL, }; DisplayActVconf::DisplayActVconf(int type) - : PluginAction(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) { } bool DisplayActVconf::IsCurrentValue(int val) { - int ret = vconf_get_int(KEY[keyType], &oldVal); - if (0 != ret) { - ERR("vconf_get_int(%s) Fail(%d)", KEY[keyType], ret); - return false; - } - - if (oldVal == val) { - INFO("%s already set(%d)", NAME[keyType].c_str(), val); - return true; - } - - return false; + int ret = vconf_get_int(KEY[keyType], &oldVal); + if (0 != ret) { + ERR("vconf_get_int(%s) Fail(%d)", KEY[keyType], ret); + return false; + } + + if (oldVal == val) { + INFO("%s already set(%d)", NAME[keyType].c_str(), val); + return true; + } + + return false; } int DisplayActVconf::set(int val) { - requestVal = 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; - } + 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; + return MODES_ERROR_NONE; } void DisplayActVconf::undo() { - int ret = vconf_set_int(KEY[keyType], oldVal); - if (0 != ret) - ERR("vconf_set_int(%s, %d) Fail(%d)", KEY[keyType], oldVal, ret); + 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::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int DisplayActVconf::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int DisplayActVconf::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - 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; - } + 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; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void DisplayActVconf::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - 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; - } + 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; + cbData = nullptr; + cb = nullptr; } void DisplayActVconf::changedCB(keynode_t *node) { - const char *vconfKey = vconf_keynode_get_name(node); - 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); + const char *vconfKey = vconf_keynode_get_name(node); + 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); + RET_IF(nullptr == userData); - DisplayActVconf *action = (DisplayActVconf*)userData; - action->changedCB(node); + DisplayActVconf *action = (DisplayActVconf *)userData; + action->changedCB(node); } diff --git a/display/DisplayActVconf.h b/display/DisplayActVconf.h index 554cc59..86ea78b 100644 --- a/display/DisplayActVconf.h +++ b/display/DisplayActVconf.h @@ -15,37 +15,40 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN 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 getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) 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; - valueChangedCB cb; - void *cbData; + public: + DisplayActVconf(int type); + ~DisplayActVconf() override = default; + + bool IsCurrentValue(int val) override; + int set(int val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) 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; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/display/DisplayBrightness.cpp b/display/DisplayBrightness.cpp index cb028b8..fe07ae1 100644 --- a/display/DisplayBrightness.cpp +++ b/display/DisplayBrightness.cpp @@ -14,166 +14,170 @@ * limitations under the License. */ #include "DisplayBrightness.h" + +#include +#include +#include + #include #include #include -#include -#include -#include + #include "plugin-log.h" MODES_NAMESPACE_USE; const std::string DisplayBrightness::NAME = "brightness"; -const char* const DisplayBrightness::KEY = VCONFKEY_SETAPPL_LCD_BRIGHTNESS; +const char *const DisplayBrightness::KEY = VCONFKEY_SETAPPL_LCD_BRIGHTNESS; DisplayBrightness::DisplayBrightness() - :PluginAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr) + : PluginAction(NAME), requestVal(0), cb(nullptr), cbData(nullptr) { - device_display_get_numbers(&numDisplay); + device_display_get_numbers(&numDisplay); } bool DisplayBrightness::IsCurrentValue(int val) { - int old; - int ret = vconf_get_int(KEY, &old); - if (0 != ret) { - ERR("vconf_get_int(%s) Fail(%d)", KEY, ret); - return false; - } - - if (old == val) { - INFO("%s already set(%d)", NAME.c_str(), val); - return true; - } - - return false; + int old; + int ret = vconf_get_int(KEY, &old); + if (0 != ret) { + ERR("vconf_get_int(%s) Fail(%d)", KEY, ret); + return false; + } + + 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); - if (DEVICE_ERROR_NONE != ret) { - ERR("device_display_get_brightness(%d) Fail(%s)", i, get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - oldValList.push_back(oldVal); - } - - for (int i = 0; i < numDisplay ; i++) { - int realVal = val; - if (realVal < 0) { - int realVal = 100; - ret = device_display_get_max_brightness(i, &realVal); - if (DEVICE_ERROR_NONE != ret) - ERR("device_display_get_max_brightness() Fail(%d)", ret); - } - - ret = device_display_set_brightness(i, realVal); - if (DEVICE_ERROR_NONE != ret) { - ERR("device_display_set_brightness(%d, %d) Fail(%s)", i, realVal, get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - } - - return MODES_ERROR_NONE; + int ret; + requestVal = val; + + for (int i = 0; i < numDisplay; i++) { + int oldVal = 0; + ret = device_display_get_brightness(i, &oldVal); + if (DEVICE_ERROR_NONE != ret) { + ERR("device_display_get_brightness(%d) Fail(%s)", i, get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + oldValList.push_back(oldVal); + } + + for (int i = 0; i < numDisplay; i++) { + int realVal = val; + if (realVal < 0) { + int realVal = 100; + ret = device_display_get_max_brightness(i, &realVal); + if (DEVICE_ERROR_NONE != ret) + ERR("device_display_get_max_brightness() Fail(%d)", ret); + } + + ret = device_display_set_brightness(i, realVal); + if (DEVICE_ERROR_NONE != ret) { + ERR("device_display_set_brightness(%d, %d) Fail(%s)", i, realVal, + get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + } + + return MODES_ERROR_NONE; } void DisplayBrightness::undo() { - int i = 0; - for (auto it = oldValList.begin(); it != oldValList.end(); ++it, ++i) { - int ret = device_display_set_brightness(i, *it); - if (DEVICE_ERROR_NONE != ret) - ERR("device_display_set_brightness(%d, %d) Fail(%s)", i, *it, get_error_message(ret)); - } + int i = 0; + for (auto it = oldValList.begin(); it != oldValList.end(); ++it, ++i) { + int ret = device_display_set_brightness(i, *it); + if (DEVICE_ERROR_NONE != ret) + ERR("device_display_set_brightness(%d, %d) Fail(%s)", i, *it, get_error_message(ret)); + } } std::string DisplayBrightness::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - for (auto it = oldValList.begin(); it != oldValList.end(); ++it) { - ostr << *it << delimiter; - } - return ostr.str(); + for (auto it = oldValList.begin(); it != oldValList.end(); ++it) { + ostr << *it << delimiter; + } + return ostr.str(); } int DisplayBrightness::setUndoInfo(const std::string &data) { - size_t pos; - size_t start = 0; - oldValList.clear(); - while ((pos = data.find(delimiter, start)) != std::string::npos) { - int oldVal = 0; - std::istringstream iss(data.substr(start, pos - start)); - iss >> oldVal; - start = pos + 1; - oldValList.push_back(oldVal); - } - - return MODES_ERROR_NONE; + size_t pos; + size_t start = 0; + oldValList.clear(); + while ((pos = data.find(delimiter, start)) != std::string::npos) { + int oldVal = 0; + std::istringstream iss(data.substr(start, pos - start)); + iss >> oldVal; + start = pos + 1; + oldValList.push_back(oldVal); + } + + return MODES_ERROR_NONE; } int DisplayBrightness::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - 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; - } + 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; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void DisplayBrightness::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - int ret = vconf_ignore_key_changed(KEY, vconfChangedCB); - if (0 != ret) { - ERR("vconf_ignore_key_changed(%s) Fail(%d)", KEY, ret); - return; - } + 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; + cbData = nullptr; + cb = nullptr; } void DisplayBrightness::changedCB(keynode_t *node) { - const char *vconfKey = vconf_keynode_get_name(node); - if (nullptr == vconfKey || MDSP_EQUAL != strcmp(KEY, vconfKey)) { - WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); - return; - } - - int realVal = requestVal; - if (realVal < 0) { - int ret = device_display_get_max_brightness(0, &realVal); - if (DEVICE_ERROR_NONE != ret) - ERR("device_display_get_max_brightness() Fail(%d)", ret); - } - - int val = vconf_keynode_get_int(node); - if (cb && (val != requestVal)) - cb(cbData); + const char *vconfKey = vconf_keynode_get_name(node); + if (nullptr == vconfKey || MDSP_EQUAL != strcmp(KEY, vconfKey)) { + WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); + return; + } + + int realVal = requestVal; + if (realVal < 0) { + int ret = device_display_get_max_brightness(0, &realVal); + if (DEVICE_ERROR_NONE != ret) + ERR("device_display_get_max_brightness() Fail(%d)", ret); + } + + int val = vconf_keynode_get_int(node); + if (cb && (val != requestVal)) + cb(cbData); } void DisplayBrightness::vconfChangedCB(keynode_t *node, void *userData) { - RET_IF(nullptr == userData); + RET_IF(nullptr == userData); - DisplayBrightness *action = (DisplayBrightness*)userData; - action->changedCB(node); + DisplayBrightness *action = (DisplayBrightness *)userData; + action->changedCB(node); } diff --git a/display/DisplayBrightness.h b/display/DisplayBrightness.h index 5765286..096f955 100644 --- a/display/DisplayBrightness.h +++ b/display/DisplayBrightness.h @@ -15,39 +15,42 @@ */ #pragma once +#include +#include + #include #include -#include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class DisplayBrightness : public PluginAction { -public: - DisplayBrightness(); - ~DisplayBrightness() override = default; - - bool IsCurrentValue(int val) override; - int set(int val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) 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 oldValList; - valueChangedCB cb; - void *cbData; + public: + DisplayBrightness(); + ~DisplayBrightness() override = default; + + bool IsCurrentValue(int val) override; + int set(int val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) 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 oldValList; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/display/DisplayDenyPalmTouch.cpp b/display/DisplayDenyPalmTouch.cpp index 6ada315..eb468ad 100644 --- a/display/DisplayDenyPalmTouch.cpp +++ b/display/DisplayDenyPalmTouch.cpp @@ -15,74 +15,75 @@ */ #include "DisplayDenyPalmTouch.h" -#include -#include +#include #include #include -#include + +#include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; const std::string DisplayDenyPalmTouch::NAME = "denyPalmTouch"; -DisplayDenyPalmTouch::DisplayDenyPalmTouch() - : PluginAction(NAME), oldVal(false) +DisplayDenyPalmTouch::DisplayDenyPalmTouch() : PluginAction(NAME), oldVal(false) { } int DisplayDenyPalmTouch::set(bool val) { - ecore_wl2_init(); - Ecore_Wl2_Display *displayHandle = ecore_wl2_display_connect(NULL); - if (nullptr == displayHandle) { - ERR("ecore_wl2_display_connect() Fail(%d)", get_last_result()); - return MODES_ERROR_SYSTEM; - } - - efl_util_gesture_h gestureHandle = efl_util_gesture_initialize(); - if (nullptr == gestureHandle) { - ERR("efl_util_gesture_initialize() Fail(%d)", get_last_result()); - return MODES_ERROR_SYSTEM; - } - - int ret = efl_util_gesture_activate_set(gestureHandle, EFL_UTIL_GESTURE_TYPE_PALM_COVER, !val); - efl_util_gesture_deinitialize(gestureHandle); - ecore_wl2_display_disconnect(displayHandle); - ecore_wl2_shutdown(); - - if (EFL_UTIL_ERROR_NONE != ret) { - ERR("efl_util_gesture_activate_set() Fail(%d)", ret); - return MODES_ERROR_SYSTEM; - } - - return MODES_ERROR_NONE; + ecore_wl2_init(); + Ecore_Wl2_Display *displayHandle = ecore_wl2_display_connect(NULL); + if (nullptr == displayHandle) { + ERR("ecore_wl2_display_connect() Fail(%d)", get_last_result()); + return MODES_ERROR_SYSTEM; + } + + efl_util_gesture_h gestureHandle = efl_util_gesture_initialize(); + if (nullptr == gestureHandle) { + ERR("efl_util_gesture_initialize() Fail(%d)", get_last_result()); + return MODES_ERROR_SYSTEM; + } + + int ret = efl_util_gesture_activate_set(gestureHandle, EFL_UTIL_GESTURE_TYPE_PALM_COVER, !val); + efl_util_gesture_deinitialize(gestureHandle); + ecore_wl2_display_disconnect(displayHandle); + ecore_wl2_shutdown(); + + if (EFL_UTIL_ERROR_NONE != ret) { + ERR("efl_util_gesture_activate_set() Fail(%d)", ret); + return MODES_ERROR_SYSTEM; + } + + return MODES_ERROR_NONE; } void DisplayDenyPalmTouch::undo() { - set(false); + set(false); } std::string DisplayDenyPalmTouch::getUndoInfo() { - WARN("Not Support getUndoInfo()"); - return std::string(); + WARN("Not Support getUndoInfo()"); + return std::string(); } int DisplayDenyPalmTouch::setUndoInfo(const std::string &info) { - WARN("Palm Touch setting is volatile"); - return MODES_ERROR_NOT_SUPPORTED; + WARN("Palm Touch setting is volatile"); + return MODES_ERROR_NOT_SUPPORTED; } int DisplayDenyPalmTouch::setChangedCallback(valueChangedCB callback, void *userData) { - WARN("Not Support Changed Callback"); - return MODES_ERROR_NOT_SUPPORTED; + WARN("Not Support Changed Callback"); + return MODES_ERROR_NOT_SUPPORTED; } void DisplayDenyPalmTouch::unSetChangedCallback(valueChangedCB callback) { - WARN("Not Support Changed Callback"); + WARN("Not Support Changed Callback"); } diff --git a/display/DisplayDenyPalmTouch.h b/display/DisplayDenyPalmTouch.h index 387a993..46562df 100644 --- a/display/DisplayDenyPalmTouch.h +++ b/display/DisplayDenyPalmTouch.h @@ -15,27 +15,30 @@ */ #pragma once -#include #include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class DisplayDenyPalmTouch : public PluginAction { -public: - DisplayDenyPalmTouch(); - ~DisplayDenyPalmTouch() override = default; - - int set(bool val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; - - static const std::string NAME; -private: - bool oldVal; + public: + DisplayDenyPalmTouch(); + ~DisplayDenyPalmTouch() override = default; + + int set(bool val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + static const std::string NAME; + + private: + bool oldVal; }; MODES_NAMESPACE_END diff --git a/display/DisplayFactory.cpp b/display/DisplayFactory.cpp index 3885f72..210929a 100644 --- a/display/DisplayFactory.cpp +++ b/display/DisplayFactory.cpp @@ -15,54 +15,56 @@ */ #include "DisplayFactory.h" -#include #include -#include "plugin-log.h" + +#include + #include "DisplayActVconf.h" #include "DisplayBrightness.h" #include "DisplayDenyPalmTouch.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; DisplayFactory::DisplayFactory() { - actionMap[DisplayActVconf::NAME[AUTO_BRIGHTNESS_VCONF]] = AUTO_BRIGHTNESS_VCONF; - actionMap[DisplayActVconf::NAME[TIMEOUT_VCONF]] = TIMEOUT_VCONF; - actionMap[DisplayBrightness::NAME] = BRIGHTNESS; - actionMap[DisplayDenyPalmTouch::NAME] = DENY_PALM_TOUCH; + actionMap[DisplayActVconf::NAME[AUTO_BRIGHTNESS_VCONF]] = AUTO_BRIGHTNESS_VCONF; + actionMap[DisplayActVconf::NAME[TIMEOUT_VCONF]] = TIMEOUT_VCONF; + actionMap[DisplayBrightness::NAME] = BRIGHTNESS; + actionMap[DisplayDenyPalmTouch::NAME] = DENY_PALM_TOUCH; } -PluginAction* DisplayFactory::createAction(const std::string &key) +PluginAction *DisplayFactory::createAction(const std::string &key) { - auto search = actionMap.find(key); - if (actionMap.end() == search) { - ERR("No Display PluginAction(%s)", key.c_str()); - return nullptr; - } + auto search = actionMap.find(key); + if (actionMap.end() == search) { + ERR("No Display PluginAction(%s)", key.c_str()); + return nullptr; + } - PluginAction *action; - switch (search->second) { - case AUTO_BRIGHTNESS_VCONF: - action = new DisplayActVconf(AUTO_BRIGHTNESS_VCONF); - break; - case TIMEOUT_VCONF: - action = new DisplayActVconf(TIMEOUT_VCONF); - break; - case BRIGHTNESS: - action = new DisplayBrightness(); - break; - case DENY_PALM_TOUCH: - action = new DisplayDenyPalmTouch(); - break; - default: - action = nullptr; - break; - } + PluginAction *action; + switch (search->second) { + case AUTO_BRIGHTNESS_VCONF: + action = new DisplayActVconf(AUTO_BRIGHTNESS_VCONF); + break; + case TIMEOUT_VCONF: + action = new DisplayActVconf(TIMEOUT_VCONF); + break; + case BRIGHTNESS: + action = new DisplayBrightness(); + break; + case DENY_PALM_TOUCH: + action = new DisplayDenyPalmTouch(); + break; + default: + action = nullptr; + break; + } - return action; + return action; } void DisplayFactory::destroyAction(PluginAction *action) { - delete action; + delete action; } diff --git a/display/DisplayFactory.h b/display/DisplayFactory.h index 18f6433..a3aaf73 100644 --- a/display/DisplayFactory.h +++ b/display/DisplayFactory.h @@ -15,29 +15,32 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class DisplayFactory { -public: - DisplayFactory(); - ~DisplayFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey{ - AUTO_BRIGHTNESS_VCONF, - TIMEOUT_VCONF, - BRIGHTNESS, - DENY_PALM_TOUCH, - }; - - std::map actionMap; + public: + DisplayFactory(); + ~DisplayFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { + AUTO_BRIGHTNESS_VCONF, + TIMEOUT_VCONF, + BRIGHTNESS, + DENY_PALM_TOUCH, + }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/display/DisplayPlugin.cpp b/display/DisplayPlugin.cpp index dfa5592..4173a45 100644 --- a/display/DisplayPlugin.cpp +++ b/display/DisplayPlugin.cpp @@ -13,46 +13,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include "plugin-log.h" -#include "plugin-def.h" + +#include + #include "DisplayFactory.h" +#include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class DisplayPlugin : public Plugin { -public: - DisplayPlugin(); - ~DisplayPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - DisplayFactory displayFactory; + public: + DisplayPlugin(); + ~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; + return new DisplayPlugin; } extern "C" API void objectDelete(Plugin *plugin) { - delete plugin; + delete plugin; } DisplayPlugin::DisplayPlugin() { - setName("display"); + setName("display"); } -PluginAction* DisplayPlugin::newAction(const std::string &key) +PluginAction *DisplayPlugin::newAction(const std::string &key) { - return displayFactory.createAction(key); + return displayFactory.createAction(key); } void DisplayPlugin::deleteAction(PluginAction *piAction) { - displayFactory.destroyAction(piAction); + displayFactory.destroyAction(piAction); } diff --git a/include/plugin-log.h b/include/plugin-log.h index 60859cf..e232b76 100644 --- a/include/plugin-log.h +++ b/include/plugin-log.h @@ -67,48 +67,48 @@ #define ERR(fmt, arg...) _ERR(fmt, ##arg) #endif /* MDS_PLUGIN */ -#define RET_IF(expr) \ - do { \ - if (expr) { \ - ERR("(%s)", #expr); \ - return; \ - } \ - } while (0) +#define RET_IF(expr) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + return; \ + } \ + } while (0) -#define RETV_IF(expr, val) \ - do { \ - if (expr) { \ - ERR("(%s)", #expr); \ - return (val); \ - } \ - } while (0) +#define RETV_IF(expr, val) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + return (val); \ + } \ + } while (0) #define RETM_IF(expr, fmt, arg...) \ - do { \ - if (expr) { \ - ERR(fmt, ##arg); \ - return; \ - } \ - } while (0) + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return; \ + } \ + } while (0) #define RETVM_IF(expr, val, fmt, arg...) \ - do { \ - if (expr) { \ - ERR(fmt, ##arg); \ - return (val); \ - } \ - } while (0) + do { \ + if (expr) { \ + ERR(fmt, ##arg); \ + return (val); \ + } \ + } while (0) -#define ERR_IF(expr) \ - do { \ - if (expr) { \ - ERR("(%s)", #expr); \ - } \ - } while (0) +#define ERR_IF(expr) \ + do { \ + if (expr) { \ + ERR("(%s)", #expr); \ + } \ + } while (0) #define WARN_IF(expr, fmt, arg...) \ - do { \ - if (expr) { \ - WARN(fmt, ##arg); \ - } \ - } while (0) + do { \ + if (expr) { \ + WARN(fmt, ##arg); \ + } \ + } while (0) diff --git a/media/MediaFactory.cpp b/media/MediaFactory.cpp index b96cd32..a92d8f8 100644 --- a/media/MediaFactory.cpp +++ b/media/MediaFactory.cpp @@ -15,55 +15,55 @@ */ #include "MediaFactory.h" -#include "plugin-log.h" #include "MediaPlayer.h" #include "SoundVolume.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; MediaFactory::MediaFactory() { - actionMap[SoundVolume::NAME[SYSTEM_VOL]] = SYSTEM_VOL; - actionMap[SoundVolume::NAME[NOTIFICATION_VOL]] = NOTIFICATION_VOL; - actionMap[SoundVolume::NAME[RINGTONE_VOL]] = RINGTONE_VOL; - actionMap[SoundVolume::NAME[MEDIA_VOL]] = MEDIA_VOL; - actionMap[MediaPlayer::NAME] = PLAYER; + actionMap[SoundVolume::NAME[SYSTEM_VOL]] = SYSTEM_VOL; + actionMap[SoundVolume::NAME[NOTIFICATION_VOL]] = NOTIFICATION_VOL; + actionMap[SoundVolume::NAME[RINGTONE_VOL]] = RINGTONE_VOL; + actionMap[SoundVolume::NAME[MEDIA_VOL]] = MEDIA_VOL; + actionMap[MediaPlayer::NAME] = PLAYER; } -PluginAction* MediaFactory::createAction(const std::string &key) +PluginAction *MediaFactory::createAction(const std::string &key) { - auto search = actionMap.find(key); - if (actionMap.end() == search) { - ERR("No Media PluginAction(%s)", key.c_str()); - return nullptr; - } + auto search = actionMap.find(key); + if (actionMap.end() == search) { + ERR("No Media PluginAction(%s)", key.c_str()); + return nullptr; + } - PluginAction *action; - switch (search->second) { - case SYSTEM_VOL: - action = new SoundVolume(SYSTEM_VOL, SOUND_TYPE_SYSTEM); - break; - case NOTIFICATION_VOL: - action = new SoundVolume(NOTIFICATION_VOL, SOUND_TYPE_NOTIFICATION); - break; - case RINGTONE_VOL: - action = new SoundVolume(RINGTONE_VOL, SOUND_TYPE_RINGTONE); - break; - case MEDIA_VOL: - action = new SoundVolume(MEDIA_VOL, SOUND_TYPE_MEDIA); - break; - case PLAYER: - action = new MediaPlayer(); - break; - default: - action = nullptr; - break; - } + PluginAction *action; + switch (search->second) { + case SYSTEM_VOL: + action = new SoundVolume(SYSTEM_VOL, SOUND_TYPE_SYSTEM); + break; + case NOTIFICATION_VOL: + action = new SoundVolume(NOTIFICATION_VOL, SOUND_TYPE_NOTIFICATION); + break; + case RINGTONE_VOL: + action = new SoundVolume(RINGTONE_VOL, SOUND_TYPE_RINGTONE); + break; + case MEDIA_VOL: + action = new SoundVolume(MEDIA_VOL, SOUND_TYPE_MEDIA); + break; + case PLAYER: + action = new MediaPlayer(); + break; + default: + action = nullptr; + break; + } - return action; + return action; } void MediaFactory::destroyAction(PluginAction *action) { - delete action; + delete action; } diff --git a/media/MediaFactory.h b/media/MediaFactory.h index 63a8dda..0659ac8 100644 --- a/media/MediaFactory.h +++ b/media/MediaFactory.h @@ -15,30 +15,27 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class MediaFactory { -public: - MediaFactory(); - ~MediaFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey{ - SYSTEM_VOL, - NOTIFICATION_VOL, - RINGTONE_VOL, - MEDIA_VOL, - PLAYER - }; - - std::map actionMap; + public: + MediaFactory(); + ~MediaFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { SYSTEM_VOL, NOTIFICATION_VOL, RINGTONE_VOL, MEDIA_VOL, PLAYER }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/media/MediaPlayer.cpp b/media/MediaPlayer.cpp index 44fcefe..d9ddbe5 100644 --- a/media/MediaPlayer.cpp +++ b/media/MediaPlayer.cpp @@ -15,8 +15,10 @@ */ #include "MediaPlayer.h" -#include #include + +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; @@ -24,116 +26,116 @@ MODES_NAMESPACE_USE; const std::string MediaPlayer::NAME = "player"; MediaPlayer::MediaPlayer() - : PluginAction(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) { - ERR("player_create() Fail(%s)", get_error_message(ret)); - return; - } - - ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &streamInfo); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_create_stream_information() Fail(%s)", get_error_message(ret)); - return; - } - - ret = player_set_sound_stream_info(player, streamInfo); - if (PLAYER_ERROR_NONE != ret) { - ERR("player_set_sound_stream_info() Fail(%s)", get_error_message(ret)); - return; - } + int ret = player_create(&player); + if (PLAYER_ERROR_NONE != ret) { + ERR("player_create() Fail(%s)", get_error_message(ret)); + return; + } + + ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &streamInfo); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_create_stream_information() Fail(%s)", get_error_message(ret)); + return; + } + + ret = player_set_sound_stream_info(player, streamInfo); + if (PLAYER_ERROR_NONE != ret) { + ERR("player_set_sound_stream_info() Fail(%s)", get_error_message(ret)); + return; + } } MediaPlayer::~MediaPlayer() { - sound_manager_destroy_stream_information(streamInfo); - - if (player) { - player_state_e state; - player_get_state(player, &state); - if (PLAYER_STATE_PLAYING == state || PLAYER_STATE_PAUSED == state) - player_stop(player); - player_unprepare(player); - player_destroy(player); - } + sound_manager_destroy_stream_information(streamInfo); + + if (player) { + player_state_e state; + player_get_state(player, &state); + if (PLAYER_STATE_PLAYING == state || PLAYER_STATE_PAUSED == state) + player_stop(player); + player_unprepare(player); + player_destroy(player); + } } int MediaPlayer::set(const std::string &val) { - //Todo: check the validation of uri(only storage, not internet) - int ret = player_set_uri(player, val.c_str()); - if (PLAYER_ERROR_NONE != ret) { - ERR("player_set_uri() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - ret = player_prepare(player); - if (PLAYER_ERROR_NONE != ret) { - ERR("player_prepare() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - ret = player_start(player); - if (PLAYER_ERROR_NONE != ret) { - ERR("player_start() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - - return MODES_ERROR_NONE; + // Todo: check the validation of uri(only storage, not internet) + int ret = player_set_uri(player, val.c_str()); + if (PLAYER_ERROR_NONE != ret) { + ERR("player_set_uri() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + ret = player_prepare(player); + if (PLAYER_ERROR_NONE != ret) { + ERR("player_prepare() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + ret = player_start(player); + if (PLAYER_ERROR_NONE != ret) { + ERR("player_start() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + + return MODES_ERROR_NONE; } void MediaPlayer::undo() { - player_stop(player); + player_stop(player); } std::string MediaPlayer::getUndoInfo() { - //Not Support - return std::string(); + // Not Support + return std::string(); } int MediaPlayer::setUndoInfo(const std::string &info) { - WARN("MediaPlayer is volatile"); - return MODES_ERROR_NOT_SUPPORTED; + WARN("MediaPlayer is volatile"); + return MODES_ERROR_NOT_SUPPORTED; } int MediaPlayer::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - int ret = player_set_completed_cb(player, completeCB, this); - if (PLAYER_ERROR_NONE != ret) { - ERR("player_set_completed_cb() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } + int ret = player_set_completed_cb(player, completeCB, this); + if (PLAYER_ERROR_NONE != ret) { + ERR("player_set_completed_cb() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void MediaPlayer::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - int ret = player_unset_completed_cb(player); - if (PLAYER_ERROR_NONE != ret) - ERR("player_unset_completed_cb() Fail(%s)", get_error_message(ret)); + int ret = player_unset_completed_cb(player); + if (PLAYER_ERROR_NONE != ret) + ERR("player_unset_completed_cb() Fail(%s)", get_error_message(ret)); - cb = nullptr; - cbData = nullptr; + cb = nullptr; + cbData = nullptr; } void MediaPlayer::completeCB(void *data) { - MediaPlayer *action = (MediaPlayer*)data; + MediaPlayer *action = (MediaPlayer *)data; - RET_IF(nullptr == data); + RET_IF(nullptr == data); - if (action->cb) - action->cb(action->cbData); + if (action->cb) + action->cb(action->cbData); } diff --git a/media/MediaPlayer.h b/media/MediaPlayer.h index 74ba7a5..eb63000 100644 --- a/media/MediaPlayer.h +++ b/media/MediaPlayer.h @@ -15,33 +15,35 @@ */ #pragma once +#include #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class MediaPlayer : public PluginAction { -public: - MediaPlayer(); - ~MediaPlayer() override; - - int set(const std::string &val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; - - static const std::string NAME; -private: - static void completeCB(void *data); - - player_h player; - sound_stream_info_h streamInfo; - valueChangedCB cb; - void *cbData; + public: + MediaPlayer(); + ~MediaPlayer() override; + + int set(const std::string &val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + static const std::string NAME; + + private: + static void completeCB(void *data); + + player_h player; + sound_stream_info_h streamInfo; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/media/MediaPlugin.cpp b/media/MediaPlugin.cpp index 9a2e395..6a37646 100644 --- a/media/MediaPlugin.cpp +++ b/media/MediaPlugin.cpp @@ -13,46 +13,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include "plugin-log.h" -#include "plugin-def.h" + +#include + #include "MediaFactory.h" +#include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class MediaPlugin : public Plugin { -public: - MediaPlugin(); - ~MediaPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - MediaFactory mediaFactory; + public: + MediaPlugin(); + ~MediaPlugin() override = default; + + 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; + return new MediaPlugin; } extern "C" API void objectDelete(Plugin *plugin) { - delete plugin; + delete plugin; } MediaPlugin::MediaPlugin() { - setName("media"); + setName("media"); } -PluginAction* MediaPlugin::newAction(const std::string &key) +PluginAction *MediaPlugin::newAction(const std::string &key) { - return mediaFactory.createAction(key); + return mediaFactory.createAction(key); } void MediaPlugin::deleteAction(PluginAction *piAction) { - mediaFactory.destroyAction(piAction); + mediaFactory.destroyAction(piAction); } diff --git a/media/SoundVolume.cpp b/media/SoundVolume.cpp index dc162ba..5094995 100644 --- a/media/SoundVolume.cpp +++ b/media/SoundVolume.cpp @@ -15,134 +15,137 @@ */ #include "SoundVolume.h" -#include -#include #include + +#include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; // It should align with actionKey in MediaFactory -const std::string SoundVolume::NAME[4] = { - "systemVolume", - "notificationVolume", - "ringtoneVolume", - "mediaVolume" -}; +const std::string SoundVolume::NAME[4] = {"systemVolume", "notificationVolume", "ringtoneVolume", + "mediaVolume"}; SoundVolume::SoundVolume(int key, sound_type_e soundType) - : PluginAction(NAME[key]), type(soundType), - requestVal(-1), oldVal(-1), callbackID(0), cb(nullptr), cbData(nullptr) + : PluginAction(NAME[key]), + type(soundType), + requestVal(-1), + oldVal(-1), + callbackID(0), + cb(nullptr), + cbData(nullptr) { } bool SoundVolume::IsCurrentValue(int val) { - 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 false; - } - 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]", getKey().c_str(), val); - return true; - } - - return false; + 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 false; + } + 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]", 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_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; + int ret; + requestVal = val; + + 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; + } + 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; } void SoundVolume::undo() { - int ret = sound_manager_set_volume(type, oldVal); - if (SOUND_MANAGER_ERROR_NONE != ret) - ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret)); + int ret = sound_manager_set_volume(type, oldVal); + if (SOUND_MANAGER_ERROR_NONE != ret) + ERR("sound_manager_set_volume() Fail(%s)", get_error_message(ret)); } std::string SoundVolume::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int SoundVolume::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int SoundVolume::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - int ret = sound_manager_add_volume_changed_cb(volumeChangedCB, this, &callbackID); - if (SOUND_MANAGER_ERROR_NONE != ret) { - ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } + int ret = sound_manager_add_volume_changed_cb(volumeChangedCB, this, &callbackID); + if (SOUND_MANAGER_ERROR_NONE != ret) { + ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void SoundVolume::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - int ret = sound_manager_remove_volume_changed_cb(callbackID); - if (SOUND_MANAGER_ERROR_NONE != ret) - ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); + int ret = sound_manager_remove_volume_changed_cb(callbackID); + if (SOUND_MANAGER_ERROR_NONE != ret) + ERR("sound_manager_add_volume_changed_cb() Fail(%s)", get_error_message(ret)); - cb = nullptr; - cbData = nullptr; + cb = nullptr; + cbData = nullptr; } void SoundVolume::volumeChangedCB(sound_type_e type, unsigned int volume, void *userData) { - SoundVolume *action = (SoundVolume*)userData; + SoundVolume *action = (SoundVolume *)userData; - RET_IF(nullptr == userData); - RET_IF(type != action->type); + RET_IF(nullptr == userData); + RET_IF(type != action->type); - if (action->cb && action->requestVal != (int)volume) - action->cb(action->cbData); + if (action->cb && action->requestVal != (int)volume) + action->cb(action->cbData); } diff --git a/media/SoundVolume.h b/media/SoundVolume.h index c6cf850..ce40cd6 100644 --- a/media/SoundVolume.h +++ b/media/SoundVolume.h @@ -15,36 +15,39 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class SoundVolume : public PluginAction { -public: - SoundVolume(int key, sound_type_e soundType); - ~SoundVolume() override = default; - - bool IsCurrentValue(int val); - int set(int val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; - - static const std::string NAME[4]; -private: - static void volumeChangedCB(sound_type_e type, unsigned int volume, void *userData); - - sound_type_e type; //not same with the NAME[] order - int requestVal; - int oldVal; - int callbackID; - valueChangedCB cb; - void *cbData; + public: + SoundVolume(int key, sound_type_e soundType); + ~SoundVolume() override = default; + + bool IsCurrentValue(int val); + int set(int val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + static const std::string NAME[4]; + + private: + static void volumeChangedCB(sound_type_e type, unsigned int volume, void *userData); + + sound_type_e type; // not same with the NAME[] order + int requestVal; + int oldVal; + int callbackID; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/pkg/PkgEnableSupportMode.cpp b/pkg/PkgEnableSupportMode.cpp index 0f938cc..730b831 100644 --- a/pkg/PkgEnableSupportMode.cpp +++ b/pkg/PkgEnableSupportMode.cpp @@ -16,136 +16,137 @@ #include "PkgEnableSupportMode.h" #include +#include +#include + #include -#include #include -#include -#include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; const std::string PkgSupportMode::NAME = "supportMode"; -PkgSupportMode::PkgSupportMode() - : PluginAction(NAME), requestVal(0) +PkgSupportMode::PkgSupportMode() : PluginAction(NAME), requestVal(0) { } int PkgSupportMode::set(int val) { - int ret; - pkgmgrinfo_appinfo_filter_h filter; - - switch (val) { - case ULTRA_POWER_SAVING: - case COOL_DOWN: - case SCREEN_READER: - requestVal = val; - break; - default: - ERR("Unknown Mode(%d)", val); - return MODES_ERROR_INVALID_PARAMETER; - } - - ret = pkgmgrinfo_appinfo_filter_create(&filter); - if (ret != PMINFO_R_OK) { - ERR("pkgmgrinfo_appinfo_filter_create() Fail(%d)", ret); - return MODES_ERROR_SYSTEM; - } - - pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, appListCB, this); - pkgmgrinfo_appinfo_filter_destroy(filter); - - int nApps = 0; - const char *appIDs[inactiveApps.size()]; - for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) { - appIDs[nApps] = it->c_str(); - 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); - - return MODES_ERROR_NONE; + int ret; + pkgmgrinfo_appinfo_filter_h filter; + + switch (val) { + case ULTRA_POWER_SAVING: + case COOL_DOWN: + case SCREEN_READER: + requestVal = val; + break; + default: + ERR("Unknown Mode(%d)", val); + return MODES_ERROR_INVALID_PARAMETER; + } + + ret = pkgmgrinfo_appinfo_filter_create(&filter); + if (ret != PMINFO_R_OK) { + ERR("pkgmgrinfo_appinfo_filter_create() Fail(%d)", ret); + return MODES_ERROR_SYSTEM; + } + + pkgmgrinfo_appinfo_filter_foreach_appinfo(filter, appListCB, this); + pkgmgrinfo_appinfo_filter_destroy(filter); + + int nApps = 0; + const char *appIDs[inactiveApps.size()]; + for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) { + appIDs[nApps] = it->c_str(); + 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); + + return MODES_ERROR_NONE; } void PkgSupportMode::undo() { - //If the appList is empty, it will be ignored at subroutines. - int nApps = 0; - const char *appIDs[inactiveApps.size()]; - for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) { - appIDs[nApps] = it->c_str(); - 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); - if (reqId < 0) - ERR("pkgmgr_client_activate_apps() Fail(%d)", reqId); - DBG("Request id[%d] count[%d]", reqId, nApps); - - pkgmgr_client_free(pc); + // If the appList is empty, it will be ignored at subroutines. + int nApps = 0; + const char *appIDs[inactiveApps.size()]; + for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++, nApps++) { + appIDs[nApps] = it->c_str(); + 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); + if (reqId < 0) + ERR("pkgmgr_client_activate_apps() Fail(%d)", reqId); + DBG("Request id[%d] count[%d]", reqId, nApps); + + pkgmgr_client_free(pc); } std::string PkgSupportMode::getUndoInfo() { - std::ostringstream ostr; - for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++) - ostr << *it << delimiter; + std::ostringstream ostr; + for (auto it = inactiveApps.begin(); it != inactiveApps.end(); it++) + ostr << *it << delimiter; - return ostr.str(); + return ostr.str(); } int PkgSupportMode::setUndoInfo(const std::string &info) { - size_t pos; - size_t start = 0; - while ((pos = info.find(delimiter, start)) != std::string::npos) { - inactiveApps.push_back(info.substr(start, pos - start)); - start = pos + 1; - } - return MODES_ERROR_NONE; + size_t pos; + size_t start = 0; + while ((pos = info.find(delimiter, start)) != std::string::npos) { + inactiveApps.push_back(info.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; + ERR("Not Support Changed Callback"); + return MODES_ERROR_NOT_SUPPORTED; } void PkgSupportMode::unSetChangedCallback(valueChangedCB callback) { - ERR("Not Support Changed Callback"); + 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; + 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 6fcfc97..1e83f67 100644 --- a/pkg/PkgEnableSupportMode.h +++ b/pkg/PkgEnableSupportMode.h @@ -15,37 +15,40 @@ */ #pragma once +#include +#include + #include #include -#include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class PkgSupportMode : public PluginAction { -public: - PkgSupportMode(); - - int set(int val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &data) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; - - static const std::string NAME; -private: - 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 - }; - static int appListCB(const pkgmgrinfo_appinfo_h handle, void *userData); - - const char delimiter = '#'; - int requestVal; - std::list inactiveApps; + public: + PkgSupportMode(); + + int set(int val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &data) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + static const std::string NAME; + + private: + 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 + }; + static int appListCB(const pkgmgrinfo_appinfo_h handle, void *userData); + + const char delimiter = '#'; + int requestVal; + std::list inactiveApps; }; MODES_NAMESPACE_END diff --git a/pkg/PkgFactory.cpp b/pkg/PkgFactory.cpp index bd9fc69..3e98c7c 100644 --- a/pkg/PkgFactory.cpp +++ b/pkg/PkgFactory.cpp @@ -14,38 +14,39 @@ * limitations under the License. */ #include "PkgFactory.h" -#include "plugin-log.h" + #include "PkgEnableSupportMode.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; PkgFactory::PkgFactory() { - actionMap[PkgSupportMode::NAME] = PKG_ACT_SUPPORTMODE; + actionMap[PkgSupportMode::NAME] = PKG_ACT_SUPPORTMODE; } -PluginAction* PkgFactory::createAction(const std::string &key) +PluginAction *PkgFactory::createAction(const std::string &key) { - auto search = actionMap.find(key); - if (actionMap.end() == search) { - ERR("No Pkg PluginAction(%s)", key.c_str()); - return nullptr; - } + auto search = actionMap.find(key); + if (actionMap.end() == search) { + ERR("No Pkg PluginAction(%s)", key.c_str()); + return nullptr; + } - PluginAction *action; - switch (search->second) { - case PKG_ACT_SUPPORTMODE: - action = new PkgSupportMode(); - break; - default: - action = nullptr; - break; - } + PluginAction *action; + switch (search->second) { + case PKG_ACT_SUPPORTMODE: + action = new PkgSupportMode(); + break; + default: + action = nullptr; + break; + } - return action; + return action; } void PkgFactory::destroyAction(PluginAction *action) { - delete action; + delete action; } diff --git a/pkg/PkgFactory.h b/pkg/PkgFactory.h index 047c218..ff6c63f 100644 --- a/pkg/PkgFactory.h +++ b/pkg/PkgFactory.h @@ -15,26 +15,27 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class PkgFactory { -public: - PkgFactory(); - ~PkgFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey{ - PKG_ACT_SUPPORTMODE - }; - - std::map actionMap; + public: + PkgFactory(); + ~PkgFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { PKG_ACT_SUPPORTMODE }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/pkg/PkgPlugin.cpp b/pkg/PkgPlugin.cpp index e187009..6cee628 100644 --- a/pkg/PkgPlugin.cpp +++ b/pkg/PkgPlugin.cpp @@ -13,46 +13,49 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include "plugin-log.h" -#include "plugin-def.h" + +#include + #include "PkgFactory.h" +#include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class PkgPlugin : public Plugin { -public: - PkgPlugin(); - ~PkgPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - PkgFactory pkgFactory; + public: + PkgPlugin(); + ~PkgPlugin() override = default; + + 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) { - delete plugin; + delete plugin; } PkgPlugin::PkgPlugin() { - setName("pkg"); + setName("pkg"); } -PluginAction* PkgPlugin::newAction(const std::string &key) +PluginAction *PkgPlugin::newAction(const std::string &key) { - return pkgFactory.createAction(key); + return pkgFactory.createAction(key); } void PkgPlugin::deleteAction(PluginAction *piAction) { - pkgFactory.destroyAction(piAction); + pkgFactory.destroyAction(piAction); } diff --git a/std/StdFactory.cpp b/std/StdFactory.cpp index 7471b6e..82d0aff 100644 --- a/std/StdFactory.cpp +++ b/std/StdFactory.cpp @@ -15,46 +15,46 @@ */ #include "StdFactory.h" -#include "plugin-log.h" #include "StdTimeout.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; StdFactory::StdFactory() { - actionMap[StdTimeout::NAME[StdTimeout::SECONDS]] = TIMEOUT_SECONDS; - actionMap[StdTimeout::NAME[StdTimeout::MINUTES]] = TIMEOUT_MINUTES; - actionMap[StdTimeout::NAME[StdTimeout::HOURS]] = TIMEOUT_HOURS; + actionMap[StdTimeout::NAME[StdTimeout::SECONDS]] = TIMEOUT_SECONDS; + actionMap[StdTimeout::NAME[StdTimeout::MINUTES]] = TIMEOUT_MINUTES; + actionMap[StdTimeout::NAME[StdTimeout::HOURS]] = TIMEOUT_HOURS; } -PluginAction* StdFactory::createAction(const std::string &key) +PluginAction* StdFactory::createAction(const std::string& key) { - auto found = actionMap.find(key); - if (actionMap.end() == found) { - ERR("No Std PluginAction(%s)", key.c_str()); - return nullptr; - } + auto found = actionMap.find(key); + if (actionMap.end() == found) { + ERR("No Std PluginAction(%s)", key.c_str()); + return nullptr; + } - PluginAction* action; - switch (found->second) { - case TIMEOUT_SECONDS: - action = new StdTimeout(StdTimeout::SECONDS); - break; - case TIMEOUT_MINUTES: - action = new StdTimeout(StdTimeout::MINUTES); - break; - case TIMEOUT_HOURS: - action = new StdTimeout(StdTimeout::HOURS); - break; - default: - action = nullptr; - break; - } + PluginAction* action; + switch (found->second) { + case TIMEOUT_SECONDS: + action = new StdTimeout(StdTimeout::SECONDS); + break; + case TIMEOUT_MINUTES: + action = new StdTimeout(StdTimeout::MINUTES); + break; + case TIMEOUT_HOURS: + action = new StdTimeout(StdTimeout::HOURS); + break; + default: + action = nullptr; + break; + } - return action; + return action; } -void StdFactory::destroyAction(PluginAction *action) +void StdFactory::destroyAction(PluginAction* action) { - delete action; + delete action; } diff --git a/std/StdFactory.h b/std/StdFactory.h index 8743413..5a52875 100644 --- a/std/StdFactory.h +++ b/std/StdFactory.h @@ -15,28 +15,27 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class StdFactory { -public: - StdFactory(); - ~StdFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey { - TIMEOUT_SECONDS, - TIMEOUT_MINUTES, - TIMEOUT_HOURS - }; - - std::map actionMap; + public: + StdFactory(); + ~StdFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { TIMEOUT_SECONDS, TIMEOUT_MINUTES, TIMEOUT_HOURS }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/std/StdPlugin.cpp b/std/StdPlugin.cpp index 0198427..70eea6e 100644 --- a/std/StdPlugin.cpp +++ b/std/StdPlugin.cpp @@ -14,44 +14,46 @@ * limitations under the License. */ #include -#include "plugin-log.h" -#include "plugin-def.h" + #include "StdFactory.h" +#include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class StdPlugin : public Plugin { -public: - StdPlugin(); - ~StdPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - StdFactory stdFactory; + public: + StdPlugin(); + ~StdPlugin() override = default; + + PluginAction *newAction(const std::string &key) override; + void deleteAction(PluginAction *piAction) override; + + private: + StdFactory stdFactory; }; -extern "C" API Plugin* objectCreate(void) +extern "C" API Plugin *objectCreate(void) { - return new StdPlugin(); + return new StdPlugin(); } extern "C" API void objectDelete(Plugin *plugin) { - delete plugin; + delete plugin; } StdPlugin::StdPlugin() { - setName("std"); + setName("std"); } -PluginAction* StdPlugin::newAction(const std::string &key) +PluginAction *StdPlugin::newAction(const std::string &key) { - return stdFactory.createAction(key); + return stdFactory.createAction(key); } void StdPlugin::deleteAction(PluginAction *piAction) { - stdFactory.destroyAction(piAction); + stdFactory.destroyAction(piAction); } diff --git a/std/StdTimeout.cpp b/std/StdTimeout.cpp index a649662..70c1b6a 100644 --- a/std/StdTimeout.cpp +++ b/std/StdTimeout.cpp @@ -16,80 +16,84 @@ #include "StdTimeout.h" #include -#include + #include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; -const std::string StdTimeout::NAME[StdTimeout::UNIT_MAX] = { - "timeout.seconds", - "timeout.minutes", - "timeout.hours" -}; +const std::string StdTimeout::NAME[StdTimeout::UNIT_MAX] = {"timeout.seconds", "timeout.minutes", + "timeout.hours"}; StdTimeout::StdTimeout(StdTimeout::UnitOfTime unit) - : PluginAction("timeout"), timeUnit(unit), requestVal(0), timer(0), cb(nullptr), cbData(nullptr) + : PluginAction("timeout"), + timeUnit(unit), + requestVal(0), + timer(0), + cb(nullptr), + cbData(nullptr) { } int StdTimeout::set(int val) { - switch (timeUnit) { - case HOURS: - requestVal = val * 60 * 60; - break; - case MINUTES: - requestVal = val * 60; - break; - case SECONDS: - default: - requestVal = val; - break; - } - - timer = g_timeout_add_seconds(requestVal, changedCB, this); - - return MODES_ERROR_NONE; + switch (timeUnit) { + case HOURS: + requestVal = val * 60 * 60; + break; + case MINUTES: + requestVal = val * 60; + break; + case SECONDS: + default: + requestVal = val; + break; + } + + timer = g_timeout_add_seconds(requestVal, changedCB, this); + + return MODES_ERROR_NONE; } void StdTimeout::undo() { - g_source_remove(timer); - //Nothing to do + g_source_remove(timer); + // Nothing to do } std::string StdTimeout::getUndoInfo() { - //Not Support : Volitile - return std::string(); + // Not Support : Volitile + return std::string(); } int StdTimeout::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void StdTimeout::unSetChangedCallback(valueChangedCB callback) { - RET_IF(callback != cb); + RET_IF(callback != cb); - cbData = nullptr; - cb = nullptr; + cbData = nullptr; + cb = nullptr; } gboolean StdTimeout::changedCB(gpointer data) { - RETV_IF(nullptr == data, G_SOURCE_REMOVE); + RETV_IF(nullptr == data, G_SOURCE_REMOVE); - StdTimeout *action = (StdTimeout*)data; - if (action->cb) - action->cb(action->cbData); + StdTimeout *action = (StdTimeout *)data; + if (action->cb) + action->cb(action->cbData); - return G_SOURCE_REMOVE; + return G_SOURCE_REMOVE; } diff --git a/std/StdTimeout.h b/std/StdTimeout.h index 27ec5d9..72c7cb7 100644 --- a/std/StdTimeout.h +++ b/std/StdTimeout.h @@ -15,38 +15,36 @@ */ #pragma once +#include #include + #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class StdTimeout : public PluginAction { -public: - enum UnitOfTime { - SECONDS, - MINUTES, - HOURS, - UNIT_MAX - }; - StdTimeout(StdTimeout::UnitOfTime unit); - - int set(int val) override; - void undo() override; - std::string getUndoInfo() override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; - - static const std::string NAME[UNIT_MAX]; -private: - static gboolean changedCB(gpointer data); - - UnitOfTime timeUnit; - int requestVal; - guint timer; - valueChangedCB cb; - void *cbData; + public: + enum UnitOfTime { SECONDS, MINUTES, HOURS, UNIT_MAX }; + StdTimeout(StdTimeout::UnitOfTime unit); + + int set(int val) override; + void undo() override; + std::string getUndoInfo() override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + static const std::string NAME[UNIT_MAX]; + + private: + static gboolean changedCB(gpointer data); + + UnitOfTime timeUnit; + int requestVal; + guint timer; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/tests/mdsp_test_app.cpp b/tests/mdsp_test_app.cpp index e7e8658..5181b5a 100644 --- a/tests/mdsp_test_app.cpp +++ b/tests/mdsp_test_app.cpp @@ -13,107 +13,108 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include - -#include -#include -#include #include #include #include +#include +#include +#include + +#include +#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class AppPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean appUndoTimeout(gpointer data) - { - PluginAction *action = (PluginAction*)data; - action->undo(); - g_main_loop_quit(loop); - plugin->deleteAction(action); - - return G_SOURCE_REMOVE; - } - - static gboolean checkSetUndoIdler(gpointer data) - { - 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) { - g_timeout_add(1000, appUndoTimeout, action); - } else { - g_main_loop_quit(loop); - plugin->deleteAction(action); - } - return G_SOURCE_REMOVE; - } - - static void changedCB(void *userData) - { - PluginAction *action = (PluginAction*)userData; - - cbCalled = true; - std::cout << ">>>>>>>> changedCB: Terminated <<<<<<<<" << std::endl; - appUndoTimeout(action); - } - - static gboolean checkChangedCBIdler(gpointer data) - { - sleep(1); - 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) { - int ret = action->setChangedCallback(changedCB, action); - EXPECT_EQ(MODES_ERROR_NONE, ret); - g_timeout_add(20000, appUndoTimeout, action); //For running continue - } else { - g_main_loop_quit(loop); - plugin->deleteAction(action); - } - - sleep(1); - app_context_h runAppContext = NULL; - int ret = app_manager_get_app_context(testApp, &runAppContext); - if (APP_MANAGER_ERROR_NONE != ret) - std::cout << testApp << " get_app_context() Fail:" << ret << std::endl; - else - app_manager_terminate_app(runAppContext); - - return G_SOURCE_REMOVE; - } - - static const char *testApp; - static int result; - static bool cbCalled; - static GMainLoop *loop; - static GThread *my_thread; - static Plugin *plugin; + protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean appUndoTimeout(gpointer data) + { + PluginAction *action = (PluginAction *)data; + action->undo(); + g_main_loop_quit(loop); + plugin->deleteAction(action); + + return G_SOURCE_REMOVE; + } + + static gboolean checkSetUndoIdler(gpointer data) + { + 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) { + g_timeout_add(1000, appUndoTimeout, action); + } else { + g_main_loop_quit(loop); + plugin->deleteAction(action); + } + return G_SOURCE_REMOVE; + } + + static void changedCB(void *userData) + { + PluginAction *action = (PluginAction *)userData; + + cbCalled = true; + std::cout << ">>>>>>>> changedCB: Terminated <<<<<<<<" << std::endl; + appUndoTimeout(action); + } + + static gboolean checkChangedCBIdler(gpointer data) + { + sleep(1); + 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) { + int ret = action->setChangedCallback(changedCB, action); + EXPECT_EQ(MODES_ERROR_NONE, ret); + g_timeout_add(20000, appUndoTimeout, action); // For running continue + } else { + g_main_loop_quit(loop); + plugin->deleteAction(action); + } + + sleep(1); + app_context_h runAppContext = NULL; + int ret = app_manager_get_app_context(testApp, &runAppContext); + if (APP_MANAGER_ERROR_NONE != ret) + std::cout << testApp << " get_app_context() Fail:" << ret << std::endl; + else + app_manager_terminate_app(runAppContext); + + return G_SOURCE_REMOVE; + } + + static const char *testApp; + static int result; + static bool cbCalled; + static GMainLoop *loop; + static GThread *my_thread; + static Plugin *plugin; }; const char *AppPluginTest::testApp = "org.tizen.setting"; @@ -124,20 +125,21 @@ GMainLoop *AppPluginTest::loop = NULL; TEST_F(AppPluginTest, CheckSetUndo) { - g_idle_add(checkSetUndoIdler, plugin); - g_main_loop_run(loop); + g_idle_add(checkSetUndoIdler, plugin); + g_main_loop_run(loop); } TEST_F(AppPluginTest, checkChangedCB) { - cbCalled = false; - g_idle_add(checkChangedCBIdler, NULL); - g_main_loop_run(loop); - //TODO: at posttrans of unittest, changedCB is not called - //EXPECT_EQ(cbCalled, true); + cbCalled = false; + g_idle_add(checkChangedCBIdler, NULL); + g_main_loop_run(loop); + // TODO: at posttrans of unittest, changedCB is not called + // EXPECT_EQ(cbCalled, true); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_bt.cpp b/tests/mdsp_test_bt.cpp index 5194d8f..d55a092 100644 --- a/tests/mdsp_test_bt.cpp +++ b/tests/mdsp_test_bt.cpp @@ -13,60 +13,62 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include #include #include -#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class BtPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - plugin = objectCreate(); - loop = g_main_loop_new(NULL, FALSE); - handle = modes_connect(); - } - - void TearDown() override - { - objectDelete(plugin); - plugin = nullptr; - g_main_loop_unref(loop); - loop = NULL; - modes_disconnect(handle); - handle = NULL; - } - - static gboolean apply_mode_idler(gpointer data) - { - result = modes_apply_mode(handle, (const char*)data); - - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean undo_mode_idler(gpointer data) - { - result = modes_apply_mode(handle, (const char*)data); - EXPECT_EQ(MODES_ERROR_NONE, result); - sleep(5); - result = modes_undo_mode(handle, (const char*)data); - - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static modes_h handle; - static int result; - static GMainLoop *loop; - Plugin *plugin; + protected: + void SetUp() override + { + plugin = objectCreate(); + loop = g_main_loop_new(NULL, FALSE); + handle = modes_connect(); + } + + void TearDown() override + { + objectDelete(plugin); + plugin = nullptr; + g_main_loop_unref(loop); + loop = NULL; + modes_disconnect(handle); + handle = NULL; + } + + static gboolean apply_mode_idler(gpointer data) + { + result = modes_apply_mode(handle, (const char *)data); + + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean undo_mode_idler(gpointer data) + { + result = modes_apply_mode(handle, (const char *)data); + EXPECT_EQ(MODES_ERROR_NONE, result); + sleep(5); + result = modes_undo_mode(handle, (const char *)data); + + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static modes_h handle; + static int result; + static GMainLoop *loop; + Plugin *plugin; }; int BtPluginTest::result = 0; @@ -75,51 +77,50 @@ modes_h BtPluginTest::handle = NULL; TEST_F(BtPluginTest, undoModebtOff) { - g_idle_add(undo_mode_idler, (gpointer)"http://tizen.org/mode/example.btOff"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(undo_mode_idler, (gpointer) "http://tizen.org/mode/example.btOff"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(BtPluginTest, undoModebtOn) { - g_idle_add(undo_mode_idler, (gpointer)"http://tizen.org/mode/example.btOn"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(undo_mode_idler, (gpointer) "http://tizen.org/mode/example.btOn"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } // btAudioConnect does not support undo mode TEST_F(BtPluginTest, btAudioConnect) { - g_idle_add(apply_mode_idler, (gpointer)"http://tizen.org/mode/example.btAudioConnect"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(apply_mode_idler, (gpointer) "http://tizen.org/mode/example.btAudioConnect"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(BtPluginTest, btTest) { - int ret; + int ret; - ASSERT_TRUE(nullptr != plugin); + ASSERT_TRUE(nullptr != plugin); - PluginAction *action = plugin->newAction("power"); - ret = action->set(false); - EXPECT_EQ(ret, MODES_ERROR_NONE); - sleep(3);//for avoiding the NOW_IN_PROGRESS error + 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 = action->set(true); - EXPECT_EQ(ret, MODES_ERROR_NONE); + ret = action->set(true); + EXPECT_EQ(ret, MODES_ERROR_NONE); - ret = action->set(std::string("on")); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - plugin->deleteAction(action); + ret = action->set(std::string("on")); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + plugin->deleteAction(action); - action = plugin->newAction("abcdefg"); - EXPECT_EQ(action, nullptr); + action = plugin->newAction("abcdefg"); + EXPECT_EQ(action, nullptr); } int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } - diff --git a/tests/mdsp_test_display.cpp b/tests/mdsp_test_display.cpp index 7f70bfc..9dc4aa3 100644 --- a/tests/mdsp_test_display.cpp +++ b/tests/mdsp_test_display.cpp @@ -13,95 +13,96 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class displayPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean displayPluginBrightnessIdler(gpointer data) - { - PluginAction *action = plugin->newAction("brightness"); - int value = 100; - if (action->IsCurrentValue(value)) - value--; - result = action->set(value); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean displayPluginDenyPalmTouchIdler(gpointer data) - { - PluginAction *action = plugin->newAction("denyPalmTouch"); - EXPECT_FALSE(action->IsCurrentValue(true)); - result = action->set(true); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean displayPluginAlwaysOnIdler(gpointer data) - { - PluginAction *action = plugin->newAction("timeout"); - EXPECT_FALSE(action->IsCurrentValue(0)); - result = action->set(0); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - plugin->deleteAction(action); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - static gboolean displayPluginAutoBrightnessIdler(gpointer data) - { - PluginAction *action = plugin->newAction("autoBrightness"); - EXPECT_FALSE(action->IsCurrentValue(1)); - result = action->set(1); - EXPECT_EQ(MODES_ERROR_NONE, result); - - action->undo(); - - 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; - static GMainLoop *loop; - static Plugin *plugin; + protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean displayPluginBrightnessIdler(gpointer data) + { + PluginAction *action = plugin->newAction("brightness"); + int value = 100; + if (action->IsCurrentValue(value)) + value--; + result = action->set(value); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean displayPluginDenyPalmTouchIdler(gpointer data) + { + PluginAction *action = plugin->newAction("denyPalmTouch"); + EXPECT_FALSE(action->IsCurrentValue(true)); + result = action->set(true); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean displayPluginAlwaysOnIdler(gpointer data) + { + PluginAction *action = plugin->newAction("timeout"); + EXPECT_FALSE(action->IsCurrentValue(0)); + result = action->set(0); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + plugin->deleteAction(action); + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static gboolean displayPluginAutoBrightnessIdler(gpointer data) + { + PluginAction *action = plugin->newAction("autoBrightness"); + EXPECT_FALSE(action->IsCurrentValue(1)); + result = action->set(1); + EXPECT_EQ(MODES_ERROR_NONE, result); + + action->undo(); + + 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; + static GMainLoop *loop; + static Plugin *plugin; }; int displayPluginTest::result = 0; @@ -110,29 +111,30 @@ GMainLoop *displayPluginTest::loop = NULL; TEST_F(displayPluginTest, setBrightness) { - g_idle_add(displayPluginBrightnessIdler, plugin); - g_main_loop_run(loop); + g_idle_add(displayPluginBrightnessIdler, plugin); + g_main_loop_run(loop); } TEST_F(displayPluginTest, setAutoBrightness) { - g_idle_add(displayPluginAutoBrightnessIdler, plugin); - g_main_loop_run(loop); + g_idle_add(displayPluginAutoBrightnessIdler, plugin); + g_main_loop_run(loop); } TEST_F(displayPluginTest, setAlwaysOn) { - g_idle_add(displayPluginAlwaysOnIdler, plugin); - g_main_loop_run(loop); + g_idle_add(displayPluginAlwaysOnIdler, plugin); + g_main_loop_run(loop); } TEST_F(displayPluginTest, setDenyPalmTouch) { - g_idle_add(displayPluginDenyPalmTouchIdler, plugin); - g_main_loop_run(loop); + g_idle_add(displayPluginDenyPalmTouchIdler, plugin); + g_main_loop_run(loop); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_integration.cpp b/tests/mdsp_test_integration.cpp index 7083400..5ead943 100644 --- a/tests/mdsp_test_integration.cpp +++ b/tests/mdsp_test_integration.cpp @@ -15,41 +15,41 @@ */ #include #include -#include #include +#include class IntegrationTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - handle = modes_connect(); - } + protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + handle = modes_connect(); + } - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - modes_disconnect(handle); - handle = NULL; - vconf_set_str("db/setting/menuscreen/package_name", "org.tizen.homescreen-efl"); - } + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + modes_disconnect(handle); + handle = NULL; + vconf_set_str("db/setting/menuscreen/package_name", "org.tizen.homescreen-efl"); + } - static gboolean check_mode_idler(gpointer data) - { - modes_undo_mode(handle, (const char*)data); - result = modes_apply_mode(handle, (const char*)data); - EXPECT_EQ(MODES_ERROR_NONE, result); - sleep(2); - result = modes_undo_mode(handle, (const char*)data); + static gboolean check_mode_idler(gpointer data) + { + modes_undo_mode(handle, (const char *)data); + result = modes_apply_mode(handle, (const char *)data); + EXPECT_EQ(MODES_ERROR_NONE, result); + sleep(2); + result = modes_undo_mode(handle, (const char *)data); - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } - static modes_h handle; - static int result; - static GMainLoop *loop; + static modes_h handle; + static int result; + static GMainLoop *loop; }; int IntegrationTest::result = 0; @@ -58,55 +58,55 @@ modes_h IntegrationTest::handle = NULL; TEST_F(IntegrationTest, runMode_btAudioConnect) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.btAudioConnect"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.btAudioConnect"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(IntegrationTest, runMode_btOff) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.btOff"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.btOff"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(IntegrationTest, runMode_btOn) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.btOn"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.btOn"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(IntegrationTest, runMode_powerSave) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.Power-Save"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.Power-Save"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(IntegrationTest, runMode_displayBlock) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.displayBlock"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.displayBlock"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(IntegrationTest, runMode_wifiOn) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.wifi-on"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.wifi-on"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } TEST_F(IntegrationTest, runMode_waterlock) { - g_idle_add(check_mode_idler, (gpointer)"http://tizen.org/mode/example.Water-Lock"); - g_main_loop_run(loop); - EXPECT_EQ(MODES_ERROR_NONE, result); + g_idle_add(check_mode_idler, (gpointer) "http://tizen.org/mode/example.Water-Lock"); + g_main_loop_run(loop); + EXPECT_EQ(MODES_ERROR_NONE, result); } int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_media.cpp b/tests/mdsp_test_media.cpp index 31d8b45..8f3c796 100644 --- a/tests/mdsp_test_media.cpp +++ b/tests/mdsp_test_media.cpp @@ -13,130 +13,133 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include #include -#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class MediaPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } - - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean mediaPlaySetUndoTimeout(gpointer data) - { - PluginAction *action = (PluginAction*)data; - action->undo(); - g_main_loop_quit(loop); - return false; - } - - static gboolean mediaPlaySetUndoIdler(gpointer data) - { - 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); - - if (MODES_ERROR_NONE == result) - g_timeout_add(1000, mediaPlaySetUndoTimeout, action); - else - g_main_loop_quit(loop); - - return G_SOURCE_REMOVE; - } - - static gboolean VolumeSetUndoIdler(gpointer data) - { - PluginAction *action; - action = plugin->newAction("mediaVolume"); - EXPECT_FALSE(action->IsCurrentValue(5)); - result = action->set(5); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("systemVolume"); - EXPECT_FALSE(action->IsCurrentValue(2)); - result = action->set(2); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("ringtoneVolume"); - EXPECT_FALSE(action->IsCurrentValue(9)); - result = action->set(9); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("notificationVolume"); - EXPECT_FALSE(action->IsCurrentValue(1)); - result = action->set(1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("mediaVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("systemVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("ringtoneVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - action = plugin->newAction("notificationVolume"); - EXPECT_FALSE(action->IsCurrentValue(-1)); - result = action->set(-1); - EXPECT_EQ(MODES_ERROR_NONE, result); - action->undo(); - plugin->deleteAction(action); - - g_main_loop_quit(loop); - - return G_SOURCE_REMOVE; - } - - static int result; - static GMainLoop *loop; - static Plugin *plugin; + protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } + + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean mediaPlaySetUndoTimeout(gpointer data) + { + PluginAction *action = (PluginAction *)data; + action->undo(); + g_main_loop_quit(loop); + return false; + } + + static gboolean mediaPlaySetUndoIdler(gpointer data) + { + 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); + + if (MODES_ERROR_NONE == result) + g_timeout_add(1000, mediaPlaySetUndoTimeout, action); + else + g_main_loop_quit(loop); + + return G_SOURCE_REMOVE; + } + + static gboolean VolumeSetUndoIdler(gpointer data) + { + PluginAction *action; + action = plugin->newAction("mediaVolume"); + EXPECT_FALSE(action->IsCurrentValue(5)); + result = action->set(5); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("systemVolume"); + EXPECT_FALSE(action->IsCurrentValue(2)); + result = action->set(2); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("ringtoneVolume"); + EXPECT_FALSE(action->IsCurrentValue(9)); + result = action->set(9); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("notificationVolume"); + EXPECT_FALSE(action->IsCurrentValue(1)); + result = action->set(1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("mediaVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("systemVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("ringtoneVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + action = plugin->newAction("notificationVolume"); + EXPECT_FALSE(action->IsCurrentValue(-1)); + result = action->set(-1); + EXPECT_EQ(MODES_ERROR_NONE, result); + action->undo(); + plugin->deleteAction(action); + + g_main_loop_quit(loop); + + return G_SOURCE_REMOVE; + } + + static int result; + static GMainLoop *loop; + static Plugin *plugin; }; int MediaPluginTest::result = 0; @@ -145,19 +148,20 @@ GMainLoop *MediaPluginTest::loop = nullptr; TEST_F(MediaPluginTest, setUndoMediaPlay) { - PluginAction *action = plugin->newAction("player"); - g_idle_add(mediaPlaySetUndoIdler, action); - g_main_loop_run(loop); - plugin->deleteAction(action); + 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, NULL); - g_main_loop_run(loop); + g_idle_add(VolumeSetUndoIdler, NULL); + g_main_loop_run(loop); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_pkg.cpp b/tests/mdsp_test_pkg.cpp index f0c3f69..99e0d7b 100644 --- a/tests/mdsp_test_pkg.cpp +++ b/tests/mdsp_test_pkg.cpp @@ -13,66 +13,69 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include #include #include -#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class PkgPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } + protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - vconf_set_str("db/setting/menuscreen/package_name", "org.tizen.homescreen-efl"); - } + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + vconf_set_str("db/setting/menuscreen/package_name", "org.tizen.homescreen-efl"); + } - static gboolean pkgPluginIdler(gpointer data) - { - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } + static gboolean pkgPluginIdler(gpointer data) + { + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } - static int result; - static GMainLoop *loop; - Plugin *plugin; + static int result; + static GMainLoop *loop; + Plugin *plugin; }; GMainLoop *PkgPluginTest::loop = NULL; TEST_F(PkgPluginTest, setUndoTest) { - PluginAction *action = plugin->newAction("supportMode"); - EXPECT_FALSE(action->IsCurrentValue(1)); - int ret = action->set(1); - EXPECT_EQ(MODES_ERROR_NONE, ret); + 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); + g_idle_add(pkgPluginIdler, plugin); + g_main_loop_run(loop); - action->undo(); + action->undo(); - g_idle_add(pkgPluginIdler, plugin); - g_main_loop_run(loop); - plugin->deleteAction(action); + g_idle_add(pkgPluginIdler, plugin); + g_main_loop_run(loop); + plugin->deleteAction(action); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_std.cpp b/tests/mdsp_test_std.cpp index 3bb41eb..657fb38 100644 --- a/tests/mdsp_test_std.cpp +++ b/tests/mdsp_test_std.cpp @@ -13,48 +13,50 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include #include -#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class StdPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - loop = g_main_loop_new(NULL, FALSE); - plugin = objectCreate(); - } + protected: + void SetUp() override + { + loop = g_main_loop_new(NULL, FALSE); + plugin = objectCreate(); + } - void TearDown() override - { - g_main_loop_unref(loop); - loop = NULL; - objectDelete(plugin); - plugin = nullptr; - } + void TearDown() override + { + g_main_loop_unref(loop); + loop = NULL; + objectDelete(plugin); + plugin = nullptr; + } - static void changedCB(void *userData) - { - result = true; - g_main_loop_quit(loop); - } + static void changedCB(void *userData) + { + result = true; + g_main_loop_quit(loop); + } - static gboolean exitIdler(gpointer data) - { - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } + static gboolean exitIdler(gpointer data) + { + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } - static bool result; - static GMainLoop *loop; - static Plugin *plugin; + static bool result; + static GMainLoop *loop; + static Plugin *plugin; }; bool StdPluginTest::result = 0; @@ -63,37 +65,37 @@ GMainLoop *StdPluginTest::loop = nullptr; TEST_F(StdPluginTest, IsCurrentValue) { - PluginAction *action = plugin->newAction("timeout.seconds"); - EXPECT_FALSE(action->IsCurrentValue(3)); - plugin->deleteAction(action); + PluginAction *action = plugin->newAction("timeout.seconds"); + EXPECT_FALSE(action->IsCurrentValue(3)); + plugin->deleteAction(action); } TEST_F(StdPluginTest, setTimeoutSeconds) { - result = false; - PluginAction *action = plugin->newAction("timeout.seconds"); - action->set(1); - action->setChangedCallback(changedCB, nullptr); - g_main_loop_run(loop); - EXPECT_TRUE(result); - plugin->deleteAction(action); + result = false; + PluginAction *action = plugin->newAction("timeout.seconds"); + action->set(1); + action->setChangedCallback(changedCB, nullptr); + g_main_loop_run(loop); + EXPECT_TRUE(result); + plugin->deleteAction(action); } TEST_F(StdPluginTest, undoTimeoutSeconds) { - result = false; - PluginAction *action = plugin->newAction("timeout.seconds"); - action->set(1); - action->setChangedCallback(changedCB, nullptr); - action->undo(); - g_idle_add(exitIdler, nullptr); - g_main_loop_run(loop); - EXPECT_FALSE(result); - plugin->deleteAction(action); + result = false; + PluginAction *action = plugin->newAction("timeout.seconds"); + action->set(1); + action->setChangedCallback(changedCB, nullptr); + action->undo(); + g_idle_add(exitIdler, nullptr); + g_main_loop_run(loop); + EXPECT_FALSE(result); + plugin->deleteAction(action); } int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_vconf.cpp b/tests/mdsp_test_vconf.cpp index 1a393c9..7d9a848 100644 --- a/tests/mdsp_test_vconf.cpp +++ b/tests/mdsp_test_vconf.cpp @@ -13,78 +13,79 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include #include -#include -#include "plugin-log.h" +#include + #include "plugin-def.h" +#include "plugin-log.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 { -protected: - void SetUp() override - { - plugin = objectCreate(); - loop = g_main_loop_new(NULL, FALSE); - } - - void TearDown() override - { - objectDelete(plugin); - g_main_loop_unref(loop); - loop = NULL; - cb1Called = false; - cb2Called = false; - } - - static void shouldNotBeCalled(void *userData) - { - ERR("This Callback(%s) should not be called", (char*)userData); - g_main_loop_quit(loop); - GTEST_FAIL(); - } - - static void valChangedCb(void *userData) - { - DBG("%s changed callback called!", (char*)userData); - g_main_loop_quit(loop); - } - - static void callback1(void *userData) - { - PluginAction *action = (PluginAction*)userData; - ASSERT_TRUE(nullptr != action); - DBG("%s changed callback called!", action->getKey().c_str()); - - //In practice, it is handled by Action. refer to Action.cpp - action->unSetChangedCallback(callback1); - - cb1Called = true; - } - - static void callback2(void *userData) - { - DBG("%s changed callback called!", (char*)userData); - cb2Called = true; - g_main_loop_quit(loop); - } - - static gboolean changedCallbackidler(gpointer data) - { - DBG("start change the value db/setting/psmode"); - vconf_set_int("db/setting/psmode", 7); - return G_SOURCE_REMOVE; - } - - static GMainLoop *loop; - static Plugin *plugin; - static bool cb1Called; - static bool cb2Called; + protected: + void SetUp() override + { + plugin = objectCreate(); + loop = g_main_loop_new(NULL, FALSE); + } + + void TearDown() override + { + objectDelete(plugin); + g_main_loop_unref(loop); + loop = NULL; + cb1Called = false; + cb2Called = false; + } + + static void shouldNotBeCalled(void *userData) + { + ERR("This Callback(%s) should not be called", (char *)userData); + g_main_loop_quit(loop); + GTEST_FAIL(); + } + + static void valChangedCb(void *userData) + { + DBG("%s changed callback called!", (char *)userData); + g_main_loop_quit(loop); + } + + static void callback1(void *userData) + { + PluginAction *action = (PluginAction *)userData; + ASSERT_TRUE(nullptr != action); + DBG("%s changed callback called!", action->getKey().c_str()); + + // In practice, it is handled by Action. refer to Action.cpp + action->unSetChangedCallback(callback1); + + cb1Called = true; + } + + static void callback2(void *userData) + { + DBG("%s changed callback called!", (char *)userData); + cb2Called = true; + g_main_loop_quit(loop); + } + + static gboolean changedCallbackidler(gpointer data) + { + DBG("start change the value db/setting/psmode"); + vconf_set_int("db/setting/psmode", 7); + return G_SOURCE_REMOVE; + } + + static GMainLoop *loop; + static Plugin *plugin; + static bool cb1Called; + static bool cb2Called; }; bool VconfPluginTest::cb1Called = false; @@ -92,114 +93,116 @@ bool VconfPluginTest::cb2Called = false; Plugin *VconfPluginTest::plugin = nullptr; GMainLoop *VconfPluginTest::loop = NULL; - TEST_F(VconfPluginTest, VconfInt) { - int ret; - const char *key = "db.setting.psmode"; + int ret; + const char *key = "db.setting.psmode"; - PluginAction *action = plugin->newAction(key);; - ASSERT_TRUE(nullptr != action); + PluginAction *action = plugin->newAction(key); + ; + ASSERT_TRUE(nullptr != action); - ret = action->set(0); - EXPECT_EQ(ret, MODES_ERROR_NONE); + ret = action->set(0); + EXPECT_EQ(ret, MODES_ERROR_NONE); - EXPECT_FALSE(action->IsCurrentValue(1)); - ret = action->set(1); - EXPECT_EQ(ret, MODES_ERROR_NONE); + EXPECT_FALSE(action->IsCurrentValue(1)); + ret = action->set(1); + EXPECT_EQ(ret, MODES_ERROR_NONE); - action->undo(); - plugin->deleteAction(action); + action->undo(); + plugin->deleteAction(action); } TEST_F(VconfPluginTest, VconfDouble) { - int ret; - const char *key = "db.system.timechange_external"; + int ret; + const char *key = "db.system.timechange_external"; - PluginAction *action = plugin->newAction(key); - ASSERT_TRUE(nullptr != action); + PluginAction *action = plugin->newAction(key); + ASSERT_TRUE(nullptr != action); - ret = action->set(0.0); - EXPECT_EQ(ret, MODES_ERROR_NONE); + ret = action->set(0.0); + EXPECT_EQ(ret, MODES_ERROR_NONE); - EXPECT_FALSE(action->IsCurrentValue(1.0)); - ret = action->set(1.0); - EXPECT_EQ(ret, MODES_ERROR_NONE); + EXPECT_FALSE(action->IsCurrentValue(1.0)); + ret = action->set(1.0); + EXPECT_EQ(ret, MODES_ERROR_NONE); - action->undo(); - plugin->deleteAction(action); + action->undo(); + plugin->deleteAction(action); } TEST_F(VconfPluginTest, VconfBool) { - int ret; - const char *key = "db.setting.sound.sound_on"; + int ret; + const char *key = "db.setting.sound.sound_on"; - PluginAction *action = plugin->newAction(key);; - ASSERT_TRUE(nullptr != action); + PluginAction *action = plugin->newAction(key); + ; + ASSERT_TRUE(nullptr != action); - ret = action->set(true); - EXPECT_EQ(ret, MODES_ERROR_NONE); + ret = action->set(true); + EXPECT_EQ(ret, MODES_ERROR_NONE); - EXPECT_FALSE(action->IsCurrentValue(false)); - ret = action->set(false); - EXPECT_EQ(ret, MODES_ERROR_NONE); + EXPECT_FALSE(action->IsCurrentValue(false)); + ret = action->set(false); + EXPECT_EQ(ret, MODES_ERROR_NONE); - action->undo(); - plugin->deleteAction(action); + action->undo(); + plugin->deleteAction(action); } TEST_F(VconfPluginTest, VconfStr) { - int ret; - const char *key = "db.setting.device_name"; - const std::string devName = "Tizen"; - const std::string tmpName = "ModesTest"; + int ret; + const char *key = "db.setting.device_name"; + const std::string devName = "Tizen"; + const std::string tmpName = "ModesTest"; - PluginAction *action = plugin->newAction(key); - ASSERT_TRUE(nullptr != action); + PluginAction *action = plugin->newAction(key); + ASSERT_TRUE(nullptr != action); - ret = action->set(devName); - EXPECT_EQ(ret, MODES_ERROR_NONE); + ret = action->set(devName); + EXPECT_EQ(ret, MODES_ERROR_NONE); - EXPECT_FALSE(action->IsCurrentValue(tmpName)); - ret = action->set(tmpName); - EXPECT_EQ(ret, MODES_ERROR_NONE); + EXPECT_FALSE(action->IsCurrentValue(tmpName)); + ret = action->set(tmpName); + EXPECT_EQ(ret, MODES_ERROR_NONE); - action->undo(); - plugin->deleteAction(action); + action->undo(); + plugin->deleteAction(action); } TEST_F(VconfPluginTest, callbackPluginVconf) { - int oldVal = 0; - const char *key = "db.setting.psmode"; - int ret = vconf_get_int("db/setting/psmode", &oldVal); - EXPECT_EQ(ret, 0); - - PluginAction *action = plugin->newAction(key); - ASSERT_TRUE(nullptr != action); - - ret = action->set(0); - EXPECT_EQ(ret, MODES_ERROR_NONE); - - ret = action->setChangedCallback(valChangedCb, (void*)key); - EXPECT_EQ(ret, MODES_ERROR_NONE); - g_idle_add(changedCallbackidler, nullptr); - g_main_loop_run(loop); - - // It should be removed by the changed callback procedure. - action->unSetChangedCallback(valChangedCb); - - ret = action->setChangedCallback(shouldNotBeCalled, (void*)key); - EXPECT_EQ(ret, MODES_ERROR_NONE); - action->unSetChangedCallback(shouldNotBeCalled); - plugin->deleteAction(action); - vconf_set_int("db/setting/psmode", oldVal); + int oldVal = 0; + const char *key = "db.setting.psmode"; + int ret = vconf_get_int("db/setting/psmode", &oldVal); + EXPECT_EQ(ret, 0); + + PluginAction *action = plugin->newAction(key); + ASSERT_TRUE(nullptr != action); + + ret = action->set(0); + EXPECT_EQ(ret, MODES_ERROR_NONE); + + ret = action->setChangedCallback(valChangedCb, (void *)key); + EXPECT_EQ(ret, MODES_ERROR_NONE); + g_idle_add(changedCallbackidler, nullptr); + g_main_loop_run(loop); + + // It should be removed by the changed callback procedure. + action->unSetChangedCallback(valChangedCb); + + ret = action->setChangedCallback(shouldNotBeCalled, (void *)key); + EXPECT_EQ(ret, MODES_ERROR_NONE); + action->unSetChangedCallback(shouldNotBeCalled); + plugin->deleteAction(action); + vconf_set_int("db/setting/psmode", oldVal); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/tests/mdsp_test_wifi.cpp b/tests/mdsp_test_wifi.cpp index 76ae3f8..513f470 100644 --- a/tests/mdsp_test_wifi.cpp +++ b/tests/mdsp_test_wifi.cpp @@ -13,83 +13,83 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include #include -#include #include -#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_USE; -extern "C" Plugin* objectCreate(void); +extern "C" Plugin *objectCreate(void); extern "C" void objectDelete(Plugin *plugin); class WifiPluginTest : public ::testing::Test { -protected: - void SetUp() override - { - plugin = objectCreate(); - } - - void TearDown() override - { - objectDelete(plugin); - plugin = nullptr; - } - - static gboolean timer(gpointer data) - { - GMainLoop *loop = (GMainLoop*)data; - g_main_loop_quit(loop); - return G_SOURCE_REMOVE; - } - - Plugin *plugin; + protected: + void SetUp() override { plugin = objectCreate(); } + + void TearDown() override + { + objectDelete(plugin); + plugin = nullptr; + } + + static gboolean timer(gpointer data) + { + GMainLoop *loop = (GMainLoop *)data; + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + Plugin *plugin; }; TEST_F(WifiPluginTest, wifiTest) { - int ret; + int ret; - ASSERT_TRUE(nullptr != plugin); + ASSERT_TRUE(nullptr != plugin); - bool val; - PluginAction *action = plugin->newAction("power"); - val = action->IsCurrentValue(false); - ret = action->set(val); - EXPECT_EQ(ret, MODES_ERROR_NONE); + bool val; + PluginAction *action = plugin->newAction("power"); + val = action->IsCurrentValue(false); + ret = action->set(val); + EXPECT_EQ(ret, MODES_ERROR_NONE); - GMainLoop *loop = g_main_loop_new(NULL, FALSE); - g_timeout_add(1000, timer, (gpointer)loop); - g_main_loop_run(loop); + 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 = action->set(!val); + EXPECT_EQ(ret, MODES_ERROR_NONE); - ret = action->set(0); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + ret = action->set(0); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - ret = action->set(1); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + ret = action->set(1); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - ret = action->set(0.0); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + ret = action->set(0.0); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - ret = action->set(1.0); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + ret = action->set(1.0); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - ret = action->set(std::string("off")); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + ret = action->set(std::string("off")); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - ret = action->set(std::string("on")); - EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); - plugin->deleteAction(action); + ret = action->set(std::string("on")); + EXPECT_EQ(ret, MODES_ERROR_NOT_SUPPORTED); + plugin->deleteAction(action); - action = plugin->newAction("abcdefg"); - EXPECT_EQ(action, nullptr); + action = plugin->newAction("abcdefg"); + EXPECT_EQ(action, nullptr); } -int main(int argc, char **argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); } diff --git a/vconf/VconfBool.cpp b/vconf/VconfBool.cpp index 9a39f26..a2b5c45 100644 --- a/vconf/VconfBool.cpp +++ b/vconf/VconfBool.cpp @@ -15,119 +15,126 @@ */ #include "VconfBool.h" -#include -#include #include + +#include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; VconfBool::VconfBool(const std::string &vconfKey) - : PluginAction("boolVconf"), key(vconfKey), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr) + : PluginAction("boolVconf"), + key(vconfKey), + requestVal(false), + oldVal(false), + cb(nullptr), + cbData(nullptr) { } bool VconfBool::IsCurrentValue(bool val) { - 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 false; - } - oldVal = tmp; - - if (oldVal == val) { - INFO("vconf(%s) already set(%d)", key.c_str(), val); - return true; - } - - return false; + 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 false; + } + oldVal = tmp; + + if (oldVal == val) { + INFO("vconf(%s) already set(%d)", key.c_str(), val); + return true; + } + + return false; } int VconfBool::set(bool val) { - requestVal = 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; - } + 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; + return MODES_ERROR_NONE; } 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); + 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 VconfBool::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int VconfBool::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int VconfBool::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - 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; - } + 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; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void VconfBool::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - 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; - } + 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; + cbData = nullptr; + cb = nullptr; } void VconfBool::changedCB(keynode_t *node) { - const char *vconfKey = vconf_keynode_get_name(node); - if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { - WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); - return; - } - - int val = vconf_keynode_get_bool(node); - if (cb && (val != requestVal)) - cb(cbData); + const char *vconfKey = vconf_keynode_get_name(node); + if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { + WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); + return; + } + + 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); + RET_IF(nullptr == userData); - VconfBool *action = (VconfBool*)userData; - action->changedCB(node); + VconfBool *action = (VconfBool *)userData; + action->changedCB(node); } diff --git a/vconf/VconfBool.h b/vconf/VconfBool.h index f6a9d5e..60f5919 100644 --- a/vconf/VconfBool.h +++ b/vconf/VconfBool.h @@ -15,33 +15,36 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class VconfBool : public PluginAction { -public: - VconfBool(const std::string &vconfKey); - - bool IsCurrentValue(bool val) override; - int set(bool val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; -private: - void changedCB(keynode_t *node); - static void vconfChangedCB(keynode_t *node, void *userData); - - std::string key; - bool requestVal; - bool oldVal; - valueChangedCB cb; - void *cbData; + public: + VconfBool(const std::string &vconfKey); + + bool IsCurrentValue(bool val) override; + int set(bool val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + private: + void changedCB(keynode_t *node); + static void vconfChangedCB(keynode_t *node, void *userData); + + std::string key; + bool requestVal; + bool oldVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/vconf/VconfDbl.cpp b/vconf/VconfDbl.cpp index 1166835..e1d9f91 100644 --- a/vconf/VconfDbl.cpp +++ b/vconf/VconfDbl.cpp @@ -15,117 +15,124 @@ */ #include "VconfDbl.h" -#include -#include #include + +#include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; VconfDbl::VconfDbl(const std::string &vconfKey) - : PluginAction("dblVconf"), key(vconfKey), requestVal(0.0), oldVal(0.0), cb(nullptr), cbData(nullptr) + : PluginAction("dblVconf"), + key(vconfKey), + requestVal(0.0), + oldVal(0.0), + cb(nullptr), + cbData(nullptr) { } bool VconfDbl::IsCurrentValue(double val) { - int ret = vconf_get_dbl(key.c_str(), &oldVal); - if (0 != ret) { - ERR("vconf_get_dbl(%s) Fail(%d)", key.c_str(), ret); - return false; - } - - if (oldVal == val) { - INFO("vconf(%s) already set(%f)", key.c_str(), val); - return true; - } - - return false; + int ret = vconf_get_dbl(key.c_str(), &oldVal); + if (0 != ret) { + ERR("vconf_get_dbl(%s) Fail(%d)", key.c_str(), ret); + return false; + } + + if (oldVal == val) { + INFO("vconf(%s) already set(%f)", key.c_str(), val); + return true; + } + + return false; } int VconfDbl::set(double val) { - requestVal = 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; - } + 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; + return MODES_ERROR_NONE; } 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); + 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 VconfDbl::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int VconfDbl::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int VconfDbl::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - 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; - } + 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; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void VconfDbl::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - 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; - } + 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; + cbData = nullptr; + cb = nullptr; } void VconfDbl::changedCB(keynode_t *node) { - const char *vconfKey = vconf_keynode_get_name(node); - if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { - WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); - return; - } - - double val = vconf_keynode_get_dbl(node); - if (cb && (val != requestVal)) - cb(cbData); + const char *vconfKey = vconf_keynode_get_name(node); + if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { + WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); + return; + } + + double val = vconf_keynode_get_dbl(node); + if (cb && (val != requestVal)) + cb(cbData); } void VconfDbl::vconfChangedCB(keynode_t *node, void *userData) { - RET_IF(nullptr == userData); + RET_IF(nullptr == userData); - VconfDbl *action = (VconfDbl*)userData; - action->changedCB(node); + VconfDbl *action = (VconfDbl *)userData; + action->changedCB(node); } diff --git a/vconf/VconfDbl.h b/vconf/VconfDbl.h index 4e38641..9c6f5d0 100644 --- a/vconf/VconfDbl.h +++ b/vconf/VconfDbl.h @@ -15,33 +15,36 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class VconfDbl : public PluginAction { -public: - VconfDbl(const std::string &vconfKey); - - bool IsCurrentValue(double val) override; - int set(double val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; -private: - void changedCB(keynode_t *node); - static void vconfChangedCB(keynode_t *node, void *userData); - - std::string key; - double requestVal; - double oldVal; - valueChangedCB cb; - void *cbData; + public: + VconfDbl(const std::string &vconfKey); + + bool IsCurrentValue(double val) override; + int set(double val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + private: + void changedCB(keynode_t *node); + static void vconfChangedCB(keynode_t *node, void *userData); + + std::string key; + double requestVal; + double oldVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/vconf/VconfFactory.cpp b/vconf/VconfFactory.cpp index de8b52f..2a0c00c 100644 --- a/vconf/VconfFactory.cpp +++ b/vconf/VconfFactory.cpp @@ -16,48 +16,51 @@ #include "VconfFactory.h" #include -#include "plugin-log.h" + #include "VconfBool.h" #include "VconfDbl.h" #include "VconfInt.h" #include "VconfStr.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; -template PluginAction* newVconf(const std::string &key) +template +PluginAction *newVconf(const std::string &key) { - return new T(key); + return new T(key); } VconfFactory::VconfFactory() { - actionMap["db.setting.psmode"] = &newVconf; - actionMap["db.setting.sound.sound_on"] = &newVconf; - actionMap["db.setting.sound.vibration_on"] = &newVconf; - actionMap["db.location.setting.Usemylocation"] = &newVconf; - actionMap["db.setting.auto_rotate_screen"] = &newVconf; - actionMap["db.setting.menuscreen.package_name"] = &newVconf; + actionMap["db.setting.psmode"] = &newVconf; + actionMap["db.setting.sound.sound_on"] = &newVconf; + actionMap["db.setting.sound.vibration_on"] = &newVconf; + actionMap["db.location.setting.Usemylocation"] = &newVconf; + actionMap["db.setting.auto_rotate_screen"] = &newVconf; + actionMap["db.setting.menuscreen.package_name"] = &newVconf; #ifdef MDS_TEST - actionMap["db.system.timechange_external"] = &newVconf; - actionMap["db.setting.device_name"] = &newVconf; + actionMap["db.system.timechange_external"] = &newVconf; + actionMap["db.setting.device_name"] = &newVconf; #endif } -PluginAction* VconfFactory::createAction(const std::string &key) +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; - } + 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(), '.', '/'); + std::string newKey(key); + std::replace(newKey.begin(), newKey.end(), '.', '/'); - return found->second(newKey);; + return found->second(newKey); + ; } void VconfFactory::destroyAction(PluginAction *action) { - delete action; + delete action; } diff --git a/vconf/VconfFactory.h b/vconf/VconfFactory.h index cefc6d8..0f4360d 100644 --- a/vconf/VconfFactory.h +++ b/vconf/VconfFactory.h @@ -15,22 +15,25 @@ */ #pragma once +#include + #include #include -#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class VconfFactory { -public: - VconfFactory(); - ~VconfFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - std::map actionMap; + public: + VconfFactory(); + ~VconfFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/vconf/VconfInt.cpp b/vconf/VconfInt.cpp index 7855bdf..0108eae 100644 --- a/vconf/VconfInt.cpp +++ b/vconf/VconfInt.cpp @@ -15,117 +15,124 @@ */ #include "VconfInt.h" -#include -#include #include + +#include +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; VconfInt::VconfInt(const std::string &vconfKey) - : PluginAction("intVconf"), key(vconfKey), requestVal(0), oldVal(0), cb(nullptr), cbData(nullptr) + : PluginAction("intVconf"), + key(vconfKey), + requestVal(0), + oldVal(0), + cb(nullptr), + cbData(nullptr) { } bool VconfInt::IsCurrentValue(int val) { - int ret = vconf_get_int(key.c_str(), &oldVal); - if (0 != ret) { - ERR("vconf_get_int(%s) Fail(%d)", key.c_str(), ret); - return false; - } - - if (oldVal == val) { - INFO("vconf(%s) already set(%d)", key.c_str(), val); - return true; - } - - return false; + int ret = vconf_get_int(key.c_str(), &oldVal); + if (0 != ret) { + ERR("vconf_get_int(%s) Fail(%d)", key.c_str(), ret); + return false; + } + + if (oldVal == val) { + INFO("vconf(%s) already set(%d)", key.c_str(), val); + return true; + } + + return false; } int VconfInt::set(int val) { - requestVal = 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; - } + 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; + return MODES_ERROR_NONE; } 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); + 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 VconfInt::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int VconfInt::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int VconfInt::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - 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; - } + 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; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void VconfInt::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - 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; - } + 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; + cbData = nullptr; + cb = nullptr; } void VconfInt::changedCB(keynode_t *node) { - const char *vconfKey = vconf_keynode_get_name(node); - if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { - WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); - return; - } - - int val = vconf_keynode_get_int(node); - if (cb && (val != requestVal)) - cb(cbData); + const char *vconfKey = vconf_keynode_get_name(node); + if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { + WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); + return; + } + + int val = vconf_keynode_get_int(node); + if (cb && (val != requestVal)) + cb(cbData); } void VconfInt::vconfChangedCB(keynode_t *node, void *userData) { - RET_IF(nullptr == userData); + RET_IF(nullptr == userData); - VconfInt *action = (VconfInt*)userData; - action->changedCB(node); + VconfInt *action = (VconfInt *)userData; + action->changedCB(node); } diff --git a/vconf/VconfInt.h b/vconf/VconfInt.h index 4da57d9..2ccd4e3 100644 --- a/vconf/VconfInt.h +++ b/vconf/VconfInt.h @@ -15,33 +15,36 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class VconfInt : public PluginAction { -public: - VconfInt(const std::string &vconfKey); - - bool IsCurrentValue(int val) override; - int set(int val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; -private: - void changedCB(keynode_t *node); - static void vconfChangedCB(keynode_t *node, void *userData); - - std::string key; - int requestVal; - int oldVal; - valueChangedCB cb; - void *cbData; + public: + VconfInt(const std::string &vconfKey); + + bool IsCurrentValue(int val) override; + int set(int val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + private: + void changedCB(keynode_t *node); + static void vconfChangedCB(keynode_t *node, void *userData); + + std::string key; + int requestVal; + int oldVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/vconf/VconfPlugin.cpp b/vconf/VconfPlugin.cpp index f531e0e..339a9b0 100644 --- a/vconf/VconfPlugin.cpp +++ b/vconf/VconfPlugin.cpp @@ -13,46 +13,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include "plugin-log.h" -#include "plugin-def.h" +#include + #include "VconfFactory.h" +#include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class VconfPlugin : public Plugin { -public: - VconfPlugin(); - ~VconfPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - VconfFactory vconfFactory; + public: + VconfPlugin(); + ~VconfPlugin() override = default; + + 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) { - delete plugin; + delete plugin; } VconfPlugin::VconfPlugin() { - setName("vconf"); + setName("vconf"); } -PluginAction* VconfPlugin::newAction(const std::string &key) +PluginAction *VconfPlugin::newAction(const std::string &key) { - return vconfFactory.createAction(key); + return vconfFactory.createAction(key); } void VconfPlugin::deleteAction(PluginAction *piAction) { - vconfFactory.destroyAction(piAction); + vconfFactory.destroyAction(piAction); } diff --git a/vconf/VconfStr.cpp b/vconf/VconfStr.cpp index ad17d4a..d04be34 100644 --- a/vconf/VconfStr.cpp +++ b/vconf/VconfStr.cpp @@ -15,112 +15,114 @@ */ #include "VconfStr.h" -#include #include + +#include + #include "plugin-log.h" MODES_NAMESPACE_USE; VconfStr::VconfStr(const std::string &vconfKey) - : PluginAction("strVconf"), key(vconfKey), cb(nullptr), cbData(nullptr) + : PluginAction("strVconf"), key(vconfKey), cb(nullptr), cbData(nullptr) { } bool VconfStr::IsCurrentValue(const std::string &val) { - char *prev = vconf_get_str(key.c_str()); - if (nullptr == prev) { - ERR("vconf_get_str(%s) Fail()", key.c_str()); - return false; - } - oldVal = prev; - free(prev); - - if (oldVal == val) { - INFO("vconf(%s) already set(%s)", key.c_str(), val.c_str()); - return true; - } - return false; + char *prev = vconf_get_str(key.c_str()); + if (nullptr == prev) { + ERR("vconf_get_str(%s) Fail()", key.c_str()); + return false; + } + oldVal = prev; + free(prev); + + if (oldVal == val) { + INFO("vconf(%s) already set(%s)", key.c_str(), val.c_str()); + return true; + } + return false; } int VconfStr::set(const std::string &val) { - requestVal = 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; - } + 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; + return MODES_ERROR_NONE; } 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); + 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 VconfStr::getUndoInfo() { - return oldVal; + return oldVal; } int VconfStr::setUndoInfo(const std::string &info) { - oldVal = info; - return MODES_ERROR_NONE; + oldVal = info; + return MODES_ERROR_NONE; } int VconfStr::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - 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; - } + 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; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void VconfStr::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - 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; - } + 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; + cbData = nullptr; + cb = nullptr; } -void VconfStr::changedCB(keynode_t * node) +void VconfStr::changedCB(keynode_t *node) { - const char *vconfKey = vconf_keynode_get_name(node); - if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { - WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); - return; - } - - char *val = vconf_keynode_get_str(node); - if (cb && val && (val != requestVal)) - cb(cbData); + const char *vconfKey = vconf_keynode_get_name(node); + if (nullptr == vconfKey || MDSP_EQUAL != strcmp(key.c_str(), vconfKey)) { + WARN("Unknown vconf(%s) notification", vconfKey ? vconfKey : "NULL"); + return; + } + + char *val = vconf_keynode_get_str(node); + if (cb && val && (val != requestVal)) + cb(cbData); } void VconfStr::vconfChangedCB(keynode_t *node, void *userData) { - RET_IF(nullptr == userData); + RET_IF(nullptr == userData); - VconfStr *action = (VconfStr*)userData; - action->changedCB(node); + VconfStr *action = (VconfStr *)userData; + action->changedCB(node); } diff --git a/vconf/VconfStr.h b/vconf/VconfStr.h index f0bb1f1..37a5f66 100644 --- a/vconf/VconfStr.h +++ b/vconf/VconfStr.h @@ -15,34 +15,36 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class VconfStr : public PluginAction { -public: - VconfStr(const std::string &vconfKey); - - bool IsCurrentValue(const std::string &val) override; - int set(const std::string &val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; -private: - void changedCB(keynode_t *node); - static void vconfChangedCB(keynode_t *node, void *userData); - - std::string key; - std::string requestVal; - std::string oldVal; - valueChangedCB cb; - void *cbData; + public: + VconfStr(const std::string &vconfKey); + + bool IsCurrentValue(const std::string &val) override; + int set(const std::string &val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + private: + void changedCB(keynode_t *node); + static void vconfChangedCB(keynode_t *node, void *userData); + + std::string key; + std::string requestVal; + std::string oldVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END - diff --git a/wifi/WifiAction.cpp b/wifi/WifiAction.cpp index fb01d25..b9d4189 100644 --- a/wifi/WifiAction.cpp +++ b/wifi/WifiAction.cpp @@ -15,20 +15,19 @@ */ #include "WifiAction.h" -#include "plugin-log.h" #include "plugin-def.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; -WifiAction::WifiAction(const std::string &name) - : PluginAction(name), handle(NULL) +WifiAction::WifiAction(const std::string &name) : PluginAction(name), handle(NULL) { - int ret = wifi_manager_initialize(&handle); - if (WIFI_MANAGER_ERROR_NONE != ret) - ERR("wifi_manager_initialize() Fail(%s)", get_error_message(ret)); + int ret = wifi_manager_initialize(&handle); + if (WIFI_MANAGER_ERROR_NONE != ret) + ERR("wifi_manager_initialize() Fail(%s)", get_error_message(ret)); } WifiAction::~WifiAction() { - wifi_manager_deinitialize(handle); + wifi_manager_deinitialize(handle); } diff --git a/wifi/WifiAction.h b/wifi/WifiAction.h index da057fc..d3b0da9 100644 --- a/wifi/WifiAction.h +++ b/wifi/WifiAction.h @@ -15,21 +15,22 @@ */ #pragma once -#include -#include #include +#include + +#include + #include "plugin-def.h" MODES_NAMESPACE_BEGIN class WifiAction : public PluginAction { -public: - WifiAction(const std::string &name); - ~WifiAction(); + public: + WifiAction(const std::string &name); + ~WifiAction(); -protected: - wifi_manager_h handle; + protected: + wifi_manager_h handle; }; MODES_NAMESPACE_END - diff --git a/wifi/WifiActionPower.cpp b/wifi/WifiActionPower.cpp index f5d18b4..f0afd9b 100644 --- a/wifi/WifiActionPower.cpp +++ b/wifi/WifiActionPower.cpp @@ -16,6 +16,7 @@ #include "WifiActionPower.h" #include + #include "plugin-log.h" MODES_NAMESPACE_USE; @@ -23,126 +24,125 @@ MODES_NAMESPACE_USE; const std::string WifiActionPower::NAME = "power"; WifiActionPower::WifiActionPower() - : WifiAction(NAME), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr) + : WifiAction(NAME), requestVal(false), oldVal(false), cb(nullptr), cbData(nullptr) { } bool WifiActionPower::IsCurrentValue(bool val) { - wifi_manager_is_activated(handle, &oldVal); - if (oldVal == val) { - INFO("Already wifi is [%s]", val ? "On" : "Off"); - return true; - } + wifi_manager_is_activated(handle, &oldVal); + if (oldVal == val) { + INFO("Already wifi is [%s]", val ? "On" : "Off"); + return true; + } - return false; + 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) { - ERR("wifi_manager_activate() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - } else { - int ret = wifi_manager_deactivate(handle, deactivateCB, this); - if (WIFI_MANAGER_ERROR_NONE != ret) { - ERR("wifi_manager_deactivate() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } - } - - INFO("Wifi power [%s]", val ? "On" : "Off"); - return MODES_ERROR_NONE; + requestVal = val; + + if (val) { + int ret = wifi_manager_activate(handle, activateCB, this); + if (WIFI_MANAGER_ERROR_NONE != ret) { + ERR("wifi_manager_activate() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + } else { + int ret = wifi_manager_deactivate(handle, deactivateCB, this); + if (WIFI_MANAGER_ERROR_NONE != ret) { + ERR("wifi_manager_deactivate() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } + } + + INFO("Wifi power [%s]", val ? "On" : "Off"); + return MODES_ERROR_NONE; } void WifiActionPower::undo() { - set(oldVal); + set(oldVal); } std::string WifiActionPower::getUndoInfo() { - std::ostringstream ostr; + std::ostringstream ostr; - ostr << oldVal; - return ostr.str(); + ostr << oldVal; + return ostr.str(); } int WifiActionPower::setUndoInfo(const std::string &info) { - std::istringstream iss(info); - iss >> oldVal; + std::istringstream iss(info); + iss >> oldVal; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } int WifiActionPower::setChangedCallback(valueChangedCB callback, void *userData) { - RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); - int ret = wifi_manager_set_device_state_changed_cb(handle, wifiStateChangedCB, this); - if (WIFI_MANAGER_ERROR_NONE != ret) { - ERR("wifi_manager_set_device_state_changed_cb() Fail(%s)", get_error_message(ret)); - return MODES_ERROR_SYSTEM; - } + int ret = wifi_manager_set_device_state_changed_cb(handle, wifiStateChangedCB, this); + if (WIFI_MANAGER_ERROR_NONE != ret) { + ERR("wifi_manager_set_device_state_changed_cb() Fail(%s)", get_error_message(ret)); + return MODES_ERROR_SYSTEM; + } - cb = callback; - cbData = userData; + cb = callback; + cbData = userData; - return MODES_ERROR_NONE; + return MODES_ERROR_NONE; } void WifiActionPower::unSetChangedCallback(valueChangedCB callback) { - RET_IF(nullptr == callback); + RET_IF(nullptr == callback); - int ret = wifi_manager_unset_device_state_changed_cb(handle); - if (WIFI_MANAGER_ERROR_NONE != ret) { - ERR("wifi_manager_unset_device_state_changed_cb() Fail(%s)", - get_error_message(ret)); - } + int ret = wifi_manager_unset_device_state_changed_cb(handle); + if (WIFI_MANAGER_ERROR_NONE != ret) { + ERR("wifi_manager_unset_device_state_changed_cb() Fail(%s)", get_error_message(ret)); + } - cb = nullptr; - cbData = nullptr; + cb = nullptr; + cbData = nullptr; } void WifiActionPower::activateCB(wifi_manager_error_e result, void *user_data) { - INFO("wifi Activated"); - if (WIFI_MANAGER_ERROR_NONE != result) { - ERR("activateCB() Fail(%s)", get_error_message(result)); - } + INFO("wifi Activated"); + if (WIFI_MANAGER_ERROR_NONE != result) { + ERR("activateCB() Fail(%s)", get_error_message(result)); + } } void WifiActionPower::deactivateCB(wifi_manager_error_e result, void *userData) { - INFO("wifi Deactivated"); - if (WIFI_MANAGER_ERROR_NONE != result) { - ERR("deactivateCB() Fail(%s)", get_error_message(result)); - } + INFO("wifi Deactivated"); + if (WIFI_MANAGER_ERROR_NONE != result) { + ERR("deactivateCB() Fail(%s)", get_error_message(result)); + } } void WifiActionPower::wifiStateChangedCB(wifi_manager_device_state_e state, void *userData) { - WifiActionPower *action = (WifiActionPower*)userData; + WifiActionPower *action = (WifiActionPower *)userData; - RET_IF(nullptr == userData); + RET_IF(nullptr == userData); - bool changedVal = action->requestVal; - if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) - changedVal = true; - else if (state == WIFI_MANAGER_DEVICE_STATE_DEACTIVATED) - changedVal = false; - else - ERR("Unknown state(%d)", state); + bool changedVal = action->requestVal; + if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) + changedVal = true; + else if (state == WIFI_MANAGER_DEVICE_STATE_DEACTIVATED) + changedVal = false; + else + ERR("Unknown state(%d)", state); - INFO("state:%d", state); + INFO("state:%d", state); - if (action->cb && changedVal != action->requestVal) - action->cb(action->cbData); + if (action->cb && changedVal != action->requestVal) + action->cb(action->cbData); } diff --git a/wifi/WifiActionPower.h b/wifi/WifiActionPower.h index 2e91766..a1b3831 100644 --- a/wifi/WifiActionPower.h +++ b/wifi/WifiActionPower.h @@ -16,32 +16,34 @@ #pragma once #include + #include "WifiAction.h" MODES_NAMESPACE_BEGIN class WifiActionPower : public WifiAction { -public: - WifiActionPower(); - - bool IsCurrentValue(bool val) override; - int set(bool val) override; - void undo() override; - std::string getUndoInfo() override; - int setUndoInfo(const std::string &info) override; - int setChangedCallback(valueChangedCB callback, void *userData) override; - void unSetChangedCallback(valueChangedCB callback) override; - - static const std::string NAME; -private: - static void activateCB(wifi_manager_error_e result, void *user_data); - static void deactivateCB(wifi_manager_error_e result, void *user_data); - static void wifiStateChangedCB(wifi_manager_device_state_e state, void * user_data); - - bool requestVal; - bool oldVal; - valueChangedCB cb; - void *cbData; + public: + WifiActionPower(); + + bool IsCurrentValue(bool val) override; + int set(bool val) override; + void undo() override; + std::string getUndoInfo() override; + int setUndoInfo(const std::string &info) override; + int setChangedCallback(valueChangedCB callback, void *userData) override; + void unSetChangedCallback(valueChangedCB callback) override; + + static const std::string NAME; + + private: + static void activateCB(wifi_manager_error_e result, void *user_data); + static void deactivateCB(wifi_manager_error_e result, void *user_data); + static void wifiStateChangedCB(wifi_manager_device_state_e state, void *user_data); + + bool requestVal; + bool oldVal; + valueChangedCB cb; + void *cbData; }; MODES_NAMESPACE_END diff --git a/wifi/WifiFactory.cpp b/wifi/WifiFactory.cpp index d7cd15b..ca1ddf9 100644 --- a/wifi/WifiFactory.cpp +++ b/wifi/WifiFactory.cpp @@ -15,31 +15,35 @@ */ #include "WifiFactory.h" +#include "WifiActionPower.h" #include "modes_errors.h" #include "plugin-log.h" -#include "WifiActionPower.h" MODES_NAMESPACE_USE; -template PluginAction* newWifiAction() { return new T(); } +template +PluginAction* newWifiAction() +{ + return new T(); +} WifiFactory::WifiFactory() { - actionMap[WifiActionPower::NAME] = &newWifiAction; + actionMap[WifiActionPower::NAME] = &newWifiAction; } -PluginAction* WifiFactory::createAction(const std::string &key) +PluginAction* WifiFactory::createAction(const std::string& key) { - auto found = actionMap.find(key); - if (actionMap.end() == found) { - ERR("No WifiAction(%s)", key.c_str()); - return nullptr; - } + auto found = actionMap.find(key); + if (actionMap.end() == found) { + ERR("No WifiAction(%s)", key.c_str()); + return nullptr; + } - return found->second(); + return found->second(); } -void WifiFactory::destroyAction(PluginAction *action) +void WifiFactory::destroyAction(PluginAction* action) { - delete action; + delete action; } diff --git a/wifi/WifiFactory.h b/wifi/WifiFactory.h index 0ae5504..64e6d82 100644 --- a/wifi/WifiFactory.h +++ b/wifi/WifiFactory.h @@ -15,25 +15,25 @@ */ #pragma once -#include #include +#include + #include "WifiAction.h" MODES_NAMESPACE_BEGIN class WifiFactory { -public: - WifiFactory(); - ~WifiFactory() = default; - - PluginAction* createAction(const std::string &key); - void destroyAction(PluginAction *action); -private: - enum actionKey { - POWER - }; - - std::map actionMap; + public: + WifiFactory(); + ~WifiFactory() = default; + + PluginAction *createAction(const std::string &key); + void destroyAction(PluginAction *action); + + private: + enum actionKey { POWER }; + + std::map actionMap; }; MODES_NAMESPACE_END diff --git a/wifi/WifiPlugin.cpp b/wifi/WifiPlugin.cpp index 8c4ce75..2ada258 100644 --- a/wifi/WifiPlugin.cpp +++ b/wifi/WifiPlugin.cpp @@ -13,45 +13,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include #include -#include "plugin-log.h" + +#include + #include "WifiFactory.h" +#include "plugin-log.h" MODES_NAMESPACE_USE; class WifiPlugin : public Plugin { -public: - WifiPlugin(); - ~WifiPlugin() override = default; - - PluginAction* newAction(const std::string &key) override; - void deleteAction(PluginAction *piAction) override; -private: - WifiFactory wifiFactory; + public: + WifiPlugin(); + ~WifiPlugin() override = default; + + 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) { - delete plugin; + delete plugin; } WifiPlugin::WifiPlugin() { - setName("wifi"); + setName("wifi"); } -PluginAction* WifiPlugin::newAction(const std::string &key) +PluginAction *WifiPlugin::newAction(const std::string &key) { - return wifiFactory.createAction(key); + return wifiFactory.createAction(key); } void WifiPlugin::deleteAction(PluginAction *piAction) { - wifiFactory.destroyAction(piAction); + wifiFactory.destroyAction(piAction); }