From: heewon Park Date: Tue, 23 Apr 2019 05:43:48 +0000 (+0900) Subject: Change dbus own_name function to own_name_on_connection. X-Git-Tag: accepted/tizen/unified/20190425.111806~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=66f43c329dba5d61a7ff6841e0eb1d574e9a27e5;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git Change dbus own_name function to own_name_on_connection. - Fixed use of duplicate functions in getting dbus connection in dbus initialize logic. Change-Id: I011f8f1fd8c8d23cc6535c3889962a1c7ca65bce Signed-off-by: heewon Park --- diff --git a/src/CMain/inc/gdbus_interface.h b/src/CMain/inc/gdbus_interface.h index 895a772..c3e810a 100644 --- a/src/CMain/inc/gdbus_interface.h +++ b/src/CMain/inc/gdbus_interface.h @@ -26,14 +26,13 @@ extern "C" #include typedef GDBusConnection *(*_g_bus_get_sync)(GBusType bus_type, GCancellable *cancellable, GError **error); -typedef guint (*_g_bus_own_name)(GBusType bus_type, - const gchar *name, - GBusNameOwnerFlags flags, - GBusAcquiredCallback bus_acquired_handler, - GBusNameAcquiredCallback name_acquired_handler, - GBusNameLostCallback name_lost_handler, - gpointer user_data, - GDestroyNotify user_data_free_func); +typedef guint (*_g_bus_own_name_on_connection)(GDBusConnection *connection, + const gchar *name, + GBusNameOwnerFlags flags, + GBusNameAcquiredCallback name_acquired_handler, + GBusNameLostCallback name_lost_handler, + gpointer user_data, + GDestroyNotify user_data_free_func); typedef void (*_g_bus_unown_name)(guint owner_id); typedef GDBusNodeInfo *(*_g_dbus_node_info_new_for_xml)(const gchar *xml_data, GError **error); @@ -55,7 +54,7 @@ typedef GError *(*_g_error_new)(GQuark domain, ...); typedef void (*_g_error_free)(GError *error); typedef void (*_g_dbus_method_invocation_return_value)(GDBusMethodInvocation *invocation, - GVariant *parameters); + GVariant *parameters); typedef void (*_g_dbus_method_invocation_return_gerror)(GDBusMethodInvocation *invocation, const GError *error); /* ---------------------------------------------------------------------------------------------------- */ @@ -63,7 +62,7 @@ typedef void (*_g_dbus_method_invocation_return_gerror)(GDBusMethodInvocation *i typedef struct { _g_bus_get_sync get_sync; - _g_bus_own_name own_name; + _g_bus_own_name_on_connection own_name_on_connection; _g_bus_unown_name unown_name; _g_dbus_node_info_new_for_xml node_info_new_for_xml; _g_dbus_node_info_unref node_info_unref; diff --git a/src/CMain/src/orchestration_server.c b/src/CMain/src/orchestration_server.c index 3d613c5..4f0ab40 100644 --- a/src/CMain/src/orchestration_server.c +++ b/src/CMain/src/orchestration_server.c @@ -55,7 +55,7 @@ static gchar introspection_xml[] = void set_default_dbus_interface(void) { _gdbus.get_sync = g_bus_get_sync; - _gdbus.own_name = g_bus_own_name; + _gdbus.own_name_on_connection = g_bus_own_name_on_connection; _gdbus.unown_name = g_bus_unown_name; _gdbus.node_info_new_for_xml = g_dbus_node_info_new_for_xml; _gdbus.node_info_unref = g_dbus_node_info_unref; @@ -159,20 +159,20 @@ static int _get_sync(void) return ORCH_ERROR_NONE; } -static int _own_name(void) +static int _own_name_on_connection(void) { int result = ORCH_ERROR_NONE; - owner_id = _gdbus.own_name(G_BUS_TYPE_SYSTEM, - _ORCHESTRATION_BUS_NAME, - G_BUS_NAME_OWNER_FLAGS_NONE, - NULL, - NULL, - NULL, - NULL, NULL); + owner_id = _gdbus.own_name_on_connection(_gdbus_conn, + _ORCHESTRATION_BUS_NAME, + G_BUS_NAME_OWNER_FLAGS_NONE, + NULL, + NULL, + NULL, + NULL); if (!owner_id) { - printf("Failed to own name\n"); + printf("Failed to own name on connection\n"); result = ORCH_ERROR_DBUS_FAILURE; } return result; @@ -203,8 +203,12 @@ static int _connection_register_object(void) guint orch_registration_id; orch_registration_id = _gdbus.connection_register_object(_gdbus_conn, - _ORCHESTRATION_OBJECT_PATH, introspection_data->interfaces[0], - &_interface_vtable, NULL, NULL, NULL); + _ORCHESTRATION_OBJECT_PATH, + introspection_data->interfaces[0], + &_interface_vtable, + NULL, + NULL, + NULL); if (orch_registration_id == 0) { @@ -239,10 +243,10 @@ static int orch_dbus_initialize(void) goto out; } - result = _own_name(); + result = _own_name_on_connection(); if (result != ORCH_ERROR_NONE) { - printf("Failed to _dbus_own_name\n"); + printf("Failed to _dbus_own_name_onconnection\n"); goto out; } diff --git a/src/CMain/unittest/test_orchestration_server.cpp b/src/CMain/unittest/test_orchestration_server.cpp index 4f086bd..b13d8de 100644 --- a/src/CMain/unittest/test_orchestration_server.cpp +++ b/src/CMain/unittest/test_orchestration_server.cpp @@ -11,7 +11,7 @@ const char *SERVICE_INFO = "SERVICE_INFO"; GDBusConnection *valid_GDBusConnection; GDBusNodeInfo *valid_GDBusNodeInfo; -GDBusInterfaceInfo* valid_GDBusinterface; +GDBusInterfaceInfo *valid_GDBusinterface; gboolean requestCbResult; void fake_request_cb(char *app_name, char *service_info) @@ -20,7 +20,8 @@ void fake_request_cb(char *app_name, char *service_info) { requestCbResult = true; } - else{ + else + { requestCbResult = false; } } @@ -38,10 +39,9 @@ GDBusConnection *fake_get_sync_success(GBusType bus_type, GCancellable *cancella return valid_GDBusConnection; } -guint fake_own_name_return_error(GBusType bus_type, +guint fake_own_name_return_error(GDBusConnection *connection, const gchar *name, GBusNameOwnerFlags flags, - GBusAcquiredCallback bus_acquired_handler, GBusNameAcquiredCallback name_acquired_handler, GBusNameLostCallback name_lost_handler, gpointer user_data, @@ -50,10 +50,9 @@ guint fake_own_name_return_error(GBusType bus_type, return 0; } -guint fake_own_name_success(GBusType bus_type, +guint fake_own_name_success(GDBusConnection *connection, const gchar *name, GBusNameOwnerFlags flags, - GBusAcquiredCallback bus_acquired_handler, GBusNameAcquiredCallback name_acquired_handler, GBusNameLostCallback name_lost_handler, gpointer user_data, @@ -74,9 +73,9 @@ GDBusNodeInfo *fake_node_info_new_for_xml_success(const gchar *xml_data, { *error = NULL; valid_GDBusNodeInfo = (GDBusNodeInfo *)malloc(sizeof(_GDBusNodeInfo)); - GDBusInterfaceInfo* _interfaces[2]; + GDBusInterfaceInfo *_interfaces[2]; valid_GDBusNodeInfo->interfaces = _interfaces; - valid_GDBusinterface = (GDBusInterfaceInfo*)malloc(sizeof(_GDBusInterfaceInfo)); + valid_GDBusinterface = (GDBusInterfaceInfo *)malloc(sizeof(_GDBusInterfaceInfo)); valid_GDBusNodeInfo->interfaces[0] = valid_GDBusinterface; return valid_GDBusNodeInfo; } @@ -125,7 +124,6 @@ void fake_error_free(GError *error) { } - void fake_error_register_error_domain(const gchar *error_domain_quark_name, volatile gsize *quark_volatile, const GDBusErrorEntry *entries, @@ -135,7 +133,7 @@ void fake_error_register_error_domain(const gchar *error_domain_quark_name, class OrchestrationServerTests : public testing::Test { - protected: +protected: virtual void SetUp() { } @@ -170,11 +168,12 @@ TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_OwnNameFailure_ExpectedE { set_default_dbus_interface(); _gdbus.get_sync = fake_get_sync_success; - _gdbus.own_name = fake_own_name_return_error; + _gdbus.own_name_on_connection = fake_own_name_return_error; ASSERT_EQ(orch_dbus_initialize(), ORCH_ERROR_DBUS_FAILURE); - if (valid_GDBusConnection != NULL) { + if (valid_GDBusConnection != NULL) + { free(valid_GDBusConnection); valid_GDBusConnection = NULL; } @@ -184,12 +183,13 @@ TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_SetNodeInfoNewForXMLFail { set_default_dbus_interface(); _gdbus.get_sync = fake_get_sync_success; - _gdbus.own_name = fake_own_name_success; + _gdbus.own_name_on_connection = fake_own_name_success; _gdbus.node_info_new_for_xml = fake_node_info_new_for_xml_return_NULL; ASSERT_EQ(orch_dbus_initialize(), ORCH_ERROR_DBUS_FAILURE); - if (valid_GDBusConnection != NULL) { + if (valid_GDBusConnection != NULL) + { free(valid_GDBusConnection); valid_GDBusConnection = NULL; } @@ -199,21 +199,24 @@ TEST_F(OrchestrationServerTests, WhenCalledOrchDbusInit_ConnectionRegisterObject { set_default_dbus_interface(); _gdbus.get_sync = fake_get_sync_success; - _gdbus.own_name = fake_own_name_success; + _gdbus.own_name_on_connection = fake_own_name_success; _gdbus.node_info_new_for_xml = fake_node_info_new_for_xml_success; _gdbus.connection_register_object = fake_connection_register_object_return_error; ASSERT_EQ(orch_dbus_initialize(), ORCH_ERROR_DBUS_FAILURE); - if (valid_GDBusConnection != NULL) { + if (valid_GDBusConnection != NULL) + { free(valid_GDBusConnection); valid_GDBusConnection = NULL; } - if (valid_GDBusNodeInfo != NULL) { + if (valid_GDBusNodeInfo != NULL) + { free(valid_GDBusNodeInfo); valid_GDBusNodeInfo = NULL; } - if (valid_GDBusinterface != NULL) { + if (valid_GDBusinterface != NULL) + { free(valid_GDBusinterface); valid_GDBusinterface = NULL; } @@ -223,17 +226,19 @@ TEST_F(OrchestrationServerTests, WhenCalledServerInit_ExpectedSuccess) { set_default_dbus_interface(); _gdbus.get_sync = fake_get_sync_success; - _gdbus.own_name = fake_own_name_success; + _gdbus.own_name_on_connection = fake_own_name_success; _gdbus.node_info_new_for_xml = fake_node_info_new_for_xml_success; _gdbus.connection_register_object = fake_connection_register_object_success; ASSERT_EQ(orchestration_server_initialize(fake_request_cb), ORCH_ERROR_NONE); - if (valid_GDBusConnection != NULL) { + if (valid_GDBusConnection != NULL) + { free(valid_GDBusConnection); valid_GDBusConnection = NULL; } - if (valid_GDBusNodeInfo != NULL) { + if (valid_GDBusNodeInfo != NULL) + { free(valid_GDBusNodeInfo); valid_GDBusNodeInfo = NULL; } @@ -244,7 +249,7 @@ TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithRequestServiceMe { set_default_dbus_interface(); _gdbus.get_sync = fake_get_sync_success; - _gdbus.own_name = fake_own_name_success; + _gdbus.own_name_on_connection = fake_own_name_success; _gdbus.node_info_new_for_xml = fake_node_info_new_for_xml_success; _gdbus.connection_register_object = fake_connection_register_object_success; _gdbus.invocation_return_value = fake_invocation_return_value; @@ -263,11 +268,13 @@ TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithRequestServiceMe EXPECT_EQ(requestCbResult, false); - if (valid_GDBusConnection != NULL) { + if (valid_GDBusConnection != NULL) + { free(valid_GDBusConnection); valid_GDBusConnection = NULL; } - if (valid_GDBusNodeInfo != NULL) { + if (valid_GDBusNodeInfo != NULL) + { free(valid_GDBusNodeInfo); valid_GDBusNodeInfo = NULL; }