--- /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 <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);
+}
#pragma once
#include "modes.h"
+#include "common/dbus.h"
#include "common/log.h"
#include "common/definitions.h"
+
+struct mds_handle {
+ mdsDbus *conn;
+};
#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;
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;
}
#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;
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;
}
+++ /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 "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;
-}
#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)
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;
}
free(mode->name);
free(mode);
}
+
API void modes_free_modes(GList *list)
{
g_list_foreach(list, _free_mode, NULL);
#include <glib.h>
#include "mdsc.h"
-#include "mdsc_dbus.h"
+#include "common/dbus.h"
struct mdsc_noti_data_s {
modes_noti_fn cb;
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);
}
//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);
}
#include <stdlib.h>
#include <glib.h>
#include "mdsc.h"
-#include "mdsc_dbus.h"
#include "common/dbus.h"
#include "common/dbus_def.h"
char *value;
};
-struct mds_handle {
+struct mds_mode_handle {
char *name;
modes_type_mode_e type;
bool hidden;
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);
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);
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);
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;
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);
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);
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);
#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)
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;
}
* @{
*/
+/**
+ * @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.
* @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.
* @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.
* @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);
/**
* 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.
* @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.
* 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);
/**
* @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.
* @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.
* @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
* @param[in] Mode handle to destroy
* @return void
*/
-void modes_destroy_mode(modes_h mode);
+void modes_destroy_mode(modes_mode_h mode);
/**
*
* @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.
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);
/**
/**
* @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;
+
+
/**
* @}
*/
#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);
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);
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);
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]);
}
g_main_loop_run(_modes_loop);
-
g_main_loop_unref(_modes_loop);
+
+ modes_disconnect(_handle);
+ _handle = NULL;
return 0;
}
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);
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);
}
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);
}
protected:
void SetUp() override
{
+ handle = modes_connect();
loop = g_main_loop_new(NULL, FALSE);
}
{
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;
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;
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);
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)
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);
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);
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)) {
protected:
void SetUp() override
{
+ handle = modes_connect();
loop = g_main_loop_new(NULL, FALSE);
}
{
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;
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);