#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,
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);
" </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'/>"
" <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'/>"
" <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>";
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 */
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
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);
HAPI int shortcut_service_fini(void)
{
+ g_hash_table_destroy(_invocation_hash);
+
DbgPrint("Successfully Finalized\n");
return SERVICE_COMMON_ERROR_NONE;
}