add standard plugin
authorYoungjae Shin <yj99.shin@samsung.com>
Fri, 22 May 2020 02:02:14 +0000 (11:02 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Mon, 15 Jun 2020 07:25:06 +0000 (16:25 +0900)
Change-Id: Id17289ef01c430fd3d17ef89049d50998c6ec5f7

CMakeLists.txt
packaging/modes-plugins.spec
std/CMakeLists.txt [new file with mode: 0644]
std/StdFactory.cpp [new file with mode: 0644]
std/StdFactory.h [new file with mode: 0644]
std/StdPlugin.cpp [new file with mode: 0644]
std/StdTimeout.cpp [new file with mode: 0644]
std/StdTimeout.h [new file with mode: 0644]
std/tizen_std_rule.xml [new file with mode: 0644]
tests/CMakeLists.txt
tests/mdsp_test_std.cpp [new file with mode: 0644]

index 7a1e34dd24e85e617b2869ab95db9da48a5ae56b..446d003cceaf8166b031012cd965b3e658e45487 100644 (file)
@@ -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")
index b163dbd66ec537ea25036989e3d9421317ca4a25..dc41490bc69628f4b433b376e25c420d7ffa56f4 100644 (file)
@@ -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 (file)
index 0000000..3d5637d
--- /dev/null
@@ -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 (file)
index 0000000..f97f678
--- /dev/null
@@ -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 (file)
index 0000000..4d93fe8
--- /dev/null
@@ -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 <map>
+#include <string>
+#include <PluginAction.h>
+#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<std::string, enum actionKey> actionMap;
+};
+
+MODES_NAMESPACE_END
diff --git a/std/StdPlugin.cpp b/std/StdPlugin.cpp
new file mode 100644 (file)
index 0000000..9fa0b79
--- /dev/null
@@ -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 <Plugin.h>
+#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 (file)
index 0000000..10f3ce7
--- /dev/null
@@ -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 <glib.h>
+#include <string>
+#include <sstream>
+#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 (file)
index 0000000..3925e7d
--- /dev/null
@@ -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 <glib.h>
+#include <string>
+#include <PluginAction.h>
+#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 (file)
index 0000000..a17cddc
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+  <actionRule>
+    <rule name="std.timeout.seconds" type="int" life="volatile" since="6.0" plugin="std">
+      <privilege>http://tizen.org/privilege/systemsettings.admin</privilege>
+      <desc>Timer, It is be called changed Callback after value seconds</desc>
+      <domain>System</domain>
+    </rule>
+  </actionRule>
+</tizenModes>
index aedb09ae40ee34ad4e1208b3174d1e1cc7d6f4c5..5c246402c38ffac798a5a73cb1e836ae398043c2 100644 (file)
@@ -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 (file)
index 0000000..6324a1c
--- /dev/null
@@ -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 <glib.h>
+#include <string>
+#include <gtest/gtest.h>
+#include <Plugin.h>
+#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();
+}