Fixed the uts-app failed testcases
[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         return __pNotiImpl->GetBadgeNumber();
87 }
88
89
90 result
91 _NotificationManagerImpl::Notify(int badgeNumber) const
92 {
93         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
94         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "badgeNumber is less than 0.");
95
96         String messageText = String(L"");
97         String appMessage = String(L"");
98
99         return __pNotiImpl->Notify(messageText, badgeNumber, appMessage);
100 }
101
102
103 result
104 _NotificationManagerImpl::Notify(const String& messageText) const
105 {
106         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
107
108         String appMessage = String(L"");
109
110         return __pNotiImpl->Notify(messageText, -1, appMessage);
111 }
112
113
114 result
115 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber) const
116 {
117         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
118         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "badgeNumber is less than 0.");
119
120         String appMessage = String(L"");
121
122         return __pNotiImpl->Notify(messageText, badgeNumber, appMessage);
123 }
124
125
126 result
127 _NotificationManagerImpl::Notify(const String& messageText, int badgeNumber, const String& launchArguments) const
128 {
129         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
130         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "badgeNumber is less than 0.");
131
132         return __pNotiImpl->Notify(messageText, badgeNumber, launchArguments);
133 }
134
135 int
136 _NotificationManagerImpl::GetBadgeNumber(const AppId& appId) const
137 {
138         SysTryReturn(NID_APP, __pNotiImpl != null, -1, E_SYSTEM, "[E_SYSTEM] Notification interface error.");
139
140
141         const int ret = __pNotiImpl->GetBadgeNumber(appId);
142         result r = GetLastResult();
143         if (r == E_APP_NOT_INSTALLED)
144         {
145                 SetLastResult(E_OBJ_NOT_FOUND);
146         }
147
148         return ret;
149 }
150
151
152 result
153 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, int badgeNumber) const
154 {
155         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
156         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
157
158         String messageText = String(L"");
159         String appMessage = String(L"");
160
161         return __pNotiImpl->NotifyByAppId(appId, messageText, -1, appMessage);
162 }
163
164
165 result
166 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText) const
167 {
168         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
169
170         return __pNotiImpl->NotifyByAppId(appId, messageText, -1, String(L""));
171 }
172
173
174 result
175 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText, int badgeNumber) const
176 {
177         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
178         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
179
180         return __pNotiImpl->NotifyByAppId(appId, messageText, badgeNumber, String(L""));
181 }
182
183
184 result
185 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText, const String& launchArguments) const
186 {
187         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
188         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
189                                                    "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
190
191         return __pNotiImpl->NotifyByAppId(appId, messageText, -1, launchArguments);
192 }
193
194
195 result
196 _NotificationManagerImpl::NotifyOnBehalf(const AppId& appId, const String& messageText, int badgeNumber,
197                                                                                  const String& launchArguments) const
198 {
199         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
200         SysTryReturnResult(NID_APP, badgeNumber >= 0, E_INVALID_ARG, "BadgeNumber is less than 0.");
201
202         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
203                                                    "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
204
205         return __pNotiImpl->NotifyByAppId(appId, messageText, badgeNumber, launchArguments);
206 }
207
208
209 result
210 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText) const
211 {
212         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
213
214         return __pNotiImpl->NotifyOngoingActivity(messageText, String(L""));
215 }
216
217
218 result
219 _NotificationManagerImpl::NotifyOngoingActivity(const String& messageText, const String& launchArguments) const
220 {
221         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
222         SysTryReturnResult(NID_APP, launchArguments.GetLength() <= MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH, E_INVALID_ARG,
223                                                    "launchArguments is greater than MAX_NOTIFICATION_LAUNCH_ARGUMENTS_LENGTH.");
224
225         return __pNotiImpl->NotifyOngoingActivity(messageText, launchArguments);
226 }
227
228
229 result
230 _NotificationManagerImpl::NotifyOngoingActivityOnBehalf(const AppId& appId, const String& messageText) const
231 {
232         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
233         SysTryReturnResult(NID_APP, !messageText.IsEmpty(), E_INVALID_ARG, "MessageText is less than 0.");
234
235         return __pNotiImpl->NotifyOngoingActivityByAppId(appId, messageText, String(L""));
236 }
237
238
239 result
240 _NotificationManagerImpl::NotifyOngoingActivityOnBehalf(const AppId& appId, const String& messageText,
241                                                                                                                 const String& launchArguments) 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, launchArguments);
247 }
248
249
250 result
251 _NotificationManagerImpl::RemoveOngoingActivityNotification(void)
252 {
253         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
254
255         return __pNotiImpl->RemoveOngoingActivityNotification();
256 }
257
258
259 result
260 _NotificationManagerImpl::RemoveOngoingActivityNotificationOnBehalf(const AppId& appId)
261 {
262         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
263
264         return __pNotiImpl->RemoveOngoingActivityNotificationByAppId(appId);
265 }
266
267
268 result
269 _NotificationManagerImpl::RemoveNotification(void)
270 {
271         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
272
273         return __pNotiImpl->RemoveNotification();
274 }
275
276
277 result
278 _NotificationManagerImpl::RemoveNotificationOnBehalf(const AppId& appId)
279 {
280         SysTryReturnResult(NID_APP, __pNotiImpl != null, E_SYSTEM, "Notification interface error.");
281
282         return __pNotiImpl->RemoveNotificationByAppId(appId);
283 }
284
285 };
286 };    // Tizen::App