Send viewer_[dis]connected event to the provider.
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 21 Jan 2015 16:11:21 +0000 (01:11 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 21 Jan 2015 16:13:26 +0000 (01:13 +0900)
When a new client is added to instance's client list.

[model] Redwood,Kiran,B3(Wearable)
[binary_type] AP
[customer] Docomo/Orange/ATT/Open
[issue#] N/A
[problem]
[cause]
[solution]
[team] HomeTF
[request]
[horizontal_expansion]

Change-Id: Ic8a070386d0460065565664923e0103b0d55c3f8

src/instance.c
src/server.c

index 643099c..05bfbc4 100644 (file)
@@ -233,6 +233,8 @@ static inline void timer_freeze(struct inst_info *inst)
 static int viewer_deactivated_cb(struct client_node *client, void *data)
 {
        struct inst_info *inst = data;
+       unsigned int cmd = CMD_VIEWER_DISCONNECTED;
+       struct packet *packet;
 
        DbgPrint("%d is deleted from the list of viewer of %s(%s)\n", client_pid(client), package_name(instance_package(inst)), instance_id(inst));
        if (!eina_list_data_find(inst->client_list, client)) {
@@ -240,6 +242,19 @@ static int viewer_deactivated_cb(struct client_node *client, void *data)
                return DBOX_STATUS_ERROR_NOT_EXIST;
        }
 
+       packet = packet_create_noack((const char *)&cmd, "sss", package_name(inst->info), inst->id, client_direct_addr(inst->client));
+       if (packet) {
+               if (slave_rpc_request_only(package_slave(inst->info), package_name(inst->info), packet, 0) < 0) {
+                       ErrPrint("Failed to send request to slave: %s\n", package_name(inst->info));
+                       /*!
+                        * \note
+                        * From now, packet is not valid. because the slave_rpc_request_only will destroy it if it fails;)
+                        */
+               }
+       } else {
+               ErrPrint("Failed to create a packet\n");
+       }
+
        inst->client_list = eina_list_remove(inst->client_list, client);
        if (!inst->client_list && !inst->client) {
                DbgPrint("Has no clients\n");
@@ -3483,8 +3498,16 @@ HAPI int instance_client_dbox_extra_buffer_destroyed(struct inst_info *inst, int
        return client_send_event(inst, packet);
 }
 
+/**
+ * \note
+ *  this function will be called after checking the list.
+ *  only if the client is not in the list, this will be called.
+ */
 HAPI int instance_add_client(struct inst_info *inst, struct client_node *client)
 {
+       struct packet *packet;
+       unsigned int cmd = CMD_VIEWER_CONNECTED;
+
        if (inst->client == client) {
                ErrPrint("Owner cannot be the viewer\n");
                return DBOX_STATUS_ERROR_INVALID_PARAMETER;
@@ -3496,9 +3519,17 @@ HAPI int instance_add_client(struct inst_info *inst, struct client_node *client)
                return DBOX_STATUS_ERROR_FAULT;
        }
 
+       packet = packet_create_noack((const char *)&cmd, "sss", package_name(inst->info), inst->id, client_direct_addr(inst->client));
+       if (!packet) {
+               ErrPrint("Failed to create a packet\n");
+               client_event_callback_del(client, CLIENT_EVENT_DEACTIVATE, viewer_deactivated_cb, inst);
+               return DBOX_STATUS_ERROR_FAULT;
+       }
+
        instance_ref(inst);
        inst->client_list = eina_list_append(inst->client_list, client);
-       return DBOX_STATUS_ERROR_NONE;
+
+       return slave_rpc_request_only(package_slave(inst->info), package_name(inst->info), packet, 0);
 }
 
 HAPI int instance_del_client(struct inst_info *inst, struct client_node *client)
index 408fb5a..44f049a 100644 (file)
@@ -5990,7 +5990,7 @@ out:
        return result;
 }
 
-static struct packet *client_subscribed(pid_t pid, int handle, const struct packet *packet)
+static struct packet *client_subscribed_group(pid_t pid, int handle, const struct packet *packet)
 {
        const char *cluster;
        const char *category;
@@ -6021,7 +6021,7 @@ static struct packet *client_subscribed(pid_t pid, int handle, const struct pack
         * \todo
         * SUBSCRIBE cluster & sub-cluster for a client.
         */
-       ret = client_subscribe(client, cluster, category);
+       ret = client_subscribe_group(client, cluster, category);
        if (ret == 0) {
                package_alter_instances_to_client(client, ALTER_CREATE);
        }
@@ -6246,7 +6246,7 @@ out:
        return result;
 }
 
-static struct packet *client_unsubscribed(pid_t pid, int handle, const struct packet *packet)
+static struct packet *client_unsubscribed_group(pid_t pid, int handle, const struct packet *packet)
 {
        const char *cluster;
        const char *category;
@@ -6278,7 +6278,7 @@ static struct packet *client_unsubscribed(pid_t pid, int handle, const struct pa
         * \todo
         * UNSUBSCRIBE cluster & sub-cluster for a client.
         */
-       ret = client_unsubscribe(client, cluster, category);
+       ret = client_unsubscribe_group(client, cluster, category);
        if (ret == 0) {
                package_alter_instances_to_client(client, ALTER_DESTROY);
        }
@@ -8655,11 +8655,11 @@ static struct method s_client_table[] = {
        },
        {
                .cmd = CMD_STR_SUBSCRIBE, /* pid, cluster, sub-cluster */
-               .handler = client_subscribed,
+               .handler = client_subscribed_group,
        },
        {
                .cmd = CMD_STR_UNSUBSCRIBE, /* pid, cluster, sub-cluster */
-               .handler = client_unsubscribed,
+               .handler = client_unsubscribed_group,
        },
        {
                .cmd = CMD_STR_DELETE_CLUSTER,