8c0b36cf5b5eff0949522d87fa516b17631fad77
[platform/framework/native/shell.git] / src / core / FShellNotificationManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FShellNotificationManager.cpp
20  * @brief               This is the placeholder for NotificationManager class.
21  */
22
23 #include <new>
24
25 #include <FBaseSysLog.h>
26 #include <FShellNotificationManager.h>
27 #include <FShellIBadgeEventListener.h>
28 #include <FSec_AccessController.h>
29 #include "FShell_NotificationManagerImpl.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::App;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Shell
36 {
37
38 NotificationManager::NotificationManager()
39         : __pNotificationManagerImpl(null)
40 {
41         //default constructor
42 }
43
44 NotificationManager::~NotificationManager()
45 {
46         delete __pNotificationManagerImpl;
47 }
48
49 result
50 NotificationManager::Construct(void)
51 {
52         SysAssertf(__pNotificationManagerImpl == null,
53                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
54
55         __pNotificationManagerImpl = new (std::nothrow) _NotificationManagerImpl();
56         SysTryReturnResult(NID_SHELL, __pNotificationManagerImpl != null, E_OUT_OF_MEMORY, "Allocation failed.");
57
58         return __pNotificationManagerImpl->Construct();
59 }
60
61 int
62 NotificationManager::GetBadgeNumber(void)
63 {
64         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
65
66         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
67         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
68
69         return __pNotificationManagerImpl->GetBadgeNumber();
70 }
71
72 result
73 NotificationManager::Notify(int badgeNumber)
74 {
75         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
76
77         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
78         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
79
80         return __pNotificationManagerImpl->Notify(badgeNumber);
81 }
82
83 result
84 NotificationManager::Notify(const String& messageText)
85 {
86         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
87
88         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
89         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
90
91         return __pNotificationManagerImpl->Notify(messageText);
92 }
93
94 result
95 NotificationManager::Notify(const String& messageText, int badgeNumber)
96 {
97         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
98
99         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
100         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
101
102         return __pNotificationManagerImpl->Notify(messageText, badgeNumber);
103 }
104
105 result
106 NotificationManager::Notify(const String& messageText, int badgeNumber, const String& launchArguments)
107 {
108         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
109
110         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
111         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
112
113         return __pNotificationManagerImpl->Notify(messageText, badgeNumber, launchArguments);
114 }
115
116 result
117 NotificationManager::Notify(const NotificationRequest& notiMessage)
118 {
119         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
120
121         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
122         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
123
124         return __pNotificationManagerImpl->NotifyMessageImpl(notiMessage);
125 }
126
127 result
128 NotificationManager::NotifyByAppId(const AppId& appId,const NotificationRequest& notiMessage)
129 {
130         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
131
132         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
133         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
134
135         return __pNotificationManagerImpl->NotifyMessageImpl(appId, notiMessage);
136 }
137
138 int
139 NotificationManager::GetBadgeNumberByAppId(const AppId& appId)
140 {
141         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
142
143         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
144         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
145
146         return __pNotificationManagerImpl->GetBadgeNumber(appId);
147 }
148
149 result
150 NotificationManager::NotifyOngoingActivity(const String& messageText)
151 {
152         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
153
154         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
155         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
156
157         return __pNotificationManagerImpl->NotifyOngoingActivity(messageText);
158 }
159
160 result
161 NotificationManager::NotifyOngoingActivity(const String& messageText, const String& launchArguments)
162 {
163         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
164
165         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
166         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
167
168
169         return __pNotificationManagerImpl->NotifyOngoingActivity(messageText, launchArguments);
170 }
171
172 result
173 NotificationManager::NotifyOngoingActivity(const NotificationRequest& notiMessage)
174 {
175         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
176
177         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
178         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
179
180         return __pNotificationManagerImpl->NotifyMessageImpl(notiMessage, true);
181 }
182
183 result
184 NotificationManager::NotifyOngoingActivityByAppId(const AppId& appId,const NotificationRequest& notiMessage)
185 {
186         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
187
188         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
189         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
190
191         return __pNotificationManagerImpl->NotifyMessageImpl(appId, notiMessage, true);
192 }
193
194 result
195 NotificationManager::RemoveOngoingActivityNotification(void)
196 {
197         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
198
199         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
200         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
201
202         return __pNotificationManagerImpl->RemoveOngoingActivityNotification();
203 }
204
205 result
206 NotificationManager::RemoveOngoingActivityNotificationByAppId(const AppId& appId)
207 {
208         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
209
210         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
211         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
212
213         return __pNotificationManagerImpl->RemoveOngoingActivityNotificationByAppId(appId);
214 }
215
216 result
217 NotificationManager::RemoveNotification(void)
218 {
219         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
220
221         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
222         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
223
224         return __pNotificationManagerImpl->RemoveNotification();
225 }
226
227 result
228 NotificationManager::RemoveNotificationByAppId(const AppId& appId)
229 {
230         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
231
232         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION, _PRV_NOTIFICATIONMANAGER);
233         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
234
235         return __pNotificationManagerImpl->RemoveNotificationByAppId(appId);
236 }
237
238
239 result
240 NotificationManager::NotifyTextMessage(const String& messageText)
241 {
242         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
243
244         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
245         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
246
247         return __pNotificationManagerImpl->NotifyTextMessage(messageText);
248 }
249
250 result
251 NotificationManager::NotifyByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
252                                                                                 const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
253 {
254         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
255
256         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
257         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
258
259         return __pNotificationManagerImpl->NotifyByAppControl(operationId, pUriData, pDataType, pExtraData, request);
260 }
261
262 result
263 NotificationManager::NotifyOngoingActivityByAppControl(const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData, const Tizen::Base::String* pDataType,
264                                                                                                            const Tizen::Base::Collection::IMap* pExtraData, const NotificationRequest& request)
265 {
266         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
267
268         result r = _AccessController::CheckUserPrivilege(_PRV_NOTIFICATION);
269         SysTryReturnResult(NID_SHELL,  !IsFailed(r), E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
270
271         return __pNotificationManagerImpl->NotifyOngoingActivityByAppControl(operationId, pUriData, pDataType, pExtraData, request);
272 }
273
274 result
275 NotificationManager::AddBadgeEventListener(IBadgeEventListener& listener)
276 {
277         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
278
279         return __pNotificationManagerImpl->AddBadgeEventListener(listener);
280 }
281
282 result
283 NotificationManager::RemoveBadgeEventListener(IBadgeEventListener& listener)
284 {
285         SysAssertf(__pNotificationManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
286
287         return __pNotificationManagerImpl->RemoveBadgeEventListener(listener);
288 }
289
290 } }     // Tizen::Shell