Notification for timeout event is implemented
authorSeungyoun Ju <sy39.ju@samsung.com>
Thu, 6 Dec 2012 12:52:29 +0000 (21:52 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Fri, 7 Dec 2012 04:47:24 +0000 (13:47 +0900)
- Issues
  Notification should be happened when tethering
  is disabled because of timeout.

- Fix description
  Timeout notification is implemented.

Change-Id: I8c4e8af7f71d9ef8219979f5fa1439d2fec1c10f

include/mobileap_notification.h
src/mobileap_common.c
src/mobileap_handler.c
src/mobileap_notification.c

index cab348c..0177cb3 100644 (file)
 #define MH_NOTI_STR_MAX                50
 #define MH_NOTI_ICON_PATH      "/usr/apps/org.tizen.tethering/res/images/Q02_Notification_MobileAP.png"
 
-int _create_notification(const char *content, const char *title, const char *icon_path);
-int _update_notification(const char *content);
-int _delete_notification(void);
-int _set_notification_app_launch(notification_h noti);
+int _create_timeout_noti(const char *content, const char *title,
+               const char *icon_path);
+
+int _create_connected_noti(const char *content, const char *title,
+               const char *icon_path);
+int _update_connected_noti(const char *content);
+int _delete_connected_noti(void);
 
 #endif
index 128008f..0be103c 100644 (file)
@@ -133,17 +133,17 @@ void _update_station_count(int count)
 
        if (count == 0) {
                prev_cnt = 0;
-               _delete_notification();
+               _delete_connected_noti();
                return;
        }
 
        snprintf(str, MH_NOTI_STR_MAX, MH_NOTI_STR, count);
        if (prev_cnt == 0) {
                DBG("Create notification\n");
-               _create_notification(str, MH_NOTI_TITLE, MH_NOTI_ICON_PATH);
+               _create_connected_noti(str, MH_NOTI_TITLE, MH_NOTI_ICON_PATH);
        } else {
                DBG("Update notification\n");
-               _update_notification(str);
+               _update_connected_noti(str);
        }
 
        prev_cnt = count;
index 4ee8ab1..88404c8 100644 (file)
 #include "mobileap_bluetooth.h"
 #include "mobileap_wifi.h"
 #include "mobileap_usb.h"
+#include "mobileap_notification.h"
+
+/* Need translation */
+#define MH_NOTI_TIMEOUT_STR    "Tap for setting"
+#define MH_NOTI_TIMEOUT_TITLE  "Disable tethering by timeout"
 
 typedef struct {
        guint src_id;
@@ -211,6 +216,9 @@ static gboolean __wifi_timeout_cb(gpointer data)
        _emit_mobileap_dbus_signal(obj,
                        E_SIGNAL_WIFI_TETHER_OFF, SIGNAL_MSG_TIMEOUT);
 
+       _create_timeout_noti(MH_NOTI_TIMEOUT_STR, MH_NOTI_TIMEOUT_TITLE,
+                       MH_NOTI_ICON_PATH);
+
        DBG("-\n");
        return FALSE;
 }
@@ -234,6 +242,8 @@ static gboolean __bt_timeout_cb(gpointer data)
        _emit_mobileap_dbus_signal(obj,
                        E_SIGNAL_BT_TETHER_OFF, SIGNAL_MSG_TIMEOUT);
 
+       _create_timeout_noti(MH_NOTI_TIMEOUT_STR, MH_NOTI_TIMEOUT_TITLE,
+                       MH_NOTI_ICON_PATH);
        DBG("-\n");
        return FALSE;
 }
index e85eb7d..35b8b7c 100644 (file)
 
 #include "mobileap_agent.h"
 
-static int priv_id;
+static int connected_noti_id = 0;
+static int timeout_noti_id = 0;
 
-int _create_notification(const char *content, const char *title, const char *icon_path)
+int _create_timeout_noti(const char *content, const char *title,
+               const char *icon_path)
+{
+       DBG("+\n");
+       notification_h noti = NULL;
+       notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
+       if (timeout_noti_id) {
+               noti = notification_load(APPNAME, timeout_noti_id);
+               if (noti == NULL) {
+                       DBG("Notification can be deleted already\n");
+               } else {
+                       ret = notification_delete(noti);
+                       if (ret != NOTIFICATION_ERROR_NONE) {
+                               ERR("Fail to notification_delete [%d]\n", ret);
+                               return MOBILE_AP_ERROR_INTERNAL;
+                       }
+
+                       ret = notification_free(noti);
+                       if (ret != NOTIFICATION_ERROR_NONE) {
+                               ERR("Fail to notification_free [%d]\n", ret);
+                               return MOBILE_AP_ERROR_INTERNAL;
+                       }
+               }
+               timeout_noti_id = 0;
+       }
+
+       noti = notification_new(NOTIFICATION_TYPE_NOTI,
+                       NOTIFICATION_GROUP_ID_NONE, NOTIFICATION_PRIV_ID_NONE);
+       if (!noti) {
+               ERR("Fail to notification_new [%d]\n", ret);
+               return MOBILE_AP_ERROR_INTERNAL;
+       }
+
+       ret = notification_set_property(noti,
+                       NOTIFICATION_PROP_VOLATILE_DISPLAY);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_property [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_set_layout(noti, NOTIFICATION_LY_NOTI_EVENT_SINGLE);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_image [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_set_image(noti,
+                       NOTIFICATION_IMAGE_TYPE_ICON, icon_path);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_image [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_set_text(noti,
+                       NOTIFICATION_TEXT_TYPE_TITLE,
+                       title,
+                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_text [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_set_text(noti,
+                       NOTIFICATION_TEXT_TYPE_CONTENT,
+                       content,
+                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_text [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_set_pkgname(noti, APPNAME);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_pkgname [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_set_application(noti, "org.tizen.tethering");
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_set_application [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_insert(noti, &timeout_noti_id);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_insert [%d]\n", ret);
+               goto FAIL;
+       }
+
+       ret = notification_free(noti);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_free [%d]\n", ret);
+               goto FAIL;
+       }
+
+       DBG("-\n");
+       return MOBILE_AP_ERROR_NONE;
+
+FAIL:
+       ret = notification_free(noti);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               ERR("Fail to notification_free [%d]\n", ret);
+
+       return MOBILE_AP_ERROR_INTERNAL;
+}
+
+int _create_connected_noti(const char *content, const char *title,
+               const char *icon_path)
 {
        DBG("+\n");
        notification_h noti = NULL;
@@ -47,7 +156,8 @@ int _create_notification(const char *content, const char *title, const char *ico
        }
 
        ret = notification_set_property(noti,
-                       NOTIFICATION_PROP_DISABLE_AUTO_DELETE | NOTIFICATION_PROP_VOLATILE_DISPLAY);
+                       NOTIFICATION_PROP_DISABLE_AUTO_DELETE |
+                       NOTIFICATION_PROP_VOLATILE_DISPLAY);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_set_property [%d]\n", ret);
                goto FAIL;
@@ -65,15 +175,19 @@ int _create_notification(const char *content, const char *title, const char *ico
                goto FAIL;
        }
 
-       ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
-                               title, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       ret = notification_set_text(noti,
+                       NOTIFICATION_TEXT_TYPE_TITLE,
+                       title,
+                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_set_text [%d]\n", ret);
                goto FAIL;
        }
 
-       ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                               content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+       ret = notification_set_text(noti,
+                       NOTIFICATION_TEXT_TYPE_CONTENT,
+                       content,
+                       NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_set_text [%d]\n", ret);
                goto FAIL;
@@ -91,7 +205,7 @@ int _create_notification(const char *content, const char *title, const char *ico
                goto FAIL;
        }
 
-       ret = notification_insert(noti, &priv_id);
+       ret = notification_insert(noti, &connected_noti_id);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_insert [%d]\n", ret);
                goto FAIL;
@@ -113,7 +227,7 @@ FAIL:
        return MOBILE_AP_ERROR_INTERNAL;
 }
 
-int _update_notification(const char *content)
+int _update_connected_noti(const char *content)
 {
        DBG("+\n");
 
@@ -125,14 +239,14 @@ int _update_notification(const char *content)
        notification_h noti = NULL;
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
 
-       noti = notification_load(APPNAME, priv_id);
+       noti = notification_load(APPNAME, connected_noti_id);
        if (noti == NULL) {
                ERR("notification_load is failed\n");
                return MOBILE_AP_ERROR_INTERNAL;
        }
 
        ret = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
-                               content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+                       content, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_set_text [%d]\n", ret);
                return MOBILE_AP_ERROR_INTERNAL;
@@ -157,17 +271,31 @@ int _update_notification(const char *content)
        return MOBILE_AP_ERROR_NONE;
 }
 
-int _delete_notification(void)
+int _delete_connected_noti(void)
 {
        DBG("+\n");
+       notification_h noti = NULL;
        notification_error_e ret;
 
-       ret = notification_delete_all_by_type(APPNAME, NOTIFICATION_TYPE_ONGOING);
+       noti = notification_load(APPNAME, connected_noti_id);
+       if (noti == NULL) {
+               ERR("notification_load is failed\n");
+               connected_noti_id = 0;
+               return MOBILE_AP_ERROR_INTERNAL;
+       }
+       connected_noti_id = 0;
+
+       ret = notification_delete(noti);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_delete [%d]\n", ret);
+               return MOBILE_AP_ERROR_INTERNAL;
+       }
+
+       ret = notification_free(noti);
        if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_delete_all_by_type [%d]\n", ret);
+               ERR("Fail to notification_free [%d]\n", ret);
                return MOBILE_AP_ERROR_INTERNAL;
        }
-       priv_id = 0;
 
        DBG("-\n");
        return MOBILE_AP_ERROR_NONE;