2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 * @brief This is the implementation file for Alarm class.
26 #include <FSysAlarm.h>
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include <FSys_AlarmImpl.h>
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
34 namespace Tizen { namespace System
49 Alarm::Construct(IAlarmEventListener& listener)
55 __pAlarmImpl = new (std::nothrow) _AlarmImpl(this);
56 SysTryReturnResult(NID_SYS, __pAlarmImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
58 __pAlarmImpl->Construct();
61 r = __pAlarmImpl->SetAlarmEventListener(&listener);
62 SysTryReturnResult(NID_SYS, !IsFailed(r), r, "Construction is failed");
68 Alarm::Set(const DateTime& startTime)
70 return this->Set(startTime, 0, null);
74 Alarm::Set(const DateTime& startTime, int period, const DateTime* pEndTime)
77 r = _AccessController::CheckUserPrivilege(_PRV_ALARM);
78 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."));
80 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
83 SysTryReturn(NID_SYS, startTime <= *pEndTime, E_INVALID_ARG, E_INVALID_ARG,
84 "[E_INVALID_ARG] end time(%ls) is early than start time(%ls)",
85 pEndTime->ToString().GetPointer(), startTime.ToString().GetPointer());
87 SysTryReturn(NID_SYS, period >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The period(%d) must be greater than 0.", period);
89 return __pAlarmImpl->Set(startTime, period, pEndTime);
96 r = _AccessController::CheckUserPrivilege(_PRV_ALARM);
97 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."));
99 SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
100 r = __pAlarmImpl->Cancel();
105 Alarm::GetStartTime(void) const
107 return __pAlarmImpl->GetStartTime();
111 Alarm::GetPeriod(void) const
113 return __pAlarmImpl->GetPeriod();
117 Alarm::GetEndTime(void) const
119 return __pAlarmImpl->GetEndTime();