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/browser/notification_manager.h"
19 #include <notification.h>
20 #include <notification_internal.h>
24 #include "common/logger.h"
28 NotificationManager* NotificationManager::GetInstance() {
29 static NotificationManager instance;
33 NotificationManager::NotificationManager() {
36 bool NotificationManager::Show(uint64_t tag,
37 const std::string& title,
38 const std::string& body,
39 const std::string& icon_path) {
40 auto found = keymapper_.find(tag);
41 if (found != keymapper_.end()) {
45 notification_h noti_h = NULL;
46 int ret = NOTIFICATION_ERROR_NONE;
47 noti_h = notification_new(
48 NOTIFICATION_TYPE_NOTI,
49 NOTIFICATION_GROUP_ID_DEFAULT,
50 NOTIFICATION_PRIV_ID_NONE);
52 LOGGER(ERROR) << "Can't create notification handle";
56 std::unique_ptr<std::remove_pointer<notification_h>::type,
57 decltype(notification_free)*>
58 auto_release {noti_h, notification_free};
60 // set notification title
61 ret = notification_set_text(
63 NOTIFICATION_TEXT_TYPE_TITLE,
66 NOTIFICATION_VARIABLE_TYPE_NONE);
67 if (ret != NOTIFICATION_ERROR_NONE) {
68 LOGGER(ERROR) << "Can't set title";
72 // set notification content
73 ret = notification_set_text(
75 NOTIFICATION_TEXT_TYPE_CONTENT,
78 NOTIFICATION_VARIABLE_TYPE_NONE);
79 if (ret != NOTIFICATION_ERROR_NONE) {
80 LOGGER(ERROR) << "Can't set content";
84 if (!icon_path.empty()) {
85 ret = notification_set_image(
87 NOTIFICATION_IMAGE_TYPE_ICON,
89 if (ret != NOTIFICATION_ERROR_NONE) {
90 LOGGER(ERROR) << "Can't set icon";
95 // insert notification
96 int platform_key = NOTIFICATION_PRIV_ID_NONE;
97 ret = notification_insert(noti_h, &platform_key);
98 if (ret != NOTIFICATION_ERROR_NONE) {
99 LOGGER(ERROR) << "Can't insert notification";
102 keymapper_[tag] = platform_key;
106 bool NotificationManager::Hide(uint64_t tag) {
107 auto found = keymapper_.find(tag);
108 if (found == keymapper_.end()) {
109 LOGGER(ERROR) << "Can't find notification";
112 notification_delete_by_priv_id(NULL,
113 NOTIFICATION_TYPE_NOTI,
115 keymapper_.erase(found);
119 } // namespace runtime