#include <stdio.h>
#include <unistd.h>
-#include <glib.h>
-#include <gio/gio.h>
#include <stdlib.h>
#include <dlog.h>
#include <companion.h>
#include <companion_debug.h>
#include <companion_gdbus.h>
+#include <companion_internal.h>
+#include <companion_dbus_internal.h>
/**
* Companion Manager CAPI
pthread_mutex_unlock(&mutex); \
} while (0);
-#define COMP_DBUS_SERVICE "org.tizen.companion" /**< For companion dbus */
-#define COMP_DBUS_GROUP_PATH "/org/tizen/companion/group" /**< For group dbus */
-#define COMP_DBUS_ENABLER_PATH "/org/tizen/companion/enabler" /**< dbus auto-activation */
-
int ref_count = 0; /**< How many clients are alive */
bool __is_initialized = false; /**< Initialize or not */
-typedef struct _companion_group_t {
- char *uri_path; /**< URI Path for group resource */
- char *device_id; /**< Device ID of the device has this group resource */
- char *group_name; /**< Group Name (Friendly name) */
- char *host_addr; /**< Host address */
- char *resource_type; /**< Resource type */
- companion_group_type_e type; /**< Mine or Remote */
-} companion_group_t;
-
-typedef struct _companion_device_t {
- char *device_id; /**< Device ID */
- char *ip; /**< Device IP */
- char *device_type; /**< Device Type */
- int port; /**< Port Number */
-} companion_device_t;
-
-typedef struct _group_found_cb_t {
- companion_group_found_cb found_cb;
- void *user_data;
-} group_found_cb_t;
-
-typedef struct _device_found_cb_t {
- companion_device_found_cb found_cb;
- void *user_data;
-} device_found_cb_t;
-
-typedef struct _group_find_finish_cb_t {
- companion_group_find_finish_cb finish_cb;
- void *user_data;
-} group_find_finish_cb_t;
-
-typedef struct _device_find_finish_cb_t {
- companion_device_find_finish_cb finish_cb;
- void *user_data;
-} device_find_finish_cb_t;
-
-typedef struct _mowned_device_found_cb_t {
- companion_device_found_cb found_cb;
- void *user_data;
-} mowned_device_found_cb_t;
-
-typedef struct _mowned_device_find_finish_cb_t {
- companion_device_find_finish_cb finish_cb;
- void *user_data;
-} mowned_device_find_finish_cb_t;
-
-typedef struct _device_invite_result_cb_t {
- companion_device_invite_result_cb result_cb;
- void *user_data;
-} device_invite_result_cb_t;
-
-typedef struct _device_eject_result_cb_t {
- companion_device_eject_result_cb result_cb;
- void *user_data;
-} device_eject_result_cb_t;
-
-typedef struct _send_data_finish_cb_t {
- companion_send_data_finish_cb finish_cb;
- void *user_data;
-} send_data_finish_cb_t;
-
-typedef struct _request_result_cb_t {
- companion_request_result_cb result_cb;
- void *user_data;
-} request_result_cb_t;
-
-typedef struct _comp_manager_s {
- gpointer dbus_connection;
- GCancellable *ca;
-
- Group *group_proxy; /**< To receive signal from companion-manager */
- Enabler *enabler_proxy; /**< Enbler proxy */
-
- group_found_cb_t group_found_cb;
- device_found_cb_t device_found_cb;
- group_find_finish_cb_t group_find_finish_cb;
- device_find_finish_cb_t device_find_finish_cb;
- mowned_device_found_cb_t mowned_device_found_cb;
- mowned_device_find_finish_cb_t mowned_device_find_finish_cb;
- device_invite_result_cb_t device_invite_result_cb;
- device_eject_result_cb_t device_eject_result_cb;
- send_data_finish_cb_t send_data_finish_cb;
- request_result_cb_t request_result_cb;
-} comp_manager_s;
-
-static companion_group_t *_create_group_handle(char *uri_path, char *device_id,
+static companion_group_s *_create_group_handle(char *uri_path, char *device_id,
char *group_name, char *host_addr, char *resource_type, companion_group_type_e type)
{
- companion_group_t *group = calloc(1, sizeof(companion_group_t));
+ companion_group_s *group = calloc(1, sizeof(companion_group_s));
if (NULL == group) {
/* LCOV_EXCL_START */
_ERR("Memory allocation failed");
/* LCOV_EXCL_STOP */
}
-static companion_device_t *_create_device_handle(char *device_id, char *ip,
+static companion_device_s *_create_device_handle(char *device_id, char *ip,
char *device_type, int port)
{
- companion_device_t *device = calloc(1, sizeof(companion_device_t));
+ companion_device_s *device = calloc(1, sizeof(companion_device_s));
if (NULL == device) {
/* LCOV_EXCL_START */
_ERR("Memory allocation failed");
/* LCOV_EXCL_STOP */
}
+/* LCOV_EXCL_START */
static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
{
GVariantIter *iter = NULL;
const gchar *key;
GVariant *key_value = NULL;
- companion_group_t *group = NULL;
+ companion_group_s *group = NULL;
char *uri_path = NULL;
char *device_id = NULL;
char *group_name = NULL;
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
g_variant_get(va, "a{sv}", &iter);
while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->group_find_finish_cb.finish_cb)
handle->group_find_finish_cb.finish_cb(ret,
handle->group_find_finish_cb.user_data);
GVariantIter *iter_row = NULL;
const gchar *key;
GVariant *key_value;
- companion_device_t *device = NULL;
+ companion_device_s *device = NULL;
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
g_variant_get(va, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->device_find_finish_cb.finish_cb)
handle->device_find_finish_cb.finish_cb(ret,
handle->device_find_finish_cb.user_data);
GVariantIter *iter_row = NULL;
const gchar *key;
GVariant *key_value;
- companion_device_t *device = NULL;
+ companion_device_s *device = NULL;
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
g_variant_get(va, "aa{sv}", &iter);
while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->mowned_device_find_finish_cb.finish_cb)
handle->mowned_device_find_finish_cb.finish_cb(ret,
handle->mowned_device_find_finish_cb.user_data);
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->device_invite_result_cb.result_cb)
handle->device_invite_result_cb.result_cb(ret,
handle->device_invite_result_cb.user_data);
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->device_eject_result_cb.result_cb)
handle->device_eject_result_cb.result_cb(ret,
handle->device_eject_result_cb.user_data);
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->send_data_finish_cb.finish_cb)
handle->send_data_finish_cb.finish_cb(ret, resp_data,
handle->send_data_finish_cb.user_data);
NOTUSED(object);
comp_manager_s *handle = user_data;
- if (!handle) {
- /* LCOV_EXCL_START */
- _ERR("handle is null");
- return;
- /* LCOV_EXCL_STOP */
- }
+ companion_check_null_ret("user_data", user_data);
+
if (handle->request_result_cb.result_cb)
handle->request_result_cb.result_cb(cmd, arg, ret,
handle->request_result_cb.user_data);
}
-
-static int _group_proxy_init(comp_manager_s *handle);
-static int _enabler_proxy_init(comp_manager_s *handle);
-static void _group_proxy_deinit(comp_manager_s *handle);
-static void _enabler_proxy_deinit(comp_manager_s *handle);
-
-static int _gdbus_initialize(comp_manager_s *handle)
-{
- int ret = COMP_ERROR_NONE;
-
- _group_proxy_init(handle);
- _enabler_proxy_init(handle);
-
- if (handle->group_proxy == NULL)
- ret = -1; /* LCOV_EXCL_LINE */
-
- if (handle->enabler_proxy == NULL)
- ret = -1; /* LCOV_EXCL_LINE */
-
- handle->ca = g_cancellable_new();
-
- return ret;
-}
-
-static int _gdbus_deinitialize(comp_manager_s *handle)
-{
- int ret = COMP_ERROR_NONE;
-
- _group_proxy_deinit(handle);
- _enabler_proxy_deinit(handle);
-
- g_cancellable_cancel(handle->ca);
- g_object_unref(handle->ca);
- handle->ca = NULL;
-
- return ret;
-}
-
-static int _enabler_proxy_init(comp_manager_s *handle)
-{
- int ret = COMP_ERROR_NONE;
- GError *error = NULL;
- handle->enabler_proxy = enabler_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE, COMP_DBUS_SERVICE,
- COMP_DBUS_ENABLER_PATH, NULL, &error);
- if (NULL == handle->enabler_proxy) {
- /* LCOV_EXCL_START */
- if (error != NULL) {
- _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
- g_error_free(error);
- }
- return COMP_ERROR_IO_ERROR;
- /* LCOV_EXCL_STOP */
- }
- return ret;
-}
-
-static void _group_proxy_deinit(comp_manager_s *handle)
-{
- g_object_unref(handle->group_proxy);
- handle->group_proxy = NULL;
-}
-
-static void _enabler_proxy_deinit(comp_manager_s *handle)
-{
- int ret;
-
- enabler_call_disable_sync(handle->enabler_proxy, &ret, NULL, NULL);
- g_object_unref(handle->enabler_proxy);
- handle->enabler_proxy = NULL;
-}
-
-/* LCOV_EXCL_START */
-static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
- gpointer *user_data)
-{
- GDBusProxy *proxy = G_DBUS_PROXY(object);
- gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
- comp_manager_s *handle = (comp_manager_s *)user_data;
- if (!handle) {
- _ERR("handle is null");
- return;
- }
-
- LOGD("Name owner notify [%s]", name_owner);
-
- if (NULL == name_owner)
- _gdbus_deinitialize(handle);
- free(name_owner);
-
-}
/* LCOV_EXCL_STOP */
-static int _group_proxy_init(comp_manager_s *handle)
-{
- int id = -1;
- GError *error = NULL;
-
- handle->group_proxy = group_proxy_new_for_bus_sync(
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_NONE,
- COMP_DBUS_SERVICE,
- COMP_DBUS_GROUP_PATH,
- NULL,
- &error);
- if (NULL == handle->group_proxy) {
- /* LCOV_EXCL_START */
- if (error != NULL) {
- _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
- g_error_free(error);
- }
- return COMP_ERROR_IO_ERROR;
- /* LCOV_EXCL_STOP */
- }
-
- id = g_signal_connect(handle->group_proxy, "notify::g-name-owner",
- G_CALLBACK(_dbus_name_owner_notify), handle);
- if (0 == id) {
- /* LCOV_EXCL_START */
- _ERR("g_signal_connect() Fail");
- g_object_unref(handle->group_proxy);
- handle->group_proxy = NULL;
- return COMP_ERROR_IO_ERROR;
- /* LCOV_EXCL_STOP */
- }
-
- g_signal_connect(handle->group_proxy,
- "group-found", G_CALLBACK(__group_found_cb), handle);
- g_signal_connect(handle->group_proxy,
- "group-find-finish", G_CALLBACK(_group_find_finish_cb), handle);
- g_signal_connect(handle->group_proxy,
- "device-found", G_CALLBACK(__device_found_cb), handle);
- g_signal_connect(handle->group_proxy,
- "device-find-finish", G_CALLBACK(_device_find_finish_cb), handle);
- g_signal_connect(handle->group_proxy,
- "mowned-device-found", G_CALLBACK(__mowned_device_found_cb), handle);
- g_signal_connect(handle->group_proxy,
- "mowned-device-find-finish", G_CALLBACK(_mowned_device_find_finish_cb), handle);
- g_signal_connect(handle->group_proxy,
- "device-invite-result", G_CALLBACK(__device_invite_result_cb), handle);
- g_signal_connect(handle->group_proxy,
- "device-eject-result", G_CALLBACK(__device_eject_result_cb), handle);
- g_signal_connect(handle->group_proxy,
- "send-data-finish", G_CALLBACK(__send_data_finish_cb), handle);
- g_signal_connect(handle->group_proxy,
- "request-result", G_CALLBACK(__request_result_cb), handle);
-
- return COMP_ERROR_NONE;
-}
-
EXPORT_API int companion_initialize(companion_h *handle)
{
int ret = COMP_ERROR_NONE;
*handle = comp_manager;
if (__is_initialized) {
+ /* LCOV_EXCL_START */
_DBG("Already initialized");
return COMP_ERROR_ALREADY_INITIALIZED;
+ /* LCOV_EXCL_STOP */
}
COMPANION_LOCK;
- ret = _gdbus_initialize(*handle);
+ ret = gdbus_initialize(*handle);
__is_initialized = true;
COMPANION_UNLOCK;
ref_count++;
COMPANION_LOCK;
if (0 > --ref_count) {
+ /* LCOV_EXCL_START */
_DBG("all connections closed\n");
ref_count = 0;
return ret;
+ /* LCOV_EXCL_STOP */
}
if (__is_initialized == true && ref_count == 0) {
- ret = _gdbus_deinitialize(handle);
+ ret = gdbus_deinitialize(handle);
__is_initialized = false;
}
EXPORT_API int companion_group_create(companion_h handle, char *group_name)
{
int ret = COMP_ERROR_NONE;
+
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
/* create group to daemon using gdbus */
group_call_create_sync(_handle->group_proxy, group_name, &ret, NULL, &error);
return ret;
}
-EXPORT_API void companion_group_destroy(companion_group_t *group)
+EXPORT_API void companion_group_destroy(companion_group_s *group)
{
companion_check_null_ret("group", group);
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
_handle->group_found_cb.found_cb = found_cb;
_handle->group_find_finish_cb.finish_cb = finish_cb;
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
/* get groups from daemon using gdbus */
group_call_get_found_groups_sync(_handle->group_proxy, &ret, &va, NULL, &error);
char *host_addr = NULL;
char *resource_type = NULL;
- companion_group_t *group = NULL;
+ companion_group_s *group = NULL;
companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
void *user_data)
{
int ret = COMP_ERROR_NONE;
+
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
_handle->device_found_cb.found_cb = found_cb;
_handle->device_found_cb.user_data = user_data;
companion_device_find_finish_cb finish_cb, void *user_data)
{
int ret = COMP_ERROR_NONE;
+
GError *error = NULL;
comp_manager_s *_handle = handle;
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
- companion_device_t *dev = (companion_device_t *)device;
- if (!dev) {
- _ERR("dev is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_device_s *dev = (companion_device_s *)device;
+ companion_check_null_ret_error("dev", dev, COMP_ERROR_INVALID_PARAMETER);
buf = g_malloc0(len + 1);
if (NULL == buf) {
EXPORT_API int companion_device_get_found_devices(companion_h handle,
companion_device_h **devices, int *count)
{
- int ret = 0;
+ int ret = COMP_ERROR_NONE;
+
int num = 0;
GVariant *va = NULL;
GError *error = NULL;
comp_manager_s *_handle = handle;
-
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
/* get groups from daemon using gdbus */
group_call_get_remote_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
char *addr = NULL;
char *ver = NULL;
int port;
- companion_device_t *device = NULL;
+ companion_device_s *device = NULL;
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "DeviceID") == 0)
EXPORT_API int companion_device_get_found_mowned_devices(
companion_h handle, companion_device_h **devices, int *count)
{
- int ret = 0;
+ int ret = COMP_ERROR_NONE;
+
int num = 0;
GVariant *va = NULL;
GError *error = NULL;
comp_manager_s *_handle = handle;
-
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
/* get groups from daemon using gdbus */
group_call_get_mowned_device_sync(_handle->group_proxy, &num, &va, NULL, &error);
char *addr = NULL;
char *ver = NULL;
int port;
- companion_device_t *device = NULL;
+ companion_device_s *device = NULL;
while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
if (g_strcmp0(key, "DeviceID") == 0)
EXPORT_API int companion_device_get_my_device(companion_h handle,
companion_device_h *device)
{
- int ret = 0;
+ int ret = COMP_ERROR_NONE;
+
GError *error = NULL;
GVariant *va = NULL;
GVariantIter *iter = NULL;
char *addr = NULL;
char *ver = NULL;
int port = -1;
- comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ comp_manager_s *_handle = handle;
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
group_call_get_my_mowned_device_sync(_handle->group_proxy, &va, NULL, &error);
return ret;
}
-static void companion_device_destroy(companion_device_t *device)
+EXPORT_API void companion_device_destroy(companion_device_h device)
{
+ companion_device_s *_device = device;
companion_check_null_ret("device", device);
- if (device->device_id) {
- g_free(device->device_id);
- device->device_id = NULL;
+ if (_device->device_id) {
+ g_free(_device->device_id);
+ _device->device_id = NULL;
}
- if (device->ip) {
- g_free(device->ip);
- device->ip = NULL;
+ if (_device->ip) {
+ g_free(_device->ip);
+ _device->ip = NULL;
}
- if (device->device_type) {
- g_free(device->device_type);
- device->device_type = NULL;
+ if (_device->device_type) {
+ g_free(_device->device_type);
+ _device->device_type = NULL;
}
- g_free(device);
- device = NULL;
+ g_free(_device);
+ _device = NULL;
}
EXPORT_API int companion_device_get_my_uuid(companion_h handle, char **uuid)
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
group_call_get_my_uuid_sync(_handle->group_proxy, uuid, NULL, &error);
EXPORT_API int companion_group_merge(companion_h hadnle,
companion_group_h dest_group, companion_group_h src_group)
{
+ int ret = COMP_ERROR_NONE;
+
NOTUSED(dest_group);
NOTUSED(src_group);
- return 0;
+
+ return ret;
}
EXPORT_API int companion_group_delete(companion_h handle, companion_group_h group)
{
+ int ret = COMP_ERROR_NONE;
+
NOTUSED(handle);
NOTUSED(group);
- return 0;
+
+ return ret;
}
EXPORT_API int companion_group_get_member_devices(companion_h handle,
companion_group_h group, companion_device_h **devices, int *count)
{
+ int ret = COMP_ERROR_NONE;
+
NOTUSED(handle);
NOTUSED(group);
NOTUSED(devices);
NOTUSED(count);
- return 0;
+ return ret;
}
EXPORT_API int companion_device_invite(companion_h handle,
companion_group_h group, companion_device_h device, char *PIN,
companion_device_invite_result_cb result_cb, void *user_data)
{
- int ret = 0;
+ int ret = COMP_ERROR_NONE;
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
- companion_group_t *grp = (companion_group_t *)group;
- if (!grp) {
- _ERR("grp is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_group_s *grp = (companion_group_s *)group;
+ companion_check_null_ret_error("grp", grp, COMP_ERROR_INVALID_PARAMETER);
- companion_device_t *dev = (companion_device_t *)device;
- if (!dev) {
- _ERR("dev is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_device_s *dev = (companion_device_s *)device;
+ companion_check_null_ret_error("dev", dev, COMP_ERROR_INVALID_PARAMETER);
_handle->device_invite_result_cb.result_cb = result_cb;
_handle->device_invite_result_cb.user_data = user_data;
GError *error = NULL;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
- companion_device_t *dev = (companion_device_t *)device;
- if (!dev) {
- _ERR("dev is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_device_s *dev = (companion_device_s *)device;
+ companion_check_null_ret_error("dev", dev, COMP_ERROR_INVALID_PARAMETER);
_handle->device_eject_result_cb.result_cb = result_cb;
_handle->device_eject_result_cb.user_data = user_data;
EXPORT_API int companion_group_information_create(companion_group_h* group)
{
- companion_group_h _group = g_malloc0(sizeof(companion_group_t));
+ int ret = COMP_ERROR_NONE;
+
+ companion_group_h _group = g_malloc0(sizeof(companion_group_s));
+ if (NULL == _group) {
+ _ERR("Memory allocation Failed(%d)", errno);
+ return COMP_ERROR_OUT_OF_MEMORY;
+ }
*group = _group;
- return 0;
+ return ret;
}
EXPORT_API int companion_group_information_clone(companion_group_h target,
companion_group_h source)
{
- companion_group_t * dst = (companion_group_t *)target;
- companion_group_t * src = (companion_group_t *)source;
+ int ret = COMP_ERROR_NONE;
- if (!dst || !src) {
- _ERR("Invaild parameters: dst=%p src=%p", dst, src);
- return -1;
- }
+ companion_group_s * dst = (companion_group_s *)target;
+ companion_group_s * src = (companion_group_s *)source;
+
+ companion_check_null_ret_error("target", target, COMP_ERROR_INVALID_PARAMETER);
+ companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
if (src->uri_path)
dst->uri_path = g_strdup(src->uri_path);
dst->type = src->type;
- return 0;
+ return ret;
}
EXPORT_API int companion_group_information_destroy(companion_group_h data)
{
- companion_group_t * group = (companion_group_t *)data;
+ int ret = COMP_ERROR_NONE;
- if (!group)
- return -1;
+ companion_group_s * group = (companion_group_s *)data;
+ companion_check_null_ret_error("group", group, COMP_ERROR_INVALID_PARAMETER);
if (group->uri_path) {
g_free(group->uri_path);
group->group_name = NULL;
}
if (group->host_addr) {
- g_free((companion_group_t *)group->host_addr);
+ g_free((companion_group_s *)group->host_addr);
group->host_addr = NULL;
}
if (group->resource_type) {
- g_free((companion_group_t *)group->resource_type);
+ g_free((companion_group_s *)group->resource_type);
group->resource_type = NULL;
}
g_free(group);
group = NULL;
- return 0;
+ return ret;
}
EXPORT_API int companion_group_information_get_type(companion_group_h group,
companion_group_type_e *type)
{
- *type = ((companion_group_t *)group)->type;
+ int ret = COMP_ERROR_NONE;
- return 0;
+ *type = ((companion_group_s *)group)->type;
+
+ return ret;
}
EXPORT_API int companion_group_information_get_resource_type(
companion_group_h group, char **resource_type)
{
- *resource_type = g_strdup(((companion_group_t *)group)->resource_type);
+ int ret = COMP_ERROR_NONE;
+
+ *resource_type = g_strdup(((companion_group_s *)group)->resource_type);
- return 0;
+ return ret;
}
EXPORT_API int companion_group_information_get_uri_path(
companion_group_h group, char **uri_path)
{
- *uri_path = g_strdup(((companion_group_t *)group)->uri_path);
+ int ret = COMP_ERROR_NONE;
- return 0;
+ *uri_path = g_strdup(((companion_group_s *)group)->uri_path);
+
+ return ret;
}
EXPORT_API int companion_group_information_get_name(
companion_group_h group, char **name)
{
- *name = g_strdup(((companion_group_t *)group)->group_name);
+ int ret = COMP_ERROR_NONE;
+
+ *name = g_strdup(((companion_group_s *)group)->group_name);
- return 0;
+ return ret;
}
EXPORT_API int companion_group_information_get_host_addr
(companion_group_h group, char **host_addr)
{
- *host_addr = g_strdup(((companion_group_t *)group)->host_addr);
+ int ret = COMP_ERROR_NONE;
- return 0;
+ *host_addr = g_strdup(((companion_group_s *)group)->host_addr);
+
+ return ret;
}
EXPORT_API int companion_device_information_create(companion_device_h* device)
{
- companion_device_h _device = g_malloc0(sizeof(companion_device_t));
+ int ret = COMP_ERROR_NONE;
+
+ companion_device_h _device = g_malloc0(sizeof(companion_device_s));
+ if (NULL == device) {
+ _ERR("Memory allocation Failed(%d)", errno);
+ return COMP_ERROR_OUT_OF_MEMORY;
+ }
*device = _device;
- return 0;
+ return ret;
}
EXPORT_API int companion_device_information_clone(companion_device_h target,
companion_device_h source)
{
- companion_device_t * dst = (companion_device_t *)target;
- companion_device_t * src = (companion_device_t *)source;
+ int ret = COMP_ERROR_NONE;
- if (!dst || !src) {
- _ERR("Invaild parameters: dst=%p src=%p", dst, src);
- return -1;
- }
+ companion_device_s * dst = (companion_device_s *)target;
+ companion_device_s * src = (companion_device_s *)source;
+
+ companion_check_null_ret_error("target", target, COMP_ERROR_INVALID_PARAMETER);
+ companion_check_null_ret_error("source", source, COMP_ERROR_INVALID_PARAMETER);
if (src->device_id)
dst->device_id = g_strdup(src->device_id);
if (src->device_type)
dst->device_type = g_strdup(src->device_type);
- return 0;
+ return ret;
}
EXPORT_API int companion_device_information_destroy(companion_device_h data)
{
- companion_device_t * device = (companion_device_t *)data;
-
- if (!device) {
- _ERR("Invaild parameters: device=%p", device);
- return -1;
- }
+ int ret = COMP_ERROR_NONE;
+ companion_device_s * device = (companion_device_s *)data;
+ companion_check_null_ret_error("data", data, COMP_ERROR_INVALID_PARAMETER);
if (device->device_id) {
g_free(device->device_id);
g_free(device);
device = NULL;
- return 0;
+ return ret;
}
EXPORT_API int companion_device_information_get_device_id(
companion_device_h device, char **device_id)
{
- *device_id = g_strdup(((companion_device_t *)device)->device_id);
+ int ret = COMP_ERROR_NONE;
- return 0;
+ *device_id = g_strdup(((companion_device_s *)device)->device_id);
+
+ return ret;
}
EXPORT_API int companion_device_information_get_ip(
companion_device_h device, char **ip)
{
- *ip = g_strdup(((companion_device_t *)device)->ip);
+ int ret = COMP_ERROR_NONE;
- return 0;
+ *ip = g_strdup(((companion_device_s *)device)->ip);
+
+ return ret;
}
EXPORT_API int companion_device_information_get_device_type(
companion_device_h device, char **device_type)
{
- *device_type = g_strdup(((companion_device_t *)device)->device_type);
+ int ret = COMP_ERROR_NONE;
+
+ *device_type = g_strdup(((companion_device_s *)device)->device_type);
- return 0;
+ return ret;
}
EXPORT_API int companion_request_create_group(companion_h handle,
int ret = COMP_ERROR_NONE;
GError *error = NULL;
comp_manager_s *_handle = handle;
- companion_device_t *dev = (companion_device_t *)device;
+ companion_device_s *dev = (companion_device_s *)device;
_DBG("Device id : %s", dev->device_id);
int ret = COMP_ERROR_NONE;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
- companion_group_t *grp = (companion_group_t *)group;
+ companion_group_s *grp = (companion_group_s *)group;
if (!grp) {
_ERR("grp is null");
return COMP_ERROR_INVALID_PARAMETER;
}
- companion_device_t *dev = (companion_device_t *)device;
+ companion_device_s *dev = (companion_device_s *)device;
if (!dev) {
_ERR("dev is null");
return COMP_ERROR_INVALID_PARAMETER;
int ret = COMP_ERROR_NONE;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
- companion_group_t *grp = (companion_group_t *)group;
- if (!grp) {
- _ERR("grp is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_group_s *grp = (companion_group_s *)group;
+ companion_check_null_ret_error("group", group, COMP_ERROR_INVALID_PARAMETER);
- companion_device_t *dev = (companion_device_t *)device;
- if (!dev) {
- _ERR("dev is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_device_s *dev = (companion_device_s *)device;
+ companion_check_null_ret_error("device", device, COMP_ERROR_INVALID_PARAMETER);
_DBG("%s", grp->device_id);
_DBG("%s", grp->group_name);
{
int ret = COMP_ERROR_NONE;
comp_manager_s *_handle = handle;
- if (!handle) {
- _ERR("handle is null");
- return COMP_ERROR_INVALID_PARAMETER;
- }
+ companion_check_null_ret_error("handle", handle, COMP_ERROR_INVALID_PARAMETER);
_handle->request_result_cb.result_cb = result_cb;
_handle->request_result_cb.user_data = user_data;
--- /dev/null
+/*
+ * Copyright (c) 2016 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 <stdio.h>
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <stdlib.h>
+
+#include <dlog.h>
+#include <companion.h>
+#include <companion_debug.h>
+#include <companion_gdbus.h>
+#include <companion_internal.h>
+#include <companion_dbus_internal.h>
+
+#define COMP_DBUS_SERVICE "org.tizen.companion" /**< For companion dbus */
+#define COMP_DBUS_GROUP_PATH "/org/tizen/companion/group" /**< For group dbus */
+#define COMP_DBUS_ENABLER_PATH "/org/tizen/companion/enabler" /**< dbus auto-activation */
+
+static companion_group_s *_create_group_handle(char *uri_path, char *device_id,
+ char *group_name, char *host_addr, char *resource_type, companion_group_type_e type)
+{
+ companion_group_s *group = calloc(1, sizeof(companion_group_s));
+ if (NULL == group) {
+ /* LCOV_EXCL_START */
+ _ERR("Memory allocation failed");
+ goto CREATE_GROUP_HANDLER_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ group->uri_path = g_strdup(uri_path);
+ group->device_id = g_strdup(device_id);
+ group->group_name = g_strdup(group_name);
+ group->host_addr = g_strdup(host_addr);
+ group->resource_type = g_strdup(resource_type);
+ group->type = type;
+
+ if (!group->uri_path || !group->device_id ||
+ !group->host_addr || !group->resource_type) {
+ /* LCOV_EXCL_START */
+ _ERR("Memory allocation failed");
+ goto CREATE_GROUP_HANDLER_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+ return group;
+
+CREATE_GROUP_HANDLER_ERROR:
+ /* LCOV_EXCL_START */
+ if (group) {
+ if (group->uri_path) {
+ free(group->uri_path);
+ group->uri_path = NULL;
+ }
+ if (group->device_id) {
+ free(group->device_id);
+ group->device_id = NULL;
+ }
+ if (group->group_name) {
+ free(group->group_name);
+ group->group_name = NULL;
+ }
+ if (group->host_addr) {
+ free(group->host_addr);
+ group->host_addr = NULL;
+ }
+ if (group->resource_type) {
+ free(group->resource_type);
+ group->resource_type = NULL;
+ }
+ free(group);
+ group = NULL;
+ }
+ return NULL;
+ /* LCOV_EXCL_STOP */
+}
+
+static companion_device_s *_create_device_handle(char *device_id, char *ip,
+ char *device_type, int port)
+{
+ companion_device_s *device = calloc(1, sizeof(companion_device_s));
+ if (NULL == device) {
+ /* LCOV_EXCL_START */
+ _ERR("Memory allocation failed");
+ goto CREATE_DEVICE_HANDLER_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ device->device_id = g_strdup(device_id);
+ device->ip = g_strdup(ip);
+ device->device_type = g_strdup(device_type);
+ device->port = port;
+
+ if (!device->device_id || !device->ip || !device->device_type) {
+ /* LCOV_EXCL_START */
+ _ERR("Memory allocation failed");
+ goto CREATE_DEVICE_HANDLER_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ return device;
+
+CREATE_DEVICE_HANDLER_ERROR:
+ /* LCOV_EXCL_START */
+ if (device) {
+ if (device->device_id) {
+ free(device->device_id);
+ device->device_id = NULL;
+ }
+ if (device->ip) {
+ free(device->ip);
+ device->ip = NULL;
+ }
+ if (device->device_type) {
+ free(device->device_type);
+ device->device_type = NULL;
+ }
+ free(device);
+ device = NULL;
+ }
+ return NULL;
+ /* LCOV_EXCL_STOP */
+}
+
+/* LCOV_EXCL_START */
+static void __group_found_cb(Group *object, GVariant *va, gpointer user_data)
+{
+ GVariantIter *iter = NULL;
+ const gchar *key;
+ GVariant *key_value = NULL;
+ companion_group_s *group = NULL;
+ char *uri_path = NULL;
+ char *device_id = NULL;
+ char *group_name = NULL;
+ char *host_addr = NULL;
+ char *resource_type = NULL;
+ companion_group_type_e type = COMPANION_GROUP_TYPE_ERROR;
+
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ g_variant_get(va, "a{sv}", &iter);
+ while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+ if (g_strcmp0(key, "URI") == 0)
+ uri_path = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "DeviceID") == 0)
+ device_id = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "GroupName") == 0)
+ group_name = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "HostAddress") == 0)
+ host_addr = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "GroupDeviceType") == 0)
+ resource_type = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "GroupType") == 0)
+ type = g_variant_get_int32(key_value);
+ }
+
+ g_variant_iter_free(iter);
+
+ group = _create_group_handle(uri_path, device_id, group_name, host_addr,
+ resource_type, type);
+ if (handle->group_found_cb.found_cb)
+ handle->group_found_cb.found_cb(type, group, handle->group_found_cb.user_data);
+}
+
+static void _group_find_finish_cb(Group *object, gint ret, gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->group_find_finish_cb.finish_cb)
+ handle->group_find_finish_cb.finish_cb(ret,
+ handle->group_find_finish_cb.user_data);
+}
+
+static void __device_found_cb(Group *object, gint count, GVariant *va,
+ gpointer user_data)
+{
+ GVariantIter *iter = NULL;
+ GVariantIter *iter_row = NULL;
+ const gchar *key;
+ GVariant *key_value;
+ companion_device_s *device = NULL;
+
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ g_variant_get(va, "aa{sv}", &iter);
+ while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+ char *device_id = NULL;
+ char *ip = NULL;
+ char *device_type = NULL;
+ int port = -1;
+
+ while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+ if (g_strcmp0(key, "DeviceID") == 0)
+ device_id = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "Address") == 0)
+ ip = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "SecVer") == 0)
+ device_type = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "Port") == 0)
+ port = g_variant_get_uint16(key_value);
+ }
+ g_variant_iter_free(iter_row);
+
+ device = _create_device_handle(device_id, ip, device_type, port);
+ if (handle->device_found_cb.found_cb)
+ handle->device_found_cb.found_cb(device, handle->device_found_cb.user_data);
+ }
+ g_variant_iter_free(iter);
+}
+
+static void _device_find_finish_cb(Group *object, gint ret, gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->device_find_finish_cb.finish_cb)
+ handle->device_find_finish_cb.finish_cb(ret,
+ handle->device_find_finish_cb.user_data);
+}
+
+static void __mowned_device_found_cb(Group *object, gint count, GVariant *va,
+ gpointer user_data)
+{
+ GVariantIter *iter = NULL;
+ GVariantIter *iter_row = NULL;
+ const gchar *key;
+ GVariant *key_value;
+ companion_device_s *device = NULL;
+
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ g_variant_get(va, "aa{sv}", &iter);
+ while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+ char *device_id = NULL;
+ char *ip = NULL;
+ char *device_type = NULL;
+ int port = -1;
+
+ while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+ if (g_strcmp0(key, "DeviceID") == 0)
+ device_id = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "Address") == 0)
+ ip = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "SecVer") == 0)
+ device_type = (char *)g_variant_get_string(key_value, NULL);
+ else if (g_strcmp0(key, "Port") == 0)
+ port = g_variant_get_uint16(key_value);
+
+ }
+ g_variant_iter_free(iter_row);
+
+ device = _create_device_handle(device_id, ip, device_type, port);
+ if (handle->mowned_device_found_cb.found_cb)
+ handle->mowned_device_found_cb.found_cb(device,
+ handle->mowned_device_found_cb.user_data);
+ }
+ g_variant_iter_free(iter);
+}
+
+static void _mowned_device_find_finish_cb(Group *object, gint ret,
+ gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->mowned_device_find_finish_cb.finish_cb)
+ handle->mowned_device_find_finish_cb.finish_cb(ret,
+ handle->mowned_device_find_finish_cb.user_data);
+}
+
+static void __device_invite_result_cb(Group *object, gint ret, gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->device_invite_result_cb.result_cb)
+ handle->device_invite_result_cb.result_cb(ret,
+ handle->device_invite_result_cb.user_data);
+}
+
+static void __device_eject_result_cb(Group *object, gint ret, gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->device_eject_result_cb.result_cb)
+ handle->device_eject_result_cb.result_cb(ret,
+ handle->device_eject_result_cb.user_data);
+}
+
+static void __send_data_finish_cb(Group *object, gchar *resp_data, gint ret,
+ gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->send_data_finish_cb.finish_cb)
+ handle->send_data_finish_cb.finish_cb(ret, resp_data,
+ handle->send_data_finish_cb.user_data);
+}
+
+static void __request_result_cb(Group *object, gchar *cmd, gchar *arg, gint ret,
+ gpointer user_data)
+{
+ NOTUSED(object);
+
+ comp_manager_s *handle = user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ if (handle->request_result_cb.result_cb)
+ handle->request_result_cb.result_cb(cmd, arg, ret,
+ handle->request_result_cb.user_data);
+}
+/* LCOV_EXCL_STOP */
+
+
+static int _enabler_proxy_init(comp_manager_s *handle)
+{
+ int ret = COMP_ERROR_NONE;
+ GError *error = NULL;
+ handle->enabler_proxy = enabler_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE, COMP_DBUS_SERVICE,
+ COMP_DBUS_ENABLER_PATH, NULL, &error);
+ if (NULL == handle->enabler_proxy) {
+ /* LCOV_EXCL_START */
+ if (error != NULL) {
+ _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
+ g_error_free(error);
+ }
+ return COMP_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+ return ret;
+}
+
+/* LCOV_EXCL_START */
+static void _dbus_name_owner_notify(GObject *object, GParamSpec *pspec,
+ gpointer *user_data)
+{
+ GDBusProxy *proxy = G_DBUS_PROXY(object);
+ gchar *name_owner = g_dbus_proxy_get_name_owner(proxy);
+ comp_manager_s *handle = (comp_manager_s *)user_data;
+ companion_check_null_ret("user_data", user_data);
+
+ LOGD("Name owner notify [%s]", name_owner);
+
+ if (NULL == name_owner)
+ gdbus_deinitialize(handle);
+ free(name_owner);
+
+}
+/* LCOV_EXCL_STOP */
+
+static int _group_proxy_init(comp_manager_s *handle)
+{
+ int id = -1;
+ GError *error = NULL;
+
+ handle->group_proxy = group_proxy_new_for_bus_sync(
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ COMP_DBUS_SERVICE,
+ COMP_DBUS_GROUP_PATH,
+ NULL,
+ &error);
+ if (NULL == handle->group_proxy) {
+ /* LCOV_EXCL_START */
+ if (error != NULL) {
+ _ERR("Failed to connect to the D-BUS daemon [%s]", error->message);
+ g_error_free(error);
+ }
+ return COMP_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ id = g_signal_connect(handle->group_proxy, "notify::g-name-owner",
+ G_CALLBACK(_dbus_name_owner_notify), handle);
+ if (0 == id) {
+ /* LCOV_EXCL_START */
+ _ERR("g_signal_connect() Fail");
+ g_object_unref(handle->group_proxy);
+ handle->group_proxy = NULL;
+ return COMP_ERROR_IO_ERROR;
+ /* LCOV_EXCL_STOP */
+ }
+
+ g_signal_connect(handle->group_proxy,
+ "group-found", G_CALLBACK(__group_found_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "group-find-finish", G_CALLBACK(_group_find_finish_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "device-found", G_CALLBACK(__device_found_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "device-find-finish", G_CALLBACK(_device_find_finish_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "mowned-device-found", G_CALLBACK(__mowned_device_found_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "mowned-device-find-finish", G_CALLBACK(_mowned_device_find_finish_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "device-invite-result", G_CALLBACK(__device_invite_result_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "device-eject-result", G_CALLBACK(__device_eject_result_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "send-data-finish", G_CALLBACK(__send_data_finish_cb), handle);
+ g_signal_connect(handle->group_proxy,
+ "request-result", G_CALLBACK(__request_result_cb), handle);
+
+ return COMP_ERROR_NONE;
+}
+
+
+static void _group_proxy_deinit(comp_manager_s *handle)
+{
+ g_object_unref(handle->group_proxy);
+ handle->group_proxy = NULL;
+}
+
+static void _enabler_proxy_deinit(comp_manager_s *handle)
+{
+ int ret;
+
+ enabler_call_disable_sync(handle->enabler_proxy, &ret, NULL, NULL);
+ g_object_unref(handle->enabler_proxy);
+ handle->enabler_proxy = NULL;
+}
+
+int gdbus_initialize(comp_manager_s *handle)
+{
+ int ret = COMP_ERROR_NONE;
+
+ _group_proxy_init(handle);
+ _enabler_proxy_init(handle);
+
+ if (handle->group_proxy == NULL)
+ ret = -1; /* LCOV_EXCL_LINE */
+
+ if (handle->enabler_proxy == NULL)
+ ret = -1; /* LCOV_EXCL_LINE */
+
+ handle->ca = g_cancellable_new();
+
+ return ret;
+}
+
+int gdbus_deinitialize(comp_manager_s *handle)
+{
+ int ret = COMP_ERROR_NONE;
+
+ _group_proxy_deinit(handle);
+ _enabler_proxy_deinit(handle);
+
+ g_cancellable_cancel(handle->ca);
+ g_object_unref(handle->ca);
+ handle->ca = NULL;
+
+ return ret;
+}
+