--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="6.0">
+ <mode name="essential_ex" type="normal">
+ <action rule="test.printBool">on</action>
+ <action rule="test.connect">Modes-JBL</action>
+ <action rule="test.changeTime" restrict="essential">3</action>
+ <action rule="test.printInt">PRINT_TWO</action>
+ <undo ID="undo1" rule="test.printBool">true</undo>
+ </mode>
+</tizenModes>
-pkg_check_modules(plugin_pkgs REQUIRED dlog capi-base-common)
+SET(LIB_NAME modes-plugin-test)
+
+FILE(GLOB TEST_PLUGIN_SRCS *.cpp)
+
+PKG_CHECK_MODULES(plugin_pkgs REQUIRED dlog capi-base-common glib-2.0)
INCLUDE_DIRECTORIES(${plugin_pkgs_INCLUDE_DIRS})
LINK_DIRECTORIES(${plugin_pkgs_LIBRARY_DIRS})
-ADD_DEFINITIONS("-DMDS_PLUGIN")
-SET(LIB_NAME modes-plugin-test)
-FILE(GLOB TEST_PLUGIN_SRCS *.cpp)
+ADD_DEFINITIONS("-DMDS_PLUGIN")
ADD_LIBRARY(${LIB_NAME} SHARED ${TEST_PLUGIN_SRCS})
TARGET_LINK_LIBRARIES(${LIB_NAME} ${plugin_pkgs_LIBRARIES})
*/
#include <thread>
#include <chrono>
+#include <glib.h>
#include "modes_errors.h"
#include "Plugin.h"
#include "PluginAction.h"
double getDouble(const std::string &key) override;
bool getBool(const std::string &key) override;
std::string getString(const std::string &key) override;
+private:
+ static gboolean changeTimeout(gpointer data)
+ {
+ TestPluginAction *testAction = (TestPluginAction*)data;
+ testAction->callChangedCB();
+ return G_SOURCE_REMOVE;
+ }
};
extern "C" API Plugin *objectCreate(void)
int TestPlugin::set(const std::string &key, int val, PluginAction **piAction)
{
- TestPluginAction *testAction = new TestPluginAction();
+ TestPluginAction *testAction = new TestPluginAction(key);
if ("changeAccuracy" == key) {
DBG("set(%s, %d)", key.c_str(), val);
delete testAction;
DBG("set(%s, %d)", key.c_str(), val);
return MODES_ERROR_SYSTEM;
+ } else if ("changeTime" == key) {
+ g_timeout_add_seconds(val, changeTimeout, (void*)testAction);
+ DBG("set(%s, %d)", key.c_str(), val);
} else {
ERR("Unknown key(%s)", key.c_str());
return MODES_ERROR_NOT_SUPPORTED;
DBG("TestPlugin::set double ( %s, %lf )", key.c_str(), val);
if (piAction) {
- TestPluginAction *testAction = new TestPluginAction();
+ TestPluginAction *testAction = new TestPluginAction(key);
*piAction = testAction;
}
return MODES_ERROR_NONE;
}
if (piAction) {
- TestPluginAction *testAction = new TestPluginAction();
+ TestPluginAction *testAction = new TestPluginAction(key);
*piAction = testAction;
}
return MODES_ERROR_NONE;
DBG("TestPlugin::set string ( %s, %s )", key.c_str(), val.c_str());
if (piAction) {
- TestPluginAction *testAction = new TestPluginAction();
+ TestPluginAction *testAction = new TestPluginAction(key);
*piAction = testAction;
}
return MODES_ERROR_NONE;
PluginAction* TestPlugin::getUndoAction(const std::string &key, const std::string &info)
{
// parse the key for making PluginAction
- TestPluginAction *piAction = new TestPluginAction();
+ TestPluginAction *piAction = new TestPluginAction(key);
piAction->parse(info);
return piAction;
MODES_NAMESPACE_USE;
-TestPluginAction::TestPluginAction()
- : PluginAction("testAction")
+TestPluginAction::TestPluginAction(const std::string &name)
+ : PluginAction(name)
{
}
void TestPluginAction::undo()
{
- DBG("TestPluginAction::undo() is Called");
+ INFO("TestPluginAction::undo(%s) is Called", getName().c_str());
}
std::string TestPluginAction::serialize()
{
- return "testAction";
+ return getName();
}
int TestPluginAction::parse(const std::string &info)
int TestPluginAction::setChangedCallback(valueChangedCB callback, void *userData)
{
+ cb = callback;
+ cbData = userData;
+
return MODES_ERROR_NONE;
}
void TestPluginAction::unSetChangedCallback(valueChangedCB callback, void *userData)
{
+ cb = NULL;
+ cbData = NULL;
+}
+
+void TestPluginAction::callChangedCB()
+{
+ INFO("%s is changed", getName().c_str());
+
+ if (cb)
+ cb(cbData);
}
class TestPluginAction : public PluginAction {
public:
- TestPluginAction();
+ TestPluginAction(const std::string &name);
~TestPluginAction() override;
void undo() override;
int parse(const std::string &data) override;
int setChangedCallback(valueChangedCB callback, void *userData) override;
void unSetChangedCallback(valueChangedCB callback, void *userData) override;
+ void callChangedCB();
+private:
+ valueChangedCB cb;
+ void *cbData;
};
MODES_NAMESPACE_END
<desc>Sleep and return error after value seconds</desc>
<domain>System</domain>
</rule>
+ <rule name="test.changeTime" type="int" since="6.0" plugin="test">
+ <desc>Call Change callback after value seconds</desc>
+ <domain>System</domain>
+ </rule>
</actionRule>
</tizenModes>
return MODES_ERROR_NONE;
}
+ static int changeFn(const char *modeName, int state, void *user_data)
+ {
+ char *requestMode = (char*)user_data;
+
+ std::cout << "Changed Mode : " << modeName << std::endl;
+ EXPECT_EQ(requestMode, std::string(modeName));
+ std::cout << "state : " << state << std::endl;
+
+ if (0 == state)
+ g_main_loop_quit(loop);
+
+ return MODES_ERROR_NONE;
+ }
static modes_h handle;
static int expectedState;
static GMainLoop *loop;
modes_unsubscribe_mode_changes(handle);
}
+
+TEST_F(ClientNotiTest, essential)
+{
+ const char *testMode = "essential_ex";
+ int ret = modes_subscribe_mode_changes(handle, changeFn, (void*)testMode);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+ ret = modes_apply_mode(handle, testMode);
+ EXPECT_EQ(MODES_ERROR_NONE, ret);
+
+ g_main_loop_run(loop);
+
+ modes_unsubscribe_mode_changes(handle);
+}