From ee120b1064fc65a6d0f93ab60e4842a249500cfe Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Mon, 8 Jan 2018 19:30:20 +0900 Subject: [PATCH] Add CAPI style and comment Signed-off-by: Jihoon Jung --- capi/include/familynet.h | 47 +++++++++++++- capi/src/familynet.c | 28 ++++++++- capi/src/familynet_gdbus.xml | 30 +++++++++ capi/unittest/familynet_unit_test.cpp | 13 +++- src/fn-manager/include/fn_enum.h | 6 -- src/fn-manager/include/fn_gdbus_group.h | 18 ++++++ src/fn-manager/src/familynet_gdbus.xml | 30 +++++++++ src/fn-manager/src/fn_gdbus.c | 30 +++++++++ src/fn-manager/src/fn_gdbus_group.c | 84 ++++++++++++++++++++++++- 9 files changed, 270 insertions(+), 16 deletions(-) diff --git a/capi/include/familynet.h b/capi/include/familynet.h index e7780c6..99511c1 100755 --- a/capi/include/familynet.h +++ b/capi/include/familynet.h @@ -13,16 +13,57 @@ typedef enum { } familynet_group_type_e; typedef void *familynet_group_h; +typedef void *familynet_group_device_h; typedef bool (*familynet_group_find_cb)(familynet_group_type_e type, familynet_group_h target, void *user_data); -int familynet_initialize(); -int familynet_deinitialize(); -/*in : group name, out : group handle */ +/* Management Module APIs*/ +int familynet_initialize(); /* initialize gdbus connection with manager daemon */ +int familynet_deinitialize(); /* deinitialize gdbus connection with manager daemon */ + +/* Group Module APIs*/ +/* familynet_group_create : craete group in my daemon */ int familynet_group_create(char *group_name, familynet_group_h *group_handle); +/* familynet_group_find : find groups in my daemon + remote groups in network */ int familynet_group_find(familynet_group_find_cb callback, void *user_data); +/* familynet_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */ +int familynet_group_join(familynet_group_h group_handle, familynet_group_find_cb callback, void *user_data); +/* familynet_group_join : leave from remote group. if group handle is my daemon's, then the api return fail error */ +int familynet_group_leave(familynet_group_h group_handle, void *user_data); +/* familynet_group_delete : remove group. if group handle is remote group, then the api return fail error */ +int familynet_group_delete(char *group_name, familynet_group_h *group_handle); + +/* Group Device Module */ +/* The "Group Device" is element of group. Only one group device per target. + I do not like this " group device " term. :/ + If you have any good terms, I would appreciate your suggestions.*/ + +/* familynet_group_device_find : Find the group devices on the network. (exclude myself) */ +int familynet_group_device_find(familynet_group_h group_handle, + familynet_group_device_h group_device_handle, familynet_group_find_cb callback, void *user_data); + +/* familynet_group_device_invite : Invite a remote group device to my group. */ +int familynet_group_device_invite(familynet_group_h group_handle, + familynet_group_device_h group_device_handle, familynet_group_find_cb callback, void *user_data); //Join to device in group (async) + +/* familynet_group_device_eject : Eject a remote group device from my group. */ +int familynet_group_device_eject(familynet_group_h group_handle, + familynet_group_device_h group_device_handle, familynet_group_find_cb callback, void *user_data); //dismiss from group (async) + +/* Group Information Module */ +int familynet_group_information_get_name(familynet_group_h group_handle, char **name); +int familynet_group_information_get_device_count(familynet_group_h group_handle, int *device_count); +int familynet_group_information_get_type(familynet_group_h group_handle, familynet_group_type_e *type); + +/* Group Device Information Module */ +/* I think the information in the group device is the same as the "device informations" */ +/* +int familynet_group_device_information_get_ip?(familynet_group_device_h group_handle, ???); +int familynet_group_device_information_get_address?(familynet_group_device_h group_handle, ???); +int familynet_group_device_information_get_???(familynet_group_device_h group_handle, ???); +*/ #ifdef __cplusplus } diff --git a/capi/src/familynet.c b/capi/src/familynet.c index ae4c261..a3f1b08 100755 --- a/capi/src/familynet.c +++ b/capi/src/familynet.c @@ -179,9 +179,8 @@ int familynet_group_find(familynet_group_find_cb callback, void *user_data) } else if (g_strcmp0(key, "device_count") == 0) { device_count = g_variant_get_int32(key_value); } - g_variant_iter_free(iter_row); } - g_variant_iter_free(iter); + g_variant_iter_free(iter_row); group = _create_group_handle(type, name, device_count); result = callback(type, group, user_data); @@ -189,6 +188,7 @@ int familynet_group_find(familynet_group_find_cb callback, void *user_data) if (!result) break; } + g_variant_iter_free(iter); } g_variant_unref(va); @@ -196,3 +196,27 @@ int familynet_group_find(familynet_group_find_cb callback, void *user_data) return ret; } +int familynet_group_information_get_name(familynet_group_h group_handle, char **name) +{ + familynet_group_t *group = (familynet_group_t *)group_handle; + *name = g_strdup(group->name); + + return 0; +} + +int familynet_group_information_get_device_count(familynet_group_h group_handle, int *device_count) +{ + familynet_group_t *group = (familynet_group_t *)group_handle; + *device_count = group->device_count; + + return 0; +} + +int familynet_group_information_get_type(familynet_group_h group_handle, familynet_group_type_e *type) +{ + familynet_group_t *group = (familynet_group_t *)group_handle; + *type = group->type; + + return 0; +} + diff --git a/capi/src/familynet_gdbus.xml b/capi/src/familynet_gdbus.xml index 26dfdad..9e414f9 100755 --- a/capi/src/familynet_gdbus.xml +++ b/capi/src/familynet_gdbus.xml @@ -16,5 +16,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/capi/unittest/familynet_unit_test.cpp b/capi/unittest/familynet_unit_test.cpp index 8c86164..00322ea 100755 --- a/capi/unittest/familynet_unit_test.cpp +++ b/capi/unittest/familynet_unit_test.cpp @@ -47,9 +47,18 @@ TEST(familynet, familynet_group_create_p) { GMainLoop *main_loop = NULL; -bool _familynet_group_find_cb(familynet_group_type_e type, familynet_group_h target, void *user_data) +bool _familynet_group_find_cb(familynet_group_type_e type, familynet_group_h group_handle, void *user_data) { - cout << "find group : " << type << endl; + char *name = NULL; + int device_count = 0; + + familynet_group_information_get_name(group_handle, &name); + familynet_group_information_get_device_count(group_handle, &device_count); + + cout << "group type : " << type <<", group name : " + << name << ", device_count : " << device_count << endl; + + return true; } TEST(familynet, familynet_group_find_p) { diff --git a/src/fn-manager/include/fn_enum.h b/src/fn-manager/include/fn_enum.h index 9fbe846..0044d94 100755 --- a/src/fn-manager/include/fn_enum.h +++ b/src/fn-manager/include/fn_enum.h @@ -20,12 +20,6 @@ typedef enum { FN_ERROR_UNKNOWN = -999, } fn_error_e; -/* role enum */ -typedef enum { - FN_ROLE_OWNER, - FN_ROLE_CLIENT -} fn_role_e; - /* resource type enum */ typedef enum { FN_RESOURCE_TYPE_GROUP = 0, diff --git a/src/fn-manager/include/fn_gdbus_group.h b/src/fn-manager/include/fn_gdbus_group.h index ceff14c..54851ae 100755 --- a/src/fn-manager/include/fn_gdbus_group.h +++ b/src/fn-manager/include/fn_gdbus_group.h @@ -9,4 +9,22 @@ gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *gr gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gpointer user_data); +gboolean group_join(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data); + +gboolean group_leave(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data); + +gboolean group_delete(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data); + +gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data); + +gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data); + +gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data); + #endif diff --git a/src/fn-manager/src/familynet_gdbus.xml b/src/fn-manager/src/familynet_gdbus.xml index 26dfdad..9e414f9 100755 --- a/src/fn-manager/src/familynet_gdbus.xml +++ b/src/fn-manager/src/familynet_gdbus.xml @@ -16,5 +16,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/fn-manager/src/fn_gdbus.c b/src/fn-manager/src/fn_gdbus.c index da50b8f..2e6ab2a 100755 --- a/src/fn-manager/src/fn_gdbus.c +++ b/src/fn-manager/src/fn_gdbus.c @@ -23,6 +23,36 @@ static bool __group_init(GDBusConnection *connection) G_CALLBACK(group_find), NULL); + g_signal_connect(group_skeleton, + "handle-join", + G_CALLBACK(group_join), + NULL); + + g_signal_connect(group_skeleton, + "handle-leave", + G_CALLBACK(group_leave), + NULL); + + g_signal_connect(group_skeleton, + "handle-delete", + G_CALLBACK(group_delete), + NULL); + + g_signal_connect(group_skeleton, + "handle-delete", + G_CALLBACK(group_device_find), + NULL); + + g_signal_connect(group_skeleton, + "handle-delete", + G_CALLBACK(group_device_invite), + NULL); + + g_signal_connect(group_skeleton, + "handle-delete", + G_CALLBACK(group_device_eject), + NULL); + group = g_dbus_object_manager_server_new(FN_DBUS_GROUP_PATH); // Set connection to 'manager' diff --git a/src/fn-manager/src/fn_gdbus_group.c b/src/fn-manager/src/fn_gdbus_group.c index 9b8d339..c0ad916 100755 --- a/src/fn-manager/src/fn_gdbus_group.c +++ b/src/fn-manager/src/fn_gdbus_group.c @@ -1,6 +1,7 @@ #include -/* Manager */ +/* GDBUS Group Layer */ +/* In this gdbus group layer, Please call the "fn_group" service layer function.*/ gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *group_name, gpointer user_data) @@ -9,7 +10,7 @@ gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *gr LOG_DEBUG("group create called using dbus successful"); - fn_group_create(group_name); + result = fn_group_create(group_name); group_complete_create(group, invocation, result); @@ -19,12 +20,89 @@ gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *gr gboolean group_find(Group *group, GDBusMethodInvocation *invocation, gpointer user_data) { + int count = 0; + gint result = 0; + GVariant *gv = NULL; + GVariantBuilder b; + LOG_DEBUG("group find called using dbus successful"); + g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}")); /* - packing mine group + remote group in GVariant + 1. packing mine groups + remote groups in GVariant, entire group count. + example is below code. */ + g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(&b, "{sv}", "type", g_variant_new_int32(FN_GROUP_DEVICE)); + g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string("Group1")); + g_variant_builder_add(&b, "{sv}", "device_count", g_variant_new_int32(1)); + + g_variant_builder_close(&b); + + g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}")); + + g_variant_builder_add(&b, "{sv}", "type", g_variant_new_int32(FN_GROUP_REMOTE_DEVICE)); + g_variant_builder_add(&b, "{sv}", "name", g_variant_new_string("Group2")); + g_variant_builder_add(&b, "{sv}", "device_count", g_variant_new_int32(3)); + + g_variant_builder_close(&b); + + gv = g_variant_builder_end(&b); + + count = 2; + + LOG_DEBUG("END"); + + group_complete_find(group, invocation, count, gv, result); + + return TRUE; +} + +gboolean group_join(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + //group_complete_join(group, invocation, result); + + return TRUE; +} + +gboolean group_leave(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + //group_complete_leave(group, invocation, result); return TRUE; } +gboolean group_delete(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + //group_complete_delete(group, invocation, result); + + return TRUE; +} + +gboolean group_device_find(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + //group_complete_device_find(group, invocation, result); + + return TRUE; +} + +gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + //group_complete_device_invite(group, invocation, result); + + return TRUE; +} + +gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation, + gpointer user_data) +{ + //group_complete_device_eject(group, invocation, result); + + return TRUE; +} -- 2.34.1