Added new method to the NotificationManager Interface
[platform/framework/native/appfw.git] / src / app / FApp_NotificationManagerImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file                FApp_NotificationManagerImpl.cpp
19  * @brief               This is the placeholder for _NotificationManagerImpl class.
20  */
21
22 #include <FBaseSysLog.h>
23
24 #include <FBaseRt_LibraryImpl.h>
25
26 #include "FApp_NotificationManagerImpl.h"
27 #include "FApp_INotificationManagerImpl.h"
28 #include "FAppNotificationManager.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32
33 namespace
34 {
35
36 const wchar_t OSP_SHELL_SONAME[] = L"libosp-shell-core.so.1";
37
38 }
39
40 namespace Tizen { namespace App
41 {
42
43 _NotificationManagerImpl::_NotificationManagerImpl(void)
44 : __pNotiImpl(null)
45 {
46 }
47
48
49 _NotificationManagerImpl::~_NotificationManagerImpl(void)
50 {
51         if (__pNotiImpl)
52         {
53                 typedef void (*NotificationDeletor)(_INotificationManagerImpl*);
54
55                 NotificationDeletor pDeleter = reinterpret_cast<NotificationDeletor>(__lib.GetProcAddress(L"DeleteNotificationManagerInstance"));
56                 if (pDeleter)
57                 {
58                         (*pDeleter)(__pNotiImpl);
59                         SysLog(NID_APP, "NotificationManager stub deleted.");
60                 }
61         }
62 }
63
64
65 result
66 _NotificationManagerImpl::Construct(void)
67 {
68         result r = __lib.Construct(OSP_SHELL_SONAME, _LIBRARY_LOAD_OPTION_NODELETE | _LIBRARY_LOAD_OPTION_LAZY);
69         SysTryReturnResult(NID_APP, !IsFailed(r), E_SYSTEM, "A system error has occurred : %s.", GetErrorMessage(r));
70
71         typedef _INotificationManagerImpl* (*NotificationCreator)(void);
72         NotificationCreator pCreator = reinterpret_cast<NotificationCreator>(__lib.GetProcAddress(L"CreateNotificationManagerInstance"));
73         SysTryReturnResult(NID_APP, pCreator != null, E_SYSTEM, "No notification instance factory found.");
74
75         __pNotiImpl = (*pCreator)();
76
77         return r;
78 }
79
80
81 int
82 _NotificationManagerImpl::GetBadgeNumber(void) const
83 {
84         SysTryReturn(NID_APP, __pNotiImpl != null, -1, E_SYSTEM, "[E_SYSTEM] Notification interface error.");
85
86         int res = __pNotiImpl->GetBadgeNumber();
87         if (GetLastResult() == E_OPERATION_FAILED)
88         {
89                 SetLastResult(E_SUCCESS);
90                 return -1;
91         }
92         return res;
93 }
94
95
96 result
97 _NotificationManagerImpl::Notify(int badgeNumber) const
98 {
99         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
100         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "badgeNumber is less than 0.");
101
102         String messageText = String(L"");
103         String appMessage = String(L"");
104
105         return __pNotiImpl->Notify(messageText, badgeNumber, appMessage);
106 }
107
108
109 result
110 _NotificationManagerImpl::Notify(const String& messageText) const
111 {
112         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
113
114         String appMessage = String(L"");
115
116         return __pNotiImpl->Notify(messageText, -1, appMessage);
117 }
118
119
120 result
121 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber) const
122 {
123         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
124         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "badgeNumber is less than 0.");
125
126         String appMessage = String(L"");
127
128         return __pNotiImpl->Notify(messageText, badgeNumber, appMessage);
129 }
130
131
132 result
133 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments) const
134 {
135         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
136         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "badgeNumber is less than 0.");
137
138         return __pNotiImpl->Notify(messageText, badgeNumber, launchArguments);
139 }
140
141 int
142 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
143 {
144         SysTryReturn(NID_APP, __pNotiImpl != null, -1, E_SYSTEM, "[E_SYSTEM] Notification interface error.");
145
146
147         const int ret = __pNotiImpl->GetBadgeNumber(appId);
148         result r = GetLastResult();
149         if (r == E_APP_NOT_INSTALLED)
150         {
151                 SetLastResult(E_OBJ_NOT_FOUND);
152         }
153
154         if (GetLastResult() == E_OPERATION_FAILED)
155         {
156                 SetLastResult(E_SUCCESS);
157                 return -1;
158         }
159         return ret;
160 }
161
162
163 result
164 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, int badgeNumber) const
165 {
166         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
167         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
168
169         String messageText = String(L"");
170         String appMessage = String(L"");
171
172         return __pNotiImpl->NotifyByAppId(appId, messageText, -1, appMessage);
173 }
174
175
176 result
177 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText) const
178 {
179         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
180
181         return __pNotiImpl->NotifyByAppId(appId, messageText, -1, String(L""));
182 }
183
184
185 result
186 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText, int badgeNumber) const
187 {
188         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
189         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
190
191         return __pNotiImpl->NotifyByAppId(appId, messageText, badgeNumber, String(L""));
192 }
193
194
195 result
196 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText, const String& launchArguments) const
197 {
198         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
199         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
200                                                    "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
201
202         return __pNotiImpl->NotifyByAppId(appId, messageText, -1, launchArguments);
203 }
204
205
206 result
207 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText, int badgeNumber,
208                                                                                  const String& launchArguments) const
209 {
210         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
211         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
212
213         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
214                                                    "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
215
216         return __pNotiImpl->NotifyByAppId(appId, messageText, badgeNumber, launchArguments);
217 }
218
219
220 result
221 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText) const
222 {
223         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
224
225         return __pNotiImpl->NotifyOngoingActivity(messageText);
226 }
227
228
229 result
230 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments) const
231 {
232         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
233         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
234                                                    "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
235
236         return __pNotiImpl->NotifyOngoingActivity(messageText, launchArguments);
237 }
238
239
240 result
241 _NotificationManagerImpl::NotifyOngoingActivityOnBehalf(const AppId& appId, const String& messageText) const
242 {
243         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
244         SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
245
246         return __pNotiImpl->NotifyOngoingActivityByAppId(appId, messageText, String(L""));
247 }
248
249
250 result
251 _NotificationManagerImpl::NotifyOngoingActivityOnBehalf(const AppId& appId, const String& messageText,
252                                                                                                                 const String& launchArguments) const
253 {
254         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
255         SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
256
257         return __pNotiImpl->NotifyOngoingActivityByAppId(appId, messageText, launchArguments);
258 }
259
260
261 result
262 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
263 {
264         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
265
266         return __pNotiImpl->RemoveOngoingActivityNotification();
267 }
268
269
270 result
271 _NotificationManagerImpl::RemoveOngoingActivityNotificationOnBehalf(const AppId& appId)
272 {
273         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
274
275         return __pNotiImpl->RemoveOngoingActivityNotificationByAppId(appId);
276 }
277
278
279 result
280 _NotificationManagerImpl::RemoveNotification(void)
281 {
282         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
283
284         return __pNotiImpl->RemoveNotification();
285 }
286
287
288 result
289 _NotificationManagerImpl::RemoveNotificationOnBehalf(const AppId& appId)
290 {
291         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
292
293         return __pNotiImpl->RemoveNotificationByAppId(appId);
294 }
295
296 };
297 };    // Tizen::App