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);
61 SysTryReturnResult(NID_SYS, !IsFailed(r), r, "Construction is failed");
67 Alarm::Set(const DateTime& startTime)
69 return this->Set(startTime, 0, null);
73 Alarm::Set(const DateTime& startTime, int period, const DateTime* pEndTime)
76 r = _AccessController::CheckUserPrivilege(_PRV_ALARM);
77 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."));
79 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
82 SysTryReturn(NID_SYS, startTime <= *pEndTime, E_INVALID_ARG, E_INVALID_ARG,
83 "[E_INVALID_ARG] end time(%ls) is early than start time(%ls)",
84 pEndTime->ToString().GetPointer(), startTime.ToString().GetPointer());
86 SysTryReturn(NID_SYS, period >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The period(%d) must be greater than 0.", period);
88 return __pAlarmImpl->Set(startTime, period, pEndTime);
95 r = _AccessController::CheckUserPrivilege(_PRV_ALARM);
96 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."));
98 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
99 r = __pAlarmImpl->Cancel();
104 Alarm::GetStartTime(void) const
106 return __pAlarmImpl->GetStartTime();
110 Alarm::GetPeriod(void) const
112 return __pAlarmImpl->GetPeriod();
116 Alarm::GetEndTime(void) const
118 return __pAlarmImpl->GetEndTime();