2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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.
19 * @brief This is the implementation file for Alarm class.
25 #include <FSysAlarm.h>
26 #include <FBaseSysLog.h>
27 #include <FSec_AccessController.h>
28 #include <FSys_AlarmImpl.h>
30 using namespace Tizen::Base;
31 using namespace Tizen::Security;
33 namespace Tizen { namespace System
48 Alarm::Construct(IAlarmEventListener& listener)
54 __pAlarmImpl = new (std::nothrow) _AlarmImpl(this);
55 SysTryReturnResult(NID_SYS, __pAlarmImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
57 __pAlarmImpl->Construct();
60 r = __pAlarmImpl->SetAlarmEventListener(&listener);
66 SysTryReturnResult(NID_SYS, !IsFailed(r), r, "Construction is failed");
72 Alarm::Set(const DateTime& startTime)
74 return this->Set(startTime, 0, null);
78 Alarm::Set(const DateTime& startTime, int period, const DateTime* pEndTime)
81 r = _AccessController::CheckUserPrivilege(_PRV_ALARM);
82 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
84 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
87 SysTryReturn(NID_SYS, startTime <= *pEndTime, E_INVALID_ARG, E_INVALID_ARG,
88 "[E_INVALID_ARG] end time(%ls) is early than start time(%ls)",
89 pEndTime->ToString().GetPointer(), startTime.ToString().GetPointer());
91 SysTryReturn(NID_SYS, period >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The period(%d) must be greater than 0.", period);
93 return __pAlarmImpl->Set(startTime, period, pEndTime);
100 r = _AccessController::CheckUserPrivilege(_PRV_ALARM);
101 SysTryReturn(NID_SYS, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, ("[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."));
103 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
104 r = __pAlarmImpl->Cancel();
109 Alarm::GetStartTime(void) const
111 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
112 return __pAlarmImpl->GetStartTime();
116 Alarm::GetPeriod(void) const
118 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
119 return __pAlarmImpl->GetPeriod();
123 Alarm::GetEndTime(void) const
125 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
126 return __pAlarmImpl->GetEndTime();