Provider controll API is added. 30/18430/1
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 24 Mar 2014 01:15:53 +0000 (10:15 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 24 Mar 2014 01:15:53 +0000 (10:15 +0900)
Provider can select the termination & reactivation behaviours of master.
As default setting, the master will terminate the provider if it has no running instances.
And it will reactivate the provider if a provider has termianted abnormally even though it has running instances.

But using this new API, the provider can select what the master should do for those cases.

To make the disconnection from a provider without termination a provider,
The provider now support the "disconnect" event.
So the master will send "disconnect" request instead of "terminate".

Change-Id: Iec89cc1c762ceadcf96ee1085ef481f61848d835

include/provider.h
packaging/libprovider.spec
src/fb.c
src/provider.c

index 1c7deeb..17ef64f 100644 (file)
@@ -28,6 +28,18 @@ extern "C" {
 
 /*!
  * \brief
+ * Update the provider control
+ * \see provider_control
+ * MUST HAS TO BE SYNC'd WITH THE DATA-PROVIDER-MASTER
+ */
+enum PROVIDER_CTRL {
+       PROVIDER_CTRL_DEFAULT = 0x00,                   /*!< Set default control operation */
+       PROVIDER_CTRL_MANUAL_TERMINATION = 0x01,        /*!< Terminate process manually */
+       PROVIDER_CTRL_MANUAL_REACTIVATION = 0x02,       /*!< Reactivate process manually */
+};
+
+/*!
+ * \brief
  * Text signal & Content event uses this data structure.
  */
 struct event_info {
@@ -603,6 +615,18 @@ extern int provider_send_key_status(const char *pkgname, const char *id, int sta
  * \see provider_send_key_status
  */
 extern int provider_send_request_close_pd(const char *pkgname, const char *id, int reason);
+
+/*!
+ * \brief Change the provider control policy.
+ * \details N/A
+ * \remarks N/A
+ * \param[in] ctrl enumeration list - enum PROVIDER_CTRL
+ * \return int
+ * \retval LB_STATUS_SUCCESS Successfully changed
+ * \pre
+ * \post
+ */
+extern int provider_control(int ctrl);
 /*!
  * \}
  */
index f835e4b..a51cc6e 100644 (file)
@@ -2,7 +2,7 @@
 
 Name: libprovider
 Summary: Library for developing the livebox service provider
-Version: 0.20.0
+Version: 0.21.0
 Release: 1
 Group: Web Framework/Libraries
 License: Flora
index 6c409d6..8b8ea51 100644 (file)
--- a/src/fb.c
+++ b/src/fb.c
@@ -611,8 +611,9 @@ static inline void release_gem(struct gem_data *gem)
                        gap = gem->dri2_buffer->pitch - (gem->w * gem->depth);
 
                        for (y = 0; y < gem->h; y++) {
-                               for (x = 0; x < gem->w; x++)
+                               for (x = 0; x < gem->w; x++) {
                                        *gem_pixel++ = *pixel++;
+                               }
 
                                gem_pixel = (int *)(((char *)gem_pixel) + gap);
                        }
index daa611d..862901b 100644 (file)
 #include "fb.h"
 
 static struct info {
+       int closing_fd;
        int fd;
        char *name;
        struct event_handler table;
        void *data;
        int prevent_overwrite;
 } s_info = {
+       .closing_fd = 0,
        .fd = -1,
        .name = NULL,
        .data = NULL,
@@ -579,6 +581,28 @@ out:
        return NULL;
 }
 
+struct packet *master_disconnect(pid_t pid, int handle, const struct packet *packet)
+{
+       double timestamp;
+       int ret;
+
+       ret = packet_get(packet, "d", &timestamp);
+       if (ret != 1) {
+               ErrPrint("Invalid packet\n");
+               goto errout;
+       }
+
+       if (s_info.fd >= 0 && s_info.closing_fd == 0) {
+               s_info.closing_fd = 1;
+               com_core_packet_client_fini(s_info.fd);
+               s_info.fd = -1;
+               s_info.closing_fd = 0;
+       }
+       
+errout:
+       return NULL;
+}
+
 struct packet *master_pd_move(pid_t pid, int handle, const struct packet *packet)
 {
        struct event_arg arg;
@@ -852,6 +876,10 @@ static struct method s_table[] = {
                .cmd = "update_mode",
                .handler = master_update_mode,
        },
+       {
+               .cmd = "disconnect",
+               .handler = master_disconnect,
+       },
 
        {
                .cmd = NULL,
@@ -988,9 +1016,11 @@ EAPI void *provider_fini(void)
 
        provider_fini_called = 1;
 
-       if (s_info.fd >= 0) {
+       if (s_info.fd >= 0 && s_info.closing_fd == 0) {
+               s_info.closing_fd = 1;
                com_core_packet_client_fini(s_info.fd);
                s_info.fd = -1;
+               s_info.closing_fd = 0;
        }
 
        provider_fini_called = 0;
@@ -1575,4 +1605,27 @@ const char *provider_name(void)
        return s_info.name;
 }
 
+EAPI int provider_control(int ctrl)
+{
+       struct packet *packet;
+       int ret;
+
+       if (s_info.fd < 0) {
+               ErrPrint("Connection is not established\n");
+               return LB_STATUS_ERROR_INVALID;
+       }
+
+       packet = packet_create_noack("ctrl", "i", ctrl);
+       if (!packet) {
+               ErrPrint("Failed to build a packet\n");
+               return LB_STATUS_ERROR_FAULT;
+       }
+
+       ret = com_core_packet_send_only(s_info.fd, packet);
+       packet_destroy(packet);
+
+       DbgPrint("[CTRL] Request: 0x%x\n", (unsigned int)ctrl);
+       return ret < 0 ? LB_STATUS_ERROR_FAULT : LB_STATUS_SUCCESS;
+}
+
 /* End of a file */