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;
}
#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;
}
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;