summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjusung son <jusung07.son@samsung.com>2016-09-23 19:45:19 +0900
committerjusung son <jusung07.son@samsung.com>2016-09-26 10:43:04 +0900
commitc9ebf4700cf360ee8250bdd1e544d07918ffc3c6 (patch)
tree53eaacc6c2b0f4d88fc54573e6234354151f5f06
parent488fbfdfffe5357c3f362e48b3b3a5b9fead4d36 (diff)
downloadshortcut-accepted/tizen/mobile/20160927.020946.tar.gz
shortcut-accepted/tizen/mobile/20160927.020946.tar.bz2
shortcut-accepted/tizen/mobile/20160927.020946.zip
Change-Id: I0433e87a68c7a4b69a3a99844e995f7956365c4a Signed-off-by: jusung son <jusung07.son@samsung.com>
-rwxr-xr-xlib/include/shortcut_internal.h131
-rwxr-xr-xlib/src/shortcut_internal.c149
2 files changed, 272 insertions, 8 deletions
diff --git a/lib/include/shortcut_internal.h b/lib/include/shortcut_internal.h
index e9b2e5d..e2c7796 100755
--- a/lib/include/shortcut_internal.h
+++ b/lib/include/shortcut_internal.h
@@ -22,18 +22,146 @@
#include <gio/gio.h>
#include <glib.h>
#include "shortcut.h"
+#include "shortcut_manager.h"
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__ ((visibility("default")))
+#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
+/**
+ * @addtogroup SHORTCUT_INTERNAL
+ * @{
+ */
+
+
struct result_cb_item {
result_internal_cb_t result_internal_cb;
result_cb_t result_cb;
void *data;
};
+
+/**
+ * @brief Enumeration for shortcut error extension.
+ * @since_tizen 3.0
+ */
+enum shortcut_error_extension_e {
+ SHORTCUT_ERROR_NOT_EXIST = TIZEN_ERROR_SHORTCUT | 0x0008, /* Not exist shortcut */
+};
+
+
+/**
+ * @internal
+ * @brief Called to the shortcut_remove_from_home request.
+ * @since_tizen 3.0
+ * @param[in] package_name The name of package
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] sender_pid The process ID of who request shortcut_remove_from_home
+ * @param[in] user_data The user data passed from the callback register function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SHORTCUT_ERROR_NONE Successful
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @retval #SHORTCUT_ERROR_NOT_EXIST Shortcut not exist
+ */
+typedef int (*shortcut_remove_cb)(const char *package_name, const char *name, int sender_pid, void *user_data);
+
+
+/**
+ * @internal
+ * @brief Registers a callback function for the shortcut removal request.
+ * @remarks Should be used in the homescreen.\n
+ * Should check the return value of this function.
+ * Prospective Clients: Homescreen.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ *
+ * @param[in] request_cb The callback function pointer that is invoked when shortcut_remove_from_home is requested
+ * @param[in] data The callback data to deliver to the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SHORTCUT_ERROR_NONE Successful
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ * @pre You have to prepare a callback function.
+ *
+ * @post If a request is sent from the application, the registered callback will be invoked.
+ *
+ * @see shortcut_remove_cb
+ */
+extern int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_data);
+
+/**
+ * @internal
+ * @brief Removes a shortcut from home, asynchronously.
+ * @since_tizen 3.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/shortcut
+ * @param[in] name The name of the created shortcut icon
+ * @param[in] result_cb The address of the callback function that is called when the result comes back from the viewer
+ * @param[in] user_data The callback data that is used in the callback function
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #SHORTCUT_ERROR_NONE Successful
+ * @retval #SHORTCUT_ERROR_INVALID_PARAMETER Invalid function parameter
+ * @retval #SHORTCUT_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #SHORTCUT_ERROR_IO_ERROR I/O Error
+ * @retval #SHORTCUT_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SHORTCUT_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SHORTCUT_ERROR_RESOURCE_BUSY Device or resource busy
+ * @retval #SHORTCUT_ERROR_FAULT Unrecoverable error
+ * @retval #SHORTCUT_ERROR_COMM Connection not established or communication problem
+ *
+ * @pre You have to prepare the callback function.
+ *
+ * @post You have to check the return status from the callback function which is passed by the argument.
+ *
+ * @see result_cb_t
+ *
+ * @par Example
+ * @code
+
+#include <shortcut_internal.h>
+...
+ int result_cb(int ret, void *data)
+ {
+ if (ret < 0)
+ dlog_print("Failed to remove a shortcut: %d\n", ret);
+
+ return 0;
+ }
+
+ ...
+
+{
+ int result;
+
+ result = shortcut_remove_from_home("shortcut_name", result_cb, NULL);
+
+ if (result != SHORTCUT_ERROR_NONE) {
+ dlog_print("Failed to remove a shortcut: %d\n", result);
+ return result;
+ }
+...
+
+ }
+
+ * @endcode
+ */
+extern int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data);
+
int _dbus_init(void);
int _dbus_signal_init();
char *_shortcut_get_pkgname_by_pid(void);
@@ -44,6 +172,9 @@ int _check_privilege(void);
void _set_request_cb(shortcut_request_cb request_cb, void *data);
int _dbus_set_watch_name();
+/**
+ * @}
+ */
#ifdef __cplusplus
diff --git a/lib/src/shortcut_internal.c b/lib/src/shortcut_internal.c
index 569dfcd..776d2f7 100755
--- a/lib/src/shortcut_internal.c
+++ b/lib/src/shortcut_internal.c
@@ -29,7 +29,6 @@
#include "shortcut.h"
#include "shortcut_private.h"
#include "shortcut_internal.h"
-#include "shortcut_manager.h"
#define SHORTCUT_PKGNAME_LEN 512
@@ -58,12 +57,19 @@ static const GDBusErrorEntry dbus_error_entries[] = {
{SHORTCUT_ERROR_COMM, "org.freedesktop.Shortcut.Error.COMM"},
};
-typedef struct _shortcut_cb_info {
+typedef struct _shortcut_request_cb_info {
int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data);
void *data;
-} shortcut_cb_info;
+} shortcut_request_cb_info;
+
+typedef struct _shortcut_remove_cb_info {
+ int (*remove_cb)(const char *package_name, const char *name, int sender_pid, void *user_data);
+ void *data;
+} shortcut_remove_cb_info;
+
+static shortcut_request_cb_info _request_callback_info;
+static shortcut_remove_cb_info _remove_callback_info;
-static shortcut_cb_info _callback_info;
#define SHORTCUT_ERROR_QUARK "shortcut-error-quark"
@@ -104,7 +110,11 @@ static void _add_shortcut_notify(GVariant *parameters)
g_variant_get(parameters, "(i&s&si&s&si)", &sender_pid, &appid, &name, &type, &content, &icon, &allow_duplicate);
DbgPrint("_add_shortcut_notify sender_pid: %d ", sender_pid);
- _callback_info.request_cb(appid, name, type, content, icon, sender_pid, -1.0f, allow_duplicate, _callback_info.data);
+
+ if (_request_callback_info.request_cb != NULL)
+ _request_callback_info.request_cb(appid, name, type, content, icon, sender_pid, -1.0f, allow_duplicate, _request_callback_info.data);
+ else
+ DbgPrint("request_cb is null.");
}
/* LCOV_EXCL_STOP */
@@ -121,10 +131,29 @@ static void _add_shortcut_widget_notify(GVariant *parameters)
double period;
g_variant_get(parameters, "(i&s&si&s&sdi)", &sender_pid, &appid, &name, &type, &content, &icon, &period, &allow_duplicate);
- _callback_info.request_cb(appid, name, type, content, icon, sender_pid, period, allow_duplicate, _callback_info.data);
+
+ if (_request_callback_info.request_cb != NULL)
+ _request_callback_info.request_cb(appid, name, type, content, icon, sender_pid, period, allow_duplicate, _request_callback_info.data);
+ else
+ DbgPrint("request_cb is null.");
}
/* LCOV_EXCL_STOP */
+static void _remove_shortcut_notify(GVariant *parameters)
+{
+ const char *appid;
+ const char *name;
+ int sender_pid;
+
+ g_variant_get(parameters, "(i&s&s)", &sender_pid, &appid, &name);
+ DbgPrint("_add_shortcut_notify sender_pid: %d ", sender_pid);
+
+ if (_remove_callback_info.remove_cb != NULL)
+ _remove_callback_info.remove_cb(appid, name, sender_pid, _remove_callback_info.data);
+ else
+ DbgPrint("remove_cb is null.");
+}
+
/* LCOV_EXCL_START */
static void _handle_shortcut_notify(GDBusConnection *connection,
const gchar *sender_name,
@@ -139,6 +168,8 @@ static void _handle_shortcut_notify(GDBusConnection *connection,
_add_shortcut_notify(parameters);
else if (g_strcmp0(signal_name, "add_shortcut_widget_notify") == 0)
_add_shortcut_widget_notify(parameters);
+ else if (g_strcmp0(signal_name, "remove_shortcut_notify") == 0)
+ _remove_shortcut_notify(parameters);
}
/* LCOV_EXCL_STOP */
@@ -442,8 +473,8 @@ static void _on_name_vanished(GDBusConnection *connection,
void _set_request_cb(shortcut_request_cb request_cb, void *data)
{
- _callback_info.request_cb = request_cb;
- _callback_info.data = data;
+ _request_callback_info.request_cb = request_cb;
+ _request_callback_info.data = data;
}
int _dbus_set_watch_name()
@@ -469,5 +500,107 @@ int _dbus_set_watch_name()
return SHORTCUT_ERROR_NONE;
}
+EXPORT_API int shortcut_set_remove_cb(shortcut_remove_cb remove_cb, void *user_data)
+{
+ int ret;
+
+ if(remove_cb == NULL)
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _dbus_signal_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init dbus_signal %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _send_service_register();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init ipc_monitor_register %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _dbus_set_watch_name();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init _dbus_set_watch_name %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ _remove_callback_info.remove_cb = remove_cb;
+ _remove_callback_info.data = user_data;
+
+ return SHORTCUT_ERROR_NONE;
+}
+
+EXPORT_API int shortcut_remove_from_home(const char *name, result_cb_t result_cb, void *user_data)
+{
+ struct result_cb_item *item;
+ char *appid;
+ int ret;
+ GVariant *body;
+
+ if(name == NULL) {
+ ErrPrint("name is NULL.");
+ return SHORTCUT_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _dbus_init();
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ ErrPrint("Can't init dbus %d", ret);
+ return ret;
+ /* LCOV_EXCL_STOP */
+ }
+
+ ret = _check_privilege();
+ if (ret != SHORTCUT_ERROR_NONE)
+ return ret;
+ appid = _shortcut_get_pkgname_by_pid();
+ item = malloc(sizeof(struct result_cb_item));
+ if (!item) {
+ /* LCOV_EXCL_START */
+ if (appid)
+ free(appid);
+
+ ErrPrint("Heap: %d\n", errno);
+ return SHORTCUT_ERROR_OUT_OF_MEMORY;
+ /* LCOV_EXCL_STOP */
+ }
+
+ item->result_cb = result_cb;
+ item->result_internal_cb = NULL;
+ item->data = user_data;
+
+ body = g_variant_new("(iss)", getpid(), appid, name);
+
+ ret = _send_async_shortcut(body, item, "remove_shortcut");
+ if (ret != SHORTCUT_ERROR_NONE) {
+ /* LCOV_EXCL_START */
+ free(item);
+ item = NULL;
+ /* LCOV_EXCL_STOP */
+ }
+
+ if (appid)
+ free(appid);
+ if (body)
+ g_variant_unref(body);
+
+ return ret;
+
+}