Revise the code for server_requests and tg_buddy_list 38/47938/1
authorSung-jae Park <nicesj.park@samsung.com>
Thu, 10 Sep 2015 07:42:53 +0000 (16:42 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Thu, 10 Sep 2015 07:42:53 +0000 (16:42 +0900)
Change-Id: I609ec044ccc330ac665e59acbb72130c9d96f34b

TelegramTizen/src/server_requests.c
TelegramTizen/src/service_client.c
TelegramTizen/src/telegramtizen.c
TelegramTizen/src/tg_buddy_list.c

index 5abeff5..8c71ce8 100644 (file)
@@ -145,8 +145,7 @@ void send_request_for_validation(service_client* service_client, const char* sms
 void send_request_for_marked_as_read(service_client* service_client, const int buddy_id, const int type_of_chat)
 {
        bundle *msg;
-       char type_of_chat_str[50];
-       char buddy_id_str[50];
+       char tmp[50];
        int result;
 
        if (!service_client) {
@@ -171,16 +170,16 @@ void send_request_for_marked_as_read(service_client* service_client, const int b
                return;
        }
 
-       snprintf(buddy_id_str, sizeof(buddy_id_str) - 1, "%d", buddy_id);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
 
-       if (bundle_add_str(msg, "buddy_id", buddy_id_str) != 0) {
+       if (bundle_add_str(msg, "buddy_id", tmp) != 0)  {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
        }
 
-       snprintf(type_of_chat_str, sizeof(type_of_chat_str) - 1, "%d", type_of_chat);
-       if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
+       snprintf(tmp, sizeof(tmp) - 1, "%d", type_of_chat);
+       if (bundle_add_str(msg, "type_of_chat", tmp) != 0)      {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -195,11 +194,8 @@ void send_request_for_marked_as_read(service_client* service_client, const int b
 
 void send_request_for_message_transport(service_client* service_client, const int buddy_id, const int message_id, const int msg_type, const char* data, const int type_of_chat)
 {
-       char buddy_id_str[50];
+       char tmp[50];
        bundle *msg;
-       char message_id_str[50];
-       char msg_type_str[10];
-       char type_of_chat_str[50];
        int result;
 
        if (!service_client || !data) {
@@ -224,25 +220,25 @@ void send_request_for_message_transport(service_client* service_client, const in
                return;
        }
 
-       snprintf(buddy_id_str, sizeof(buddy_id_str), "%d", buddy_id);
+       snprintf(tmp, sizeof(tmp), "%d", buddy_id);
 
-       if (bundle_add_str(msg, "buddy_id", buddy_id_str) != 0) {
+       if (bundle_add_str(msg, "buddy_id", tmp) != 0)  {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
        }
 
-       snprintf(message_id_str, sizeof(message_id_str) - 1, "%d", message_id);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", message_id);
 
-       if (bundle_add_str(msg, "message_id", message_id_str) != 0)     {
+       if (bundle_add_str(msg, "message_id", tmp) != 0)        {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
        }
 
-       snprintf(msg_type_str, sizeof(msg_type_str) - 1, "%d", msg_type);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", msg_type);
 
-       if (bundle_add_str(msg, "message_type", msg_type_str) != 0)     {
+       if (bundle_add_str(msg, "message_type", tmp) != 0)      {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -255,9 +251,9 @@ void send_request_for_message_transport(service_client* service_client, const in
        }
 
 
-       snprintf(type_of_chat_str, sizeof(type_of_chat_str), "%d", type_of_chat);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", type_of_chat);
 
-       if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
+       if (bundle_add_str(msg, "type_of_chat", tmp) != 0)      {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -273,11 +269,7 @@ void send_request_for_message_transport(service_client* service_client, const in
 void send_request_for_media_transport(service_client* service_client, const int buddy_id, const int message_id, const int media_id,  const int msg_type, const char* file_path, const int type_of_chat)
 {
        bundle *msg;
-       char buddy_id_str[50];
-       char message_id_str[50];
-       char media_id_str[50];
-       char msg_type_str[10];
-       char type_of_chat_str[50];
+       char tmp[50];
        int result;
 
        if (!service_client || !file_path) {
@@ -302,32 +294,32 @@ void send_request_for_media_transport(service_client* service_client, const int
                return;
        }
 
-       snprintf(buddy_id_str, sizeof(buddy_id_str) - 1, "%d", buddy_id);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
 
-       if (bundle_add_str(msg, "buddy_id", buddy_id_str) != 0) {
+       if (bundle_add_str(msg, "buddy_id", tmp) != 0)  {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
        }
 
-       snprintf(message_id_str, sizeof(message_id_str) - 1, "%d", message_id);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", message_id);
 
-       if (bundle_add_str(msg, "message_id", message_id_str) != 0)     {
+       if (bundle_add_str(msg, "message_id", tmp) != 0)        {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
        }
 
-       snprintf(media_id_str, sizeof(media_id_str) - 1, "%d", media_id);
-       if (bundle_add_str(msg, "media_id", media_id_str) != 0) {
+       snprintf(tmp, sizeof(tmp) - 1, "%d", media_id);
+       if (bundle_add_str(msg, "media_id", tmp) != 0)  {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
        }
 
-       sprintf(msg_type_str, "%d", msg_type);
+       sprintf(tmp, "%d", msg_type);
 
-       if (bundle_add_str(msg, "message_type", msg_type_str) != 0)     {
+       if (bundle_add_str(msg, "message_type", tmp) != 0)      {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -339,9 +331,9 @@ void send_request_for_media_transport(service_client* service_client, const int
                return;
        }
 
-       snprintf(type_of_chat_str, sizeof(type_of_chat_str) - 1, "%d", type_of_chat);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", type_of_chat);
 
-       if (bundle_add_str(msg, "type_of_chat", type_of_chat_str) != 0) {
+       if (bundle_add_str(msg, "type_of_chat", tmp) != 0)      {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -358,8 +350,7 @@ void send_request_for_media_transport(service_client* service_client, const int
 void send_request_for_image_downloading(service_client* service_client, const int buddy_id, const long long  media_id)
 {
        bundle *msg;
-       char buddy_id_str[50];
-       char media_id_str[50];
+       char tmp[50];
        int result;
 
        if (!service_client) {
@@ -384,16 +375,16 @@ void send_request_for_image_downloading(service_client* service_client, const in
                return;
        }
 
-       snprintf(buddy_id_str, sizeof(buddy_id_str) - 1, "%d", buddy_id);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", buddy_id);
 
-       if (bundle_add_str(msg, "buddy_id", buddy_id_str) != 0) {
+       if (bundle_add_str(msg, "buddy_id", tmp) != 0)  {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
        }
 
 
-       snprintf(media_id_str, sizeof(media_id_str) - 1, "%lld", media_id);
-       if (bundle_add_str(msg, "media_id", media_id_str) != 0) {
+       snprintf(tmp, sizeof(tmp) - 1, "%lld", media_id);
+       if (bundle_add_str(msg, "media_id", tmp) != 0)  {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
        }
@@ -409,10 +400,7 @@ void send_contacts_list_to_server(service_client* service_client, Eina_List* con
 {
        bundle *msg;
        int count;
-       char count_str[50];
-       char first_name_key[20];
-       char last_name_key[20];
-       char phone_number_key[20];
+       char tmp[50];
        char *first_name;
        char *last_name;
        char *phone_number;
@@ -443,10 +431,9 @@ void send_contacts_list_to_server(service_client* service_client, Eina_List* con
        }
 
        count = eina_list_count(contacts_list);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", count);
 
-       snprintf(count_str, sizeof(count_str) - 1, "%d", count);
-
-       if (bundle_add_str(msg, "count", count_str) != 0) {
+       if (bundle_add_str(msg, "count", tmp) != 0) {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -475,23 +462,22 @@ void send_contacts_list_to_server(service_client* service_client, Eina_List* con
                        last_name = "";
                }
 
-               snprintf(first_name_key, sizeof(first_name_key) - 1, "first_name_%d", i);
-               snprintf(last_name_key, sizeof(last_name_key) - 1, "last_name_%d", i);
-               snprintf(phone_number_key, sizeof(phone_number_key) - 1, "phone_number_%d", i);
-
-               if (bundle_add_str(msg, first_name_key, first_name) != 0) {
+               snprintf(tmp, sizeof(tmp) - 1, "first_name_%d", i);
+               if (bundle_add_str(msg, tmp, first_name) != 0) {
                        ERR("Failed to add data by key to bundle");
                        bundle_free(msg);
                        return;
                }
 
-               if (bundle_add_str(msg, last_name_key, last_name) != 0) {
+               snprintf(tmp, sizeof(tmp) - 1, "last_name_%d", i);
+               if (bundle_add_str(msg, tmp, last_name) != 0) {
                        ERR("Failed to add data by key to bundle");
                        bundle_free(msg);
                        return;
                }
 
-               if (bundle_add_str(msg, phone_number_key, phone_number) != 0) {
+               snprintf(tmp, sizeof(tmp) - 1, "phone_number_%d", i);
+               if (bundle_add_str(msg, tmp, phone_number) != 0) {
                        ERR("Failed to add data by key to bundle");
                        bundle_free(msg);
                        return;
@@ -515,12 +501,11 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_
 {
        bundle *msg;
        int count;
-       char count_str[50];
+       char tmp[50];
        user_data_with_pic_s *item;
        user_data_s *contact_data;
        Eina_List *l;
        int i;
-       char buddy_id_str[50];
        char buddy_id_key[20];
        int result;
 
@@ -547,9 +532,9 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_
        }
 
        count = eina_list_count(buddy_list);
-       snprintf(count_str, sizeof(count_str) - 1, "%d", count);
+       snprintf(tmp, sizeof(tmp) - 1, "%d", count);
 
-       if (bundle_add_str(msg, "count", count_str) != 0) {
+       if (bundle_add_str(msg, "count", tmp) != 0) {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
                return;
@@ -563,10 +548,10 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_
                        continue;
                }
 
-               snprintf(buddy_id_str, sizeof(buddy_id_str) - 1, "%d", contact_data->user_id.id);
+               snprintf(tmp, sizeof(tmp) - 1, "%d", contact_data->user_id.id);
                snprintf(buddy_id_key, sizeof(buddy_id_key) - 1, "buddy_id_%d", i);
 
-               if (bundle_add_str(msg, buddy_id_key, buddy_id_str) != 0) {
+               if (bundle_add_str(msg, buddy_id_key, tmp) != 0) {
                        ERR("Failed to add data by key to bundle");
                        bundle_free(msg);
                        return;
@@ -575,7 +560,6 @@ void send_group_creation_request_to_server(service_client* service_client, Eina_
                i++;
        }
 
-
        if (bundle_add_str(msg, "group_name", group_name) != 0) {
                ERR("Failed to add data by key to bundle");
                bundle_free(msg);
index 9d13b5c..141524a 100644 (file)
@@ -9,8 +9,7 @@
 #include <stdbool.h>
 #include <message_port.h>
 
-struct _service_client
-{
+struct _service_client {
        int local_port_id;
        char *remote_port_name;
        char *remote_app_name;
@@ -52,8 +51,7 @@ int service_client_register_port(service_client *service_cl, const char *const p
        RETVM_IF(!port_name, result, "Message port name is NULL");
 
        int temp_id = message_port_register_local_port(port_name, _on_message_received_cb, service_cl);
-       if (temp_id < 0)
-       {
+       if (temp_id < 0) {
                _service_client_convert_msg_port_result(temp_id);
                ERR("Failed to register local message port");
                service_cl->local_port_id = 0;
@@ -110,30 +108,26 @@ int _service_client_set_remote_data(service_client *service_cl,
        char *temp_rem_app_name = NULL;
        char *temp_rem_port_name = NULL;
 
-       if (!service_cl->remote_app_name && rem_app_name)
-       {
+       if (!service_cl->remote_app_name && rem_app_name) {
                temp_rem_app_name = strdup(rem_app_name);
                RETVM_IF(!temp_rem_app_name, SVC_RES_FAIL,
                                "Failed to set remote application name. Strdup failed");
        }
 
-       if (!service_cl->remote_port_name && rem_port_name)
-       {
+       if (!service_cl->remote_port_name && rem_port_name) {
                temp_rem_port_name = strdup(rem_port_name);
-               if (!temp_rem_port_name)
-               {
+               if (!temp_rem_port_name) {
                        ERR("Failed to set remote port name. Strdup failed");
                        free(temp_rem_app_name);
                        return SVC_RES_FAIL;
                }
        }
 
-       if (temp_rem_app_name)
-       {
+       if (temp_rem_app_name) {
                service_cl->remote_app_name = temp_rem_app_name;
        }
-       if (temp_rem_port_name)
-       {
+
+       if (temp_rem_port_name){
                service_cl->remote_port_name = temp_rem_port_name;
        }
 
@@ -186,13 +180,10 @@ static void _on_message_received_cb(int port_id,
        int res = _service_client_set_remote_data(service_cl, rem_app_name, rem_port_name);
        RETM_IF(res != SVC_RES_OK ,"Failed to set remote data to message port");
 
-       if (service_cl->cb_func)
-       {
+       if (service_cl->cb_func) {
                res = service_cl->cb_func(service_cl->cb_data, rec_msg);
                RETM_IF(res != SVC_RES_OK ,"Message port callback function failed");
-       }
-       else
-       {
+       } else {
                DBG("Message port callback function not set");
        }
 }
index 473b567..5624290 100644 (file)
@@ -1480,6 +1480,7 @@ app_create(void *data)
        ad->loaded_msg_list = NULL;
        create_base_gui(ad);
        init_service(ad);
+
        return true;
 }
 
index 5433bf5..6a4cc59 100644 (file)
@@ -337,7 +337,7 @@ static void on_buddy_clicked(void *data, Evas_Object *obj, void *event_info)
        Elm_Object_Item *it = event_info;
        elm_genlist_item_selected_set(it, EINA_FALSE);
 
-       int item_id = (int) data;
+       int item_id = (int)data;
        appdata_s* ad = evas_object_data_get(obj, "app_data");
 
        peer_with_pic_s *sel_item = eina_list_nth(ad->peer_list, item_id);
@@ -356,13 +356,19 @@ void on_search_clicked(void *data, Evas_Object *obj, void *event_info)
 void left_panel_button_clicked_cb(void *data, Evas_Object * obj, void *event_info)
 {
        appdata_s *ad = data;
-       if (!elm_object_disabled_get(ad->panel)) elm_panel_toggle(ad->panel);
+
+       if (!elm_object_disabled_get(ad->panel)) {
+               elm_panel_toggle(ad->panel);
+       }
 }
 
 void buddylist_naviframe_more_cb(void *data, Evas_Object *obj, void *event_info)
 {
        appdata_s *ad = data;
-       if (!elm_object_disabled_get(ad->panel)) elm_panel_toggle(ad->panel);
+
+       if (!elm_object_disabled_get(ad->panel)) {
+               elm_panel_toggle(ad->panel);
+       }
 }
 
 void refresh_buddy_list(void *data)
@@ -370,6 +376,16 @@ void refresh_buddy_list(void *data)
        appdata_s* ad = data;
        Evas_Object *buddy_list = evas_object_data_get(ad->nf, "buddy_list");
        if (buddy_list) {
+               int i = 0;
+               int size;
+               Eina_List *l;
+               static Elm_Genlist_Item_Class itc = {
+                       .item_style = "double_label",
+                       .func.text_get = on_list_text_get_cb,
+                       .func.content_get = on_list_content_get_cb,
+                       .func.state_get = NULL,
+                       .func.del = NULL,
+               };
 
                elm_genlist_clear(buddy_list);
 
@@ -377,15 +393,7 @@ void refresh_buddy_list(void *data)
                load_group_chat_data(ad);
                load_peer_data(ad);
 
-               int i = 0;
-               static Elm_Genlist_Item_Class itc;
-               itc.item_style = "double_label";
-               itc.func.text_get = on_list_text_get_cb;
-               itc.func.content_get = on_list_content_get_cb;
-               itc.func.state_get = NULL;
-               itc.func.del = NULL;
-
-               int size = eina_list_count(ad->peer_list);
+               size = eina_list_count(ad->peer_list);
                if(size > 0) {
                        for (i = 0; i < size; i++) {
                                elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_clicked, (void*) i);
@@ -395,49 +403,44 @@ void refresh_buddy_list(void *data)
                        elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_clicked, (void*) i);
                }
                evas_object_show(buddy_list);
-
        }
 }
 
 void launch_buddy_list_cb(void *data)
 {
+       int i;
+       Evas_Object *buddy_list;
        appdata_s* ad = data;
-
        Evas_Object *nf = ad->nf;
        Elm_Object_Item* detail_nav_item = NULL;
+       int size;
+       static Elm_Genlist_Item_Class itc = {
+               .item_style = "double_label",
+               .func.text_get = on_list_text_get_cb,
+               .func.content_get = on_list_content_get_cb,
+               .func.state_get = NULL,
+               .func.del = NULL,
+       };
 
        ad->current_app_state = TG_BUDDY_LIST_STATE;
        elm_layout_theme_set(ad->layout, "layout", "drawer", "panel");
        create_main_view(ad);
 
-       int i;
-       static Elm_Genlist_Item_Class itc;
-       Evas_Object *buddy_list = NULL;
-
        buddy_list = elm_genlist_add(nf);
        elm_list_mode_set(buddy_list, ELM_LIST_COMPRESS);
        elm_genlist_mode_set(buddy_list, ELM_LIST_COMPRESS);
        evas_object_size_hint_weight_set(buddy_list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(buddy_list, EVAS_HINT_FILL, EVAS_HINT_FILL);
-
-
        evas_object_data_set(buddy_list, "app_data", ad);
 
-       itc.item_style = "double_label";
-       itc.func.text_get = on_list_text_get_cb;
-       itc.func.content_get = on_list_content_get_cb;
-       itc.func.state_get = NULL;
-       itc.func.del = NULL;
-
-       int size = eina_list_count(ad->peer_list);
-
+       size = eina_list_count(ad->peer_list);
        if(size > 0) {
                for (i = 0; i < size; i++) {
-                       elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_clicked, (void*) i);
+                       elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_clicked, (void *)i);
                }
        } else {
                i = 1;
-               elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_clicked, (void*) i);
+               elm_genlist_item_append(buddy_list, &itc, (void *) i, NULL, ELM_GENLIST_ITEM_NONE, on_buddy_clicked, (void *)i);
        }
 
        evas_object_show(buddy_list);
@@ -465,5 +468,4 @@ void launch_buddy_list_cb(void *data)
        evas_object_data_set(nf, "buddy_list", buddy_list);
 
        eext_object_event_callback_add(nf, EEXT_CALLBACK_MORE, buddylist_naviframe_more_cb, ad);
-
 }