Add category info to client ADT.
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 21 Jan 2015 11:25:10 +0000 (20:25 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 21 Jan 2015 11:25:10 +0000 (20:25 +0900)
alternate instance info regarding newly added client object.

[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: I383de7d9c170a35937cc48480038af7d3bcbdd41

include/client_life.h
src/client_life.c
src/server.c

index b844659..9e7cf7f 100644 (file)
@@ -91,10 +91,16 @@ extern void *client_del_data(struct client_node *client, const char *tag);
 extern void client_paused(struct client_node *client);
 extern void client_resumed(struct client_node *client);
 
+/* Related with Context-Aware service */
 extern int client_subscribe(struct client_node *client, const char *cluster, const char *category);
 extern int client_unsubscribe(struct client_node *client, const char *cluster, const char *category);
 extern int client_is_subscribed(struct client_node *client, const char *cluster, const char *category);
 
+/* Related with category */
+extern int client_subscribe_category(struct client_node *client, const char *category);
+extern int client_unsubscribe_category(struct client_node *client, const char *category);
+extern int client_is_subscribed_by_category(struct client_node *client, const char *category);
+
 extern int client_init(void);
 extern void client_fini(void);
 
index edb5048..6c3c44e 100644 (file)
@@ -62,11 +62,15 @@ static struct {
        .destroy_event_list = NULL,
 };
 
-struct subscribe_item {
+struct subscribe_item {        /* Cluster & Sub-cluster. related with Context-aware service */
        char *cluster;
        char *category;
 };
 
+struct category_subscribe_item {
+       char *category;
+};
+
 struct global_event_item {
        void *cbdata;
        int (*cb)(struct client_node *client, void *data);
@@ -100,6 +104,7 @@ struct client_node {
 
        Eina_List *data_list;
        Eina_List *subscribe_list;
+       Eina_List *category_subscribe_list;
 
        int faulted;
        char *direct_addr;
@@ -209,6 +214,7 @@ static inline void destroy_client_data(struct client_node *client)
        struct event_item *event;
        struct data_item *data;
        struct subscribe_item *item;
+       struct category_subscribe_item *category_item;
        Ecore_Timer *timer;
 
        timer = client_del_data(client, "create,timer");
@@ -237,6 +243,11 @@ static inline void destroy_client_data(struct client_node *client)
                DbgFree(item);
        }
 
+       EINA_LIST_FREE(client->category_subscribe_list, category_item) {
+               DbgFree(category_item->category);
+               DbgFree(category_item);
+       }
+
        if (client->paused) {
                s_info.nr_of_paused_clients--;
        }
@@ -752,6 +763,59 @@ HAPI int client_global_event_handler_del(enum client_global_event event_type, in
        return DBOX_STATUS_ERROR_NOT_EXIST;
 }
 
+HAPI int client_subscribe_category(struct client_node *client, const char *category)
+{
+       struct category_subscribe_item *item;
+
+       item = malloc(sizeof(*item));
+       if (!item) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
+       }
+
+       item->category = strdup(category);
+       if (!item->category) {
+               ErrPrint("Heap: %s\n", strerror(errno));
+               DbgFree(item);
+               return DBOX_STATUS_ERROR_OUT_OF_MEMORY;
+       }
+
+       client->category_subscribe_list = eina_list_append(client->category_subscribe_list, item);
+       return DBOX_STATUS_ERROR_NONE;
+}
+
+HAPI int client_unsubscribe_category(struct client_node *client, const char *category)
+{
+       struct category_subscribe_item *item;
+       Eina_List *l;
+       Eina_List *n;
+
+       EINA_LIST_FOREACH_SAFE(client->category_subscribe_list, l, n, item) {
+               if (!strcasecmp(category, item->category)) {
+                       client->category_subscribe_list = eina_list_remove(client->category_subscribe_list, item);
+                       DbgFree(item->category);
+                       DbgFree(item);
+                       return DBOX_STATUS_ERROR_NONE;
+               }
+       }
+
+       return DBOX_STATUS_ERROR_NOT_EXIST;
+}
+
+HAPI int client_is_subscribed_by_category(struct client_node *client, const char *category)
+{
+       struct category_subscribe_item *item;
+       Eina_List *l;
+
+       EINA_LIST_FOREACH(client->category_subscribe_list, l, item) {
+               if (!strcasecmp(item->category, category)) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 HAPI int client_subscribe(struct client_node *client, const char *cluster, const char *category)
 {
        struct subscribe_item *item;
index 95efff3..408fb5a 100644 (file)
@@ -6288,7 +6288,7 @@ out:
        return NULL;
 }
 
-static struct packet *client_subscribe_category(pid_t pid, int handle, const struct packet *packet)
+static struct packet *client_subscribed_category(pid_t pid, int handle, const struct packet *packet)
 {
        struct client_node *client;
        const char *category;
@@ -6320,13 +6320,16 @@ static struct packet *client_subscribe_category(pid_t pid, int handle, const str
         * 2. Send created events to the client.
         * 3. Add this client to "client_only_view_list"
         */
+       if (client_subscribe_category(client, category) == DBOX_STATUS_ERROR_NONE) {
+               package_alter_instances_to_client(client, ALTER_CREATE);
+       }
 
 out:
        /*! \note No reply packet */
        return NULL;
 }
 
-static struct packet *client_unsubscribe_category(pid_t pid, int handle, const struct packet *packet)
+static struct packet *client_unsubscribed_category(pid_t pid, int handle, const struct packet *packet)
 {
        struct client_node *client;
        const char *category;
@@ -6354,17 +6357,20 @@ static struct packet *client_unsubscribe_category(pid_t pid, int handle, const s
 
        /*!
         * \TODO
+        * 0. Is this client subscribed to given "category"?
         * 1. Get a list of created dynamicbox instances
         * 2. and then send destroyed event to this client.
         * 3. Remove this client from the "client_only_view_list"
         */
+       if (client_unsubscribe_category(client, category) == DBOX_STATUS_ERROR_NONE) {
+               package_alter_instances_to_client(client, ALTER_DESTROY);
+       }
 
 out:
        /*! \note No reply packet */
        return NULL;
 }
 
-
 static struct packet *slave_hello(pid_t pid, int handle, const struct packet *packet) /* slave_name, ret */
 {
        struct slave_node *slave;
@@ -8708,11 +8714,11 @@ static struct method s_client_table[] = {
        },
        {
                .cmd = CMD_STR_SUBSCRIBE_CATEGORY,
-               .handler = client_subscribe_category,
+               .handler = client_subscribed_category,
        },
        {
                .cmd = CMD_STR_UNSUBSCRIBE_CATEGORY,
-               .handler = client_unsubscribe_category,
+               .handler = client_unsubscribed_category,
        },
 
        {