From: Youngjae Shin Date: Fri, 22 May 2020 02:02:14 +0000 (+0900) Subject: add standard plugin X-Git-Tag: submit/tizen/20200615.073011~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d60475424f928c78d1db4daa0ac72af18fadadb2;p=platform%2Fcore%2Fsystem%2Fmodes-plugins.git add standard plugin Change-Id: Id17289ef01c430fd3d17ef89049d50998c6ec5f7 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a1e34d..446d003 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,10 +5,13 @@ INCLUDE(FindPkgConfig) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) SET(EXTRA_FLAGS "-Wall -Werror -fvisibility=hidden") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_FLAGS} -std=c++11") ADD_DEFINITIONS("-DMDS_PLUGIN") +IF(STDOUT_LOG) + ADD_DEFINITIONS("-DMDS_STDOUT") +ENDIF(STDOUT_LOG) IF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR) MESSAGE("No MODES_PLUGIN_DEFAULT_DIR. Check build system") @@ -25,6 +28,8 @@ SET(MEDIA_PLUGIN "modes-plugin-media") ADD_SUBDIRECTORY(media) SET(PKG_PLUGIN "modes-plugin-pkg") ADD_SUBDIRECTORY(pkg) +SET(STD_PLUGIN "modes-plugin-std") +ADD_SUBDIRECTORY(std) SET(VCONF_PLUGIN "modes-plugin-vconf") ADD_SUBDIRECTORY(vconf) SET(WIFI_PLUGIN "modes-plugin-wifi") diff --git a/packaging/modes-plugins.spec b/packaging/modes-plugins.spec index b163dbd..dc41490 100644 --- a/packaging/modes-plugins.spec +++ b/packaging/modes-plugins.spec @@ -93,6 +93,7 @@ tar xf %{name}-gcov.tar -C %{buildroot}%{_datadir}/gcov/obj %check xmllint --noout --schema %{modes_ro_dir}/schema/tizen_action_rule.xsd %{buildroot}%{modes_ro_dir}/rule/tizen_*_rule.xml xmllint --noout --schema %{modes_ro_dir}/schema/tizen_mode.xsd %{buildroot}%{modes_ro_dir}/mode/tizen_*_mode.xml +LD_LIBRARY_PATH=std tests/modes-plugintest-std %post /sbin/ldconfig diff --git a/std/CMakeLists.txt b/std/CMakeLists.txt new file mode 100644 index 0000000..3d5637d --- /dev/null +++ b/std/CMakeLists.txt @@ -0,0 +1,10 @@ +FILE(GLOB STD_SRCS *.cpp) + +PKG_CHECK_MODULES(std_pkgs REQUIRED modes dlog glib-2.0) +INCLUDE_DIRECTORIES(${std_pkgs_INCLUDE_DIRS}) +LINK_DIRECTORIES(${std_pkgs_LIBRARY_DIRS}) + +ADD_LIBRARY(${STD_PLUGIN} SHARED ${STD_SRCS}) +TARGET_LINK_LIBRARIES(${STD_PLUGIN} ${std_pkgs_LIBRARIES}) +INSTALL(TARGETS ${STD_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR}) +INSTALL(FILES tizen_std_rule.xml DESTINATION ${MODES_ACTIONRULE_DEFAULT_DIR}) diff --git a/std/StdFactory.cpp b/std/StdFactory.cpp new file mode 100644 index 0000000..f97f678 --- /dev/null +++ b/std/StdFactory.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "StdFactory.h" + +#include "plugin-log.h" +#include "StdTimeout.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; +} + +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; + } + + 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; +} + +void StdFactory::destroyAction(PluginAction *action) +{ + delete action; +} diff --git a/std/StdFactory.h b/std/StdFactory.h new file mode 100644 index 0000000..4d93fe8 --- /dev/null +++ b/std/StdFactory.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#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; +}; + +MODES_NAMESPACE_END diff --git a/std/StdPlugin.cpp b/std/StdPlugin.cpp new file mode 100644 index 0000000..9fa0b79 --- /dev/null +++ b/std/StdPlugin.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include "plugin-log.h" +#include "plugin-def.h" +#include "StdFactory.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; +}; + +extern "C" API Plugin* objectCreate(void) +{ + return new StdPlugin(); +} + +extern "C" API void objectDelete(Plugin *plugin) +{ + delete plugin; +} + +StdPlugin::StdPlugin() +{ + setName("std"); +} + +PluginAction* StdPlugin::newAction(const std::string &key) +{ + return stdFactory.createAction(key); +} + +void StdPlugin::deleteAction(PluginAction *piAction) +{ + stdFactory.destroyAction(piAction); +} diff --git a/std/StdTimeout.cpp b/std/StdTimeout.cpp new file mode 100644 index 0000000..10f3ce7 --- /dev/null +++ b/std/StdTimeout.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "StdTimeout.h" + +#include +#include +#include +#include "plugin-log.h" + +MODES_NAMESPACE_USE; + +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) +{ +} + +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; +} + +void StdTimeout::undo() +{ + g_source_remove(timer); + //Nothing to do +} + +std::string StdTimeout::getUndoInfo() +{ + //Not Support : Volitile + return std::string(); +} + +int StdTimeout::setChangedCallback(valueChangedCB callback, void *userData) +{ + RETV_IF(nullptr == callback, MODES_ERROR_INVALID_PARAMETER); + + cb = callback; + cbData = userData; + + return MODES_ERROR_NONE; +} + +void StdTimeout::unSetChangedCallback(valueChangedCB callback) +{ + RET_IF(callback != cb); + + cbData = nullptr; + cb = nullptr; +} + +gboolean StdTimeout::changedCB(gpointer data) +{ + RETV_IF(nullptr == data, G_SOURCE_REMOVE); + + StdTimeout *action = (StdTimeout*)data; + if (action->cb) + action->cb(action->cbData); + + return G_SOURCE_REMOVE; +} diff --git a/std/StdTimeout.h b/std/StdTimeout.h new file mode 100644 index 0000000..3925e7d --- /dev/null +++ b/std/StdTimeout.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#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; +}; + +MODES_NAMESPACE_END diff --git a/std/tizen_std_rule.xml b/std/tizen_std_rule.xml new file mode 100644 index 0000000..a17cddc --- /dev/null +++ b/std/tizen_std_rule.xml @@ -0,0 +1,10 @@ + + + + + http://tizen.org/privilege/systemsettings.admin + Timer, It is be called changed Callback after value seconds + System + + + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aedb09a..5c24640 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,6 +53,13 @@ ADD_EXECUTABLE(${PKG_PLUGIN_TEST} mdsp_test_pkg.cpp) TARGET_LINK_LIBRARIES(${PKG_PLUGIN_TEST} ${test_pkgs_LIBRARIES} ${PKG_PLUGIN}) INSTALL(TARGETS ${PKG_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) #===================================================================# +LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/std) +SET(STD_PLUGIN_TEST "modes-plugintest-std") + +ADD_EXECUTABLE(${STD_PLUGIN_TEST} mdsp_test_std.cpp) +TARGET_LINK_LIBRARIES(${STD_PLUGIN_TEST} ${test_pkgs_LIBRARIES} ${STD_PLUGIN}) +INSTALL(TARGETS ${STD_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR}) +#===================================================================# LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/vconf) SET(VCONF_PLUGIN_TEST "modes-plugintest-vconf") diff --git a/tests/mdsp_test_std.cpp b/tests/mdsp_test_std.cpp new file mode 100644 index 0000000..6324a1c --- /dev/null +++ b/tests/mdsp_test_std.cpp @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by medialicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include "plugin-def.h" + +MODES_NAMESPACE_USE; + +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(); + } + + 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 gboolean exitIdler(gpointer data) + { + g_main_loop_quit(loop); + return G_SOURCE_REMOVE; + } + + static bool result; + static GMainLoop *loop; + static Plugin *plugin; +}; + +bool StdPluginTest::result = 0; +Plugin *StdPluginTest::plugin = nullptr; +GMainLoop *StdPluginTest::loop = nullptr; + +TEST_F(StdPluginTest, IsCurrentValue) +{ + 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); +} + +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); +} + +int main(int argc, char **argv) +{ + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +}