Notification Manager refactoring code changes
authorJiban Prakash <p.jiban@samsung.com>
Thu, 13 Dec 2012 05:46:55 +0000 (11:16 +0530)
committerJiban Prakash <p.jiban@samsung.com>
Thu, 13 Dec 2012 05:51:49 +0000 (11:21 +0530)
Change-Id: Ie0ac56539eac23300145ff60c4c8caedaebf6817
Signed-off-by: Jiban Prakash <p.jiban@samsung.com>
src/core/FShell_NotificationManagerImpl.cpp
src/core/FShell_NotificationRequestImpl.cpp
src/inc/FShell_NotificationManagerEventParamTraits.h [moved from src/core/FShell_NotificationManagerEventParamTraits.h with 97% similarity]
src/inc/FShell_NotificationManagerIpcMessages.h [moved from src/core/FShell_NotificationManagerIpcMessages.h with 100% similarity]
src/inc/FShell_NotificationManagerProxy.h [moved from src/core/FShell_NotificationManagerProxy.h with 100% similarity]
src/inc/FShell_NotificationRequestImpl.h [moved from src/core/FShell_NotificationRequestImpl.h with 100% similarity]

index 3ebf9d2..96cf197 100644 (file)
@@ -47,6 +47,7 @@ using namespace Tizen::App;
 using namespace Tizen::Shell;
 
 extern "C" int service_create_request(bundle *data, service_h *service);
+extern "C" int service_to_bundle(service_h service, bundle** data);
 
 namespace
 {
@@ -56,17 +57,17 @@ ConvertNotificationResult(int error)
 {
        switch (error)
        {
-       case UI_NOTIFICATION_ERROR_NONE:
+       case NOTIFICATION_ERROR_NONE:
                return E_SUCCESS;
-       case UI_NOTIFICATION_ERROR_INVALID_PARAMETER:
+       case NOTIFICATION_ERROR_INVALID_DATA:
                return E_INVALID_ARG;
-       case UI_NOTIFICATION_ERROR_OUT_OF_MEMORY:
+       case NOTIFICATION_ERROR_NO_MEMORY:
                return E_OUT_OF_MEMORY;
-       case UI_NOTIFICATION_ERROR_DB_FAILED:
+       case NOTIFICATION_ERROR_FROM_DB:
                return E_DATABASE;
-       case UI_NOTIFICATION_ERROR_NO_SUCH_FILE:
+       case NOTIFICATION_ERROR_ALREADY_EXIST_ID:
                return E_OPERATION_FAILED;
-       case UI_NOTIFICATION_ERROR_INVALID_STATE:
+       case NOTIFICATION_ERROR_NOT_EXIST_ID:
                return E_OPERATION_FAILED;
        default:
                return E_OPERATION_FAILED;
@@ -81,22 +82,6 @@ GetMessageLength()
        return length;
 }
 
-ui_notification_progress_type_e
-ConvertToNotificationProgressType(int progressType)
-{
-       switch (progressType)
-       {
-       case ONGOING_ACTIVITY_TYPE_TEXT:
-               return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
-       case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
-               return UI_NOTIFICATION_PROGRESS_TYPE_SIZE;
-       case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
-               return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
-       default:
-               return UI_NOTIFICATION_PROGRESS_TYPE_PERCENTAGE;
-       }
-}
-
 bool
 IsPosted(ui_notification_h handle)
 {
@@ -198,10 +183,13 @@ _NotificationManagerImpl::NotifyImpl(const String& messageText, int badgeNumber,
                                                                         bool isOngoing) const
 {
        result r = E_SUCCESS;
-       int retcode = 0;
        char* pMsg = null;
-       ui_notification_h core = NULL;
+       notification_h core = NULL;
        char* pkgname = NULL;
+       bundle* pKb = NULL;
+       bundle* service_data = NULL;
+       service_h svc = NULL;
+       _AppArg arg;
 
        if (!messageText.IsEmpty())
        {
@@ -209,17 +197,19 @@ _NotificationManagerImpl::NotifyImpl(const String& messageText, int badgeNumber,
                                          messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
                                          "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
 
-               retcode = ui_notification_create(isOngoing, &core);
-               SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Notification creation error : 0x%x.", retcode);
+               if (isOngoing)
+               {
+                       core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+                       SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+               }
+               else
+               {
+                       core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+                       SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+               }
 
                pMsg = _StringConverter::CopyToCharArrayN(messageText);
-
-               int ret = ui_notification_set_content(core, pMsg);
-               SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
-
-               bundle* pKb = NULL;
-               service_h svc = NULL;
-               _AppArg arg;
+               notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
                app_get_package(&pkgname);
                SysTryCatch(NID_APP, pkgname != NULL, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Cannot acquire package name for current application.");
@@ -230,12 +220,15 @@ _NotificationManagerImpl::NotifyImpl(const String& messageText, int badgeNumber,
                pKb = arg.GetBundle();
                service_create_request(pKb, &svc);
                service_set_package(svc, pkgname);
-               ui_notification_set_service(core, svc);
-
-               SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
-
-               r = ConvertNotificationResult(ui_notification_post(core));
-
+               
+               if (service_to_bundle(svc, &service_data) == SERVICE_ERROR_NONE)
+               {
+                        notification_set_property(core, 0);
+                        notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
+                        SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
+               }
+
+               r = ConvertNotificationResult(notification_insert(core, NULL));
                SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
        }
 
@@ -254,7 +247,7 @@ CATCH:
 
        if (core)
        {
-               ui_notification_destroy(core);
+               notification_free(core);
        }
 
        return r;
@@ -266,12 +259,15 @@ _NotificationManagerImpl::NotifyImpl(const AppId& appId, const String& messageTe
                                                                         bool isOngoing) const
 {
        result r = E_SUCCESS;
-       int retcode = 0;
        char* pMsg = null;
        char* pIcon = NULL;
        char* pName = NULL;
-       ui_notification_h core = NULL;
+       notification_h core = NULL;
        char buffer[256];
+       bundle* pKb = NULL;
+       bundle* service_data = NULL;
+       service_h svc = NULL;
+       _AppArg arg;
 
        memset(buffer, 0, 256);
 
@@ -279,31 +275,33 @@ _NotificationManagerImpl::NotifyImpl(const AppId& appId, const String& messageTe
 
        SysTryReturnResult(NID_APP, b == true, E_APP_NOT_INSTALLED, "The application %ls is not installed", appId.GetPointer());
 
-       if (!isOngoing || !messageText.IsEmpty())
+       if (isOngoing || !messageText.IsEmpty())
        {
                SysTryReturnResult(NID_APP,
                                          messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
                                          "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
 
-               retcode = ui_notification_create(isOngoing, &core);
-               SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Notification creation error : 0x%x.", retcode);
+               if (isOngoing)
+               {
+                       core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+                       SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+               }
+               else
+               {
+                       core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+                       SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+               }
 
                pMsg = _StringConverter::CopyToCharArrayN(messageText);
-
-               int ret = ui_notification_set_content(core, pMsg);
-               SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
-
-               bundle* pKb = NULL;
-               service_h svc = NULL;
-               _AppArg arg;
+               notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
                snprintf(buffer, 256, "%ls", appId.GetPointer());
 
                app_manager_get_app_icon_path(buffer, &pIcon);
-               ui_notification_set_icon(core, pIcon);
+               notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, pIcon);
 
                app_manager_get_app_name(buffer, &pName);
-               ui_notification_set_title(core, pName);
+               notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, pName, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
 
                r = arg.Construct(launchArguments);
                SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s] Propagating.", GetErrorMessage(r));
@@ -311,12 +309,15 @@ _NotificationManagerImpl::NotifyImpl(const AppId& appId, const String& messageTe
                pKb = arg.GetBundle();
                service_create_request(pKb, &svc);
                service_set_app_id(svc, buffer);
-               ui_notification_set_service(core, svc);
-
-               SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), buffer);
-
-               r = ConvertNotificationResult(ui_notification_post(core));
-
+               
+               if (service_to_bundle(svc, &service_data) == SERVICE_ERROR_NONE)
+               {
+                        notification_set_property(core, 0);
+                        notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
+                        SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), buffer);
+               }
+
+               r = ConvertNotificationResult(notification_insert(core,NULL));
                SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
        }
 
@@ -331,7 +332,7 @@ CATCH:
 
        if (core)
        {
-               ui_notification_destroy(core);
+               notification_free(core);
        }
 
        if (pIcon)
@@ -352,13 +353,16 @@ result
 _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessage, bool isOngoing)
 {
        result r = E_SUCCESS;
-       int retcode = 0;
        int progress = -1;
-       ui_notification_h core = NULL;
+       notification_h core = NULL;
        char* pkgname = NULL;
        char* pTitleText = NULL;
        char* pIconPath = NULL;
        char* pSoundPath = NULL;
+       bundle* pKb = NULL;
+       bundle* service_data = NULL;
+       service_h svc = NULL;
+       _AppArg arg;
 
        const String& messageText = notiMessage.GetAlertText();
        const String& launchArguments = notiMessage.GetAppMessage();
@@ -374,39 +378,42 @@ _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessa
                                          messageText.GetLength() <= GetMessageLength(), E_INVALID_ARG,
                                          "MessageText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
 
-               retcode = ui_notification_create(isOngoing, &core);
-               SysTryReturnResult(NID_APP, retcode == UI_NOTIFICATION_ERROR_NONE, E_OPERATION_FAILED, "Notification creation error : 0x%x.", retcode);
+               if (isOngoing)
+               {
+                       core = notification_new(NOTIFICATION_TYPE_ONGOING, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+                               SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+                       }
+               else
+               {
+                       core = notification_new(NOTIFICATION_TYPE_NOTI, NOTIFICATION_GROUP_ID_DEFAULT, NOTIFICATION_PRIV_ID_NONE);
+                       SysTryReturnResult(NID_APP, core!= NULL , E_SYSTEM, "Notification creation failed ");
+               }
 
                std::unique_ptr<char[]> pMsg(_StringConverter::CopyToCharArrayN(messageText));
 
                if (pMsg)
                {
-                       int ret = ui_notification_set_content(core, pMsg.get());
-                       SysTryLog(NID_APP, ret == UI_NOTIFICATION_ERROR_NONE, "Setting notification content failure : %d.", ret);
+                       notification_set_text(core, NOTIFICATION_TEXT_TYPE_CONTENT, pMsg.get(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                }
 
                if (!titleText.IsEmpty())
                {
                        pTitleText = _StringConverter::CopyToCharArrayN(titleText);
-                       ui_notification_set_title(core, pTitleText);
+                       notification_set_text(core, NOTIFICATION_TEXT_TYPE_TITLE, pTitleText, NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
                }
 
                if (!iconPath.IsEmpty())
                {
                        pIconPath = _StringConverter::CopyToCharArrayN(iconPath);
-                       ui_notification_set_icon(core, pIconPath);
+                       notification_set_image(core, NOTIFICATION_IMAGE_TYPE_ICON, pIconPath);
                }
 
                if (!soundPath.IsEmpty())
                {
                        pSoundPath = _StringConverter::CopyToCharArrayN(soundPath);
-                       ui_notification_set_sound(core, pSoundPath);
+                       notification_set_sound(core, NOTIFICATION_SOUND_TYPE_USER_DATA, pSoundPath);
                }
 
-               bundle* pKb = NULL;
-               service_h svc = NULL;
-               _AppArg arg;
-
                app_get_id(&pkgname);
                SysTryCatch(NID_APP, pkgname != NULL, r = E_OBJ_NOT_FOUND, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] Cannot acquire package name for current application.");
 
@@ -417,8 +424,12 @@ _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessa
                service_create_request(pKb, &svc);
                service_set_app_id(svc, pkgname);
 
-               ui_notification_set_service(core, svc);
-               SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
+               if (service_to_bundle(svc, &service_data) == SERVICE_ERROR_NONE)
+               {
+                        notification_set_property(core, 0);
+                        notification_set_execute_option(core, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, NULL, NULL, service_data);
+                        SysLog(NID_APP, "Sending notification[%ls] for package %s.", messageText.GetPointer(), pkgname);
+               }
 
                if (isOngoing)
                {
@@ -427,21 +438,20 @@ _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessa
                        switch (activityType)
                        {
                        case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
-                               if (!IsPosted(core))
-                               {
-                                       ui_notification_post(core);
-                               }
-                               r = ConvertNotificationResult(ui_notification_update_progress(core, ConvertToNotificationProgressType(activityType), progress/100.));
+                               r = ConvertNotificationResult(notification_insert(core,NULL));
+                               SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+                               r = ConvertNotificationResult(notification_update_progress(core, NOTIFICATION_PRIV_ID_NONE, progress/100.));
+                               SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
                                break;
                        case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
-                               if (!IsPosted(core))
-                               {
-                                       ui_notification_post(core);
-                               }
-                               r = ConvertNotificationResult(ui_notification_update_progress(core, ConvertToNotificationProgressType(activityType), progress));
+                               r = ConvertNotificationResult(notification_insert(core,NULL));
+                               SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
+                               r = ConvertNotificationResult(notification_update_size(core, NOTIFICATION_PRIV_ID_NONE, progress));
+                               SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification update failure.", GetErrorMessage(r));
                                break;
                        case ONGOING_ACTIVITY_TYPE_TEXT:
-                               r = ConvertNotificationResult(ui_notification_post(core));
+                               r = ConvertNotificationResult(notification_insert(core,NULL));
+                               SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
                                break;
                        default:
                                r = E_OPERATION_FAILED;
@@ -451,7 +461,7 @@ _NotificationManagerImpl::NotifyMessageImpl(const NotificationRequest& notiMessa
                }
                else
                {
-                       r = ConvertNotificationResult(ui_notification_post(core));
+                       r = ConvertNotificationResult(notification_insert(core,NULL));
                        SysTryLog(NID_APP, !IsFailed(r), "[%s] Notification post failure.", GetErrorMessage(r));
                }
        }
@@ -493,7 +503,7 @@ CATCH:
        }
        if (core)
        {
-               ui_notification_destroy(core);
+               notification_free(core);
        }
 
        return r;
index 4261ae3..6f73cb9 100644 (file)
@@ -346,7 +346,7 @@ _NotificationRequestImpl::SetOngoingActivityProgress(int progressValue)
 
        // use int type instead of OngoingActivityType to evade weired gcc optimization
        int activitytype = static_cast<int>(GetOngoingActivityType());
-       SysTryReturnResult(NID_APP, activitytype > ONGOING_ACTIVITY_TYPE_TEXT && activitytype <= ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE,
+       SysTryReturnResult(NID_APP, activitytype >= ONGOING_ACTIVITY_TYPE_TEXT && activitytype <= ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE,
                        E_INVALID_STATE,"Invalid activity Type %d.", activitytype);
 
        if (activitytype == ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE)
@@ -51,7 +51,7 @@ struct ParamTraits<Tizen::Shell::NotificationRequest>
 
                m->WriteInt(p.GetBadgeNumber());
                m->WriteInt(p.GetBadgeOffset());
-               m->WriteInt((int)p.GetOngoingActivityType());
+               m->WriteInt((Tizen::Shell::OngoingActivityType)p.GetOngoingActivityType());
                m->WriteInt(p.GetOngoingActivityProgress());
        }
 
@@ -65,8 +65,9 @@ struct ParamTraits<Tizen::Shell::NotificationRequest>
 
                int badgeNo = -1;
                int badgeOffset = 0;
-               int progressValue = -1;
                int activityType = Tizen::Shell::ONGOING_ACTIVITY_TYPE_TEXT;
+               int progressValue = -1;
+
 
                if (!ReadParam(m, iter, &alertText))
                {
@@ -90,8 +91,9 @@ struct ParamTraits<Tizen::Shell::NotificationRequest>
                }
                m->ReadInt(iter, &badgeNo);
                m->ReadInt(iter, &badgeOffset);
-               m->ReadInt(iter, &progressValue);
                m->ReadInt(iter, &activityType);
+               m->ReadInt(iter, &progressValue);
+
 
                Tizen::Shell::NotificationRequest notimessage;
                notimessage.SetAlertText(alertText);
@@ -102,8 +104,9 @@ struct ParamTraits<Tizen::Shell::NotificationRequest>
 
                notimessage.SetBadgeNumber(badgeNo);
                notimessage.SetBadgeOffset(badgeOffset);
-               notimessage.SetOngoingActivityProgress(progressValue);
                notimessage.SetOngoingActivityType((Tizen::Shell::OngoingActivityType)activityType);
+               notimessage.SetOngoingActivityProgress(progressValue);
+
 
                *r = notimessage;