From: heewon Park Date: Tue, 23 Apr 2019 10:02:23 +0000 (+0900) Subject: Update dbus return value & Match error code with orchestration module. X-Git-Tag: accepted/tizen/unified/20190425.111806~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90dd4d98dd50614d1bde87baa82221d30eb20e95;p=platform%2Fcore%2Fsystem%2Fedge-orchestration.git Update dbus return value & Match error code with orchestration module. Change-Id: Ib8d884d213dd8d72fabe33af8fa427e4707ed849 Signed-off-by: heewon Park --- diff --git a/src/CMain/inc/gdbus_interface.h b/src/CMain/inc/gdbus_interface.h index c3e810a..6c653f5 100644 --- a/src/CMain/inc/gdbus_interface.h +++ b/src/CMain/inc/gdbus_interface.h @@ -44,19 +44,9 @@ typedef guint (*_g_dbus_connection_register_object)(GDBusConnection *connection, gpointer user_data, GDestroyNotify user_data_free_func, GError **error); -typedef void (*_g_dbus_error_register_error_domain)(const gchar *error_domain_quark_name, - volatile gsize *quark_volatile, - const GDBusErrorEntry *entries, - guint num_entries); -typedef GError *(*_g_error_new)(GQuark domain, - gint code, - const gchar *format, - ...); typedef void (*_g_error_free)(GError *error); typedef void (*_g_dbus_method_invocation_return_value)(GDBusMethodInvocation *invocation, GVariant *parameters); -typedef void (*_g_dbus_method_invocation_return_gerror)(GDBusMethodInvocation *invocation, - const GError *error); /* ---------------------------------------------------------------------------------------------------- */ typedef struct @@ -67,11 +57,8 @@ typedef struct _g_dbus_node_info_new_for_xml node_info_new_for_xml; _g_dbus_node_info_unref node_info_unref; _g_dbus_connection_register_object connection_register_object; - _g_dbus_error_register_error_domain register_error_domain; - _g_error_new error_new; _g_error_free error_free; _g_dbus_method_invocation_return_value invocation_return_value; - _g_dbus_method_invocation_return_gerror invocation_return_gerror; } _gdbus_interface; #ifdef __cplusplus diff --git a/src/CMain/inc/orchestration_server.h b/src/CMain/inc/orchestration_server.h index e6b5203..f5bb154 100644 --- a/src/CMain/inc/orchestration_server.h +++ b/src/CMain/inc/orchestration_server.h @@ -26,13 +26,20 @@ extern "C" #define DEBUG(format, ...) printLog("[%s:%d] "format, __FILE__, __LINE__, ##__VA_ARGS__); typedef enum { + /* Errors of Orchestration*/ + ORCH_ERROR_NOT_READY = -1, + ORCH_ERROR_WIFI_UNREACHABLE = -2, + + /* Errors of DBus*/ + ORCH_ERROR_FAULT = -100, + ORCH_ERROR_INVALID_PARAMETER = -101, + ORCH_ERROR_DBUS_FAILURE = -102, + + /*Success Error Code*/ ORCH_ERROR_NONE = 0, - ORCH_ERROR_INVALID_PARAMETER, - ORCH_ERROR_DBUS_FAILURE, - ORCH_ERROR_FAULT, } _orchestration_state_e; -typedef void (*request_service_cb)(char* app_name, char* service_info); +typedef int (*request_service_cb)(char* app_name, char* service_info); void set_default_dbus_interface(void); int orchestration_server_initialize(request_service_cb cb); diff --git a/src/CMain/src/main.c b/src/CMain/src/main.c index 73f38c0..ec369b5 100644 --- a/src/CMain/src/main.c +++ b/src/CMain/src/main.c @@ -24,15 +24,14 @@ #include #include -void request_cb(char* app_name, char* service_info){ +int request_cb(char* app_name, char* service_info){ int result = ORCH_ERROR_FAULT; DEBUG("app_name : %s\n", app_name); DEBUG("service_info : %s\n", service_info); result = OrchestrationRequestService(app_name, service_info); - if (result != ORCH_ERROR_NONE) { - DEBUG("OrchestrationRequestService failed\n"); - } + + return result; } void* thread_orchestration() { diff --git a/src/CMain/src/orchestration_server.c b/src/CMain/src/orchestration_server.c index 4f0ab40..56b08da 100644 --- a/src/CMain/src/orchestration_server.c +++ b/src/CMain/src/orchestration_server.c @@ -31,14 +31,6 @@ request_service_cb _request_service_cb = NULL; #define _ORCHESTRATION_BUS_NAME "org.tizen.orchestration" #define _ORCHESTRATION_OBJECT_PATH "/org/tizen/orchestration" -#define _ORCHESTRATION_SVC_ERROR_DOMAIN "orchestration" - -GDBusErrorEntry _orchestration_svc_errors[] = { - {ORCH_ERROR_NONE, "NoError"}, - {ORCH_ERROR_INVALID_PARAMETER, "Invalid parameter"}, - {ORCH_ERROR_DBUS_FAILURE, "dbus failure"}, - {ORCH_ERROR_FAULT, "Orchestration Failed"}, -}; /* Introspection data for the service we are exporting */ static gchar introspection_xml[] = @@ -47,6 +39,7 @@ static gchar introspection_xml[] = " " " " " " + " " " " " " " "; @@ -60,45 +53,28 @@ void set_default_dbus_interface(void) _gdbus.node_info_new_for_xml = g_dbus_node_info_new_for_xml; _gdbus.node_info_unref = g_dbus_node_info_unref; _gdbus.connection_register_object = g_dbus_connection_register_object; - _gdbus.register_error_domain = g_dbus_error_register_error_domain; - _gdbus.error_new = g_error_new; _gdbus.error_free = g_error_free; _gdbus.invocation_return_value = g_dbus_method_invocation_return_value; - _gdbus.invocation_return_gerror = g_dbus_method_invocation_return_gerror; } -static GQuark _ORCHESTRATION_ERROR_quark(void) +static int _request_service(GVariant *parameters) { - static volatile gsize quark_volatile = 0; - _gdbus.register_error_domain(_ORCHESTRATION_SVC_ERROR_DOMAIN, - &quark_volatile, - _orchestration_svc_errors, - G_N_ELEMENTS(_orchestration_svc_errors)); - return (GQuark)quark_volatile; -} + int result = ORCH_ERROR_NONE; -static int _request_service(GVariant *parameters, GVariant **reply_body) -{ char *app_name, *service_info; if (!parameters) { return ORCH_ERROR_INVALID_PARAMETER; } + g_variant_get(parameters, "(&ss)", &app_name, &service_info); - if (app_name == NULL) + if (g_strcmp0(app_name, "") == 0) return ORCH_ERROR_INVALID_PARAMETER; - _request_service_cb(app_name, service_info); + result = _request_service_cb(app_name, service_info); - *reply_body = g_variant_new("()"); - if (*reply_body == NULL) - { - printf("Failed to make reply_body\n"); - return ORCH_ERROR_FAULT; - } - - return ORCH_ERROR_NONE; + return result; } static void _handle_method_call( @@ -112,26 +88,21 @@ static void _handle_method_call( gpointer user_data) { int ret = ORCH_ERROR_NONE; - GVariant *reply_body = NULL; if (g_strcmp0(method_name, "request_service") == 0) { - ret = _request_service(parameters, &reply_body); + ret = _request_service(parameters); } if (ret == ORCH_ERROR_NONE) { printf("Orchestration service Success, method name : %s\n", method_name); - g_dbus_method_invocation_return_value(invocation, reply_body); } else { printf("Orchestration service fail, method name : %s\n", method_name); - - GError *error = _gdbus.error_new(_ORCHESTRATION_ERROR_quark(), ret, "orchestration failed"); - _gdbus.invocation_return_gerror(invocation, error); - _gdbus.error_free(error); } + _gdbus.invocation_return_value(invocation, g_variant_new("(i)", ret)); } static const GDBusInterfaceVTable _interface_vtable = diff --git a/src/CMain/unittest/test_orchestration_server.cpp b/src/CMain/unittest/test_orchestration_server.cpp index b13d8de..3cf943d 100644 --- a/src/CMain/unittest/test_orchestration_server.cpp +++ b/src/CMain/unittest/test_orchestration_server.cpp @@ -14,15 +14,15 @@ GDBusNodeInfo *valid_GDBusNodeInfo; GDBusInterfaceInfo *valid_GDBusinterface; gboolean requestCbResult; -void fake_request_cb(char *app_name, char *service_info) +int fake_request_cb(char *app_name, char *service_info) { if (app_name == APP_NAME && service_info == SERVICE_INFO) { - requestCbResult = true; + return 1; } else { - requestCbResult = false; + return -1; } } @@ -107,30 +107,10 @@ void fake_invocation_return_value(GDBusMethodInvocation *invocation, { } -void fake_invocation_return_gerror(GDBusMethodInvocation *invocation, - const GError *error) -{ -} - -GError *fake_error_new(GQuark domain, - gint code, - const gchar *format, - ...) -{ - return NULL; -} - 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, - guint num_entries) -{ -} - class OrchestrationServerTests : public testing::Test { protected: @@ -253,9 +233,6 @@ TEST_F(OrchestrationServerTests, WhenCalledHandleMethodCall_WithRequestServiceMe _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; - _gdbus.invocation_return_gerror = fake_invocation_return_gerror; - _gdbus.register_error_domain = fake_error_register_error_domain; - _gdbus.error_new = fake_error_new; _gdbus.error_free = fake_error_free; _handle_method_call(NULL, NULL,