Fix client API for handle
authorJinWang An <jinwang.an@samsung.com>
Wed, 15 Jan 2020 07:41:22 +0000 (16:41 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 18 Mar 2020 08:53:50 +0000 (17:53 +0900)
15 files changed:
client/mdsc.c [new file with mode: 0644]
client/mdsc.h
client/mdsc_apply_mode.c
client/mdsc_can_apply.c
client/mdsc_dbus.c [deleted file]
client/mdsc_get_modes.c
client/mdsc_noti_mode.c
client/mdsc_register_mode.c
client/mdsc_undo_mode.c
include/modes.h
include/modes_types.h
unittest/modes_mode_test.c
unittest/modes_test_async.cpp
unittest/modes_test_client.cpp
unittest/modes_test_noti.cpp

diff --git a/client/mdsc.c b/client/mdsc.c
new file mode 100644 (file)
index 0000000..8d5d857
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * 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 <stdlib.h>
+#include <glib.h>
+#include "mdsc.h"
+#include "common/dbus.h"
+#include "common/dbus_def.h"
+
+API modes_h modes_connect()
+{
+       modes_h handle = malloc(sizeof(struct mds_handle));
+       RETV_IF(NULL == handle, NULL);
+
+       mdsDbus *proxy;
+       GError *gdbusErr = NULL;
+       proxy = mds_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+                       G_DBUS_PROXY_FLAGS_NONE, MODES_DBUS_INTERFACE, MODES_DBUS_OBJPATH, NULL, &gdbusErr);
+       if (NULL == proxy) {
+               ERR("mds_dbus_proxy_new_for_bus_sync() Fail(%s)", gdbusErr ? gdbusErr->message : "unknown");
+               g_error_free(gdbusErr);
+               free(handle);
+               return NULL;
+       }
+       handle->conn = proxy;
+
+       return handle;
+}
+
+API void modes_disconnect(modes_h handle)
+{
+       RET_IF(NULL == handle);
+       if (handle->conn) {
+               g_object_unref(handle->conn);
+               handle->conn = NULL;
+       }
+       free(handle);
+}
index f7935dba151ec56238e1274165d4a033c7404399..a8ef234f29ec517731dc131923469af916f7010b 100644 (file)
 #pragma once
 
 #include "modes.h"
+#include "common/dbus.h"
 #include "common/log.h"
 #include "common/definitions.h"
+
+struct mds_handle {
+       mdsDbus *conn;
+};
index d30c5b3c41f0ce576893cbc013d6e985e7fd9126..2dda68290b3ea5fefb2ea77037a82ba812164512 100644 (file)
 
 #include <glib.h>
 #include "mdsc.h"
-#include "mdsc_dbus.h"
 #include "common/dbus.h"
 
-int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
+static int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
 {
        int result = MODES_ERROR_NONE;
        gboolean ret;
@@ -38,26 +37,17 @@ int _mdsc_dbus_apply_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
        return result;
 }
 
-API int modes_apply_mode(const char *name)
+API int modes_apply_mode(modes_h handle, const char *name)
 {
        int ret;
-       mdsDbus* dbus_handle;
-
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
 
-       dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle) {
-               ERR("_mdsc_dbus_start() Fail");
-               return MODES_ERROR_SYSTEM;
-       }
-
-       ret = _mdsc_dbus_apply_mode_sync(dbus_handle, name);
+       ret = _mdsc_dbus_apply_mode_sync(handle->conn, name);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
                return ret;
        }
 
-       mdsc_dbus_stop(dbus_handle);
-
        return MODES_ERROR_NONE;
 }
index c711ee868f5fe1005bc484c2181183d5cbf4f330..64525495d86f92eb4e25d02977b985192cc9407a 100644 (file)
 
 #include <glib.h>
 #include "mdsc.h"
-#include "mdsc_dbus.h"
 #include "common/dbus.h"
 
-int _mdsc_dbus_can_apply_sync(mdsDbus *mdsc_dbus, const char *mode)
+static int _mdsc_dbus_can_apply_sync(mdsDbus *mdsc_dbus, const char *mode)
 {
        int result = MODES_ERROR_NONE;
        gboolean ret;
@@ -38,26 +37,17 @@ int _mdsc_dbus_can_apply_sync(mdsDbus *mdsc_dbus, const char *mode)
        return result;
 }
 
-API int modes_can_apply(const char *name)
+API int modes_can_apply(modes_h handle, const char *name)
 {
        int ret;
-       mdsDbus *dbus_handle;
-
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
 
-       dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle) {
-               ERR("_mdsc_dbus_start() Fail");
-               return MODES_ERROR_SYSTEM;
-       }
-
-       ret = _mdsc_dbus_can_apply_sync(dbus_handle, name);
+       ret = _mdsc_dbus_can_apply_sync(handle->conn, name);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_dbus_precheck_mode_sync() Fail(%d)", ret);
                return ret;
        }
 
-       mdsc_dbus_stop(dbus_handle);
-
        return MODES_ERROR_NONE;
 }
diff --git a/client/mdsc_dbus.c b/client/mdsc_dbus.c
deleted file mode 100644 (file)
index 8c5eeb6..0000000
+++ /dev/null
@@ -1,57 +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 "mdsc_dbus.h"
-
-#include <glib.h>
-#include "mdsc.h"
-#include "common/dbus.h"
-#include "common/dbus_def.h"
-
-static mdsDbus *mdsc_proxy = NULL;
-static int mdsc_dbus_cnt = 0;
-
-mdsDbus* mdsc_dbus_start()
-{
-       if (mdsc_proxy) {
-               DBG("bus is already connected");
-               mdsc_dbus_cnt++;
-               return mdsc_proxy;
-       }
-
-       GError *gdbusErr = NULL;
-       mdsc_proxy = mds_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
-                       G_DBUS_PROXY_FLAGS_NONE, MODES_DBUS_INTERFACE, MODES_DBUS_OBJPATH, NULL, &gdbusErr);
-       if (NULL == mdsc_proxy) {
-               ERR("mds_dbus_proxy_new_for_bus_sync() Fail(%s)", gdbusErr ? gdbusErr->message : "unknown");
-               g_error_free(gdbusErr);
-               return NULL;
-       }
-       return mdsc_proxy;
-}
-
-void mdsc_dbus_stop(mdsDbus *handle)
-{
-       //TODO: I'm not sure when the handle should be released.
-       if (mdsc_dbus_cnt) {
-               mdsc_dbus_cnt--;
-               return;
-       }
-
-       if (handle)
-               g_object_unref(handle);
-
-       mdsc_proxy = NULL;
-}
index 982576b310b01e0a8169507d59235ae4a73bb859..f3751a3221259d09e3ec465197e8ab5efc2652c2 100644 (file)
@@ -17,7 +17,7 @@
 #include <stdlib.h>
 #include <glib.h>
 #include "mdsc.h"
-#include "mdsc_dbus.h"
+#include "common/dbus.h"
 #include "common/dbus_def.h"
 
 static GList* _get_mode_list(GVariant *in_data)
@@ -65,27 +65,19 @@ static int _mdsc_dbus_get_modes_sync(mdsDbus *mdsc_dbus, GList **list)
        return result;
 }
 
-API int modes_get_modes(GList **list)
+API int modes_get_modes(modes_h handle, GList **list)
 {
        int ret;
-       mdsDbus* dbus_handle;
 
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == list, MODES_ERROR_INVALID_PARAMETER);
 
-       dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle) {
-               ERR("_mdsc_dbus_start() Fail");
-               return MODES_ERROR_SYSTEM;
-       }
-
-       ret = _mdsc_dbus_get_modes_sync(dbus_handle, list);
+       ret = _mdsc_dbus_get_modes_sync(handle->conn, list);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
                return ret;
        }
 
-       mdsc_dbus_stop(dbus_handle);
-
        return MODES_ERROR_NONE;
 }
 
@@ -95,6 +87,7 @@ static void _free_mode(gpointer data, gpointer user_data)
        free(mode->name);
        free(mode);
 }
+
 API void modes_free_modes(GList *list)
 {
        g_list_foreach(list, _free_mode, NULL);
index 809c86f532496c7df078ce18ccc1fcc4d1f58ea5..9b24f7a0b0ecb870c0b274150dc30e061b3f9aad 100644 (file)
@@ -17,7 +17,7 @@
 
 #include <glib.h>
 #include "mdsc.h"
-#include "mdsc_dbus.h"
+#include "common/dbus.h"
 
 struct mdsc_noti_data_s {
        modes_noti_fn cb;
@@ -35,20 +35,16 @@ static void _on_changed_mode(mdsDbus *mdsc_dbus, const char *mode, int state, gp
        mdsc_noti_data.cb(mode, state, mdsc_noti_data.user_data);
 }
 
-API int modes_subscribe_mode_changes(modes_noti_fn cb, void *user_data)
+API int modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_data)
 {
        RETV_IF(0 != mdsc_noti_signal_ID, MODES_ERROR_ALREADY);
-
-       mdsDbus *dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle) {
-               ERR("_mdsc_dbus_start() Fail");
-               return MODES_ERROR_SYSTEM;
-       }
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
+       RETV_IF(NULL == handle->conn, MODES_ERROR_INVALID_PARAMETER);
 
        mdsc_noti_data.cb = cb;
        mdsc_noti_data.user_data = user_data;
 
-       mdsc_noti_signal_ID = g_signal_connect(dbus_handle,
+       mdsc_noti_signal_ID = g_signal_connect(handle->conn,
                "changed-mode",
                G_CALLBACK(_on_changed_mode),
                NULL);
@@ -57,17 +53,13 @@ API int modes_subscribe_mode_changes(modes_noti_fn cb, void *user_data)
 }
 
 //TODO: modes_noti_disconnect(ModesNotiFunc cb, void *user_data)
-API void modes_unsubscribe_mode_changes()
+API void modes_unsubscribe_mode_changes(modes_h handle)
 {
        RET_IF(0 == mdsc_noti_signal_ID);
+       RET_IF(NULL == handle);
+       RET_IF(NULL == handle->conn);
 
-       mdsDbus *dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle)
-               ERR("mdsc_dbus_start() Fail");
-
-       g_signal_handler_disconnect(dbus_handle, mdsc_noti_signal_ID);
+       g_signal_handler_disconnect(handle->conn, mdsc_noti_signal_ID);
        mdsc_noti_data.cb = NULL;
        mdsc_noti_data.user_data = NULL;
-
-       mdsc_dbus_stop(dbus_handle);
 }
index 7eb958e0388136b939ae47247084f32b032f6de8..cea8916b7824068a1133f6188ceda53ffdb611d6 100644 (file)
@@ -18,7 +18,6 @@
 #include <stdlib.h>
 #include <glib.h>
 #include "mdsc.h"
-#include "mdsc_dbus.h"
 #include "common/dbus.h"
 #include "common/dbus_def.h"
 
@@ -28,7 +27,7 @@ struct mds_action_handle {
        char *value;
 };
 
-struct mds_handle {
+struct mds_mode_handle {
        char *name;
        modes_type_mode_e type;
        bool hidden;
@@ -65,7 +64,7 @@ static void _mdsc_free_action(gpointer data)
        free(action_data);
 }
 
-static GVariant* _mdsc_create_mode_data(modes_h mode)
+static GVariant* _mdsc_create_mode_data(modes_mode_h mode)
 {
        RETV_IF(NULL == mode, NULL);
 
@@ -86,13 +85,13 @@ static GVariant* _mdsc_create_mode_data(modes_h mode)
        return mode_data;
 }
 
-API modes_h modes_create_mode(const char *name, modes_type_mode_e type)
+API modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type)
 {
-       struct mds_handle *mode;
+       struct mds_mode_handle *mode;
 
        RETV_IF(NULL == name, NULL);
 
-       mode = malloc(sizeof(struct mds_handle));
+       mode = malloc(sizeof(struct mds_mode_handle));
        RETV_IF(NULL == mode, NULL);
 
        mode->name = strdup(name);
@@ -103,7 +102,7 @@ API modes_h modes_create_mode(const char *name, modes_type_mode_e type)
        return mode;
 }
 
-API int modes_set_hidden(modes_h mode, bool hidden)
+API int modes_set_hidden(modes_mode_h mode, bool hidden)
 {
        RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
 
@@ -112,7 +111,7 @@ API int modes_set_hidden(modes_h mode, bool hidden)
        return MODES_ERROR_NONE;
 }
 
-API action_h modes_create_action(const char *name, const char *value)
+API modes_action_h modes_create_action(const char *name, const char *value)
 {
        struct mds_action_handle *action;
 
@@ -129,7 +128,7 @@ API action_h modes_create_action(const char *name, const char *value)
        return action;
 }
 
-API int modes_action_set_id(action_h action, const char *id)
+API int modes_action_set_id(modes_action_h action, const char *id)
 {
        RETV_IF(NULL == action, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == id, MODES_ERROR_INVALID_PARAMETER);
@@ -138,7 +137,7 @@ API int modes_action_set_id(action_h action, const char *id)
        return MODES_ERROR_NONE;
 }
 
-API int modes_mode_add_action(modes_h mode, action_h 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);
@@ -148,34 +147,26 @@ API int modes_mode_add_action(modes_h mode, action_h action)
        return MODES_ERROR_NONE;
 }
 
-API int modes_register_mode(modes_h mode)
+API int modes_register_mode(modes_h handle, modes_mode_h mode)
 {
        int ret;
-       mdsDbus *dbus_handle;
 
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == mode, MODES_ERROR_INVALID_PARAMETER);
 
-       dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle) {
-               ERR("mdsc_dbus_start() Fail");
-               return MODES_ERROR_SYSTEM;
-       }
-
        GVariant *mode_data = _mdsc_create_mode_data(mode);
        RETV_IF(NULL == mode_data, MODES_ERROR_INVALID_PARAMETER);
 
-       ret = _mdsc_dbus_register_mode_sync(dbus_handle, mode_data);
+       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;
        }
 
-       mdsc_dbus_stop(dbus_handle);
-
        return MODES_ERROR_NONE;
 }
 
-API void modes_destroy_mode(modes_h mode)
+API void modes_destroy_mode(modes_mode_h mode)
 {
        RET_IF(NULL == mode);
 
index 685020b7fe81aac88f3342577de589210a2671b9..b5dd7745037c0aa65a9f7766de32a19ca927b571 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <glib.h>
 #include "mdsc.h"
-#include "mdsc_dbus.h"
 #include "common/dbus.h"
 
 static int _mdsc_dbus_undo_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
@@ -38,26 +37,18 @@ static int _mdsc_dbus_undo_mode_sync(mdsDbus *mdsc_dbus, const char *mode)
        return result;
 }
 
-API int modes_undo_mode(const char *name)
+API int modes_undo_mode(modes_h handle, const char *name)
 {
        int ret;
-       mdsDbus *dbus_handle;
 
+       RETV_IF(NULL == handle, MODES_ERROR_INVALID_PARAMETER);
        RETV_IF(NULL == name, MODES_ERROR_INVALID_PARAMETER);
 
-       dbus_handle = mdsc_dbus_start();
-       if (NULL == dbus_handle) {
-               ERR("mdsc_dbus_start() Fail");
-               return MODES_ERROR_SYSTEM;
-       }
-
-       ret = _mdsc_dbus_undo_mode_sync(dbus_handle, name);
+       ret = _mdsc_dbus_undo_mode_sync(handle->conn, name);
        if (MODES_ERROR_NONE != ret) {
                ERR("_mdsc_bus_client_change_mode_sync() Fail(%d)", ret);
                return ret;
        }
 
-       mdsc_dbus_stop(dbus_handle);
-
        return MODES_ERROR_NONE;
 }
index 7ed9076073cb0df685b722a3940b6e1a7e6ee775..606ceefdca2a3015363a55d9ad41c76bef6f635c 100644 (file)
@@ -35,6 +35,28 @@ extern "C" {
  * @{
  */
 
+/**
+ * @brief connect mode server.
+ * @details Calls this function to connect mode server
+ * @since_tizen 6.0
+ * @privlevel public
+ * @return @c handle of modes server
+ *         otherwise a negative error value
+ * @retval #MODES_ERROR_NONE Successful
+ * @retval #MODES_ERROR_NOT_SUPPORTED Not supported
+ * @retval #MODES_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #MODES_ERROR_SYSTEM System errors
+ */
+modes_h modes_connect();
+
+/**
+ * @brief disconnect mode server.
+ * @details Calls this function to disconnect mode server
+ * @since_tizen 6.0
+ * @privlevel public
+ */
+void modes_disconnect(modes_h handle);
+
 /**
  * @brief Apply mode with the given name.
  * @details Calls this function to change Modes.
@@ -51,7 +73,7 @@ extern "C" {
  * @retval #MODES_ERROR_PERMISSION_DENIED Permission denied
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_apply_mode(const char *name);
+int modes_apply_mode(modes_h handle, const char *name);
 
 /**
  * @brief Precheck to apply mode with the given name.
@@ -69,7 +91,7 @@ int modes_apply_mode(const char *name);
  * @retval #MODES_ERROR_CONFLICT Conflict
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_can_apply(const char *name);
+int modes_can_apply(modes_h handle, const char *name);
 
 /**
  * @brief undo mode with the given name.
@@ -87,7 +109,7 @@ int modes_can_apply(const char *name);
  * @retval #MODES_ERROR_PERMISSION_DENIED Permission denied
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_undo_mode(const char *name);
+int modes_undo_mode(modes_h handle, const char *name);
 
 
 /**
@@ -102,7 +124,7 @@ int modes_undo_mode(const char *name);
  *         otherwise NULL value
  * @retval NULL Failed to create the mode handler
  */
-modes_h modes_create_mode(const char *name, modes_type_mode_e type);
+modes_mode_h modes_create_mode(const char *name, modes_type_mode_e type);
 
 /**
  * @brief Set Mode hidden.
@@ -117,7 +139,7 @@ modes_h modes_create_mode(const char *name, modes_type_mode_e type);
  * @retval #MODES_ERROR_NONE Successful
  * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
  */
-int modes_set_hidden(modes_h mode, bool hidden);
+int modes_set_hidden(modes_mode_h mode, bool hidden);
 
 /**
  * @brief Create Action.
@@ -132,7 +154,7 @@ int modes_set_hidden(modes_h mode, bool hidden);
  *         otherwise  NULL value
  * @retval NULL Failed to create the action handler
  */
-action_h modes_create_action(const char *name, const char *value);
+modes_action_h modes_create_action(const char *name, const char *value);
 
 
 /**
@@ -147,7 +169,7 @@ action_h modes_create_action(const char *name, const char *value);
  * @retval #MODES_ERROR_NONE Successful
  * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
  */
-int modes_action_set_id(action_h action, const char *id);
+int modes_action_set_id(modes_action_h action, const char *id);
 
 /**
  * @brief Add Action to Mode.
@@ -161,7 +183,7 @@ int modes_action_set_id(action_h action, const char *id);
  * @retval #MODES_ERROR_NONE Successful
  * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
  */
-int modes_mode_add_action(modes_h mode, action_h action);
+int modes_mode_add_action(modes_mode_h mode, modes_action_h action);
 
 /**
  * @brief Register Mode.
@@ -175,7 +197,7 @@ int modes_mode_add_action(modes_h mode, action_h action);
  * @retval #MODES_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #MODES_ERROR_SYSTEM System errors
  */
-int modes_register_mode(modes_h mode);
+int modes_register_mode(modes_h handle, modes_mode_h mode);
 
 /**
  * @brief Destroy Mode handle
@@ -185,7 +207,7 @@ int modes_register_mode(modes_h mode);
  * @param[in] Mode handle to destroy
  * @return void
  */
-void modes_destroy_mode(modes_h mode);
+void modes_destroy_mode(modes_mode_h mode);
 
 
 /**
@@ -216,7 +238,7 @@ typedef int (*modes_noti_fn) (const char *mode_name, int state, void *user_data)
  *
  * @see modes_unsubscribe_mode_changes()
  */
-int modes_subscribe_mode_changes(modes_noti_fn cb, void *user_data);
+int modes_subscribe_mode_changes(modes_h handle, modes_noti_fn cb, void *user_data);
 
 /**
  * @brief stop recognizing the changed of mode.
@@ -234,7 +256,7 @@ typedef struct {
        int state;
 } modes_mode_t;
 
-int modes_get_modes(GList **list);
+int modes_get_modes(modes_h handle, GList **list);
 void modes_free_modes(GList *list);
 
 /**
index 92e04160c3ec498f019cea8665c1dde2e0ca41a5..dc4e1a396f7b65473decf3f31203f50ab812ea9c 100644 (file)
 
 /**
  * @brief The Modes handle.
- * @details @a modes_h is an opaque data structure to represent Modes handler.
+ * @details @a modes_h is an opaque data structure to represent modes handler.
  * @since_tizen 6.0
  */
 typedef struct mds_handle* modes_h;
 
-
 /**
- * @brief The mds_action_handle type values action handle.
- * @details @a action_h is an opaque data structure.
+ * @brief The Modes mode handle.
+ * @details @a modes_mode_h is an opaque data structure to represent mode data.
  * @since_tizen 6.0
  */
-typedef struct mds_action_handle* action_h;
+typedef struct mds_mode_handle* modes_mode_h;
 
 
 /**
- * @brief The modes_value_h type values list handle.
- * @details @a modes_list_h is an opaque data structure.
+ * @brief The mds_action_handle type values action handle.
+ * @details @a action_h is an opaque data structure.
  * @since_tizen 6.0
  */
-typedef struct mds_list_s* modes_list_h;
+typedef struct mds_action_handle* modes_action_h;
+
+
 /**
  * @}
  */
index 2788b454df2b630b40898db4f039d520f944e2be..25931117d87cad0d6af8e0ca950f6cc8116993c9 100644 (file)
 #include "common/log.h"
 
 static GMainLoop *_modes_loop;
+static modes_h _handle;
 
 #define PERR(fmt, arg...) printf("\033[31m %d:" fmt "\n \033[0m", __LINE__, ##arg)
 
 static gboolean apply_idler(gpointer data)
 {
-       int ret = modes_apply_mode(data);
+       int ret = modes_apply_mode(_handle, data);
        if (MODES_ERROR_NONE != ret)
                PERR("modes_apply_mode() Fail(%d)", ret);
 
@@ -37,7 +38,7 @@ static gboolean apply_idler(gpointer data)
 
 static gboolean can_apply_idler(gpointer data)
 {
-       int ret = modes_can_apply(data);
+       int ret = modes_can_apply(_handle, data);
        if (MODES_ERROR_NONE != ret)
                PERR("modes_can_apply() Fail(%d)", ret);
 
@@ -47,7 +48,7 @@ static gboolean can_apply_idler(gpointer data)
 
 static gboolean undo_idler(gpointer data)
 {
-       int ret = modes_undo_mode(data);
+       int ret = modes_undo_mode(_handle, data);
        if (MODES_ERROR_NONE != ret)
                PERR("modes_undo_mode() Fail(%d)", ret);
 
@@ -69,7 +70,7 @@ int main(int argc, char **argv)
                print_usage(argv[0]);
                return -1;
        }
-
+       _handle = modes_connect();
        _modes_loop = g_main_loop_new(NULL, FALSE);
        if (0 == strcasecmp(argv[1], "apply")) {
                g_idle_add(apply_idler, argv[2]);
@@ -83,7 +84,9 @@ int main(int argc, char **argv)
        }
 
        g_main_loop_run(_modes_loop);
-
        g_main_loop_unref(_modes_loop);
+
+       modes_disconnect(_handle);
+       _handle = NULL;
        return 0;
 }
index 3d42d6bad325fbdb529eebdfe2c2cbf98caecaeb..7a591b5d79e92b779ffe8655bb4a42ece16eeaff 100644 (file)
@@ -22,21 +22,24 @@ protected:
        void SetUp() override
        {
                loop = g_main_loop_new(NULL, FALSE);
+               handle = modes_connect();
        }
 
        void TearDown() override
        {
                g_main_loop_unref(loop);
                loop = NULL;
+               modes_disconnect(handle);
+               handle = NULL;
        }
 
        static gboolean ModeIdler(gpointer data)
        {
                int ret;
-               ret = modes_apply_mode((char*)data);
+               ret = modes_apply_mode(handle, (char*)data);
                EXPECT_EQ(MODES_ERROR_NONE, ret);
                sleep(1);
-               ret = modes_undo_mode((char*)data);
+               ret = modes_undo_mode(handle, (char*)data);
                EXPECT_EQ(MODES_ERROR_NONE, ret);
 
                g_main_loop_quit(loop);
@@ -46,25 +49,26 @@ protected:
        static gboolean failIdler(gpointer data)
        {
                int ret;
-               ret = modes_apply_mode((char*)data);
+               ret = modes_apply_mode(handle, (char*)data);
                EXPECT_EQ(MODES_ERROR_SYSTEM, ret);
                sleep(1);
-               ret = modes_undo_mode((char*)data);
+               ret = modes_undo_mode(handle, (char*)data);
                EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
        }
-
+       static modes_h handle;
        static GMainLoop *loop;
 };
 
+modes_h AsyncTest::handle = NULL;
 GMainLoop *AsyncTest::loop = NULL;
 
 TEST_F(AsyncTest, normalAsync)
 {
        const char *modeName = "asyncEx1";
-       modes_undo_mode(modeName);
+       modes_undo_mode(handle, modeName);
        g_idle_add(ModeIdler, (gpointer)modeName);
        g_main_loop_run(loop);
 }
@@ -72,14 +76,14 @@ TEST_F(AsyncTest, normalAsync)
 TEST_F(AsyncTest, oneshotAsync)
 {
        const char *modeName = "asyncEx2";
-       int ret = modes_apply_mode(modeName);
+       int ret = modes_apply_mode(handle, modeName);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 }
 
 TEST_F(AsyncTest, normalAsyncFail)
 {
        const char *modeName = "asyncFail1";
-       modes_undo_mode(modeName);
+       modes_undo_mode(handle, modeName);
        g_idle_add(failIdler, (gpointer)modeName);
        g_main_loop_run(loop);
 }
index 1d2466713f8e4bc253128f88b61c8dc106303700..3018a84c172ab9a8fab199f262a0a3923ef8fbdd 100644 (file)
@@ -22,6 +22,7 @@ class ClientTest : public ::testing::Test {
 protected:
        void SetUp() override
        {
+               handle = modes_connect();
                loop = g_main_loop_new(NULL, FALSE);
        }
 
@@ -29,11 +30,13 @@ protected:
        {
                g_main_loop_unref(loop);
                loop = NULL;
+               modes_disconnect(handle);
+               handle = NULL;
        }
 
        static gboolean applyModeIdler(gpointer data)
        {
-               result = modes_apply_mode((const char*)data);
+               result = modes_apply_mode(handle, (const char*)data);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
@@ -41,10 +44,10 @@ protected:
 
        static gboolean undoModeIdler(gpointer data)
        {
-               result = modes_apply_mode((const char*)data);
+               result = modes_apply_mode(handle, (const char*)data);
                EXPECT_EQ(MODES_ERROR_NONE, result);
                sleep(1);
-               result = modes_undo_mode((const char*)data);
+               result = modes_undo_mode(handle, (const char*)data);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
@@ -52,38 +55,40 @@ protected:
 
        static gboolean registerModeIdler(gpointer data)
        {
-               modes_h mode_handle = modes_create_mode("created", MODES_TYPE_MODE_NORMAL);
-               action_h action_handle[2];
+               modes_mode_h created_mode = modes_create_mode("created", MODES_TYPE_MODE_NORMAL);
+               modes_action_h action_handle[2];
                action_handle[0] = modes_create_action("test.printBool", "on");
                modes_action_set_id(action_handle[0], "printBoolOn");
                action_handle[1] = modes_create_action("test.printBool", "off");
                modes_action_set_id(action_handle[1], "printBoolOff");
 
                for (int i = 0; i < 2; i++) {
-                       result = modes_mode_add_action(mode_handle, action_handle[i]);
+                       result = modes_mode_add_action(created_mode, action_handle[i]);
                        EXPECT_EQ(MODES_ERROR_NONE, result);
                }
 
-               result = modes_set_hidden(mode_handle, true);
+               result = modes_set_hidden(created_mode, true);
                EXPECT_EQ(MODES_ERROR_NONE, result);
 
-               result = modes_register_mode(mode_handle);
-               modes_destroy_mode(mode_handle);
+               result = modes_register_mode(handle, created_mode);
+               modes_destroy_mode(created_mode);
 
                g_main_loop_quit(loop);
                return G_SOURCE_REMOVE;
        }
 
+       static modes_h handle;
        static int result;
        static GMainLoop *loop;
 };
 
+modes_h ClientTest::handle = NULL;
 int ClientTest::result = 0;
 GMainLoop *ClientTest::loop = NULL;
 
 TEST_F(ClientTest, applyModeP)
 {
-       modes_undo_mode("ex1");
+       modes_undo_mode(handle, "ex1");
        g_idle_add(applyModeIdler, (gpointer)"ex1");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
@@ -98,25 +103,25 @@ TEST_F(ClientTest, applyModeN)
 
 TEST_F(ClientTest, canApplyModeP)
 {
-       modes_undo_mode("ex1");
-       int ret = modes_can_apply("ex1");
+       modes_undo_mode(handle, "ex1");
+       int ret = modes_can_apply(handle, "ex1");
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 }
 
 TEST_F(ClientTest, canApplyModeN)
 {
-       int ret = modes_can_apply("ex4");
+       int ret = modes_can_apply(handle, "ex4");
        EXPECT_EQ(MODES_ERROR_NO_DATA, ret);
 }
 
 TEST_F(ClientTest, canApplyModeConflictExclusive)
 {
-       modes_undo_mode("ex2");
+       modes_undo_mode(handle, "ex2");
        g_idle_add(applyModeIdler, (gpointer)"ex2");
        g_main_loop_run(loop);
-       int ret = modes_can_apply("ex1");
+       int ret = modes_can_apply(handle, "ex1");
        EXPECT_EQ(MODES_ERROR_CONFLICT, ret);
-       modes_undo_mode("ex2");
+       modes_undo_mode(handle, "ex2");
 }
 
 TEST_F(ClientTest, registerMode)
@@ -128,7 +133,7 @@ TEST_F(ClientTest, registerMode)
 
 TEST_F(ClientTest, undoModeEx1)
 {
-       modes_undo_mode("ex1");
+       modes_undo_mode(handle, "ex1");
        g_idle_add(undoModeIdler, (gpointer)"ex1");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
@@ -136,7 +141,7 @@ TEST_F(ClientTest, undoModeEx1)
 
 TEST_F(ClientTest, undoModeEx2)
 {
-       modes_undo_mode("ex2");
+       modes_undo_mode(handle, "ex2");
        g_idle_add(undoModeIdler, (gpointer)"ex2");
        g_main_loop_run(loop);
        EXPECT_EQ(MODES_ERROR_NONE, result);
@@ -145,7 +150,7 @@ TEST_F(ClientTest, undoModeEx2)
 TEST_F(ClientTest, getModes)
 {
        GList *list, *cur;
-       int ret = modes_get_modes(&list);
+       int ret = modes_get_modes(handle, &list);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 
        for (cur = g_list_first(list); cur; cur = g_list_next(cur)) {
index 8c4c743273b12dfa4aabca615d4576ab6f80c91a..a051b004d8059812783af9e60af269bce72539d7 100644 (file)
@@ -21,6 +21,7 @@ class ClientNotiTest : public ::testing::Test {
 protected:
        void SetUp() override
        {
+               handle = modes_connect();
                loop = g_main_loop_new(NULL, FALSE);
        }
 
@@ -28,12 +29,14 @@ protected:
        {
                g_main_loop_unref(loop);
                loop = NULL;
+               modes_disconnect(handle);
+               handle = NULL;
        }
 
        static gboolean undoTimeout(gpointer data)
        {
                expectedState = 0;
-               int ret = modes_undo_mode((const char*)data);
+               int ret = modes_undo_mode(handle, (const char*)data);
                EXPECT_EQ(MODES_ERROR_NONE, ret);
 
                return  G_SOURCE_REMOVE;
@@ -53,21 +56,23 @@ protected:
                return MODES_ERROR_NONE;
        }
 
+       static modes_h handle;
        static int expectedState;
        static GMainLoop *loop;
 };
 
+modes_h ClientNotiTest::handle = NULL;
 int ClientNotiTest::expectedState = 1;
 GMainLoop *ClientNotiTest::loop = NULL;
 
 TEST_F(ClientNotiTest, notiConnect)
 {
        const char *testMode = "ex2";
-       int ret = modes_subscribe_mode_changes(notiFunc, (void*)testMode);
+       int ret = modes_subscribe_mode_changes(handle, notiFunc, (void*)testMode);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 
        ClientNotiTest::expectedState = 1;
-       ret = modes_apply_mode(testMode);
+       ret = modes_apply_mode(handle, testMode);
        EXPECT_EQ(MODES_ERROR_NONE, ret);
 
        g_timeout_add_seconds(1, undoTimeout, (void*)testMode);