Insert delete mode
authorJinWang An <jinwang.an@samsung.com>
Wed, 29 Apr 2020 03:55:11 +0000 (12:55 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 7 May 2020 10:41:27 +0000 (19:41 +0900)
client/mdsc_insert_del_mode.c [new file with mode: 0644]
client/mdsc_register_mode.c [deleted file]
common/dbus.xml
include/modes.h
supervisor/ModeManager.cpp
supervisor/ModeManager.h
supervisor/RequestHandler.cpp
supervisor/RequestHandler.h
supervisor/Supervisor.cpp
supervisor/org.tizen.modes.dbus.conf.in
unittest/modes_test_client.cpp

diff --git a/client/mdsc_insert_del_mode.c b/client/mdsc_insert_del_mode.c
new file mode 100644 (file)
index 0000000..b2cdfb1
--- /dev/null
@@ -0,0 +1,203 @@
+/*
+ * 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 "modes.h"
+
+#include <stdlib.h>
+#include <glib.h>
+#include "mdsc.h"
+#include "common/dbus.h"
+#include "common/dbus_def.h"
+
+struct mds_action_handle {
+       char *id;
+       char *rule;
+       char *value;
+};
+
+struct mds_mode_handle {
+       char *name;
+       modes_type_mode_e type;
+       bool hidden;
+       GList *action_list;
+};
+
+static int _mdsc_dbus_add_mode_sync(mdsDbus *mdsc_dbus, GVariant *mode_data)
+{
+       int result = MODES_ERROR_NONE;
+       gboolean ret;
+       GError *error = NULL;
+
+       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = mds_dbus_call_add_mode_sync(mdsc_dbus, mode_data, &result, NULL, &error);
+       if (FALSE == ret) {
+               ERR("mds_dbus_call_add_mode_sync() Fail(%s)", error ? error->message : "unknown");
+               g_error_free(error);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return result;
+}
+
+static int _mdsc_dbus_remove_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
+{
+       int result = MODES_ERROR_NONE;
+       gboolean ret;
+       GError *error = NULL;
+
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = mds_dbus_call_remove_mode_sync(mdsc_dbus, mode, &result, NULL, &error);
+       if (FALSE == ret) {
+               ERR("mds_dbus_call_remove_mode_sync() Fail(%s)", error ? error->message : "unknown");
+               g_error_free(error);
+               return MODES_ERROR_SYSTEM;
+       }
+
+       return result;
+}
+
+static void _mdsc_free_action(gpointer data)
+{
+       RET_IF(NULL == data);
+
+       struct mds_action_handle *action_data = data;
+
+       free(action_data->id);
+       free(action_data->rule);
+       free(action_data->value);
+       free(action_data);
+}
+
+static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
+{
+       RETV_IF(NULL == mode, NULL);
+
+       GVariantBuilder *action_builder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_ACTION_LIST_SIG));
+       GList *it = g_list_first(mode->action_list);
+
+       while (NULL != it) {
+               struct mds_action_handle *action_data = (struct mds_action_handle *)it->data;
+               g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG, MODES_DBUS_SAFE_STR(action_data->id),
+                       MODES_DBUS_SAFE_STR(action_data->rule), MODES_DBUS_SAFE_STR(action_data->value));
+               it = g_list_next(it);
+       }
+
+       GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
+       GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->name, mode->type, mode->hidden, action);
+       g_variant_builder_unref(action_builder);
+
+       return mode_data;
+}
+
+API modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type)
+{
+       struct mds_mode_handle *mode;
+
+       RETV_IF(NULL == name, NULL);
+
+       mode = malloc(sizeof(struct mds_mode_handle));
+       RETV_IF(NULL == mode, NULL);
+
+       mode->name = strdup(name);
+       mode->type = type;
+       mode->hidden = false;
+       mode->action_list = NULL;
+
+       return mode;
+}
+
+API int modes_set_hidden(modes_mode_h mode, bool hidden)
+{
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       mode->hidden = hidden;
+
+       return MODES_ERROR_NONE;
+}
+
+API modes_action_h modes_create_action(const char *name, const char *value)
+{
+       struct mds_action_handle *action;
+
+       RETV_IF(NULL == name, NULL);
+       RETV_IF(NULL == value, NULL);
+
+       action = malloc(sizeof(struct mds_action_handle));
+       RETV_IF(NULL == action, NULL);
+
+       action->rule = strdup(name);
+       action->value = strdup(value);
+       action->id = NULL;
+
+       return action;
+}
+
+API int modes_mode_add_action(modes_mode_h mode, modes_action_h action)
+{
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
+
+       mode->action_list = g_list_append(mode->action_list, action);
+
+       return MODES_ERROR_NONE;
+}
+
+API int modes_add_mode(modes_h handle, modes_mode_h mode)
+{
+       int ret;
+
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
+
+       GVariant *mode_data = _mdsc_create_mode_data(mode);
+       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = _mdsc_dbus_add_mode_sync(handle->conn, mode_data);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("_mdsc_dbus_add_mode_sync() Fail(%d)", ret);
+               return ret;
+       }
+
+       return MODES_ERROR_NONE;
+}
+
+API int modes_remove_mode(modes_h handle, const char *name)
+{
+       int ret;
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
+
+       ret = _mdsc_dbus_remove_mode_sync(handle->conn, name);
+       if (MODES_ERROR_NONE != ret) {
+               ERR("_mdsc_dbus_remove_mode_sync() Fail(%d)", ret);
+               return ret;
+       }
+
+       return MODES_ERROR_NONE;
+}
+
+API void modes_destroy_mode(modes_mode_h mode)
+{
+       RET_IF(NULL == mode);
+
+       free(mode->name);
+
+       g_list_free_full(mode->action_list, _mdsc_free_action);
+
+       free(mode);
+}
+
diff --git a/client/mdsc_register_mode.c b/client/mdsc_register_mode.c
deleted file mode 100644 (file)
index e630063..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * 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 "modes.h"
-
-#include <stdlib.h>
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-#include "common/dbus_def.h"
-
-struct mds_action_handle {
-       char *id;
-       char *rule;
-       char *value;
-};
-
-struct mds_mode_handle {
-       char *name;
-       modes_type_mode_e type;
-       bool hidden;
-       GList *action_list;
-};
-
-static int _mdsc_dbus_register_mode_sync(mdsDbus *mdsc_dbus, GVariant *mode_data)
-{
-       int result = MODES_ERROR_NONE;
-       gboolean ret;
-       GError *error = NULL;
-
-       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = mds_dbus_call_register_mode_sync(mdsc_dbus, mode_data, &result, NULL, &error);
-       if (FALSE == ret) {
-               ERR("mds_dbus_call_register_mode_sync() Fail(%s)", error ? error->message : "unknown");
-               g_error_free(error);
-               return MODES_ERROR_SYSTEM;
-       }
-
-       return result;
-}
-
-static void _mdsc_free_action(gpointer data)
-{
-       RET_IF(NULL == data);
-
-       struct mds_action_handle *action_data = data;
-
-       free(action_data->id);
-       free(action_data->rule);
-       free(action_data->value);
-       free(action_data);
-}
-
-static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
-{
-       RETV_IF(NULL == mode, NULL);
-
-       GVariantBuilder *action_builder = g_variant_builder_new(G_VARIANT_TYPE(MODES_DBUS_ACTION_LIST_SIG));
-       GList *it = g_list_first(mode->action_list);
-
-       while (NULL != it) {
-               struct mds_action_handle *action_data = (struct mds_action_handle *)it->data;
-               g_variant_builder_add(action_builder, MODES_DBUS_ACTION_SIG, MODES_DBUS_SAFE_STR(action_data->id),
-                       MODES_DBUS_SAFE_STR(action_data->rule), MODES_DBUS_SAFE_STR(action_data->value));
-               it = g_list_next(it);
-       }
-
-       GVariant *action = g_variant_new(MODES_DBUS_ACTION_LIST_SIG, action_builder);
-       GVariant *mode_data = g_variant_new(MODES_DBUS_MODE_SIG, mode->name, mode->type, mode->hidden, action);
-       g_variant_builder_unref(action_builder);
-
-       return mode_data;
-}
-
-API modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type)
-{
-       struct mds_mode_handle *mode;
-
-       RETV_IF(NULL == name, NULL);
-
-       mode = malloc(sizeof(struct mds_mode_handle));
-       RETV_IF(NULL == mode, NULL);
-
-       mode->name = strdup(name);
-       mode->type = type;
-       mode->hidden = false;
-       mode->action_list = NULL;
-
-       return mode;
-}
-
-API int modes_set_hidden(modes_mode_h mode, bool hidden)
-{
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       mode->hidden = hidden;
-
-       return MODES_ERROR_NONE;
-}
-
-API modes_action_h modes_create_action(const char *name, const char *value)
-{
-       struct mds_action_handle *action;
-
-       RETV_IF(NULL == name, NULL);
-       RETV_IF(NULL == value, NULL);
-
-       action = malloc(sizeof(struct mds_action_handle));
-       RETV_IF(NULL == action, NULL);
-
-       action->rule = strdup(name);
-       action->value = strdup(value);
-       action->id = NULL;
-
-       return action;
-}
-
-API int modes_mode_add_action(modes_mode_h mode, modes_action_h action)
-{
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
-
-       mode->action_list = g_list_append(mode->action_list, action);
-
-       return MODES_ERROR_NONE;
-}
-
-API int modes_register_mode(modes_h handle, modes_mode_h mode)
-{
-       int ret;
-
-       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
-       RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
-
-       GVariant *mode_data = _mdsc_create_mode_data(mode);
-       RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
-
-       ret = _mdsc_dbus_register_mode_sync(handle->conn, mode_data);
-       if (MODES_ERROR_NONE != ret) {
-               ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
-               return ret;
-       }
-
-       return MODES_ERROR_NONE;
-}
-
-API void modes_destroy_mode(modes_mode_h mode)
-{
-       RET_IF(NULL == mode);
-
-       free(mode->name);
-
-       g_list_free_full(mode->action_list, _mdsc_free_action);
-
-       free(mode);
-}
-
index 683a1ac259c48d8283f1ef357a4fc929d0b36bd1..15e8abff99e2e65987ccb86170d8c670e4f9116d 100644 (file)
                        <arg type="s" name="modeName" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
-               <method name="registerMode">
+               <method name="addMode">
                        <arg type="(sibv)" name="modeData" direction="in"/>
                        <arg type="i" name="ret" direction="out"/>
                </method>
+               <method name="removeMode">
+                       <arg type="s" name="modeName" direction="in"/>
+                       <arg type="i" name="ret" direction="out"/>
+               </method>
                <method name="getModes">
                        <arg type="a(sii)" name="modeList" direction="out"/>
                        <arg type="i" name="ret" direction="out"/>
index 1b27f88ce99fbbbfa34512eb09b1cfbbd69ae285..e2675ef3e5c26f63370b6dcf46fb1d5eb4364376 100644 (file)
@@ -169,20 +169,20 @@ modes_action_h modes_create_action(const char *rule, const char *value);
 int modes_mode_add_action(modes_mode_h mode, modes_action_h action);
 
 /**
- * @brief Register Mode.
- * @details Calls this function to register mode.
+ * @brief Add Mode.
+ * @details Calls this function to add mode.
  * @since_tizen 6.0
  * @privlevel platform
  * @privilege http://tizen.org/privilege/systemsettings.admin
  * @param[in] Handle of modes server
- * @param[in] Mode handle to register
+ * @param[in] Mode handle to add
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #MODES_ERROR_NONE Successful
  * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_register_mode(modes_h handle, modes_mode_h mode);
+int modes_add_mode(modes_h handle, modes_mode_h mode);
 
 /**
  * @brief Destroy Mode handle
@@ -194,6 +194,23 @@ int modes_register_mode(modes_h handle, modes_mode_h mode);
  */
 void modes_destroy_mode(modes_mode_h mode);
 
+/**
+ * @brief Remove Mode.
+ * @details Calls this function to remove mode.
+ * @since_tizen 6.0
+ * @privlevel platform
+ * @privilege http://tizen.org/privilege/systemsettings.admin
+ * @param[in] Handle of modes server
+ * @param[in] Mode name to be removed
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #MODES_ERROR_NONE Successful
+ * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #MODES_ERROR_CONFLICT Try to remove applied mode.
+ * @retval #MODES_ERROR_SYSTEM System errors
+ */
+int modes_remove_mode(modes_h handle, const char *name);
+
 /**
  * @brief Adds callback for recognizing the changed of mode.
  * @details Sets a function to be called when the mode is changed.
index d9f8d2f904837817440e3e37cdf79b10dc2f0ddb..873c663fe21daab84fad2aad1d354f8b355972a9 100644 (file)
@@ -127,9 +127,9 @@ int ModeManager::applyMode(const string &modeName, ClientPrivilege &priv, bool i
        return MODES_ERROR_NONE;
 }
 
-int ModeManager::registerMode(const Mode &mode)
+int ModeManager::addMode(const Mode &mode)
 {
-       string filename;
+       string filename = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getName() + "_mode.xml";
        XMLGenerator xmlWriter;
 
        auto element = std::make_pair(mode.getName(), std::make_tuple(filename, mode.getModeType(), false));
@@ -140,7 +140,6 @@ int ModeManager::registerMode(const Mode &mode)
        }
 
        try {
-               filename = MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" + mode.getName() + "_mode.xml";
                xmlWriter.makeModeXML(filename, mode);
        } catch (ModesEx &e) {
                ERR("XML generator Fail(%s)", e.what());
@@ -148,7 +147,37 @@ int ModeManager::registerMode(const Mode &mode)
                return MODES_ERROR_INVALID_PARAMETER;
        }
 
-       DBG("[%zu] Register modeName : %s, modePath : %s, type : %d, hidden : false", modeMap.size(), mode.getName().c_str(), filename.c_str(), mode.getModeType());
+       DBG("[%zu] addMode modeName : %s, modePath : %s, type : %d, hidden : false", modeMap.size(), mode.getName().c_str(), filename.c_str(), mode.getModeType());
+
+       return MODES_ERROR_NONE;
+}
+
+int ModeManager::removeMode(const string &modeName)
+{
+       if (true == careTaker.isSavedMode(modeName)) {
+               ERR("Mode(%s) is applied.", modeName.c_str());
+               return MODES_ERROR_CONFLICT;
+       }
+
+       auto result = modeMap.find(modeName);
+       if (result == modeMap.end()) {
+               ERR("Invalid mode(%s), not found", modeName.c_str());
+               return MODES_ERROR_INVALID_PARAMETER;
+       }
+
+       string filename = std::get<0>(result->second);
+       if (string::npos == filename.find(MODES_CUSTOM_MODE_DEFAULT_DIR))
+       {
+               ERR("Invalid mode(%s), custom mode only can be removed.", modeName.c_str());
+               return MODES_ERROR_INVALID_PARAMETER;
+       }
+
+       modeMap.erase(result);
+
+       if (0 != remove(filename.c_str()))
+               ERR("remove(%s) Fail(%d)", filename.c_str(), errno);
+
+       DBG("[%zu] Remove modeName : %s, modePath : %s", modeMap.size(), modeName.c_str(), filename.c_str());
 
        return MODES_ERROR_NONE;
 }
index 5ba709e876a140063a54a331ba7955c3d52d7c4a..57af4acf223c744fd1eb100231c702ccfeeaefc9 100644 (file)
@@ -34,7 +34,8 @@ public:
        void init();
        void addModeDirectory(const std::string &dirPath);
        int applyMode(const std::string &modeName, ClientPrivilege &priv, bool isTest);
-       int registerMode(const Mode &mode);
+       int addMode(const Mode &mode);
+       int removeMode(const std::string &modeName);
        int undoMode(const std::string &modeName);
        int undoMode(const std::string &modeName, ClientPrivilege &priv);
        std::list<std::tuple<std::string, int, int>> getModes();
index 5dd5a017e5e059f3354624d3be3fe2c25757eacd..f58e8f6c0b846fe3668288e342ade4228b5a47d7 100644 (file)
@@ -93,7 +93,7 @@ gboolean RequestHandler::undoModeHandler(mdsDbus *object, GDBusMethodInvocation
        return TRUE;
 }
 
-gboolean RequestHandler::registerModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+gboolean RequestHandler::addModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
        GVariant *modeData, gpointer userData)
 {
        RETV_IF(NULL == modeMgr, FALSE);
@@ -101,10 +101,10 @@ gboolean RequestHandler::registerModeHandler(mdsDbus *object, GDBusMethodInvocat
 
        try {
                Mode mode = getModefromData(modeData);
-               int ret = modeMgr->registerMode(mode);
-               mds_dbus_complete_register_mode(object, invocation, ret);
+               int ret = modeMgr->addMode(mode);
+               mds_dbus_complete_add_mode(object, invocation, ret);
        } catch (ModesEx &e) {
-               mds_dbus_complete_register_mode(object,
+               mds_dbus_complete_add_mode(object,
                        invocation, MODES_ERROR_INVALID_PARAMETER);
        }
 
@@ -114,6 +114,18 @@ gboolean RequestHandler::registerModeHandler(mdsDbus *object, GDBusMethodInvocat
        return TRUE;
 }
 
+gboolean RequestHandler::removeModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+               const gchar *modeName, gpointer userData)
+{
+       RETV_IF(NULL == modeMgr, FALSE);
+       RETV_IF(NULL == modeName, FALSE);
+
+       int ret = modeMgr->removeMode(modeName);
+       mds_dbus_complete_remove_mode(object, invocation, ret);
+
+       return TRUE;
+}
+
 gboolean RequestHandler::getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation, gpointer userData)
 {
        int ret = MODES_ERROR_NONE;
index c302b612b7db81f00dc8394cf87ca71320e62306..bef677ee3ef2a2b11b84434db8c54579bd0fa537 100644 (file)
@@ -30,8 +30,10 @@ public:
                const gchar *modeName, gpointer userData);
        static gboolean undoModeHandler(mdsDbus * object, GDBusMethodInvocation *invocation,
                const gchar *modeName, gpointer userData);
-       static gboolean registerModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+       static gboolean addModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
                GVariant *arg_modeData, gpointer userData);
+       static gboolean removeModeHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
+               const gchar *modeName, gpointer userData);
        static gboolean getModesHandler(mdsDbus *object, GDBusMethodInvocation *invocation,
                gpointer userData);
 
index e2b7fe82d1b3f881e45114d5dde8cc80fe9efcfb..1b018904109c21ea64bb3d85917e7f839e927318 100644 (file)
@@ -61,6 +61,7 @@ void Supervisor::registerHandler()
        clientConn.addRequestHandler("handle-can-apply", (GCallback)&RequestHandler::canApplyModeHandler);
        clientConn.addRequestHandler("handle-apply-mode", (GCallback)&RequestHandler::applyModeHandler);
        clientConn.addRequestHandler("handle-undo-mode", (GCallback)&RequestHandler::undoModeHandler);
-       clientConn.addRequestHandler("handle-register-mode", (GCallback)&RequestHandler::registerModeHandler);
+       clientConn.addRequestHandler("handle-add-mode", (GCallback)&RequestHandler::addModeHandler);
+       clientConn.addRequestHandler("handle-remove-mode", (GCallback)&RequestHandler::removeModeHandler);
        clientConn.addRequestHandler("handle-get-modes", (GCallback)&RequestHandler::getModesHandler);
 }
index d64aa31791bd45b40d2bcd6c14b72d71afcc45b1..e35958a91c7e9e505314901395233cd43beefdc8 100644 (file)
@@ -17,7 +17,8 @@
                <deny send_destination="@DBUS_INTERFACE@" send_type="method_call"/>
 
     <allow send_destination="@DBUS_INTERFACE@" send_path="/org/tizen/modes/dbus" send_interface="@DBUS_INTERFACE@"/>
-    <check send_destination="@DBUS_INTERFACE@" send_interface="@DBUS_INTERFACE@" send_member="registerMode" privilege="http://tizen.org/privilege/systemsettings.admin"/>
+    <check send_destination="@DBUS_INTERFACE@" send_interface="@DBUS_INTERFACE@" send_member="addMode" privilege="http://tizen.org/privilege/systemsettings.admin"/>
+    <check send_destination="@DBUS_INTERFACE@" send_interface="@DBUS_INTERFACE@" send_member="removeMode" privilege="http://tizen.org/privilege/systemsettings.admin"/>
     <check send_destination="@DBUS_INTERFACE@" send_interface="@DBUS_INTERFACE@" send_member="getModes" privilege="http://tizen.org/privilege/systemsettings.admin"/>
 
                <deny send_type="signal" send_path="/org/tizen/modes/dbus" send_interface="@DBUS_INTERFACE@"/>
index 4784f464e3379e25ee53aab58efe1b4bf5f78725..23acfa42facf7ee1b92befc26bc869cfad41a4ea 100644 (file)
@@ -19,8 +19,6 @@
 #include <modes.h>
 #include "common/definitions.h"
 
-#define CREATED_MODE_NAME "created"
-
 class ClientTest : public ::testing::Test {
 protected:
        void SetUp() override
@@ -39,7 +37,7 @@ protected:
 
        static gboolean applyModeIdler(gpointer data)
        {
-               result = modes_apply_mode(handle, (const char*)data);
+               result = modes_apply_mode(handle, (char*)data);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
@@ -47,18 +45,18 @@ protected:
 
        static gboolean undoModeIdler(gpointer data)
        {
-               result = modes_apply_mode(handle, (const char*)data);
+               result = modes_apply_mode(handle, (char*)data);
                EXPECT_EQ(MODES_ERROR_NONE, result);
                sleep(1);
-               result = modes_undo_mode(handle, (const char*)data);
+               result = modes_undo_mode(handle, (char*)data);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
        }
 
-       static gboolean registerModeIdler(gpointer data)
+       static void addModeTest(gpointer data)
        {
-               modes_mode_h created_mode = modes_create_mode(CREATED_MODE_NAME, MODES_TYPE_MODE_NORMAL);
+               modes_mode_h created_mode = modes_create_mode((char*)data, MODES_TYPE_MODE_NORMAL);
                modes_action_h action_handle[2];
                action_handle[0] = modes_create_action("test.printBool", "on");
                action_handle[1] = modes_create_action("test.printBool", "off");
@@ -71,8 +69,34 @@ protected:
                result = modes_set_hidden(created_mode, true);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               result = modes_register_mode(handle, created_mode);
+               result = modes_add_mode(handle, created_mode);
                modes_destroy_mode(created_mode);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+
+               result = modes_apply_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
+       }
+
+       static gboolean addModeIdler(gpointer data)
+       {
+               addModeTest(data);
+               modes_undo_mode(handle, (char*)data);
+               modes_remove_mode(handle, (char*)data);
+               g_main_loop_quit(loop);
+
+               return G_SOURCE_REMOVE;
+       }
+
+       static gboolean removeModeIdler(gpointer data)
+       {
+               addModeTest(data);
+
+               result = modes_remove_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_CONFLICT, result);
+
+               modes_undo_mode(handle, (char*)data);
+               result = modes_remove_mode(handle, (char*)data);
+               EXPECT_EQ(MODES_ERROR_NONE, result);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
@@ -115,14 +139,21 @@ TEST_F(ClientTest, canApplyModeN)
        EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
 }
 
-TEST_F(ClientTest, registerMode)
+TEST_F(ClientTest, addMode)
 {
-       g_idle_add(registerModeIdler, NULL);
+       g_idle_add(addModeIdler, (gpointer)"created");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
-       if (0 != remove(MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" CREATED_MODE_NAME "_mode.xml")) {
-               std::cout << "remove() Fail :" << MODES_CUSTOM_MODE_DEFAULT_DIR "/tizen_" CREATED_MODE_NAME "_mode.xml" << " errno = " << errno << std::endl;
-       }
+}
+
+TEST_F(ClientTest, removeMode)
+{
+       g_idle_add(removeModeIdler, (gpointer)"deltest");
+       g_main_loop_run(loop);
+       EXPECT_EQ(MODES_ERROR_NONE, result);
+
+       int ret = modes_remove_mode(handle, "deltestN");
+       EXPECT_EQ(MODES_ERROR_INVALID_PARAMETER, ret);
 }
 
 TEST_F(ClientTest, undoModeEx1)
@@ -144,8 +175,8 @@ TEST_F(ClientTest, undoModeEx2)
 TEST_F(ClientTest, getModes)
 {
        const char* const typeList[2] = {
-                       "MODES_TYPE_MODE_NORMAL",
-                       "MODES_TYPE_MODE_ONESHOT"
+               "MODES_TYPE_MODE_NORMAL",
+               "MODES_TYPE_MODE_ONESHOT"
        };
 
        GList *list, *cur;