Notification API's usage is changed
authorSeungyoun Ju <sy39.ju@samsung.com>
Thu, 15 Nov 2012 10:49:42 +0000 (19:49 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Fri, 7 Dec 2012 04:46:28 +0000 (13:46 +0900)
- Issues
  Notification API's usage is changed.

- Fix description
  1. Delete and Create approach is enhanced to update it inplace.
  2. Private ID is removed as per guide.

Change-Id: I70cbb956ea7342a6e07a315ea0a604e84f99ed34

include/mobileap_notification.h
packaging/mobileap-agent.spec
src/mobileap_common.c
src/mobileap_notification.c

index c11bbd8..cab348c 100644 (file)
@@ -29,8 +29,8 @@
 #define MH_NOTI_STR_MAX                50
 #define MH_NOTI_ICON_PATH      "/usr/apps/org.tizen.tethering/res/images/Q02_Notification_MobileAP.png"
 
-notification_h _create_notification(void);
-int _insert_notification(notification_h noti, char *title, char *content, char *icon_path);
+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);
 
index abade4a..9271a13 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mobileap-agent
 Summary:    Mobile AP daemon for setting tethering environments
-Version:    0.1.78
+Version:    0.1.79
 Release:    1
 Group:      TO_BE/FILLED_IN
 License:    Apache License Version 2.0
@@ -48,6 +48,9 @@ rm -rf %{buildroot}
 %{_bindir}/mobileap-agent
 
 %changelog
+* Thu Nov 08 2012 Seungyoun Ju <sy39.ju@samsung.com> 0.1.79-1
+- Notification's API usage is changed
+
 * Tue Nov 06 2012 Seungyoun Ju <sy39.ju@samsung.com> 0.1.78-1
 - Unnecessary BT API is removed
 
index 245ff0e..af57fb8 100644 (file)
@@ -116,42 +116,37 @@ void _send_dbus_station_info(const char *member, mobile_ap_station_info_t *info)
 
 void _update_station_count(int count)
 {
-       static int total_cnt = 0;
+       static int prev_cnt = 0;
        char str[MH_NOTI_STR_MAX] = {0, };
-       notification_h noti = NULL;
 
-       if (total_cnt == count) {
+       if (prev_cnt == count) {
                DBG("No need to update\n");
                return;
        }
 
        DBG("Update the number of station : %d\n", count);
-       total_cnt = count;
-
        if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_CONNECTED_DEVICE,
-                               total_cnt) < 0) {
+                               count) < 0) {
                ERR("Error setting up vconf\n");
                return;
        }
 
-       _delete_notification();
-       if (total_cnt == 0)
-               return;
-
-       noti = _create_notification();
-       if (noti == NULL) {
-               ERR("_create_notification() is failed\n");
+       if (count == 0) {
+               prev_cnt = 0;
+               _delete_notification();
                return;
        }
 
-       _set_notification_app_launch(noti);
-
-       /* Currently notification bar cannot be updated.
-        * So it is always deleted and inserted.
-        */
-       snprintf(str, MH_NOTI_STR_MAX, MH_NOTI_STR, total_cnt);
-       _insert_notification(noti, str, MH_NOTI_TITLE, MH_NOTI_ICON_PATH);
+       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);
+       } else {
+               DBG("Update notification\n");
+               _update_notification(str);
+       }
 
+       prev_cnt = count;
        return;
 }
 
index 7a82acc..ae5eda7 100644 (file)
 
 #include "mobileap_agent.h"
 
+static int priv_id;
 
-#define NOTI_PRIV_ID 0
-
-notification_h _create_notification(void)
+int _create_notification(const char *content, const char *title, const char *icon_path)
 {
        DBG("+\n");
        notification_h noti = NULL;
        notification_error_e ret = NOTIFICATION_ERROR_NONE;
 
-       noti = notification_new(NOTIFICATION_TYPE_NOTI, -1, NOTI_PRIV_ID);
+       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 NULL;
+               return MOBILE_AP_ERROR_INTERNAL;
        }
 
        ret = notification_set_property(noti,
                        NOTIFICATION_PROP_DISABLE_AUTO_DELETE | NOTIFICATION_PROP_VOLATILE_DISPLAY);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_set_property [%d]\n", ret);
-               return NULL;
+               goto FAIL;
        }
 
-       DBG("-\n");
-       return noti;
-}
-
-int _insert_notification(notification_h noti,
-                               char *title,
-                               char *content,
-                               char *icon_path)
-{
-       DBG("+\n");
-       notification_error_e ret;
-
-       if (!noti)
-               return MOBILE_AP_ERROR_INVALID_PARAM;
-
-       DBG("Insert noti : %d \n", noti);
+       ret = notification_set_layout(noti, NOTIFICATION_LY_ONGOING_EVENT);
+       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 error;
+               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 error;
+               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 error;
+               goto FAIL;
        }
 
-       ret = notification_insert(noti, NULL);
+       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, &priv_id);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_insert [%d]\n", ret);
-               goto error;
+               goto FAIL;
        }
 
        ret = notification_free(noti);
        if (ret != NOTIFICATION_ERROR_NONE) {
                ERR("Fail to notification_free [%d]\n", ret);
-               goto error;
+               goto FAIL;
        }
 
        DBG("-\n");
-       return ret;
+       return MOBILE_AP_ERROR_NONE;
 
-error:
+FAIL:
+       ret = notification_free(noti);
+       if (ret != NOTIFICATION_ERROR_NONE)
+               ERR("Fail to notification_free [%d]\n", ret);
        return MOBILE_AP_ERROR_INTERNAL;
 }
 
-int _delete_notification(void)
+int _update_notification(const char *content)
 {
        DBG("+\n");
-       notification_error_e ret;
 
-       ret = notification_delete_all_by_type(NULL, NOTIFICATION_TYPE_NOTI);
+       if (content == NULL) {
+               ERR("Invalid param\n");
+               return MOBILE_AP_ERROR_INVALID_PARAM;
+       }
+
+       notification_h noti = NULL;
+       notification_error_e ret = NOTIFICATION_ERROR_NONE;
+
+       noti = notification_load(APPNAME, priv_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);
        if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_delete_all_by_type [%d]\n", ret);
+               ERR("Fail to notification_set_text [%d]\n", ret);
+               return MOBILE_AP_ERROR_INTERNAL;
+       }
+
+       ret = notification_update(noti);
+       if (ret != NOTIFICATION_ERROR_NONE) {
+               ERR("Fail to notification_update [%d]\n", ret);
+               ret = notification_free(noti);
+               if (ret != NOTIFICATION_ERROR_NONE)
+                       ERR("Fail to notification_free [%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;
        }
 
@@ -124,20 +157,17 @@ int _delete_notification(void)
        return MOBILE_AP_ERROR_NONE;
 }
 
-
-int _set_notification_app_launch(notification_h noti)
+int _delete_notification(void)
 {
        DBG("+\n");
        notification_error_e ret;
 
-       if (!noti)
-               return MOBILE_AP_ERROR_INVALID_PARAM;
-
-       ret = notification_set_application(noti, "org.tizen.tethering");
+       ret = notification_delete_all_by_type(APPNAME, NOTIFICATION_TYPE_NOTI);
        if (ret != NOTIFICATION_ERROR_NONE) {
-               ERR("Fail to notification_set_application [%d]\n", ret);
+               ERR("Fail to notification_delete_all_by_type [%d]\n", ret);
                return MOBILE_AP_ERROR_INTERNAL;
        }
+       priv_id = 0;
 
        DBG("-\n");
        return MOBILE_AP_ERROR_NONE;