1 // Copyright 2015 Samsung Electronics Co, Ltd. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "runtime/notification_manager.h"
7 #include <notification.h>
10 #include "common/logger.h"
14 NotificationManager* NotificationManager::GetInstance() {
15 static NotificationManager instance;
19 NotificationManager::NotificationManager() {
22 bool NotificationManager::Show(uint64_t tag,
23 const std::string& title,
24 const std::string& body,
25 const std::string& icon_path) {
26 auto found = keymapper_.find(tag);
27 if (found != keymapper_.end()) {
31 notification_h noti_h = NULL;
32 int ret = NOTIFICATION_ERROR_NONE;
33 noti_h = notification_new(
34 NOTIFICATION_TYPE_NOTI,
35 NOTIFICATION_GROUP_ID_DEFAULT,
36 NOTIFICATION_PRIV_ID_NONE);
38 LOGGER(ERROR) << "Can't create notification handle";
42 std::unique_ptr<std::remove_pointer<notification_h>::type,
43 decltype(notification_free)*>
44 auto_release {noti_h, notification_free};
46 // set notification title
47 ret = notification_set_text(
49 NOTIFICATION_TEXT_TYPE_TITLE,
52 NOTIFICATION_VARIABLE_TYPE_NONE);
53 if (ret != NOTIFICATION_ERROR_NONE) {
54 LOGGER(ERROR) << "Can't set title";
58 // set notification content
59 ret = notification_set_text(
61 NOTIFICATION_TEXT_TYPE_CONTENT,
64 NOTIFICATION_VARIABLE_TYPE_NONE);
65 if (ret != NOTIFICATION_ERROR_NONE) {
66 LOGGER(ERROR) << "Can't set content";
70 if (!icon_path.empty()) {
71 ret = notification_set_image(
73 NOTIFICATION_IMAGE_TYPE_ICON,
75 if (ret != NOTIFICATION_ERROR_NONE) {
76 LOGGER(ERROR) << "Can't set icon";
81 // insert notification
82 int platform_key = NOTIFICATION_PRIV_ID_NONE;
83 ret = notification_insert(noti_h, &platform_key);
84 if (ret != NOTIFICATION_ERROR_NONE) {
85 LOGGER(ERROR) << "Can't insert notification";
88 keymapper_[tag] = platform_key;
92 bool NotificationManager::Hide(uint64_t tag) {
93 auto found = keymapper_.find(tag);
94 if (found == keymapper_.end()) {
95 LOGGER(ERROR) << "Can't find notification";
98 notification_delete_by_priv_id(NULL,
99 NOTIFICATION_TYPE_NOTI,
101 keymapper_.erase(found);