Revise the dbus code and fix some bugs.
authorSung-jae Park <nicesj.park@samsung.com>
Tue, 12 Jun 2012 10:14:33 +0000 (19:14 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Tue, 12 Jun 2012 10:18:04 +0000 (19:18 +0900)
Change-Id: I02c97d0e7c4968736c7738f29ec13bdbb759af2b

12 files changed:
CMakeLists.txt
debian/changelog
include/slave_life.h
include/util.h
packaging/com.samsung.data-provider-master.spec
src/client_life.c
src/dbus.c
src/package.c
src/script_handler.c
src/slave_life.c
src/slave_rpc.c
src/util.c

index 7f79825..8bf011d 100644 (file)
@@ -32,9 +32,18 @@ ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
 ADD_DEFINITIONS("-DLOCALEDIR=\"${LOCALEDIR}\"")
 
 ADD_DEFINITIONS("-DBUS_TYPE=G_BUS_TYPE_SYSTEM")        # G_BUS_TYPE_SESSION
-ADD_DEFINITIONS("-DSERVICE_INTERFACE=\"com.samsung.dataprovider.server\"")
-ADD_DEFINITIONS("-DSERVICE_NAME=\"com.samsung.dataprovider.serviceinterface\"")
-ADD_DEFINITIONS("-DOBJECT_PATH=\"/com/samsung/dataprovider/serviceobject\"")
+
+ADD_DEFINITIONS("-DMASTER_OBJECT_PATH=\"/com/samsung/masterprovider/serviceobject\"")
+ADD_DEFINITIONS("-DMASTER_SERVICE_INTERFACE=\"com.samsung.masterprovider.server\"")
+ADD_DEFINITIONS("-DMASTER_SERVICE_NAME=\"com.samsung.masterprovider.serviceinterface\"")
+
+ADD_DEFINITIONS("-DSLAVE_OBJECT_PATH=\"/com/samsung/slaveprovider/serviceobject\"")
+ADD_DEFINITIONS("-DSLAVE_SERVICE_INTERFACE=\"com.samsung.slaveprovider.server\"")
+ADD_DEFINITIONS("-DSLAVE_SERVICE_NAME=\"com.samsung.slaveprovider.serviceinterface\"")
+
+ADD_DEFINITIONS("-DCLIENT_OBJECT_PATH=\"/com/samsung/liveboxviewer/serviceobject\"")
+ADD_DEFINITIONS("-DCLIENT_SERVICE_INTERFACE=\"com.samsung.liveboxviewer.server\"")
+ADD_DEFINITIONS("-DCLIENT_SERVICE_NAME=\"com.samsung.liveboxviewer.serviceinterface\"")
 
 ADD_DEFINITIONS("-DSLAVE_PKGNAME=\"com.samsung.data-provider-slave\"")
 
index 8727274..44dafbc 100644 (file)
@@ -1,3 +1,10 @@
+data-provider-master (0.3.2) unstable; urgency=low
+
+  * Git: slp/pkgs/d/data-provider-master
+  * Tag: data-provider-master_0.3.2
+
+ -- Sung-jae Park <nicesj.park@samsung.com>  Tue, 12 Jun 2012 19:17:41 +0900
+
 data-provider-master (0.3.1) unstable; urgency=low
 
   * Git: slp/pkgs/d/data-provider-master
index 797e38e..b407432 100644 (file)
@@ -32,6 +32,7 @@ extern int slave_deactivate(struct slave_node *slave);
  * To check the slave's activation state
  */
 extern int slave_is_activated(struct slave_node *slave);
+extern int slave_activated(struct slave_node *slave);
 
 /*!
  * To mangage the unexpected termination of a slave
index ee9e93c..8c38c1a 100644 (file)
@@ -3,5 +3,6 @@ extern double util_timestamp(void);
 extern int util_check_ext(const char *filename, const char *check_ptr);
 extern int util_validate_livebox_package(const char *pkgname);
 extern int util_unlink(const char *filename);
+extern char *util_slavename(void);
 
 /* End of a file */
index f27ff03..002e12a 100644 (file)
@@ -1,6 +1,6 @@
 Name: com.samsung.data-provider-master
 Summary: Master data provider
-Version: 0.3.1
+Version: 0.3.2
 Release: 1
 Group: main/app
 License: Samsung Proprietary License
index 4ecdcf5..58383af 100644 (file)
@@ -252,7 +252,7 @@ int client_deactivated_by_fault(struct client_node *client)
        if (client->faulted)
                return 0;
 
-       DbgPrint("Client is faulted! refcnt(%d), pid(%d)\n", client_refcnt(client), client->pid);
+       DbgPrint("Client is faulted! refcnt(%d), pid(%d)\n", client->refcnt, client->pid);
        client->faulted = 1;
 
        client->pid = (pid_t)-1;
@@ -268,7 +268,7 @@ int client_fault(struct client_node *client)
        if (client->faulted)
                return 0;
 
-       DbgPrint("Client is faulted(%d), pid(%d)\n", client_refcnt(client), client->pid);
+       DbgPrint("Client is faulted(%d), pid(%d)\n", client->refcnt, client->pid);
        client->faulted = 1;
 
        client->pid = (pid_t)-1;
index db3324d..761935d 100644 (file)
@@ -33,8 +33,8 @@ static struct info {
 } s_info = {
        .node_info = NULL,
        .owner_id = 0,
-       .xml_data = "<node name ='" OBJECT_PATH "'>"
-       "<interface name='" SERVICE_INTERFACE "'>"
+       .xml_data = "<node name ='" MASTER_OBJECT_PATH "'>"
+       "<interface name='" MASTER_SERVICE_INTERFACE "'>"
 
        /* From client */
        " <method name='acquire'>"
@@ -456,26 +456,28 @@ static void method_hello(GDBusMethodInvocation *inv, GVariant *param)
 
                sender = g_dbus_method_invocation_get_sender(inv);
 
-               param = g_variant_new("(i)", 0);
-               if (!param)
-                       ErrPrint("Failed to create variant\n");
-
-               g_dbus_method_invocation_return_value(inv, param);
-
                conn = g_dbus_method_invocation_get_connection(inv);
                if (!conn) {
                        ErrPrint("Failed to get connection object\n");
                        return;
                }
 
+               DbgPrint("sender: %s\n", sender);
                g_dbus_proxy_new(conn,
                        G_DBUS_PROXY_FLAGS_NONE,
                        NULL, 
                        sender,
-                       OBJECT_PATH,
-                       SERVICE_INTERFACE,
+                       SLAVE_OBJECT_PATH,
+                       SLAVE_SERVICE_INTERFACE,
                        NULL,
                        slave_proxy_prepared_cb, slave);
+
+               param = g_variant_new("(i)", 0);
+               if (!param)
+                       ErrPrint("Failed to create variant\n");
+
+               g_dbus_method_invocation_return_value(inv, param);
+
        }
 }
 
@@ -512,6 +514,7 @@ static void method_desc_updated(GDBusMethodInvocation *inv, GVariant *param)
                        ret = 0;
                } else if (script_handler_is_loaded(instance_pd_handle(inst))) {
                        ret = script_handler_parse_desc(pkgname, id, descfile, 1);
+                       DbgPrint("DESC for PD is updated (%d - %s)\n", ret, pkgname);
                } else {
                        ret = 0;
                }
@@ -559,6 +562,7 @@ static void method_updated(GDBusMethodInvocation *inv, GVariant *param)
                        if (package_lb_type(instance_package(inst)) == LB_TYPE_SCRIPT) {
                                script_handler_resize(instance_lb_handle(inst), w, h);
                                ret = script_handler_parse_desc(pkgname, id, id, 0);
+                               DbgPrint("DESC for LB is updated (%d - %s)\n", ret, pkgname);
                        } else {
                                /*!
                                 * \check
@@ -661,12 +665,6 @@ static void method_acquire(GDBusMethodInvocation *inv, GVariant *param)
        }
 
 out:
-       param = g_variant_new("(i)", ret);
-       if (!param)
-               ErrPrint("Failed to create variant\n");
-
-       g_dbus_method_invocation_return_value(inv, param);
-
        if (ret == 0) {
                GDBusConnection *conn;
                const char *sender;
@@ -678,15 +676,23 @@ out:
                }
 
                sender = g_dbus_method_invocation_get_sender(inv);
+               DbgPrint("sender: %s\n", sender);
                g_dbus_proxy_new(conn,
                        G_DBUS_PROXY_FLAGS_NONE,
                        NULL,
                        sender,
-                       OBJECT_PATH,
-                       SERVICE_INTERFACE,
+                       CLIENT_OBJECT_PATH,
+                       CLIENT_SERVICE_INTERFACE,
                        NULL,
                        client_proxy_prepared_cb, client);
        }
+
+       param = g_variant_new("(i)", ret);
+       if (!param)
+               ErrPrint("Failed to create variant\n");
+
+       g_dbus_method_invocation_return_value(inv, param);
+
 }
 
 static void method_release(GDBusMethodInvocation *inv, GVariant *param)
@@ -1592,7 +1598,7 @@ static void on_bus_acquired(GDBusConnection *conn,
 
        err = NULL;
        s_info.reg_id = g_dbus_connection_register_object(conn,
-                       OBJECT_PATH,
+                       MASTER_OBJECT_PATH,
                        s_info.node_info->interfaces[0],
                        &iface_vtable,
                        NULL,
@@ -1601,7 +1607,7 @@ static void on_bus_acquired(GDBusConnection *conn,
 
        if (s_info.reg_id <= 0) {
                if (err) {
-                       ErrPrint("register %s - %s\n", OBJECT_PATH, err->message);
+                       ErrPrint("register %s - %s\n", MASTER_OBJECT_PATH, err->message);
                        g_error_free(err);
                }
                g_dbus_node_info_unref(s_info.node_info);
@@ -1622,7 +1628,7 @@ int dbus_init(void)
        int r;
 
        r = g_bus_own_name(BUS_TYPE,
-                       SERVICE_NAME,
+                       MASTER_SERVICE_NAME,
                        G_BUS_NAME_OWNER_FLAGS_NONE,
                        on_bus_acquired,
                        on_name_acquired,
@@ -1630,7 +1636,7 @@ int dbus_init(void)
                        NULL, /* user_data */
                        NULL /* GDestroyNotify */ );
        if (r <= 0) {
-               ErrPrint("Failed to get a name: %s\n", SERVICE_NAME);
+               ErrPrint("Failed to get a name: %s\n", MASTER_SERVICE_NAME);
                return -EFAULT;
        }
 
index 7546f7b..ae2e92e 100644 (file)
@@ -169,8 +169,13 @@ static inline void destroy_package(struct pkg_info *info)
        free(info->script);
        free(info->abi);
        free(info->pkgname);
-       slave_event_callback_del(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info);
-       slave_event_callback_del(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info);
+
+       if (info->slave) {
+               slave_unload_package(info->slave);
+               slave_event_callback_del(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info);
+               slave_event_callback_del(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info);
+       }
+
        free(info);
 }
 
@@ -356,14 +361,25 @@ struct pkg_info *package_create(const char *pkgname)
        if (!info->secured)
                info->slave = slave_find_available();
 
+       package_ref(info);
+
        if (!info->slave) {
-               char slavename[BUFSIZ];
-               snprintf(slavename, sizeof(slavename), "%lf", util_timestamp());
+               char *slavename;
+               slavename = util_slavename();
+               if (!slavename) {
+                       package_destroy(info);
+                       return NULL;
+               }
+
+               DbgPrint("New slave name is %s assigned for %s\n", slavename, pkgname);
                info->slave = slave_create(slavename, info->secured);
+               free(slavename);
                /*!
                 * \note
                 * Slave is not activated yet.
                 */
+       } else {
+               DbgPrint("Slave %s is assigned for %s\n", slave_name(info->slave), pkgname);
        }
 
        if (!info->slave) {
@@ -378,10 +394,10 @@ struct pkg_info *package_create(const char *pkgname)
                return NULL;
        }
 
+       slave_load_package(info->slave);
        slave_event_callback_add(info->slave, SLAVE_EVENT_DEACTIVATE, slave_deactivated_cb, info);
        slave_event_callback_add(info->slave, SLAVE_EVENT_ACTIVATE, slave_activated_cb, info);
 
-       package_ref(info);
        s_info.pkg_list = eina_list_append(s_info.pkg_list, info);
        return info;
 }
index a0bb8bf..f02285f 100644 (file)
@@ -180,6 +180,7 @@ int script_signal_emit(Evas *e, const char *part, const char *signal, double sx,
                return -EFAULT;
        }
 
+       DbgPrint("send %s %s %s\n", "script", signal, part);
        ret = slave_rpc_async_request(slave, pkgname, filename, "script", param, NULL, NULL); 
        return ret;
 }
@@ -581,8 +582,10 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
        block = NULL;
        inst = package_find_instance_by_id(pkgname, filename);
-       if (!inst)
-               return -EINVAL;
+       if (!inst) {
+               ErrPrint("Instance is not exists\n");
+               return -ENOENT;
+       }
 
        fp = fopen(descfile, "rt");
        if (!fp) {
@@ -590,6 +593,8 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                return -EIO;
        }
 
+       DbgPrint("descfile: %s\n", descfile);
+
        state = UNKNOWN;
        field_idx = 0;
        lineno = 1;
@@ -607,7 +612,8 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                break;
                        }
 
-                       if (!isspace(ch)) {
+                       if (!isspace(ch) && ch != EOF) {
+                               ErrPrint("%d: Syntax error: Desc is not started with '{' or space - (%c = 0x%x)\n", lineno, ch, ch);
                                fclose(fp);
                                return -EINVAL;
                        }
@@ -618,7 +624,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                break;
 
                        if (ch != '\n') {
-                               ErrPrint("Syntax error: New line must has to be started right after '{'\n");
+                               ErrPrint("%d: Syntax error: New line must has to be started right after '{'\n", lineno);
                                goto errout;
                        }
 
@@ -645,7 +651,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                        if (ch == '=') {
                                if (field_name[field_idx][idx] != '\0') {
-                                       ErrPrint("Syntax error: Unrecognized field\n");
+                                       ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
                                        goto errout;
                                }
 
@@ -705,7 +711,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                        idx = 0;
                                        break;
                                default:
-                                       ErrPrint("Syntax error: Unrecognized field\n");
+                                       ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
                                        goto errout;
                                }
 
@@ -725,7 +731,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
 
                                field_idx++;
                                if (field_name[field_idx] == NULL) {
-                                       ErrPrint("Syntax error: Unrecognized field\n");
+                                       ErrPrint("%d: Syntax error: Unrecognized field\n", lineno);
                                        goto errout;
                                }
 
@@ -742,7 +748,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                block->type =
                                        realloc(block->type, block->type_len);
                                if (!block->type) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -765,7 +771,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                block->part =
                                        realloc(block->part, block->part_len);
                                if (!block->part) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -788,7 +794,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                block->data =
                                        realloc(block->data, block->data_len);
                                if (!block->data) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -811,7 +817,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                block->file =
                                        realloc(block->file, block->file_len);
                                if (!block->file) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -834,7 +840,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                block->group = realloc(block->group,
                                                        block->group_len);
                                if (!block->group) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -855,7 +861,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                                block->id_len += 256;
                                block->id = realloc(block->id, block->id_len);
                                if (!block->id) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -875,7 +881,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                        if (!block->file) {
                                block->file = strdup(filename);
                                if (!block->file) {
-                                       ErrPrint("Failed to allocate memory\n");
+                                       ErrPrint("Heap: %s\n", strerror(errno));
                                        goto errout;
                                }
                        }
@@ -890,7 +896,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
                        }
 
                        if (!handlers[i].type)
-                               ErrPrint("Unknown block type: %s\n", block->type);
+                               ErrPrint("%d: Unknown block type: %s\n", lineno, block->type);
 
                        free(block->file);
                        free(block->type);
@@ -909,7 +915,7 @@ int script_handler_parse_desc(const char *pkgname, const char *filename, const c
        } /* while */
 
        if (state != UNKNOWN) {
-               ErrPrint("Unknown state\n");
+               ErrPrint("%d: Unknown state\n", lineno);
                goto errout;
        }
 
index f841714..6154bf9 100644 (file)
@@ -32,9 +32,34 @@ struct slave_node {
        int refcnt;
        int fault_count;
        enum pause_state {
+               /*!
+                * Launch the slave but not yet receives "hello" packet
+                */
+               SLAVE_REQUEST_TO_LAUNCH,
+
+               /*!
+                * \note
+                * Terminate the slave but not yet receives dead signal
+                */
+               SLAVE_REQUEST_TO_TERMINATE,
+
+               /*!
+                * \note
+                * No slave process exists, just slave object created
+                */
+               SLAVE_TERMINATED,
+
+               /*!
+                * \note
+                * State change request is sent,
+                */
                SLAVE_REQUEST_TO_PAUSE,
                SLAVE_REQUEST_TO_RESUME,
 
+               /*!
+                * \note
+                * SLAVE_ACTIVATED = { SLAVE_PAUSED, SLAVE_RESUMED }
+                */
                SLAVE_PAUSED,
                SLAVE_RESUMED,
        } state;
@@ -92,7 +117,7 @@ static inline struct slave_node *create_slave_node(const char *name, int is_secu
 
        slave->secured = is_secured;
        slave->pid = (pid_t)-1;
-       slave->state = SLAVE_RESUMED;
+       slave->state = SLAVE_TERMINATED;
 
        s_info.slave_list = eina_list_append(s_info.slave_list, slave);
        DbgPrint("slave data is created %p\n", slave);
@@ -269,11 +294,13 @@ int slave_activate(struct slave_node *slave)
        bundle_free(param);
 
        if (slave->pid < 0) {
-               ErrPrint("Failed to launch a new slave %s\n", slave->name);
+               ErrPrint("Failed to launch a new slave %s (%d)\n", slave->name, slave->pid);
+               slave->pid = (pid_t)-1;
                return -EFAULT;
        }
        DbgPrint("Slave launched %d\n", slave->pid);
 
+       slave->state = SLAVE_REQUEST_TO_LAUNCH;
        /*!
         * \note
         * Increase the refcnt of a slave,
@@ -281,10 +308,14 @@ int slave_activate(struct slave_node *slave)
         */
        slave_ref(slave);
 
-       invoke_activate_cb(slave);
-       slave_check_pause_or_resume();
+       return 0;
+}
 
+int slave_activated(struct slave_node *slave)
+{
        slave->state = SLAVE_RESUMED;
+       invoke_activate_cb(slave);
+       slave_check_pause_or_resume();
        return 0;
 }
 
@@ -330,6 +361,7 @@ int slave_deactivate(struct slave_node *slave)
         */
        pid = slave->pid;
        slave->pid = (pid_t)-1;
+
        DbgPrint("Terminate PID: %d\n", pid);
        if (aul_terminate_pid(pid) < 0)
                ErrPrint("Terminate failed. pid %d\n", pid);
@@ -363,7 +395,7 @@ void slave_faulted(struct slave_node *slave)
        slave_rpc_reset_proxy(slave);
 
        invoke_deactivate_cb(slave);
-       slave->state = SLAVE_PAUSED;
+       slave->state = SLAVE_TERMINATED;
        slave_unref(slave);
 }
 
@@ -386,7 +418,7 @@ void slave_deactivated_by_fault(struct slave_node *slave)
        slave_rpc_reset_proxy(slave);
 
        invoke_deactivate_cb(slave);
-       slave->state = SLAVE_PAUSED;
+       slave->state = SLAVE_TERMINATED;
        slave_unref(slave);
 }
 
@@ -559,10 +591,9 @@ struct slave_node *slave_find_available(void)
                if (slave->secured)
                        continue;
 
-               if (slave->loaded_package == g_conf.slave_max_load)
-                       continue;
-
-               return slave;
+               DbgPrint("slave[%s] %d\n", slave_name(slave), slave->loaded_package);
+               if (slave->loaded_package < g_conf.slave_max_load)
+                       return slave;
        }
 
        return NULL;
index a2b4b9e..0bd7a6a 100644 (file)
@@ -530,10 +530,11 @@ int slave_rpc_update_proxy(struct slave_node *slave, GDBusProxy *proxy)
        }
 
        if (rpc->proxy)
-               ErrPrint("RPC proxy is already exists\n");
+               ErrPrint("proxy %p is already exists (%s %d) (replaced with %p)\n", rpc->proxy, slave_name(slave), slave_pid(slave), proxy);
+       else
+               ErrPrint("proxy %p is updated (%s %d)\n", proxy, slave_name(slave), slave_pid(slave));
 
        rpc->proxy = proxy;
-       slave_reset_fault(slave);
 
        EINA_LIST_FREE(rpc->pending_request_list, packet) {
                push_packet(packet);
@@ -542,10 +543,16 @@ int slave_rpc_update_proxy(struct slave_node *slave, GDBusProxy *proxy)
        rpc->ping_count = 0;
        rpc->next_ping_count = 1;
 
+       if (rpc->pong_timer)
+               ecore_timer_del(rpc->pong_timer);
+
        rpc->pong_timer = ecore_timer_add(g_conf.ping_time, ping_timeout_cb, slave);
        if (!rpc->pong_timer)
                ErrPrint("Failed to add ping timer\n");
 
+       slave_activated(slave);
+
+       slave_reset_fault(slave);
        return 0;
 }
 
index 82e3f20..b78f030 100644 (file)
@@ -107,4 +107,13 @@ int util_unlink(const char *filename)
        return 0;
 }
 
+char *util_slavename(void)
+{
+       char slavename[BUFSIZ];
+       static unsigned long idx = 0;
+
+       snprintf(slavename, sizeof(slavename), "%lu_%lf", idx++, util_timestamp());
+       return strdup(slavename);
+}
+
 /* End of a file */