Update dbus return value & Match error code with orchestration module. 74/204374/4
authorheewon Park <h_w.park@samsung.com>
Tue, 23 Apr 2019 10:02:23 +0000 (19:02 +0900)
committerDAEKEN KWON <daeken.kwon@samsung.com>
Tue, 23 Apr 2019 10:13:31 +0000 (10:13 +0000)
Change-Id: Ib8d884d213dd8d72fabe33af8fa427e4707ed849
Signed-off-by: heewon Park <h_w.park@samsung.com>
src/CMain/inc/gdbus_interface.h
src/CMain/inc/orchestration_server.h
src/CMain/src/main.c
src/CMain/src/orchestration_server.c
src/CMain/unittest/test_orchestration_server.cpp

index c3e810a..6c653f5 100644 (file)
@@ -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
index e6b5203..f5bb154 100644 (file)
@@ -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);
index 73f38c0..ec369b5 100644 (file)
 #include <orchestration_server.h>
 #include <orchestration.h>
 
-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() {
index 4f0ab40..56b08da 100644 (file)
@@ -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[] =
     "        <method name='request_service'>"
     "          <arg type='s' name='app_name' direction='in'/>"
     "          <arg type='s' name='service_info' direction='in'/>"
+    "          <arg type='i' name='return_value' direction='out'/>"
     "        </method>"
     "  </interface>"
     "  </node>";
@@ -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 =
index b13d8de..3cf943d 100644 (file)
@@ -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,