*/
typedef void (*app_control_result_cb)(app_control_h request, app_control_error_e result, void *user_data);
+/**
+ * @brief The application control action handle.
+ * @since_tizen 5.5
+ */
+typedef struct app_control_action_s *app_control_action_h;
+
+/**
+ * @brief Called when another application sends a launch request to the application.
+ * @details Before calling app_control_cb() function, this callback function is called.
+ * @since_tizen 5.5
+ * @remarks After this callback function returns, the handle of the app_control is released.
+ * Therefore, if you want to use the handle after returning this callback function, you MUST copy it by using app_control_clone() function.
+ * @remarks The @a action must not be deallocated by the application. The platform frees the string when the app_control action handle is removed.
+ *
+ * @param[in] action The name of the app_control action
+ * @param[in] app_control The handle of the app_control
+ * @param[in] user_data The user data passed from the callback registration function
+ * @see app_control_add_action_handler()
+ * @see @ref CAPI_APP_APPLICATION_MODULE API
+ */
+typedef void (*app_control_action_cb)(const char *action,
+ app_control_h app_control, void *user_data);
/**
* @brief Creates an app_control handle.
* @param[in] mime The explicit MIME type of the data this app_control is operating on
* @param[in] category The explicit category
* @param[in] app_id The ID of the application to explicitly launch
- * @param[in] mode The launch mode of the application
- * @param[in] extra_data_count The count of a extra data
+ * @param[in] mode The launch mode of the application
+ * @param[in] extra_data_count The count of a extra data
* @param[in] ... The key-value pair list of app control extra data
* @return @c 0 on success,
* otherwise a negative error value
* @remarks The function is not allowed to send reply #APP_CONTROL_RESULT_APP_STARTED as @a result which is reserved for platform developers.
*
* @param[in] reply The app_control handle in which the results of the callee are contained
- * @param[in] request The app_control handle sent by the caller
+ * @param[in] request The app_control handle sent by the caller
* @param[in] result The result code of the launch request
* @return @c 0 on success,
* otherwise a negative error value
int app_control_send_launch_request_sync(app_control_h app_control,
app_control_h *reply, app_control_result_e *result);
+/**
+ * @brief Adds the app_control action handle.
+ * @since_tizen 5.5
+ * @remarks You should release @a handle using app_control_remove_action_handler().
+ *
+ * @param[in] action The name of the app_control action
+ * @param[in] callback The callback function
+ * @param[in] user_data The user data to be passed to the callback function
+ * @param[out] handle The app_control action handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #APP_CONTROL_ERROR_NONE Successful
+ * @retval #APP_CONTROL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #APP_CONTROL_ERROR_OUT_OF_MEMORY Out of memory
+ * @retval #APP_CONTROL_ERROR_KEY_NOT_FOUND Specified app_control ID not found
+ * @retval #APP_CONTROL_ERROR_IO_ERROR IO error
+ * @see app_control_action_cb()
+ * @see app_control_remove_action_handler()
+ */
+int app_control_add_action_handler(const char *action,
+ app_control_action_cb callback, void *user_data,
+ app_control_action_h *handle);
+
+/**
+ * @brief Removes registered app_control action handle.
+ * @since_tizen 5.5
+ *
+ * @param[in] handle The app_control action handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #APP_CONTROL_ERROR_NONE Successful
+ * @retval #APP_CONTROL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see app_control_add_action_handler()
+ */
+int app_control_remove_action_handler(app_control_action_h handle);
+
/**
* @}
*/
#include <string.h>
#include <errno.h>
+#include <glib.h>
#include <bundle.h>
#include <bundle_internal.h>
#include <aul.h>
#include <aul_svc.h>
#include <dlog.h>
+#include <appcore_base_control.h>
#include <app_control.h>
#include <app_control_internal.h>
app_control_result_e result;
};
+struct app_control_action_s {
+ char *action;
+ appcore_base_control_h handle;
+ app_control_action_cb callback;
+ void *user_data;
+};
+
typedef int (*launch_request_handler)(struct launch_request_s *req);
static int app_control_create_reply(bundle *data, struct app_control_s **app_control);
return __send_launch_request_sync(app_control, reply, result);
}
+
+static void __appcore_base_control_cb(bundle *b, void *user_data)
+{
+ struct app_control_action_s *h;
+ app_control_h app_control;
+ int r;
+
+ h = (struct app_control_action_s *)user_data;
+ r = app_control_create_event(b, &app_control);
+ if (r != APP_CONTROL_ERROR_NONE) {
+ LOGE("Failed to create app-control handle");
+ return;
+ }
+
+ h->callback(h->action, app_control, h->user_data);
+ app_control_destroy(app_control);
+}
+
+int app_control_add_action_handler(const char *action,
+ app_control_action_cb callback, void *user_data,
+ app_control_action_h *handle)
+{
+ struct app_control_action_s *h;
+ int r;
+
+ if (!action || !callback || !handle) {
+ return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, "Invalid parameter");
+ }
+
+ h = calloc(1, sizeof(struct app_control_action_s));
+ if (!h) {
+ return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY,
+ __FUNCTION__, "Out of memory");
+ }
+
+ h->action = strdup(action);
+ if (!h->action) {
+ free(h);
+ return app_control_error(APP_CONTROL_ERROR_OUT_OF_MEMORY,
+ __FUNCTION__,
+ "Failed to duplicate app-control action");
+ }
+
+ r = appcore_base_control_add(h->action, __appcore_base_control_cb, h,
+ &h->handle);
+ if (r != APPCORE_BASE_ERROR_NONE) {
+ free(h->action);
+ free(h);
+ switch (r) {
+ case APPCORE_BASE_ERROR_INVALID_PARAMETER:
+ return app_control_error(
+ APP_CONTROL_ERROR_INVALID_PARAMETER,
+ __FUNCTION__,
+ "Invalid parameter");
+ case APPCORE_BASE_ERROR_KEY_NOT_FOUND:
+ return app_control_error(
+ APP_CONTROL_ERROR_KEY_NOT_FOUND,
+ __FUNCTION__,
+ "AppControl ID is not found");
+ case APPCORE_BASE_ERROR_IO_ERROR:
+ return app_control_error(
+ APP_CONTROL_ERROR_IO_ERROR,
+ __FUNCTION__,
+ "IO error");
+ default:
+ return app_control_error(
+ APP_CONTROL_ERROR_OUT_OF_MEMORY,
+ __FUNCTION__,
+ "Out of memory");
+ }
+ }
+
+ h->callback = callback;
+ h->user_data = user_data;
+
+ *handle = h;
+
+ return APP_CONTROL_ERROR_NONE;
+}
+
+int app_control_remove_action_handler(app_control_action_h handle)
+{
+ if (!handle) {
+ return app_control_error(APP_CONTROL_ERROR_INVALID_PARAMETER,
+ __FUNCTION__, "Invalid parameter");
+ }
+
+ if (handle->handle)
+ appcore_base_control_remove(handle->handle);
+
+ if (handle->action)
+ free(handle->action);
+
+ free(handle);
+
+ return APP_CONTROL_ERROR_NONE;
+}