Add auto-launch handler hooking API.
authorSung-jae Park <nicesj.park@samsung.com>
Fri, 28 Feb 2014 11:13:27 +0000 (20:13 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Fri, 28 Feb 2014 11:13:27 +0000 (20:13 +0900)
Using this new API, homescreen developer hooks the auto-launch handler.

Change-Id: I08996dccf4e12f56d4f9854cb914ec3e4412bd3c

include/livebox.h
packaging/liblivebox-viewer.spec
src/livebox.c

index 630571c..2706245 100644 (file)
@@ -1712,6 +1712,21 @@ extern int livebox_set_option(enum livebox_option_type option, int state);
  */
 extern int livebox_option(enum livebox_option_type option);
 
+
+/*!
+ * \brief Set a handler for launching an app for auto-launch feature
+ * \details If a user clicks a box, and the box uses auto-launch option, the launcher_handler will be called.
+ * \remarks N/A
+ * \param[in] launch_handler Handler for launching an app manually
+ * \param[in] data Callback data which will be given a data for launch_handler
+ * \return int
+ * \retval
+ * \pre N/A
+ * \post N/A
+ * \see N/A
+ */
+extern int livebox_set_auto_launch_handler(int (*launch_handler)(struct livebox *handler, const char *appid, void *data), void *data);
+
 /*!
  * \}
  */
index 45998f7..dc96b83 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for developing the application
-Version: 0.20.8
+Version: 0.20.9
 Release: 1
 Group: HomeTF/Livebox
 License: Flora
index c3a6706..c6583f9 100644 (file)
@@ -49,6 +49,8 @@
 FILE *__file_log_fp;
 #endif
 
+static int default_launch_handler(struct livebox *handler, const char *appid, void *data);
+
 enum event_state {
        INFO_STATE_CALLBACK_IN_IDLE = 0x00,
        INFO_STATE_CALLBACK_IN_PROCESSING = 0x01,
@@ -67,6 +69,11 @@ static struct info {
        enum event_state fault_state;
        guint job_timer;
        struct dlist *job_list;
+
+       struct launch {
+               int (*handler)(struct livebox *handler, const char *appid, void *data);
+               void *data;
+       } launch;
 } s_info = {
        .livebox_list = NULL,
        .event_list = NULL,
@@ -77,6 +84,10 @@ static struct info {
        .fault_state = INFO_STATE_CALLBACK_IN_IDLE,
        .job_timer = 0,
        .job_list = NULL,
+       .launch = {
+               .handler = default_launch_handler,
+               .data = NULL,
+       },
 };
 
 struct cb_info {
@@ -99,6 +110,33 @@ struct fault_info {
 static void lb_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data);
 static void pd_pixmap_acquired_cb(struct livebox *handler, const struct packet *result, void *data);
 
+static int default_launch_handler(struct livebox *handler, const char *appid, void *data)
+{
+       int ret;
+
+       ret = aul_launch_app(appid, NULL);
+       if (ret <= 0) {
+               ErrPrint("Failed to launch an app %s (%d)\n", appid, ret);
+       }
+
+/*
+       service_h service;
+
+       DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->lb.auto_launch);
+
+       ret = service_create(&service);
+       if (ret == SERVICE_ERROR_NONE) {
+               service_set_package(service, handler->common->lb.auto_launch);
+               service_send_launch_request(service, NULL, NULL);
+               service_destroy(service);
+       } else {
+               ErrPrint("Failed to launch an app %s (%d)\n", handler->common->lb.auto_launch, ret);
+       }
+*/
+
+       return ret > 0 ? LB_STATUS_SUCCESS : LB_STATUS_ERROR_FAULT;
+}
+
 static inline void default_create_cb(struct livebox *handler, int ret, void *data)
 {
        DbgPrint("Default created event handler: %d\n", ret);
@@ -2115,23 +2153,11 @@ EAPI int livebox_click(struct livebox *handler, double x, double y)
        }
 
        if (handler->common->lb.auto_launch) {
-/*
-               service_h service;
-
-               DbgPrint("AUTO_LAUNCH [%s]\n", handler->common->lb.auto_launch);
-
-               ret = service_create(&service);
-               if (ret == SERVICE_ERROR_NONE) {
-                       service_set_package(service, handler->common->lb.auto_launch);
-                       service_send_launch_request(service, NULL, NULL);
-                       service_destroy(service);
-               } else {
-                       ErrPrint("Failed to launch an app %s (%d)\n", handler->common->lb.auto_launch, ret);
-               }
-*/
-               ret = aul_launch_app(handler->common->lb.auto_launch, NULL);
-               if (ret <= 0) {
-                       ErrPrint("Failed to launch an app %s (%d)\n", handler->common->lb.auto_launch, ret);
+               if (s_info.launch.handler) {
+                       ret = s_info.launch.handler(handler, handler->common->lb.auto_launch, s_info.launch.data);
+                       if (ret < 0) {
+                               ErrPrint("launch handler app %s (%d)\n", handler->common->lb.auto_launch, ret);
+                       }
                }
        }
 
@@ -4829,4 +4855,12 @@ EAPI int livebox_option(enum livebox_option_type option)
        return ret;
 }
 
+EAPI int livebox_set_auto_launch_handler(int (*launch_handler)(struct livebox *handler, const char *appid, void *data), void *data)
+{
+       s_info.launch.handler = launch_handler;
+       s_info.launch.data = data;
+
+       return LB_STATUS_SUCCESS;
+}
+
 /* End of a file */