Add to read a custum feature key.
[platform/framework/native/appfw.git] / src / system / FSysAlarm.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                FSysAlarm.cpp
19  * @brief               This is the implementation file for Alarm class.
20  */
21
22
23 #include <new>
24
25 #include <FSysAlarm.h>
26 #include <FBaseSysLog.h>
27 #include <FSec_AccessController.h>
28 #include <FSys_AlarmImpl.h>
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Security;
32
33 namespace Tizen { namespace System
34 {
35
36 Alarm::Alarm(void)
37         : __pAlarmImpl(null)
38 {
39 }
40
41 Alarm::~Alarm(void)
42 {
43         delete __pAlarmImpl;
44         __pAlarmImpl = null;
45 }
46
47 result
48 Alarm::Construct(IAlarmEventListener& listener)
49 {
50         result r = E_SUCCESS;
51
52         if (!__pAlarmImpl)
53         {
54                 __pAlarmImpl = new (std::nothrow) _AlarmImpl(this);
55                 SysTryReturnResult(NID_SYS, __pAlarmImpl, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
56
57                 __pAlarmImpl->Construct();
58         }
59
60         r = __pAlarmImpl->SetAlarmEventListener(&listener);
61         if(r != E_SUCCESS)
62         {
63                 delete __pAlarmImpl;
64                 __pAlarmImpl = null;
65         }
66         SysTryReturnResult(NID_SYS, !IsFailed(r), r, "Construction is failed");
67
68         return E_SUCCESS;
69 }
70
71 result
72 Alarm::Set(const DateTime& startTime)
73 {
74         return this->Set(startTime, 0, null);
75 }
76
77 result
78 Alarm::Set(const DateTime& startTime, int period, const DateTime* pEndTime)
79 {
80         result r = E_SUCCESS;
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."));
83
84         SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
85         if(pEndTime != null)
86         {
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());
90         }
91         SysTryReturn(NID_SYS, period >= 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The period(%d) must be greater than 0.", period);
92
93         return __pAlarmImpl->Set(startTime, period, pEndTime);
94 }
95
96 result
97 Alarm::Cancel(void)
98 {
99         result r = E_SUCCESS;
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."));
102
103         SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
104         r = __pAlarmImpl->Cancel();
105         return r;
106 }
107
108 const DateTime
109 Alarm::GetStartTime(void) const
110 {
111         SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
112         return __pAlarmImpl->GetStartTime();
113 }
114
115 int
116 Alarm::GetPeriod(void) const
117 {
118         SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
119         return __pAlarmImpl->GetPeriod();
120 }
121
122 const DateTime*
123 Alarm::GetEndTime(void) const
124 {
125         SysAssertf(__pAlarmImpl != null, "Not yet constructed. Construct() should be called before use.");
126         return __pAlarmImpl->GetEndTime();
127 }
128
129 } } // Tizen::System