#define PUSH_NOTIFICATION_H_
#include <string>
-#include <app_control.h>
+
+#include <notification.h>
namespace iotswsec
{
class PushNotification
{
public:
- /**
- @brief Return Notification singleton instance.
- @return Notification instance.
- */
- static PushNotification& GetInstance();
-
- /**
- @brief Push Tizen notification with title and body text.
- @param[in] title - title text.
- @param[in] body - body text.
- */
- void Push(const std::string& title, const std::string& body) const;
+ PushNotification(const std::string& title, const std::string& body);
+ virtual ~PushNotification();
- void LaunchDashboardApp();
-
- ~PushNotification();
-private:
- PushNotification();
- void Init();
- void Deinit();
PushNotification(const PushNotification& obj) = delete;
PushNotification& operator=(const PushNotification&) = delete;
- static void OnButtonClickCallback(int itemId, int buttonIndex, void* userData);
- static void OnNotificationTimeOutCB(int nItemId, void* userdata);
- static void OnNotificationHideCallback(char* pAppName, void* userdata);
+
+ /**
+ @brief Push Tizen notification.
+ @return 0 on success, otherwise any other value on failure
+ */
+ int push() const;
private:
- app_control_h m_appContext;
+ notification_h m_notification;
};
+
}
#endif /* PUSH_NOTIFICATION_H_ */
**/
#include <stdexcept>
-#include <notification_data_manager.h>
+#include <cassert>
+
+#include <app_control.h>
+#include <notification.h>
+#include <notification_internal.h>
-#include "push_notification.h"
-#include "utils/log.h"
#include "common_types.h"
+#include "utils/log.h"
+
+#include "push_notification.h"
#define DASHBOARD_APP_ID "62UffoiBtd.Dashboard"
namespace iotswsec
{
-PushNotification::PushNotification():
- m_appContext(nullptr)
+PushNotification::PushNotification(const std::string& title, const std::string& body) : m_notification(nullptr)
{
LOG_DBG("BEGIN");
- Init();
- LOG_DBG("END");
-}
-
-PushNotification& PushNotification::GetInstance()
-{
- static PushNotification notification;
-
- return notification;
-}
-
-void PushNotification::Push(const std::string& title, const std::string& body) const
-{
- LOG_INFO("BEGIN");
-
- notification_item_info_s notiItemInfo = {0};
-
- notiItemInfo.pAppName = (char*)"iot-manager-dashboard-proxy";
- notiItemInfo.nItemId = 1;
- notiItemInfo.bFlagAutoDelete = 1;
- notiItemInfo.bFlagBannerShow = 1;
- notiItemInfo.nBannerHideAlarmDuration = 30;
- notiItemInfo.nItemType = ITEM_TYPE_TEXT;
- notiItemInfo.nDefaultFocus = 1;
- notiItemInfo.pIconPath = (char*)"/usr/apps/iot-manager-dashboard-proxy/shared/images/icon.png";
- notiItemInfo.pTitleText = (char*)title.c_str();
- notiItemInfo.nButtonNum = 2;
- notiItemInfo.pFirstButtonText = (char*)"Show more";
- notiItemInfo.pSecondButtonText = (char*)"Dismiss";
- notiItemInfo.pDescriptionText = (char*)body.c_str();
-
- int res = 0;
-
- if ((res = add_notification_data(¬iItemInfo)) != 0)
- {
- LOG_INFO("Couldn't create global notification, error code: %d", res);
- }
-
- LOG_INFO("END");
-}
-
-void PushNotification::Init()
-{
- LOG_INFO("BEGIN");
- int res = 0;
- if ((res = init_notification_data_manager("iot-manager-dashboard-proxy", 0))
- != 0)
+ if((m_notification = notification_create(NOTIFICATION_TYPE_NOTI)) == nullptr)
{
- LOG_INFO("Couldn't init global notification instance, error code: %d", res);
-
- throw std::runtime_error(std::string(std::string("Couldn't init global notification instance, error code: ") + std::to_string(res)).c_str());
+ throw std::runtime_error("Couldn't create notification instance.");
}
- register_notification_button_callback(OnButtonClickCallback, this);
- register_notification_timeout_callback(OnNotificationTimeOutCB, this);
- register_notofication_hide_callback(OnNotificationHideCallback, this);
-
- int appControlRes = 0;
-
- if ((appControlRes = app_control_create(&m_appContext)) != 0)
+ notification_set_display_applist(m_notification, NOTIFICATION_DISPLAY_APP_ACTIVE);
+ notification_set_layout(m_notification, NOTIFICATION_LY_NONE);
+ notification_set_auto_remove(m_notification, false);
+ notification_set_time(m_notification, time(NULL));
+ notification_set_hide_timeout(m_notification, 60);
+
+ notification_set_text(m_notification, NOTIFICATION_TEXT_TYPE_TITLE, title.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ notification_set_text(m_notification, NOTIFICATION_TEXT_TYPE_CONTENT, body.c_str(), NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ notification_add_button(m_notification, NOTIFICATION_BUTTON_1);
+ notification_set_text(m_notification, NOTIFICATION_TEXT_TYPE_BUTTON_1, "Show more", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ notification_add_button(m_notification, NOTIFICATION_BUTTON_2);
+ notification_set_text(m_notification, NOTIFICATION_TEXT_TYPE_BUTTON_2, "Dismiss", NULL, NOTIFICATION_VARIABLE_TYPE_NONE);
+ notification_set_default_button(m_notification, NOTIFICATION_BUTTON_1);
+
+ app_control_h app_control = NULL;
+ app_control_create(&app_control);
+ if(!app_control)
{
- LOG_INFO("Couldn't init app context, error code: %d", appControlRes);
-
- throw std::runtime_error(std::string(std::string("Couldn't init app context, error code: ") + std::to_string(appControlRes)).c_str());
+ throw std::runtime_error("Couldn't create app_control instance.");
}
-
- if ((res = app_control_set_app_id(m_appContext, DASHBOARD_APP_ID))
- != 0)
+ app_control_set_app_id(app_control, DASHBOARD_APP_ID);
+ app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
+ notification_set_event_handler(m_notification, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_1, app_control);
+ app_control_destroy(app_control);
+
+ app_control = NULL;
+ app_control_create(&app_control);
+ if(!app_control)
{
- LOG_INFO("Couldn't set app id, error code: %d", res);
-
- throw std::runtime_error(std::string(std::string("Couldn't set app id, error code: ") + std::to_string(res)).c_str());
-
+ throw std::runtime_error("Couldn't create app_control instance.");
}
+ notification_set_event_handler(m_notification, NOTIFICATION_EVENT_TYPE_CLICK_ON_BUTTON_2, app_control);
+ app_control_destroy(app_control);
- LOG_INFO("END");
-}
-
-void PushNotification::Deinit()
-{
- close_notification_data_manager();
- app_control_destroy(m_appContext);
- m_appContext = nullptr;
+ LOG_DBG("END");
}
PushNotification::~PushNotification()
{
- Deinit();
-}
-
-void PushNotification::OnButtonClickCallback(int, int buttonIndex, void *userData)
-{
- LOG_INFO("BEGIN");
-
- if (!userData)
- {
- LOG_INFO("Error: invalid parameter");
- return;
- }
-
- PushNotification* pThis = reinterpret_cast<PushNotification*>(userData);
-
- if (buttonIndex == 0)
- {
- LOG_INFO("Clicked first button");
- pThis->LaunchDashboardApp();
- }
- else
- {
- LOG_INFO("Clicked second button");
- }
- LOG_INFO("END");
-}
-
-void PushNotification::LaunchDashboardApp()
-{
- LOG_INFO("BEGIN");
- int res = 0;
-
- if ((res = app_control_send_launch_request(m_appContext, NULL, NULL))
- != 0)
- {
- LOG_INFO("Couldn't launch the application, error code: %d", res);
- }
- LOG_INFO("END");
-}
-
-void PushNotification::OnNotificationTimeOutCB(int nItemId, void *userdata)
-{
- LOG_INFO("OnNotificationTimeOutCB");
- LOG_INFO("Hide by timeout");
+ notification_delete(m_notification);
+ notification_free(m_notification);
+ m_notification = nullptr;
}
-void PushNotification::OnNotificationHideCallback(char *pAppName, void *userdata)
+int PushNotification::push() const
{
- LOG_INFO("OnNotificationHideCallback");
- LOG_INFO("Hide by action");
+ assert(m_notification);
+ return notification_post(m_notification);
}
} //namespace iotswsec