[TBT][tizen_3.0_mobile][Push module updated, Delay push, Active push & Template push... 34/97934/1
authornazib.ullah <nazib.ullah@samsung.com>
Tue, 15 Nov 2016 10:53:33 +0000 (16:53 +0600)
committernazib.ullah <nazib.ullah@samsung.com>
Tue, 15 Nov 2016 10:56:15 +0000 (16:56 +0600)
Change-Id: Iafc3b5175c7f665aa375722b32b1ba5d493011ef

12 files changed:
release/binary-aarch64/org.tizen.tbtcoreapp-1.0.0-aarch64.tpk
release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk
release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk
release/binary-x86_64/org.tizen.tbtcoreapp-1.0.0-x86_64.tpk
tbtcoreapp/inc/utils/config.h
tbtcoreapp/inc/utils/ui-utils.h
tbtcoreapp/res/edje/3.0/mobile/push_service.edc
tbtcoreapp/src/main-app.c
tbtcoreapp/src/model/tbt-list.c
tbtcoreapp/src/view/tbt-bluetoothle-view.c
tbtcoreapp/src/view/tbt-push-view.c
tbtcoreapp/src/view/tbt-stt-view.c

index d910a1942367044c2b5b9efaecb6affc963ae811..cb4d35ed6bce7177c6fa9c641553552051d6b5d3 100644 (file)
Binary files a/release/binary-aarch64/org.tizen.tbtcoreapp-1.0.0-aarch64.tpk and b/release/binary-aarch64/org.tizen.tbtcoreapp-1.0.0-aarch64.tpk differ
index 222b27bbdec39e5d472865ef63e41017f4540861..ec2353a2d062810f345deec9cdb7f277dfdb5cac 100644 (file)
Binary files a/release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk and b/release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk differ
index cc76e97b8c7baa7e43e198412c4b45fbe2d8c608..3c46b34133d543464b491e85e5f6fc098b38a4fe 100644 (file)
Binary files a/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk and b/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk differ
index 339e415e8df68a266fb818d4fe192e861aa2f2c6..0b6d517bf9dd9447db20da16dfc190af74bb8fd0 100644 (file)
Binary files a/release/binary-x86_64/org.tizen.tbtcoreapp-1.0.0-x86_64.tpk and b/release/binary-x86_64/org.tizen.tbtcoreapp-1.0.0-x86_64.tpk differ
index 85cd25d752a93f4d19a3df87d5a14c6821a41ebc..21a0972aca8da26026baea2627fecdecf016e605 100644 (file)
@@ -332,10 +332,10 @@ static inline char *format_string(const char *format, ...)
 {
        va_list arg;
        char* chTemp;
-       chTemp= (char*)malloc(1024 * sizeof(char));
+       chTemp= (char*)malloc(2048 * sizeof(char));
        RETVM_IF(!chTemp, NULL,"malloc failed.");
        va_start(arg,format);
-       vsnprintf(chTemp,1024,format,arg);
+       vsnprintf(chTemp,2048,format,arg);
        va_end(arg);
        return chTemp;
 }
index 266b26e022f78636e30f2e7ebfea7fa34ddbe599..fce5fbef10142e90cf466f9201b7662ca89337f4 100644 (file)
@@ -89,6 +89,7 @@ Evas_Object *ui_utils_icon_create_new(Evas_Object *parent, const char *icon_name
 
 void (*_tbt_pause_resume_cb) (bool) ;
 void (*_tbt_app_terminate_cb) () ;
+void (*_tbt_app_resume_cb) (void*);
 /**
 * @function            DoesFeatureExixts
 * @since_tizen 2.3
index 78a00092361226034c12a4ca097e4199a6cd0a48..1df0e371f4824d7b31049033159edf562090d681 100644 (file)
 
 collections
 {
-    base_scale: 1.8;
-    group
-    {
-        name: "push_service";
-        parts{
-            part{
-                name: "push_text";
-                type: SWALLOW;
-                description{
-                    state: "default" 0.0;
-                    align: 0.0 0.0;
-                    visible: 1;
-                    rel1 {relative: 0.0 0.1; }
-                    rel2 {relative: 1.0 TEXT_HEIGHT; }
-                }
+   base_scale: 1.8;
+   group
+   {
+      name: "push_service";
+      parts{
+         part{
+            name: "push_text";
+            type: SWALLOW;
+            description{
+               state: "default" 0.0;
+               align: 0.0 0.0;
+               visible: 1;
+               rel1 {relative: 0.0 0.1; }
+               rel2 {relative: 1.0 TEXT_HEIGHT; }
             }
+         }
 
-            part{
-                name: "text_box_first";
-                type: SWALLOW;
-                description{
-                    state: "default" 0.0;
-                    align: 0.0 0.0;
-                    visible: 1;
-                    rel1{
-                        relative: 0.0 1.0;
-                        to_y: "push_text";
-                    }
-                    rel2{
-                        relative:1.0 TEXT_HEIGHT*2;
-                    }
-                }
-            }   
-            
-             part{
-                name: "text_box_second";
-                type: SWALLOW;
-                description{
-                    state: "default" 0.0;
-                    align: 0.0 0.0;
-                    visible: 1;
-                    rel1{
-                        relative: 0.0 1.0;
-                        to_y: "text_box_first";
-                    }
-                    rel2{
-                        relative:1.0 TEXT_HEIGHT*3;
-                    }
-                }
-            }   
-            
-             part { 
-                               name: "controlr_part";
-                type: SWALLOW;
-                description {
-                    state: "default" 0.0;
-                    rel1 {  
-                                                  relative: 0.0 0.9;
-                                       }
-                    rel2 { 
-                                                  relative: 1.0 1.0 ; }
-                    visible: 1;
-                }
+         part{
+            name: "text_box_first";
+            type: SWALLOW;
+            description{
+               state: "default" 0.0;
+               align: 0.0 0.0;
+               visible: 1;
+               rel1{
+                  relative: 0.0 1.0;
+                  to_y: "push_text";
+               }
+               rel2{
+                  relative:1.0 TEXT_HEIGHT*2;
+               }
             }
-             
-          
-    }
-}
+         }   
+
+         part{
+            name: "push_container";
+            type: SWALLOW;
+            description{
+               state: "default" 0.0;
+               align: 0.0 0.0;
+               visible: 1;
+               rel1{
+                  relative: 0.0 1.0;
+                  to_y: "text_box_first";
+               }
+               rel2{
+                  relative:1.0 0.85;
+               }
+            }
+         }   
+
+         part { 
+            name: "controlr_part";
+            type: SWALLOW;
+            description {
+               state: "default" 0.0;
+               rel1 {  
+                  relative: 0.0 0.85;
+               }
+               rel2 { 
+                  relative: 1.0 1.0 ; }
+               visible: 1;
+            }
+         }
+
+
+      }
+   }
 }
index 30c05cfa1559e6a4c200f6422a308bd1f26ed76f..c5ca72952637673cf4f663db7f485518dc32a99e 100644 (file)
@@ -142,7 +142,7 @@ int app_run(app_data *app, int argc, char **argv)
 {
        RETVM_IF(!app, -1, "app is NULL");
        _tbt_pause_resume_cb = NULL;
-
+       _tbt_app_resume_cb = NULL;
        _tbt_app_terminate_cb = NULL;
        app_error_e result;
        ui_app_lifecycle_callback_s cbs =
@@ -212,6 +212,10 @@ static void _app_pause_cb(void *user_data)
 static void _app_resume_cb(void *user_data)
 {
        DBG("INside main resume cb");
+       if(NULL != _tbt_app_resume_cb)
+    {
+               (*_tbt_app_resume_cb)(user_data);
+    }
     if(NULL != _tbt_pause_resume_cb)
     {
        (*_tbt_pause_resume_cb)(true);
index 45498a58f161fd2ef2ff1a169677320be6cafba6..05f91f5476a0a387ff3f41d8307d35f135b1e1ad 100644 (file)
@@ -1740,13 +1740,16 @@ static tbt_info tbtapps[] =
                        .apptype = TBT_APP_PUSH_SERVICE,
                        .icon_name = "dummy",
                        .info = "1.     Press <b>Start</b> button to start the push service and a successful response will be displayed.<br/>"
-                                       "2.     Then long press the Home button and clear the application instance.<br/>"
-                                       "3.     After a few moments, there will a notification.<br/>"
-                                       "4.     Click on the notification and the message will be shown.<br/>"
-                                       "5.     Secondly, Press button <b>Start</b> to start the push service.<br/>"
-                                       "6.     Press button <b>Message</b>.<br/>"
-                                       "7.     After a few moments a message will be shown.<br/>"
-                                       "8.     Press button Disconnect to <b>Disconnect</b> Push Service",
+                                       "2. Press <b>Normal</b> button, a Normal push message will be shown in list.<br/>"
+                                       "3. Press <b>Delay</b> button and then press </b>Normal</b> button a Normal push message followed by a delay push message will be shown in list.<br/>"
+                                       "4. Press <b>Active</b> button and a Active push message will be shown.<br/>"
+                                       "5. Press <b>Template</b> button and a Template push message will be shown in list.<br/>"
+                                       "6. Press <b>Normal</b> button and immediately press home button to move app to pause state, a Normal push notification will be shown in Notification panel.<br/>"
+                                       "7. Press <b>Active</b> button and immediately press home button to move app to pause state, a Active push notification will be shown in Notification panel.<br/>"
+                                       "8. Press <b>Template</b> button and immediately press home button to move app to pause state, a push notification with custom icon and sound will be shown in Notification panel.<br/>"
+                                       "9. When new push notification will come a increasing badge number will be shown on app icon.<br/>"
+                                       "10. If app is open and pressed <b>Message</b> button will show the message it is not read.<br/>"
+                                       "11. Press button Disconnect to <b>Disconnect</b> Push Service.",
                        .result = 0,
                        .required_features_count = 1,
                        .features_required = {FEATURE_NETWORK_PUSH}
index ea427ab46302176569c6fc6a5d17564f4e05df0b..3a2ad837ad386edc83a561d329ff1a025c74798e 100644 (file)
@@ -1272,8 +1272,8 @@ static void _bt_gatt_client_read_request_completed_cb(int result, bt_gatt_h requ
        RETM_IF(NULL == request_handle,"request_handle is NULL");
        result = bt_gatt_get_value(request_handle, &value, &value_length);
        RETM_IF(result != BT_ERROR_NONE, "bt_gatt_get_value failed --> error: %s", get_bluetooth_error(result));
-
-       for(int i=0; i<value_length; i++)
+       int i;
+       for(i=0; i<value_length; i++)
        {
                DBG("value : %d", value[i]);
        }
index 2e9eb523be8970047e1bd764c8dee91acdd1205b..8418d7276091b73c57b2a6dcdf58435a7bd50fa2 100644 (file)
@@ -34,6 +34,7 @@
 #include <net_connection.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
+#include <notification.h>
 
 #include "utils/logger.h"
 #include "utils/config.h"
 #include "view/tbt-common-view.h"
 
 
+#define BUNDLE_KEY_MSG "msg"
+#define BUNDLE_KEY_TIME "time"
+#define PUSH_MESSAGE_SIZE 4096
+
 typedef enum {
        CONNECTED_STATE = 0,
        DISCONNECTED_STATE,
        DISABLED_STATE
 } _push_btn_state;
 
+typedef enum{
+       NORMAL_PUSH = 0,
+       DELAY_PUSH,
+       BACKGROUND_LAUNCH_PUSH,
+       ACTIVE_NOTIFICATION_PUSH,
+       TEMPLATE_PUSH,
+
+       ALL_PUSH_TYPES
+}_push_types_e;
+
 struct _push_view
 {
        common_view* view;
@@ -66,10 +81,26 @@ struct _push_view
        char* push_app_id_text;
        char* push_app_secret_text;
 
+       char* push_test_appId;
+       char* push_test_appSecret;
+       char* push_test_regId;
+
        CURL *curl_handle;
        _push_btn_state push_btn_state;
+       _push_types_e push_type;
+
+       Evas_Object* normal_push_btn;
+       Evas_Object* delay_push_btn;
+       Evas_Object* background_push_btn;
+       Evas_Object* active_noti_push_btn;
+       Evas_Object* template_push_btn;
+       bool is_registered;
+       bundle *msg_bundle;
+       char* text;
 };
-
+/* GList for push messages */
+static GList *message_list = NULL;
+static GList *time_list = NULL;
 
 #define CONNECTED_STATE  0
 #define DISCONNECTED_STATE 1
@@ -77,7 +108,7 @@ struct _push_view
 
 static push_service_connection_h connection = NULL;
 bool bIsNotiArrived;
-
+static void on_app_resume_cb(void *user_data);
 static void _app_destroy_cb(void* this);
 static Evas_Object *add_control_layout(push_view *this, Evas_Object *parent);
 static void _control_button_push_service_start_pressed_cb(void *pData, Evas_Object *pObj, void *pEventInfo);
@@ -94,6 +125,17 @@ static size_t _curl_response_cb(char *ptr, size_t size, size_t nmemb, void *user
 static void push_service_update_btn_state(void* user_data);
 static char* push_service_get_error(int error_code);
 static char* get_xml_element_value (xmlDocPtr doc, xmlNodePtr cur, const char* tag);
+static void _button_normal_push_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static void _button_delay_push_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static void _button_background_push_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static void _button_active_noti_push_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static void _button_template_push_pressed_cb(void *data, Evas_Object *obj, void *event_info);
+static void create_notification_template();
+static void parse_notification_data(push_service_notification_h noti, void *user_data);
+static void handle_push_message(const char *data, const char *msg, long long int time_stamp, void *user_data);
+static void deliver_message(void* user_data);
+static void display_message(void* user_data);
+static void create_list_view(void* user_data);
 
 /**
  * @function           push_view_add
@@ -107,12 +149,14 @@ push_view *push_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item
        RETVM_IF(NULL == navi, NULL, "navi is null");
 
        push_view *this = NULL;
+
        this = calloc(1, sizeof(push_view));
        RETVM_IF(!this, NULL, "calloc failed");
-
        this->view = calloc(1, sizeof(common_view));
        RETVM_IF(!this->view, NULL, "calloc failed");
 
+       _tbt_app_resume_cb = on_app_resume_cb;
+
        this->push_btn_state = DISCONNECTED_STATE;
        push_service_update_btn_state(this);
 
@@ -142,6 +186,11 @@ push_view *push_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item
        this->push_app_id_text =  get_xml_element_value(doc, root_element, "appID");
        this->push_app_secret_text = get_xml_element_value(doc, root_element, "appSecret");
 
+//     this->push_test_appId =  get_xml_element_value(doc, root_element, "TestappID");
+//     this->push_test_appSecret =  get_xml_element_value(doc, root_element, "TestappSecret");
+//     this->push_test_regId =  get_xml_element_value(doc, root_element, "TestappRegID");
+
+
     DBG("appID : %s\n",this->push_app_id_text);
     DBG("appSecret : %s\n",this->push_app_secret_text);
 
@@ -154,6 +203,8 @@ push_view *push_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item
        Evas_Object *control = add_control_layout(this, this->view->layout);
        elm_object_part_content_set(this->view->layout, "controlr_part", control);
 
+       create_notification_template();
+
        if(tbt_info->is_push_from_outside == true)
        {
                //Get Push from outside
@@ -170,6 +221,12 @@ push_view *push_view_add(Evas_Object *navi, tbt_info *tbt_info, Elm_Object_Item
 
                tbt_info->is_push_from_outside = false;
        }
+       elm_object_disabled_set(this->active_noti_push_btn, true);
+       elm_object_disabled_set(this->delay_push_btn, true);
+       elm_object_disabled_set(this->message_btn, true);
+       elm_object_disabled_set(this->template_push_btn, true);
+       elm_object_disabled_set(this->normal_push_btn, true);
+       elm_object_disabled_set(this->disconnect_btn, true);
 
        return this;
 }
@@ -202,7 +259,22 @@ static Evas_Object *add_control_layout(push_view *this, Evas_Object *parent)
 
 
     this->disconnect_btn = ui_utils_push_button_add(this, table, "Disconnect", _control_button_push_service_disconnect_pressed_cb);
-    elm_table_pack(table, this->disconnect_btn, 2, 0, 1, 1);
+    elm_table_pack(table, this->disconnect_btn, 2, 0, 2, 1);
+
+    this->normal_push_btn = ui_utils_push_button_add(this, table, "Normal", _button_normal_push_pressed_cb);
+    elm_table_pack(table, this->normal_push_btn, 0, 1, 1, 1);
+
+    this->delay_push_btn = ui_utils_push_button_add(this, table, "Delay", _button_delay_push_pressed_cb);
+    elm_table_pack(table, this->delay_push_btn, 1, 1, 1, 1);
+
+    this->background_push_btn = ui_utils_push_button_add(this, table, "Background", _button_background_push_pressed_cb);
+//    elm_table_pack(table, this->background_push_btn, 2, 1, 1, 1);
+
+    this->active_noti_push_btn = ui_utils_push_button_add(this, table, "Active", _button_active_noti_push_pressed_cb);
+    elm_table_pack(table, this->active_noti_push_btn, 2, 1, 1, 1);
+
+    this->template_push_btn = ui_utils_push_button_add(this, table, "Template", _button_template_push_pressed_cb);
+    elm_table_pack(table, this->template_push_btn, 3, 1, 1, 1);
 
 
     return table;
@@ -237,6 +309,20 @@ static void _app_destroy_cb(void* this)
        SAFE_DELETE(view->view);
        SAFE_DELETE(view);
 }
+static void on_app_resume_cb(void* data)
+{
+       DBG("Inside push_app_resume_cb");
+
+       int result;
+
+       /*
+       * If connection with Push Service is succeeded,
+       * Push Receiver should request unread notification messages
+       * which are sent during disconnected state
+       */
+       result = push_service_request_unread_notification(connection);
+       RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_request_unread_notification :%s",push_service_get_error(result));
+}
 
 
 static char* get_xml_element_value (xmlDocPtr doc, xmlNodePtr cur, const char* tag)
@@ -256,6 +342,25 @@ static char* get_xml_element_value (xmlDocPtr doc, xmlNodePtr cur, const char* t
    return str;
 }
 
+static void create_notification_template()
+{
+
+
+       DBG("TEST %s", get_shared_resource_path("test.wav"));
+
+       notification_h n = NULL;
+       n = notification_create(NOTIFICATION_TYPE_NOTI);
+
+       notification_set_text(n, NOTIFICATION_TEXT_TYPE_TITLE, "template title", NULL, NOTIFICATION_TEXT_TYPE_NONE);
+       notification_set_text(n, NOTIFICATION_TEXT_TYPE_CONTENT, "template content", NULL, NOTIFICATION_TEXT_TYPE_NONE);
+       notification_set_sound(n, NOTIFICATION_SOUND_TYPE_USER_DATA, get_shared_resource_path("test.wav"));
+       notification_set_image(n, NOTIFICATION_IMAGE_TYPE_ICON, get_shared_resource_path("icon.png"));
+       notification_set_image(n, NOTIFICATION_IMAGE_TYPE_BACKGROUND, get_shared_resource_path("background.png"));
+       notification_save_as_template(n, "template_test");
+
+       notification_free(n);
+
+}
 
 /**
  * @function           _control_button_push_service_start_pressed_cb
@@ -344,6 +449,61 @@ static void _control_button_push_service_disconnect_pressed_cb(void *data, Evas_
 }
 
 
+static void _button_normal_push_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       DBG("_button_normal_push_pressed_cb");
+       push_view *this = NULL;
+       this = (push_view*)data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       this->push_type = NORMAL_PUSH;
+       send_push_data_to_server(this);
+}
+
+static void _button_delay_push_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       DBG("_button_delay_push_pressed_cb");
+       push_view *this = NULL;
+       this = (push_view*)data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       this->push_type = DELAY_PUSH;
+       send_push_data_to_server(this);
+}
+
+static void _button_background_push_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       DBG("_button_background_push_pressed_cb");
+       push_view *this = NULL;
+       this = (push_view*)data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       this->push_type = BACKGROUND_LAUNCH_PUSH;
+       send_push_data_to_server(this);
+}
+
+static void _button_active_noti_push_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       DBG("_button_active_noti_push_pressed_cb");
+       push_view *this = NULL;
+       this = (push_view*)data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       this->push_type = ACTIVE_NOTIFICATION_PUSH;
+       send_push_data_to_server(this);
+}
+
+static void _button_template_push_pressed_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       DBG("_button_template_push_pressed_cb");
+       push_view *this = NULL;
+       this = (push_view*)data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       this->push_type = TEMPLATE_PUSH;
+       send_push_data_to_server(this);
+}
+
 /**
  * @function           _state_changed_cb
  * @since_tizen                2.3
@@ -394,28 +554,286 @@ static void _notify_cb(push_service_notification_h noti, void *user_data)
        this = (push_view*)user_data;
        RETM_IF(NULL == this, "view is NULL");
 
+       parse_notification_data(noti, this);
+
+}
+
+
+static void parse_notification_data(push_service_notification_h noti, void *user_data)
+{
+       DBG("parse_notification_data");
+
+       push_view *this = NULL;
+       this = (push_view*)user_data;
+       RETM_IF(NULL == this, "view is NULL");
+
        int result;
-   char *data=NULL; // App data loaded on the notification
-   char *msg=NULL; // Noti message
-   long long int time_stamp; // Time when the noti is generated
+       char *data=NULL; // App data loaded on the notification
+       char *msg=NULL; // Noti message
+       long long int time_stamp; // Time when the noti is generated
+
+       result = push_service_get_notification_data(noti, &data);
+       RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_get_notification_data Failed %s", push_service_get_error(result));
+       RETM_IF(NULL == data, "data is NULL");
+
+       elm_object_text_set(this->push_label, data);
+
+       result = push_service_get_notification_message(noti, &msg);
+       DBG("push_service_get_notification_message Failed %s", push_service_get_error(result));
+       //RETM_IF(NULL == msg, "Message is NULL");
+
+       DBG("#### msg: %s", msg);
+
+       result = push_service_get_notification_time(noti, &time_stamp);
+       RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_get_notification_time Failed %s", push_service_get_error(result));
+
+       handle_push_message(data, msg, time_stamp, this);
+
+       SAFE_DELETE(data);
+       SAFE_DELETE(msg);
+}
+
+static char* get_value_from_message(char *text, char *key)
+{
+       /* Parsing arrival message or time */
+       /* dlog_print(DLOG_DEBUG, LOG_TAG, "message : [%s] / key : [%s]", text, key); */
+       /* dlog_print(DLOG_DEBUG, LOG_TAG, "time : [%s] / key : [%s]", text, key); */
+       if (!strcmp(text, "Delayed push"))
+               return text;
+
+       char *token = strtok(text, "=&");
+       if (!strncmp(token, key, sizeof(*key))) {
+               token = strtok(NULL, "=&");
+       } else {
+               while (token != strtok(NULL, "=&")) {
+                       token = strtok(NULL, "=&");
+                       if (!strcmp(token, key)) {
+                               token = strtok(NULL, "=&");
+                               break;
+                       }
+               }
+       }
+       DBG("token: %s", token);
+
+       return token;
+}
+
+static void handle_push_message(const char *data, const char *msg, long long int time_stamp, void *user_data)
+{
+       DBG("handle_push_message");
+       push_view *this = NULL;
+       this = (push_view*)user_data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       DBG("[Noti Data] push data : [%s]", data);
+       DBG("[Noti Data] time stamp : [%lld]", time_stamp);
+       if (!msg)
+       {
+               this->msg_bundle = NULL;
+               deliver_message(this);
+       }
+       else
+       {
+               /* Custom protocol parsing logic for sample */
+               DBG("[Noti Data] message : [%s]", msg);
+
+               /* Get action value and alertMessage value */
+               char *action = get_value_from_message(strdup(msg), "action");
+               char *alert_message = get_value_from_message(strdup(msg), "alertMessage");
+               DBG("------------- action: [%s] ---------------", action);
+               DBG("------------ alert_message: [%s] ------------", alert_message);
+
+               RETM_IF(NULL == action, "action is null");
+               RETM_IF(NULL == alert_message, "action is null");
+
+               /* Create arrival time & message */
+               char buf_msg[512];
+
+               sprintf(buf_msg, "Type : ");
+               strcat(buf_msg, action);
+               strcat(buf_msg, " / Message : ");
+               strcat(buf_msg, alert_message);
+
+               time_t timer = time(NULL);
+               struct tm *t;
+               t = localtime(&timer);
+               char buf_time[512];
+               sprintf(buf_time, "%d%02d%02d %02d:%02d:%02d", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
+
+               DBG("display_msg: [%s]", buf_msg);
+               DBG("display_time: [%s]", buf_time);
+
+               bundle *msg_bundle = bundle_create();
+               if (msg_bundle)
+               {
+                       /* Payload push message to bundle object */
+                       bundle_add_str(msg_bundle, BUNDLE_KEY_MSG, strdup(buf_msg));
+                       DBG("message [%s], key [%s]", buf_msg, BUNDLE_KEY_MSG);
+                       bundle_add_str(msg_bundle, BUNDLE_KEY_TIME, strdup(buf_time));
+                       DBG("time [%s], key [%s]", buf_time, BUNDLE_KEY_TIME);
+                       this->msg_bundle = msg_bundle;
+                       deliver_message(this);
+               }
+
+                       bundle_free(msg_bundle);
+       }
+       /* Custom protocol logic End */
+}
+static void save_message(const char *message)
+{
+       /* In this sample, just store to GList */
+       char *msg = NULL;
+
+       if (message) msg = strdup(message);
+       if (!msg) return;
+
+       /* This list will be appended at top of the list */
+       message_list = g_list_prepend(message_list, (gpointer)msg);
+}
+
+
+/*
+ * save_time() for storing time with its push messages
+ */
+static void save_time(const char *time)
+{
+       /* In this sample, just store to GList */
+       char *msg = NULL;
+
+       if (time) msg = strdup(time);
+       if (!msg) return;
+
+       /* This list will be appended at top of the list */
+       time_list = g_list_prepend(time_list, (gpointer)msg);
+}
+
+
+static void deliver_message(void* user_data)
+{
+       DBG("deliver_message() operates saving and showing push messages");
+       push_view *this = NULL;
+       this = (push_view*)user_data;
+       RETM_IF(NULL == this, "view is NULL");
+       bundle *msg_bundle = this->msg_bundle;
+
+       char *text = NULL;
+       if (msg_bundle)
+       {
+               /* Store push message */
+               int ret = bundle_get_str(msg_bundle, BUNDLE_KEY_MSG, &text);
+               if (!ret && text)
+               {
+                       DBG("Push on message port : [%s]", text);
+                       /* Save message if necessary */
+                       save_message(text);
+               }
+
+               /* Store verification time and display push message and time */
+               ret = bundle_get_str(msg_bundle, BUNDLE_KEY_TIME, &text);
+               if (!ret && text)
+               {
+                       DBG("Push on time port : [%s]", text);
+                       /* Save time if necessary */
+                       save_time(text);
+                       /* UI display function not for changed registration state but arrived push notification */
+               }
+       }
+       else
+       {
+               DBG("For Delayed push");
+               /* For delayed push */
+               text = strdup("Delayed push");
+               save_message(text);
+               save_time("This push notification is not sent immediately");
+               //////////////////////////////////////// consider non-action:backgroundLaunch
+       }
+       this->text = text;
+       display_message(this);
+}
 
-   result = push_service_get_notification_data(noti, &data);
-   RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_get_notification_data Failed %s", push_service_get_error(result));
-   RETM_IF(NULL == data, "data is NULL");
+static void display_message(void* user_data)
+{
 
-   elm_object_text_set(this->push_label, data);
+       push_view *this = NULL;
+       this = (push_view*)user_data;
+       RETM_IF(NULL == this, "view is NULL");
+       char* text = this->text;
+       DBG("[Push Message] %s", text);
 
-   result = push_service_get_notification_message(noti, &msg);
-   RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_get_notification_message Failed %s", push_service_get_error(result));
-   RETM_IF(NULL == msg, "Message is NULL");
 
+       /* Re-draw the list for verifying the arrival of push messages */
+       create_list_view(this);
 
-   result = push_service_get_notification_time(noti, &time_stamp);
-   RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_get_notification_time Failed %s", push_service_get_error(result));
+       //@TODO: work is paused here start again
+}
+/* item_data structure for generating genlist */
+typedef struct item_data {
+       Elm_Object_Item *item;
+       int index;
+} item_data_s;
+static char *
+_gl_push_text_get(void *data, Evas_Object *obj, const char *part)
+{
+       char msg_buf[PUSH_MESSAGE_SIZE];
+       char time_buf[PUSH_MESSAGE_SIZE];
+       item_data_s *id = (item_data_s *)data;
+       int index = id->index;
+       char *msg = NULL;
+
+       if (!strcmp("elm.text", part)) {
+               msg = (char *) g_list_nth_data(message_list, index);
+               snprintf(msg_buf, PUSH_MESSAGE_SIZE - 1, "%s", msg);
+               DBG("_gl_push_text_get(), message : [%s]", msg_buf);
+               return strdup(msg_buf);
+       }
 
-   SAFE_DELETE(data);
-   SAFE_DELETE(msg);
+       msg = (char *) g_list_nth_data(time_list, index);
+       snprintf(time_buf, PUSH_MESSAGE_SIZE - 1, "%s", msg);
+       DBG("_gl_push_text_get(), time : [%s]", time_buf);
+       return strdup(time_buf);
 }
+static void
+create_list_view(void* user_data)
+{
+       DBG("create_list_view");
+       push_view *this = NULL;
+       this = (push_view*)user_data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       Evas_Object *genlist = NULL;
+
+       /* Elm_Genlist_Item_Class for list */
+       Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
+
+       /* item_data for genlist */
+       item_data_s *id;
+       guint message_length = 0;
+
+
+
+       genlist = elm_genlist_add(this->view->layout);
+       elm_genlist_block_count_set(genlist, 14);
+       elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
+       elm_genlist_homogeneous_set(genlist, EINA_TRUE);
+       elm_object_part_content_set(this->view->layout, "push_container", genlist);
+
+       itc->item_style = "multiline";
+       itc->func.text_get = _gl_push_text_get;
+
+       /* Make list as much as the number of lines */
+       message_length = g_list_length(message_list);
+       int i = 0;
+       for (i = 0; i < message_length; i++) {
+               id = calloc(sizeof(item_data_s), 1);
+               id->index = i;
+               /* Append genlist item for list */
+               id->item = elm_genlist_item_append(genlist, itc, id, NULL, ELM_GENLIST_ITEM_NONE, NULL, this);
+       }
+       elm_genlist_item_class_free(itc);
+}
+
+
+
 
 
 /**
@@ -457,7 +875,15 @@ static void _on_state_registered(void *user_data)
        DBG("reg_id: %s", this->reg_id);
        RETM_IF(result != PUSH_SERVICE_ERROR_NONE, "push_service_get_registration_id Failed %s", push_service_get_error(result));
 
-       send_push_data_to_server(this);
+       this->is_registered = true;
+//     send_push_data_to_server(this);
+       elm_object_disabled_set(this->active_noti_push_btn, false);
+       elm_object_disabled_set(this->delay_push_btn, false);
+       elm_object_disabled_set(this->message_btn, false);
+       elm_object_disabled_set(this->template_push_btn, false);
+       elm_object_disabled_set(this->normal_push_btn, false);
+       elm_object_disabled_set(this->disconnect_btn, false);
+
 }
 
 
@@ -497,28 +923,70 @@ static void send_push_data_to_server(void* user_data)
        CURLcode curl_err;
        struct curl_slist *header_list = NULL;
        char* post_data = NULL;
-       int delay = 1;
        char* reg = this->reg_id;
        DBG("before format_string %s", reg);
 
-       post_data = format_string("{ \"regID\" : \"%s\", \"requestID\" : \"%s\" , \"message\" : \"badgeOption=INCREASE&badgeNumber=1&action=ALERT&alertMessage=Hi\", \"appData\" : \"Hello Tizen\", \"delayDate\" : %d}", this->reg_id,"000001", delay);
+       switch(this->push_type)
+       {
+       case NORMAL_PUSH:
+               DBG("NORMAL_PUSH");
+               post_data = format_string("{ \"regID\" : \"%s\", \"requestID\" : \"%s\" , \"message\" : \"badgeOption=INCREASE&badgeNumber=1&action=ALERT&alertMessage=Normal Push\", \"appData\" : \"Normal Push\"}", this->reg_id,"000002");
+               break;
+       case DELAY_PUSH:
+               DBG("DELAY_PUSH");
+               post_data = format_string("{ \"regID\" : \"%s\", \"requestID\" : \"%s\" , \"action\":\"backgroundLaunch\", \"appData\" : \"Delay Push\"}", this->reg_id,"000001");
+               break;
+       case BACKGROUND_LAUNCH_PUSH:
+               DBG("BACKGROUND_LAUNCH_PUSH");
+               post_data = format_string("{ \"regID\" : \"%s\", \"requestID\" : \"%s\" , \"message\":\"badgeOption=INCREASE&badgeNumber=1&action=BACKGROUNDLAUNCH&alertMessage=Background Launch\", \"appData\" : \"Background Launch\"}", this->push_test_regId,"000001");
+               break;
+       case ACTIVE_NOTIFICATION_PUSH:
+               DBG("ACTIVE_NOTIFICATION_PUSH");
+               post_data = format_string("{ \"regID\" : \"%s\", \"message\":\"setAutoRemove=true&textTypeButton1=Button1&textTypeButton2=Button2&textTypeButton3=Cancel&imageTypeButton1=indicator.png&imageTypeButton2=lock.png&imageTypeButton3=thumbnail.png&eventTypeClickOnButton1=test,test1&eventTypeClickOnButton2=test,test2&eventTypeClickOnButton3=test,good&eventTypeClickOnIcon=key,test&eventTypeClickOnThumbnail=key,test&badgeOption=INCREASE&badgeNumber=1&action=ALERT&alertMessage=Active Notification&textTypeTitle=Active Notification Title &textTypeContent=Hi How are you&textTypeGroupTitle=nono&textTypeGroupContent=yesyes&imageTypeIcon=icon.png&imageTypeIconForIndicator=indicator.png&imageTypeIconForLock=lock.png&imageTypeThumbnail=thumbnail.png&imageTypeThumbnailForLock=thumbnaillock.png&imageTypeIconSub=sub.png&imageTypeBackground=background.png&soundTypeUserData=test.wav&ledColor=100&ledOnOffTime=100,100&vibrationTypeUserData=test.png&setDisplayApplist=notificationTray|ticker|lock|indicator|active|all&lyNotiEventSingle=true&imageTypeList1=lock.png&imageTypeList2=lock.png&imageTypeList3=lock.png&imageTypeList4=lock.png&imageTypeList5=lock.png&textTypeContentForDisplayOptionIsOff=contentoptionoff&textTypeEventCount=eventcount&textTypeInfo1=push test&textTypeInfoSub1=infosub1&textTypeInfo2=info2&textTypeInfoSub2=infosub2&textTypeInfo3=info3&textTypeInfoSub3=infosub3&textTypeGroupContentForDisplayOptionIsOff=contentoptionoff&setTime=true&setTimeToText=true\", \"appData\" : \"Active Notification\", \"requestID\" : \"%s\"}", this->reg_id,"000001");
+               break;
+       case TEMPLATE_PUSH:
+               DBG("TEMPLATE_PUSH");
+               post_data = format_string("{ \"regID\" : \"%s\", \"requestID\" : \"%s\" , \"message\":\"template=template_test&action=ALERT&alertMessage=Template Push\", \"appData\" : \"Template push\"}", this->reg_id,"000001");
+               break;
+       default:
+               DBG("UNKNOWN PUSH TYPE");
+       }
+
+
 
        DBG("post_data : %s", post_data);
 
        // Creating header
        char appID[1024];
-       snprintf(appID, 1024, "appID:%s", this->push_app_id_text);
-       header_list = curl_slist_append(header_list, appID);
+       if(this->push_type == BACKGROUND_LAUNCH_PUSH)
+       {
+               //
+               snprintf(appID, 1024, "appID:%s", this->push_test_appId);
+               header_list = curl_slist_append(header_list, appID);
+       }
+       else
+       {
+               snprintf(appID, 1024, "appID:%s", this->push_app_id_text);
+               header_list = curl_slist_append(header_list, appID);
+       }
 
        char appSecret[1024];
-       snprintf(appSecret, 1024, "appSecret:%s", this->push_app_secret_text);
-       header_list = curl_slist_append(header_list, appSecret);
-
-
+       if(this->push_type == BACKGROUND_LAUNCH_PUSH)
+       {
+               //
+               snprintf(appSecret, 1024, "appSecret:%s", this->push_test_appSecret);
+               header_list = curl_slist_append(header_list, appSecret);
+       }
+       else
+       {
+               snprintf(appSecret, 1024, "appSecret:%s", this->push_app_secret_text);
+               header_list = curl_slist_append(header_list, appSecret);
+       }
 
        DBG("app_id: %s", this->push_app_id_text);
        DBG("app_secret: %s",this->push_app_secret_text);
 
+
        this->curl_handle = curl_easy_init();
        DBG("Curl handle created.");
 
index 4421f1a86c65b90be77bfd82c1f031662e5f5749..51311146d6272b7080fc11888b4e5f53d9578e13 100644 (file)
@@ -248,8 +248,8 @@ static void _stt_recognition_result_cb(stt_h stt, stt_result_event_e event, cons
 
        int ret = stt_foreach_detailed_result(stt, _stt_result_time_cb, this);
        DBG("stt_foreach_detailed_result fail > Error = %s", get_stt_error(ret));
-
-       for(int i=0; i<data_count; i++)
+       int i;
+       for(i=0; i<data_count; i++)
        {
                DBG("DATA: %s", data[i]);
                char* str = format_string("%s", data[i]);