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")
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")
%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
--- /dev/null
+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})
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <map>
+#include <string>
+#include <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
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <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);
+}
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "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;
+}
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <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
--- /dev/null
+<?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>
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")
--- /dev/null
+/*
+ * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by 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();
+}