From 1645b19379ee555a315387533d9f7060bb28751c Mon Sep 17 00:00:00 2001 From: Saurav Babu Date: Mon, 15 Jan 2018 14:17:14 +0530 Subject: [PATCH] comp-manager: Added dbus method to pair/unpair resources Signed-off-by: Saurav Babu --- .../include/comp_gdbus_group.h | 9 +++++ src/companion-manager/include/comp_group.h | 6 ++++ src/companion-manager/src/comp_gdbus.c | 10 ++++++ src/companion-manager/src/comp_gdbus_group.c | 33 +++++++++++++++++++ src/companion-manager/src/comp_group.c | 29 ++++++++++++++++ src/companion-manager/src/comp_mot_agent.c | 6 ++-- src/companion-manager/src/companion_gdbus.xml | 20 +++++++++++ 7 files changed, 110 insertions(+), 3 deletions(-) diff --git a/src/companion-manager/include/comp_gdbus_group.h b/src/companion-manager/include/comp_gdbus_group.h index 5f7e568..dce74d3 100755 --- a/src/companion-manager/include/comp_gdbus_group.h +++ b/src/companion-manager/include/comp_gdbus_group.h @@ -35,6 +35,15 @@ gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation, gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation, gpointer user_data); +gboolean group_pair_resource(Group *group, GDBusMethodInvocation *invocation, + gchar *target_1, gchar *subject_1, gchar *uri_1, gchar *rt_1, + gchar *interface_1, int permission_1, gchar *target_2, gchar *subject_2, + gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2, + gpointer user_data); + +gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation, + gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data); + void notify_group_found(GVariant *group_data); void notify_group_find_finish(int ret); void notify_device_found(int device_count, GVariant *device_data); diff --git a/src/companion-manager/include/comp_group.h b/src/companion-manager/include/comp_group.h index 241722d..7a421a3 100755 --- a/src/companion-manager/include/comp_group.h +++ b/src/companion-manager/include/comp_group.h @@ -58,6 +58,12 @@ void comp_group_notify_group_invite(int result); int comp_group_dismiss(gchar *uuid); void comp_group_notify_group_dismiss(int result); +int comp_group_pair_resource(char* target1, char *subject1, char *uri1, + char *rt1, char *interface1, int permission1, char* target2, char *subject2, + char *uri2, char *rt2, char *interface2, int permission2); + +int comp_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2); + GVariant *comp_group_get_remote_mot_enabled_devices(); int comp_group_get_mot_device_count(); diff --git a/src/companion-manager/src/comp_gdbus.c b/src/companion-manager/src/comp_gdbus.c index 82e5215..2c18863 100755 --- a/src/companion-manager/src/comp_gdbus.c +++ b/src/companion-manager/src/comp_gdbus.c @@ -69,6 +69,16 @@ static bool __group_init(GDBusConnection *connection) G_CALLBACK(group_get_remote_device), NULL); + g_signal_connect(group_skeleton, + "handle-pair-resource", + G_CALLBACK(group_pair_resource), + NULL); + + g_signal_connect(group_skeleton, + "handle-unpair-resource", + G_CALLBACK(group_unpair_resource), + NULL); + group = g_dbus_object_manager_server_new(COMP_DBUS_GROUP_PATH); // Set connection to 'manager' diff --git a/src/companion-manager/src/comp_gdbus_group.c b/src/companion-manager/src/comp_gdbus_group.c index 94b02ca..ea7b2c7 100755 --- a/src/companion-manager/src/comp_gdbus_group.c +++ b/src/companion-manager/src/comp_gdbus_group.c @@ -124,6 +124,39 @@ gboolean group_get_remote_device(Group *group, GDBusMethodInvocation *invocation return TRUE; } +gboolean group_pair_resource(Group *group, GDBusMethodInvocation *invocation, + gchar *target_1, gchar *subject_1, gchar *uri_1, gchar *rt_1, + gchar *interface_1, int permission_1, gchar *target_2, gchar *subject_2, + gchar *uri_2, gchar *rt_2, gchar *interface_2, int permission_2, + gpointer user_data) +{ + int ret = 0; + + LOG_DEBUG("pair resource called using dbus successful"); + + ret = comp_group_pair_resource(target_1, subject_1, uri_1, rt_1, + interface_1, permission_1, target_2, subject_2, uri_2, + rt_2, interface_2, permission_2); + + group_complete_pair_resource(group, invocation, ret); + + return TRUE; +} + +gboolean group_unpair_resource(Group *group, GDBusMethodInvocation *invocation, + gchar *uuid_dev1, gchar *uuid_dev2, gpointer user_data) +{ + int ret = 0; + + LOG_DEBUG("unpair resource called using dbus successful"); + + ret = comp_group_unpair_resource(uuid_dev1, uuid_dev2); + + group_complete_unpair_resource(group, invocation, ret); + + return TRUE; +} + void notify_group_found(GVariant *group_data) { group_emit_group_found(group_dbus_get_object(), group_data); diff --git a/src/companion-manager/src/comp_group.c b/src/companion-manager/src/comp_group.c index 409be02..f6672c1 100755 --- a/src/companion-manager/src/comp_group.c +++ b/src/companion-manager/src/comp_group.c @@ -355,6 +355,35 @@ int comp_group_dismiss(gchar *uuid) return ret; } +int comp_group_pair_resource(char* target1, char *subject1, char *uri1, + char *rt1, char *interface1, int permission1, char* target2, char *subject2, + char *uri2, char *rt2, char *interface2, int permission2) +{ + int ret; + + LOG_BEGIN(); + + ret = agent_pairwise(target1, subject1, uri1, rt1, interface1, permission1, + target2, subject2, uri2, rt2, interface2, permission2); + + LOG_END(); + + return ret; +} + +int comp_group_unpair_resource(gchar *uuid_dev1, gchar *uuid_dev2) +{ + int ret; + + LOG_BEGIN(); + + ret = agent_remove_myowned_device(uuid_dev1, uuid_dev2); + + LOG_END(); + + return ret; +} + /* Join to remote device group */ int comp_group_join_to(/* callback */){} //Join this device to in certain remote group (Async) diff --git a/src/companion-manager/src/comp_mot_agent.c b/src/companion-manager/src/comp_mot_agent.c index 413004e..318a6e6 100755 --- a/src/companion-manager/src/comp_mot_agent.c +++ b/src/companion-manager/src/comp_mot_agent.c @@ -228,8 +228,7 @@ int agent_remove_cred_at_local(char* uuid_str) return result; } - -int agent_remove_myowned_device(char* uuid_str) +int agent_remove_myowned_device(char* uuid_str1, char *uuid_str2) { GVariant *variant = NULL; int result = COMP_ERROR_NONE; @@ -241,7 +240,8 @@ int agent_remove_myowned_device(char* uuid_str) } variant = g_dbus_proxy_call_sync(agent.gproxy_agent_service, "unpair", - g_variant_new("(s)", uuid_str), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + g_variant_new("(ss)", uuid_str1, uuid_str2), G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); if (variant) { g_variant_get(variant, "(i)", &result); LOGD("remove_mo status 0x%x", result); diff --git a/src/companion-manager/src/companion_gdbus.xml b/src/companion-manager/src/companion_gdbus.xml index 0194923..0a3ea93 100755 --- a/src/companion-manager/src/companion_gdbus.xml +++ b/src/companion-manager/src/companion_gdbus.xml @@ -51,6 +51,26 @@ + + + + + + + + + + + + + + + + + + + + -- 2.34.1