Merge "Add Setting feature on system-server lib" into tizen_2.2
[platform/framework/native/appfw.git] / src / system / FSys_AlarmManager.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                FSys_AlarmManager.cpp
19  * @brief               This is the implementation file for _AlarmManager class.
20  */
21
22 #include <unique_ptr.h>
23
24 #include <appfw/app.h>
25 #include <alarm.h>
26 #include <appsvc/appsvc.h>
27
28 #include <FBaseSysLog.h>
29 #include <FSysSystemTime.h>
30
31 #include <FBase_NativeError.h>
32 #include <FAppApp.h>
33 #include <FBase_StringConverter.h>
34
35 #include "inc/FSys_AlarmManager.h"
36
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Io;
41
42 namespace Tizen { namespace System
43 {
44 static const long _SECOND_OF_MINUTE = 60;
45
46 _AlarmManager* _AlarmManager::__pAlarmManager = null;
47
48 _AlarmManager::_AlarmManager()
49         : __pAlarmHashMap(null)
50 {
51         result r = E_SUCCESS;
52         int ret = pthread_mutex_init(&__lock, null);
53         SysTryCatch(NID_SYS, ret == 0, r = E_SYSTEM, E_SYSTEM, "It is failed to init mutex.");
54
55         __alarmList.Construct();
56
57         if (!__pAlarmHashMap)
58         {
59                 __pAlarmHashMap = new (std::nothrow) MultiHashMap();
60                 SysTryCatch(NID_SYS, __pAlarmHashMap != null, r = E_SYSTEM, E_SYSTEM, "__pAlarmHashMap should not be null");
61
62                 r = __pAlarmHashMap->Construct();
63                 SysTryCatch(NID_SYS, r == E_SUCCESS, r= E_SYSTEM, E_SYSTEM, "[%s] Propagated.", GetErrorMessage(r));
64         }
65
66         //Checks for any alarm existence
67         alarm_cancel_all();
68
69 CATCH:
70         SetLastResult(r);
71 }
72
73 _AlarmManager::~_AlarmManager()
74 {
75         int ret = pthread_mutex_destroy(&__lock);
76         if(ret != 0)
77         {
78                 SysLogException(NID_SYS, E_SYSTEM, "It is failed to destroy mutex.");
79         }
80
81         delete __pAlarmHashMap;
82         __pAlarmHashMap = null;
83
84         //Cancel all the alarms before exiting
85         alarm_cancel_all();
86 }
87
88 _AlarmManager*
89 _AlarmManager::GetInstance(void)
90 {
91         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
92         if(__pAlarmManager == null)
93         {
94                 pthread_once(&onceBlock, InitSingleton);
95         }
96         return __pAlarmManager;
97 }
98
99 void
100 _AlarmManager::InitSingleton(void)
101 {
102         _AlarmManager* pAlarmManager = new (std::nothrow) _AlarmManager();
103         SysTryReturnVoidResult(NID_SYS, pAlarmManager, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.",
104                                                    GetErrorMessage(E_OUT_OF_MEMORY));
105
106         __pAlarmManager = pAlarmManager;
107         std::atexit(DestroySingleton);
108 }
109
110 void
111 _AlarmManager::DestroySingleton(void)
112 {
113         delete __pAlarmManager;
114 }
115
116 int
117 _AlarmManager::ReserveAlarm(Tizen::Base::String appId, Tizen::Base::DateTime startTime, int period)
118 {
119         int reservedAlarmId = -1;
120         result r = E_SUCCESS;
121
122         int ret = 0;
123         service_h service;
124
125         SysLog(NID_SYS, "Reserve time is %d/%d/%d %d:%d:%d", startTime.GetYear(), startTime.GetMonth(), startTime.GetDay(), startTime.GetHour(), startTime.GetMinute(), startTime.GetSecond());
126
127         bundle* pBundle = null;
128         alarm_entry_t* pAlarmInfo = null;
129         alarm_date_t expireTime = {0,};
130
131         std::unique_ptr<char[]> pId(_StringConverter::CopyToCharArrayN(appId));
132
133         pBundle = bundle_create();
134         SysTryCatch(NID_SYS, pBundle != null, r = E_SYSTEM, r, "It is failed to create bundle");
135
136         ret = appsvc_set_operation(pBundle,"osp.operation.ALARM");
137         SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set operation");
138
139         ret = appsvc_set_appid(pBundle, (const char*)(pId.get()));
140         SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set appid for %ls", appId.GetPointer());
141
142         pAlarmInfo = alarmmgr_create_alarm();
143         SysTryCatch(NID_SYS, pAlarmInfo != null, r = E_SYSTEM, r, "It is failed to create alarm entry");
144
145         expireTime.year = startTime.GetYear();
146         expireTime.month = startTime.GetMonth();
147         expireTime.day = startTime.GetDay();
148         expireTime.hour = startTime.GetHour();
149         expireTime.min = startTime.GetMinute();
150         expireTime.sec = startTime.GetSecond();
151
152         ret = alarmmgr_set_time(pAlarmInfo, expireTime);
153         SysTryCatch(NID_SYS, ret == ALARMMGR_RESULT_SUCCESS, r = E_SYSTEM, r, "It is failed to set new alarm time");
154
155         if(period > 0)
156         {
157                 SysLog(NID_SYS, "It is repeated alarm and period time is %d minutes", period);
158                 ret = alarmmgr_set_repeat_mode(pAlarmInfo, ALARM_REPEAT_MODE_REPEAT, period * _SECOND_OF_MINUTE);
159                 SysTryCatch(NID_SYS, ret == ALARMMGR_RESULT_SUCCESS, r = E_SYSTEM, r, "It is failed to set repeat mode");
160         }
161
162         ret = alarmmgr_set_type(pAlarmInfo, ALARM_TYPE_NOLAUNCH);
163         SysTryCatch(NID_SYS, ret == ALARMMGR_RESULT_SUCCESS, r = E_SYSTEM, r, "It is failed to set repeat mode");
164
165         ret = alarmmgr_add_alarm_appsvc_with_localtime(pAlarmInfo,(void *)pBundle, &reservedAlarmId);
166         SysTryCatch(NID_SYS, ret == ALARMMGR_RESULT_SUCCESS, r = E_SYSTEM, r, "Alarm creation failed!!! Alrmgr error code is %d", ret);
167
168 CATCH:
169         if(r == E_SYSTEM)
170         {
171                 reservedAlarmId = -1;
172         }
173         if(pAlarmInfo != null)
174         {
175                 alarmmgr_free_alarm(pAlarmInfo);
176         }
177
178         if(pBundle != null)
179         {
180                 bundle_free(pBundle);
181         }
182
183         return reservedAlarmId;
184 }
185
186 result
187 _AlarmManager::AddAlarmList(int alarmId, int period, String appId, DateTime* endTime)
188 {
189         result r = E_SUCCESS;
190
191         SysTryReturnResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
192         SysLog(NID_SYS, "New Alarm Id is added (%d, %d, %ls)", alarmId, period, appId.GetPointer());
193
194         Integer* reservedAlarmId = null;
195         Integer* alarmPeriod = null;
196         String* alarmAppId = null;
197
198         Integer* reverseAlarmId = null;
199         String* reverseAppId = null;
200
201         reservedAlarmId = new (std::nothrow) Integer(alarmId);
202         SysTryCatch(NID_SYS, reservedAlarmId != null, r = E_SYSTEM, E_SYSTEM, "reservedAlarmId should not be null");
203
204         alarmPeriod = new (std::nothrow) Integer(period);
205         SysTryCatch(NID_SYS, alarmPeriod != null, r = E_SYSTEM, E_SYSTEM, "alarmPeriod should not be null");
206
207         alarmAppId = new (std::nothrow) String(appId);
208         SysTryCatch(NID_SYS, alarmAppId != null, r = E_SYSTEM, E_SYSTEM, "alarmAppId should not be null");
209
210         //Forward
211         r = __pAlarmHashMap->Add(*reservedAlarmId, *alarmAppId);
212         SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm app id on the alarm list");
213
214         r = __pAlarmHashMap->Add(*reservedAlarmId, *alarmPeriod);
215         SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm period on the alarm list");
216
217         if(endTime != null)
218         {
219                 DateTime* alarmEndTime = new DateTime(*endTime);
220
221                 SysLog(NID_SYS, "Endtime exists %d:%d:%d", alarmEndTime->GetHour(), alarmEndTime->GetMinute(), alarmEndTime->GetSecond());
222                 r = __pAlarmHashMap->Add(*reservedAlarmId, *alarmEndTime);
223                 SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm endtime on the alarm list");
224         }
225
226         //Reverse
227         reverseAlarmId = new (std::nothrow) Integer(alarmId);
228         SysTryCatch(NID_SYS, reverseAlarmId != null, r = E_SYSTEM, E_SYSTEM, "reverseAlarmId should not be null");
229
230         reverseAppId = new (std::nothrow) String(appId);
231         SysTryCatch(NID_SYS, reverseAppId != null, r = E_SYSTEM, E_SYSTEM, "reverseAppId should not be null");
232
233         r = __pAlarmHashMap->Add(*reverseAppId, *reverseAlarmId);
234         SysTryCatch(NID_SYS, r == E_SUCCESS, r, r, "Fail to add new alarm on the alarm list");
235
236 CATCH:
237         if(r != E_SUCCESS)
238         {
239                 if(reservedAlarmId != null)
240                 {
241                         __pAlarmHashMap->Remove(*reservedAlarmId, false);
242                         delete reservedAlarmId;
243                 }
244
245                 if(alarmPeriod != null)
246                 {
247                         delete alarmPeriod;
248                 }
249
250                 if(alarmAppId != null)
251                 {
252                         delete alarmAppId;
253                 }
254
255                 if(reverseAppId != null)
256                 {
257                         __pAlarmHashMap->Remove(*reverseAppId, false);
258                         delete reverseAppId;
259                 }
260
261                 if(reverseAlarmId != null)
262                 {
263                         delete reverseAlarmId;
264                 }
265         }
266         return r;
267 }
268
269 result
270 _AlarmManager::RemoveAlarmList(int alarmId)
271 {
272         result r = E_SUCCESS;
273         Integer requiredAlarmId(alarmId);
274         std::unique_ptr<IEnumerator>pValueEnum(null);
275
276         SysTryReturnResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
277
278         alarm_cancel(alarmId);
279         SysLog(NID_SYS, "AlarmId %d disarms the timer.", alarmId);
280
281         pValueEnum.reset(__pAlarmHashMap->GetValuesN(requiredAlarmId));
282
283         if(pValueEnum != null)
284         {
285                 SysLog(NID_SYS, "Reserved Alarms are exist");
286                 String* alarmAppId = null;
287                 r = pValueEnum->MoveNext();
288                 SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "Reserved Alarm List is not valid.");
289                 alarmAppId = static_cast< String* >(pValueEnum->GetCurrent());
290
291                 if(alarmAppId != null)
292                 {
293                         SysLog(NID_SYS, "Alarm AppId is %S", alarmAppId->GetPointer());
294                         std::unique_ptr<IEnumerator>pAlarmEnum(__pAlarmHashMap->GetValuesN(*alarmAppId));
295                         if(pAlarmEnum != null)
296                         {
297                                 while(pAlarmEnum->MoveNext() == E_SUCCESS)
298                                 {
299                                         Integer* reverseAlarmId = static_cast< Integer* >(pAlarmEnum->GetCurrent());
300                                         if(reverseAlarmId != null)
301                                         {
302                                                 SysLog(NID_SYS, "Reserved Alarm is %d", reverseAlarmId->ToInt());
303                                                 if(reverseAlarmId->ToInt() == alarmId)
304                                                 {
305                                                         SysLog(NID_SYS, "Remove reservedAlarmId for reverse look-up");
306                                                          __pAlarmHashMap->Remove(*alarmAppId, *reverseAlarmId);
307                                                         delete reverseAlarmId;
308                                                         break;
309                                                 }
310                                         }
311                                 }
312                         }
313
314                         int count = 0;
315                         __pAlarmHashMap->GetCount(*alarmAppId, count);
316                         if(count == 0)
317                         {
318                                 SysLog(NID_SYS, "There is no more reserved alarm for AppId:%S", alarmAppId->GetPointer());
319                                 __pAlarmHashMap->Remove(*alarmAppId, true);
320                         }
321                 }
322         }
323         r = __pAlarmHashMap->Remove(requiredAlarmId, true);
324
325         return r;
326 }
327
328 result
329 _AlarmManager::RemoveAlarmList(String appId)
330 {
331         result r = E_SUCCESS;
332         Integer requiredAlarmId;
333         IEnumerator *pValueEnum = null;
334
335         SysTryReturnResult(NID_SYS, __pAlarmHashMap != null, E_SYSTEM, "Alarm list does not initialized");
336         pValueEnum = __pAlarmHashMap->GetValuesN(appId);
337
338         if(pValueEnum != null)
339         {
340                 SysLog(NID_SYS, "Reserved Alarms are exist for AppId:%S", appId.GetPointer());
341                 while(pValueEnum->MoveNext() == E_SUCCESS)
342                 {
343                         Integer* reverseAlarmId = static_cast< Integer* >(pValueEnum->GetCurrent());
344                         if(reverseAlarmId != null)
345                         {
346                                 SysLog(NID_SYS, "Reserved AlarmId is %d", reverseAlarmId->ToInt());
347                                 alarm_cancel(reverseAlarmId->ToInt());
348                                 __pAlarmHashMap->Remove(*reverseAlarmId, true);
349                         }
350                 }
351                 delete pValueEnum;
352         }
353         r = __pAlarmHashMap->Remove(appId, true);
354
355         return r;
356 }
357
358 result
359 _AlarmManager::RegisterAlarm(_AlarmImpl* pAlarmImpl)
360 {
361         SysTryReturnResult(NID_SYS, pAlarmImpl != null, E_INVALID_ARG, "There is no alarmImpl.");
362         Integer alarmId(pAlarmImpl->__alarmId.value);
363         SysTryReturnResult(NID_SYS, __alarmList.ContainsKey(alarmId) == false, E_OBJ_ALREADY_EXIST, "Required Alarm[%d] is already registered.", pAlarmImpl->__alarmId.value);
364
365         result r = E_SUCCESS;
366         ArrayList requestMessage;
367         ArrayList responseMessage;
368
369         String startTimeStr;
370         String periodStr;
371         String endTimeStr;
372         String appId;
373
374         int reservedAlarmId = 0;
375         int period = pAlarmImpl->GetPeriod();
376         int ret = 0;
377         Tizen::App::App* pApp = null;
378  
379         DateTime currentTime;
380         DateTime startTime = pAlarmImpl->GetStartTime();
381         const DateTime* pEndTime = pAlarmImpl->GetEndTime();
382         DateTime endTime;
383
384         //Argument check
385         startTime.AddMilliseconds(-1 * startTime.GetMillisecond());
386         r = SystemTime::GetCurrentTime(WALL_TIME, currentTime);
387         currentTime.AddMilliseconds(-1 * currentTime.GetMillisecond());
388
389         SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_SYSTEM, "It is failed to get current time.");
390         SysTryReturnResult(NID_SYS, DateTime::Compare(currentTime, startTime) < 0, E_INVALID_ARG, "Designated start time has to be greater than current time.");
391         SysTryReturnResult(NID_SYS, period > -1, E_INVALID_ARG, "Period has to greater than -1");
392
393         ret = pthread_mutex_lock(&__lock);
394         SysTryCatch(NID_SYS, ret == 0, r = E_INVALID_ARG, r, "It is failed to lock mutex.");
395
396         if(pEndTime != null)
397         {
398                 endTime = *pEndTime;
399                 endTime.AddMilliseconds(-1 * endTime.GetMillisecond());
400
401                 SysTryCatch(NID_SYS, DateTime::Compare(startTime, endTime) < 0, r = E_INVALID_ARG, r, "Designated end time is less than start time.");
402         }
403         //End Alarm validation check
404
405         pApp = Tizen::App::App::GetInstance();
406         SysTryCatch(NID_SYS, pApp != null, r = E_SYSTEM, r, "[%s] A system error has been occurred. App::GetInstance() failed.", GetErrorMessage(E_SYSTEM));
407         appId = pApp->GetAppId();
408
409         reservedAlarmId = ReserveAlarm(appId, startTime, period);
410         SysTryCatch(NID_SYS, reservedAlarmId != -1, r = E_SYSTEM, r, "It is failed to register alarm.");
411
412         SysLog(NID_SYS, "Reserved AppId %ls, alarmId: %d", appId.GetPointer(), reservedAlarmId);
413
414         if(pEndTime == null)
415         {
416                 r = AddAlarmList(reservedAlarmId, period, appId, null);
417         }
418         else
419         {
420                 r = AddAlarmList(reservedAlarmId, period, appId, (DateTime*)(&endTime));
421         }
422         SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add new alarm on the alarm list.");
423
424         pAlarmImpl->__alarmId.value = reservedAlarmId;
425         r = __alarmList.Add(&(pAlarmImpl->__alarmId), pAlarmImpl);
426
427 CATCH:
428         ret = pthread_mutex_unlock(&__lock);
429         SysTryReturnResult(NID_SYS, ret == 0, E_INVALID_ARG, "It is failed to unlock mutex.");
430         return r;
431 }
432
433 result
434 _AlarmManager::UnregisterAlarm(_AlarmImpl* pAlarmImpl)
435 {
436         result r = E_SUCCESS;
437         Integer alarmId;
438         int ret = 0;
439         SysLog(NID_SYS, "Alarm Cancel request");
440         SysTryCatch(NID_SYS, pAlarmImpl != null, r = E_INVALID_ARG, r, "There is no alarmImpl.");
441
442         ret = pthread_mutex_lock(&__lock);
443         SysTryCatch(NID_SYS, ret == 0, r = E_SYSTEM, r, "It is failed to lock mutex.");
444
445         alarmId.value = pAlarmImpl->__alarmId.value;
446         SysTryCatch(NID_SYS, __alarmList.ContainsKey(alarmId) == true, r = E_OBJ_NOT_FOUND, r, "There is no registered alarm.");
447
448         r = __alarmList.Remove(alarmId);
449         SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to remove reserved alarmImpl instance.");
450
451         r = RemoveAlarmList(alarmId.ToInt());
452         SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to remove reserved alarm list.");
453
454 CATCH:
455         ret = pthread_mutex_unlock(&__lock);
456         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to unlock mutex.");
457         return r;
458 }
459
460 result
461 _AlarmManager::UpdateAlarm(_AlarmImpl* pAlarmImpl)
462 {
463         result r = E_SUCCESS;
464         int ret = 0;
465         Integer alarmId;
466         SysTryCatch(NID_SYS, pAlarmImpl != null, r = E_INVALID_ARG, r, "There is no alarmImpl.");
467
468         ret = pthread_mutex_lock(&__lock);
469         SysTryCatch(NID_SYS, ret == 0, r = E_SYSTEM, r, "It is failed to lock mutex.");
470
471         alarmId.value = pAlarmImpl->__alarmId.value;
472         SysTryCatch(NID_SYS, __alarmList.ContainsKey(alarmId) == true, r = E_OBJ_NOT_FOUND, r, "There is no registered alarm.");
473
474         r = UnregisterAlarm(pAlarmImpl);
475         SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to unregister reserved alarm list.");
476
477         r = RegisterAlarm(pAlarmImpl);
478 CATCH:
479         ret = pthread_mutex_unlock(&__lock);
480         SysTryReturnResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to unlock mutex.");
481         return r;
482 }
483
484 void
485 _AlarmManager::OnAlarmExpired(int alarmId)
486 {
487         result r = E_SUCCESS;
488         int ret = 0;
489         String* pAppId = null;
490         Integer* pPeriod = null;
491         String alarmAppId;
492         std::unique_ptr<IEnumerator> pValueEnum(null);
493         Integer reservedAlarmId(alarmId);
494         DateTime* endTime = null;
495         _AlarmImpl* pAlarmImpl = null;
496
497         SysTryCatch(NID_SYS, __pAlarmHashMap != null, r = E_SYSTEM, r, "Alarm list does not initialized");
498         pValueEnum.reset(__pAlarmHashMap->GetValuesN(reservedAlarmId));
499
500         SysLog(NID_SYS, "Alarm expire event is delivered. alarm id is %d", alarmId);
501
502         pAlarmImpl = (_AlarmImpl*)__alarmList.GetValue(reservedAlarmId);
503         if(pAlarmImpl == null)
504         {
505                 SysLog(NID_SYS, "pAlarmImpl of reserved alarm[%d] is not found.", alarmId);
506         }
507
508         if(pValueEnum != null)
509         {
510                 ret = pthread_mutex_lock(&__lock);
511                 SysTryCatch(NID_SYS, ret == 0, r = E_SYSTEM, r, "It is failed to lock mutex.");
512
513                 SysLog(NID_SYS, "Matching Alarm Id is %d \n", alarmId);
514                 r = pValueEnum->MoveNext();
515                 SysTryCatch(NID_SYS,  r == E_SUCCESS, r = E_SYSTEM, r, "Alarm enum value is not valid.");
516                 pAppId = static_cast< String* >(pValueEnum->GetCurrent());
517                 alarmAppId.Append(*pAppId);
518                 r = pValueEnum->MoveNext();
519                 pPeriod = static_cast< Integer* >(pValueEnum->GetCurrent());
520                 SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "Alarm enum value is not valid.");
521
522                 if(pValueEnum->MoveNext() == E_SUCCESS)
523                 {
524                         endTime = static_cast< DateTime* >(pValueEnum->GetCurrent());
525                 }
526
527                 SysLog(NID_SYS, "Reserved Alarm AppId:%ls, Period:%d\n", pAppId->GetPointer(), pPeriod->ToInt());
528
529                 if (pPeriod->ToInt() > 0)
530                 {
531                         if(endTime != null)
532                         {
533                                 DateTime currentTime;
534
535                                 SystemTime::GetCurrentTime(WALL_TIME, currentTime);
536                                 currentTime.AddMilliseconds(-1 * currentTime.GetMillisecond()); //Remove millisecond
537                                 currentTime.AddMinutes(pPeriod->ToInt());
538                                 SysLog(NID_SYS, "Next time[%d min]: %d:%d:%d:%d", pPeriod->ToInt(), currentTime.GetHour(), currentTime.GetMinute(), currentTime.GetSecond(), currentTime.GetMillisecond());
539                                 SysLog(NID_SYS, "Endtime exists %d:%d:%d:%d", endTime->GetHour(), endTime->GetMinute(), endTime->GetSecond(), endTime->GetMillisecond());
540
541                                 if (currentTime.CompareTo(*endTime) > 0)
542                                 {
543                                         SysLog(NID_SYS, "Next time is greater than end time.");
544                                         RemoveAlarmList(alarmId);
545                                         pValueEnum->Reset();
546
547                                         if(pAlarmImpl != null)
548                                         {
549                                                 pAlarmImpl->__alarmId.value = 0;
550                                         }
551                                 }
552                         }
553                 }
554                 else if (pPeriod->ToInt() == 0)
555                 {
556                         RemoveAlarmList(alarmId);
557
558                         if(pAlarmImpl != null)
559                         {
560                                 pAlarmImpl->__alarmId.value = 0;
561                         }
562                 }
563                 else
564                 {
565                         pValueEnum->Reset();
566                 }
567
568                 ret = pthread_mutex_unlock(&__lock);
569         }
570
571         if(pAlarmImpl != null)
572         {
573                 pAlarmImpl->OnAlarmExpired(alarmId);
574         }
575
576         if(__pAlarmHashMap->ContainsKey(reservedAlarmId) == false)
577         {
578                 ret = pthread_mutex_lock(&__lock);
579                 SysLog(NID_SYS, "Remove an alarm list[%d].", reservedAlarmId.value);
580                 r = __alarmList.Remove(reservedAlarmId);
581                 ret = pthread_mutex_unlock(&__lock);
582                 SetLastResult(r);
583         }
584
585 CATCH:
586         ret = pthread_mutex_unlock(&__lock);
587         SysTryReturnVoidResult(NID_SYS, ret == 0, E_SYSTEM, "It is failed to unlock mutex.");
588 }
589
590 } } // Tizen::System