2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "runtime/notification_manager.h"
19 #include <notification.h>
22 #include "common/logger.h"
26 NotificationManager* NotificationManager::GetInstance() {
27 static NotificationManager instance;
31 NotificationManager::NotificationManager() {
34 bool NotificationManager::Show(uint64_t tag,
35 const std::string& title,
36 const std::string& body,
37 const std::string& icon_path) {
38 auto found = keymapper_.find(tag);
39 if (found != keymapper_.end()) {
43 notification_h noti_h = NULL;
44 int ret = NOTIFICATION_ERROR_NONE;
45 noti_h = notification_new(
46 NOTIFICATION_TYPE_NOTI,
47 NOTIFICATION_GROUP_ID_DEFAULT,
48 NOTIFICATION_PRIV_ID_NONE);
50 LOGGER(ERROR) << "Can't create notification handle";
54 std::unique_ptr<std::remove_pointer<notification_h>::type,
55 decltype(notification_free)*>
56 auto_release {noti_h, notification_free};
58 // set notification title
59 ret = notification_set_text(
61 NOTIFICATION_TEXT_TYPE_TITLE,
64 NOTIFICATION_VARIABLE_TYPE_NONE);
65 if (ret != NOTIFICATION_ERROR_NONE) {
66 LOGGER(ERROR) << "Can't set title";
70 // set notification content
71 ret = notification_set_text(
73 NOTIFICATION_TEXT_TYPE_CONTENT,
76 NOTIFICATION_VARIABLE_TYPE_NONE);
77 if (ret != NOTIFICATION_ERROR_NONE) {
78 LOGGER(ERROR) << "Can't set content";
82 if (!icon_path.empty()) {
83 ret = notification_set_image(
85 NOTIFICATION_IMAGE_TYPE_ICON,
87 if (ret != NOTIFICATION_ERROR_NONE) {
88 LOGGER(ERROR) << "Can't set icon";
93 // insert notification
94 int platform_key = NOTIFICATION_PRIV_ID_NONE;
95 ret = notification_insert(noti_h, &platform_key);
96 if (ret != NOTIFICATION_ERROR_NONE) {
97 LOGGER(ERROR) << "Can't insert notification";
100 keymapper_[tag] = platform_key;
104 bool NotificationManager::Hide(uint64_t tag) {
105 auto found = keymapper_.find(tag);
106 if (found == keymapper_.end()) {
107 LOGGER(ERROR) << "Can't find notification";
110 notification_delete_by_priv_id(NULL,
111 NOTIFICATION_TYPE_NOTI,
113 keymapper_.erase(found);