Fix wrong behavior about return value of shortcut request 91/114091/9
authorseungha.son <seungha.son@samsung.com>
Fri, 10 Feb 2017 03:26:04 +0000 (12:26 +0900)
committerseungha.son <seungha.son@samsung.com>
Fri, 10 Feb 2017 08:46:34 +0000 (17:46 +0900)
 - Currently, It is a structure in which the caller can not get
   a proper return value when there is a request such as
   shortcut add or remove.
 - The handling for gdbus invocation has been modified so that
   caller can get proper return value.
 - related patch : https://review.tizen.org/gerrit/#/c/114090/

Signed-off-by: seungha.son <seungha.son@samsung.com>
Change-Id: I24a94d5d0d137e738ecc0fd332f2c2fa5f8e0fbf

include/shortcut_service.h
src/shortcut_service.c

index c42295e..35cb758 100755 (executable)
 extern int shortcut_service_init(void);
 extern int shortcut_service_fini(void);
 
-int shortcut_add(GVariant *parameters, GVariant **reply_body, uid_t uid);
-int shortcut_add_widget(GVariant *parameters, GVariant **reply_body, uid_t uid);
-int shortcut_remove(GVariant *parameters, GVariant **reply_body, uid_t uid);
+void shortcut_add(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid);
+void shortcut_add_widget(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid);
+void shortcut_remove(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid);
 int shortcut_register_dbus_interface();
 int shortcut_get_shortcut_service_list(GVariant *parameters, GVariant **reply_body, uid_t uid);
 int shortcut_check_privilege(void);
+int shortcut_send_return_value(GVariant *parameters, GVariant **reply_body);
 /* End of a file */
index 9410008..7a4e8b9 100755 (executable)
 #include "debug.h"
 
 #define PROVIDER_SHORTCUT_INTERFACE_NAME "org.tizen.data_provider_shortcut_service"
+
+#define SHORTCUT_INVOCATION_KEY_POS 0
+
 static GHashTable *_monitoring_hash = NULL;
+static GHashTable *_invocation_hash;
 
 static void _on_name_appeared(GDBusConnection *connection,
                const gchar     *name,
@@ -61,19 +65,25 @@ static void _shortcut_dbus_method_call_handler(GDBusConnection *conn,
        int ret = SHORTCUT_ERROR_NOT_SUPPORTED;
        uid_t uid = get_sender_uid(sender);
 
-       if (g_strcmp0(method_name, "shortcut_service_register") == 0)
+       if (g_strcmp0(method_name, "shortcut_service_register") == 0) {
                ret = service_register(parameters, &reply_body, sender,
                 _on_name_appeared, _on_name_vanished, &_monitoring_hash, uid);
-       else if (g_strcmp0(method_name, "add_shortcut") == 0)
-               ret = shortcut_add(parameters, &reply_body, uid);
-       else if (g_strcmp0(method_name, "add_shortcut_widget") == 0)
-               ret = shortcut_add_widget(parameters, &reply_body, uid);
-       else if (g_strcmp0(method_name, "remove_shortcut") == 0)
-               ret = shortcut_remove(parameters, &reply_body, uid);
-       else if (g_strcmp0(method_name, "get_list") == 0)
+       } else if (g_strcmp0(method_name, "add_shortcut") == 0) {
+               shortcut_add(parameters, invocation, uid);
+               return;
+       } else if (g_strcmp0(method_name, "add_shortcut_widget") == 0) {
+               shortcut_add_widget(parameters, invocation, uid);
+               return;
+       } else if (g_strcmp0(method_name, "remove_shortcut") == 0) {
+               shortcut_remove(parameters, invocation, uid);
+               return;
+       } else if (g_strcmp0(method_name, "get_list") == 0) {
                ret = shortcut_get_shortcut_service_list(parameters, &reply_body, uid);
-       else if (g_strcmp0(method_name, "check_privilege") == 0)
+       } else if (g_strcmp0(method_name, "check_privilege") == 0) {
                ret = shortcut_check_privilege();
+       } else if (g_strcmp0(method_name, "send_return_value") == 0) {
+               ret = shortcut_send_return_value(parameters, &reply_body);
+       }
 
        if (ret == SERVICE_COMMON_ERROR_NONE) {
                DbgPrint("shortcut service success : %d", ret);
@@ -111,6 +121,7 @@ int shortcut_register_dbus_interface()
                        "        </method>"
 
                        "        <method name='add_shortcut'>"
+                       "          <arg type='s' name='request_id' direction='in'/>"
                        "          <arg type='i' name='pid' direction='in'/>"
                        "          <arg type='s' name='appid' direction='in'/>"
                        "          <arg type='s' name='name' direction='in'/>"
@@ -118,9 +129,11 @@ int shortcut_register_dbus_interface()
                        "          <arg type='s' name='uri' direction='in'/>"
                        "          <arg type='s' name='icon' direction='in'/>"
                        "          <arg type='i' name='allow_duplicate' direction='in'/>"
+                       "          <arg type='i' name='return_value' direction='out'/>"
                        "        </method>"
 
                        "        <method name='add_shortcut_widget'>"
+                       "          <arg type='s' name='request_id' direction='in'/>"
                        "          <arg type='i' name='pid' direction='in'/>"
                        "          <arg type='s' name='widget_id' direction='in'/>"
                        "          <arg type='s' name='name' direction='in'/>"
@@ -129,16 +142,24 @@ int shortcut_register_dbus_interface()
                        "          <arg type='s' name='icon' direction='in'/>"
                        "          <arg type='d' name='period' direction='in'/>"
                        "          <arg type='i' name='allow_duplicate' direction='in'/>"
+                       "          <arg type='i' name='return_value' direction='out'/>"
                        "        </method>"
 
                        "        <method name='remove_shortcut'>"
+                       "          <arg type='s' name='request_id' direction='in'/>"
                        "          <arg type='i' name='pid' direction='in'/>"
                        "          <arg type='s' name='appid' direction='in'/>"
                        "          <arg type='s' name='name' direction='in'/>"
+                       "          <arg type='i' name='return_value' direction='out'/>"
                        "        </method>"
 
                        "        <method name='check_privilege'>"
                        "        </method>"
+
+                       "        <method name='send_return_value'>"
+                       "          <arg type='i' name='return_value' direction='in'/>"
+                       "          <arg type='s' name='request_id' direction='in'/>"
+                       "        </method>"
                        "  </interface>"
                        "  </node>";
 
@@ -208,64 +229,92 @@ int shortcut_get_shortcut_service_list(GVariant *parameters, GVariant **reply_bo
        return SERVICE_COMMON_ERROR_NONE;
 }
 
+static GDBusMethodInvocation *_get_invocation(char *request_id)
+{
+       GDBusMethodInvocation *find_invocation;
+
+       find_invocation = (GDBusMethodInvocation *)g_hash_table_lookup(_invocation_hash, request_id);
+       if (!find_invocation)
+               return NULL;
+
+       return find_invocation;
+}
+
+static void _add_invocation(GDBusMethodInvocation *invocation, char *request_id)
+{
+       GDBusMethodInvocation *find_invocation;
+
+       if (request_id == NULL)
+               return;
+
+       find_invocation = _get_invocation(request_id);
+       if (find_invocation)
+               return;
+
+       g_hash_table_insert(_invocation_hash, strdup(request_id), invocation);
+
+       DbgPrint("add invocation is done, key [%s]", request_id);
+}
+
+static void _remove_invocation(char *request_id)
+{
+       if (request_id == NULL)
+               return;
+
+       g_hash_table_remove(_invocation_hash, request_id);
+
+       DbgPrint("remove invocation is done, key [%s]", request_id);
+}
+
 /* add_shortcut */
-int shortcut_add(GVariant *parameters, GVariant **reply_body, uid_t uid)
+void shortcut_add(GVariant *parameters, GDBusMethodInvocation *invocation,  uid_t uid)
 {
        int ret = SERVICE_COMMON_ERROR_NONE;
+       char *request_id = NULL;
+
+       g_variant_get_child(parameters, SHORTCUT_INVOCATION_KEY_POS, "&s", &request_id);
+
+       _add_invocation(invocation, request_id);
 
        ret = send_notify(parameters, "add_shortcut_notify", &_monitoring_hash, PROVIDER_SHORTCUT_INTERFACE_NAME, uid);
-       if (ret != SERVICE_COMMON_ERROR_NONE) {
+       if (ret != SERVICE_COMMON_ERROR_NONE)
                ErrPrint("failed to send notify:%d\n", ret);
-               return ret;
-       }
-
-       *reply_body = g_variant_new("()");
-       if (*reply_body == NULL) {
-               ErrPrint("Cannot make reply body");
-               return SHORTCUT_ERROR_OUT_OF_MEMORY;
-       }
 
-       return ret;
+       DbgPrint("shortcut_add is done");
 }
 
 /* add_shortcut_widget */
-int shortcut_add_widget(GVariant *parameters, GVariant **reply_body, uid_t uid)
+void shortcut_add_widget(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid)
 {
        int ret = SERVICE_COMMON_ERROR_NONE;
+       char *request_id = NULL;
+
+       g_variant_get_child(parameters, SHORTCUT_INVOCATION_KEY_POS, "&s", &request_id);
+
+       _add_invocation(invocation, request_id);
 
        ret = send_notify(parameters, "add_shortcut_widget_notify", &_monitoring_hash, PROVIDER_SHORTCUT_INTERFACE_NAME, uid);
-       if (ret != SERVICE_COMMON_ERROR_NONE) {
+       if (ret != SERVICE_COMMON_ERROR_NONE)
                ErrPrint("failed to send notify:%d\n", ret);
-               return ret;
-       }
-
-       *reply_body = g_variant_new("()");
-       if (*reply_body == NULL) {
-               ErrPrint("Cannot make reply body");
-               return SHORTCUT_ERROR_OUT_OF_MEMORY;
-       }
 
-       return ret;
+       DbgPrint("shortcut_add_widget is done");
 }
 
 /* remove_shortcut */
-int shortcut_remove(GVariant *parameters, GVariant **reply_body, uid_t uid)
+void shortcut_remove(GVariant *parameters, GDBusMethodInvocation *invocation, uid_t uid)
 {
        int ret = SERVICE_COMMON_ERROR_NONE;
+       char *request_id = NULL;
+
+       g_variant_get_child(parameters, SHORTCUT_INVOCATION_KEY_POS, "&s", &request_id);
+
+       _add_invocation(invocation, request_id);
 
        ret = send_notify(parameters, "remove_shortcut_notify", &_monitoring_hash, PROVIDER_SHORTCUT_INTERFACE_NAME, uid);
-       if (ret != SERVICE_COMMON_ERROR_NONE) {
+       if (ret != SERVICE_COMMON_ERROR_NONE)
                ErrPrint("failed to send notify:%d\n", ret);
-               return ret;
-       }
 
-       *reply_body = g_variant_new("()");
-       if (*reply_body == NULL) {
-               ErrPrint("Cannot make reply body");
-               return SHORTCUT_ERROR_OUT_OF_MEMORY;
-       }
-
-       return ret;
+       DbgPrint("shortcut_remove is done");
 }
 
 /*  check shortcut privilege */
@@ -274,6 +323,34 @@ int shortcut_check_privilege(void)
        return SERVICE_COMMON_ERROR_NONE;
 }
 
+int shortcut_send_return_value(GVariant *parameters, GVariant **reply_body)
+{
+       int return_value;
+       char *request_id = NULL;
+       GDBusMethodInvocation *invocation = NULL;
+
+       g_variant_get(parameters, "(i&s)", &return_value, &request_id);
+
+       if (request_id == NULL)
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
+
+       invocation = _get_invocation(request_id);
+       if (!invocation)
+               return SHORTCUT_ERROR_INVALID_PARAMETER;
+
+       g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", return_value));
+       _remove_invocation(request_id);
+
+       *reply_body = g_variant_new("()");
+       if (*reply_body == NULL) {
+               ErrPrint("Cannot make reply body");
+               return SHORTCUT_ERROR_OUT_OF_MEMORY;
+       }
+
+       DbgPrint("shortcut_send_return_value success");
+       return SHORTCUT_ERROR_NONE;
+}
+
 /*!
  * MAIN THREAD
  * Do not try to do anyother operation in these functions
@@ -283,6 +360,7 @@ HAPI int shortcut_service_init(void)
        DbgPrint("Successfully initiated\n");
        int result;
        _monitoring_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+       _invocation_hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
        result = shortcut_register_dbus_interface();
        if (result != SERVICE_COMMON_ERROR_NONE)
                ErrPrint("shortcut register dbus fail %d", result);
@@ -291,6 +369,8 @@ HAPI int shortcut_service_init(void)
 
 HAPI int shortcut_service_fini(void)
 {
+       g_hash_table_destroy(_invocation_hash);
+
        DbgPrint("Successfully Finalized\n");
        return SERVICE_COMMON_ERROR_NONE;
 }