Fix prevent issue
[platform/framework/native/appfw.git] / src / system / FSysVibrator.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                FSysVibrator.cpp
19  * @brief               This is the implementation file for Vibrator class.
20  */
21
22
23 #include <new>
24
25 #include <FSysVibrator.h>
26
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include <FSys_VibratorImpl.h>
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace System
35 {
36
37 Vibrator::Vibrator(void)
38         : __pVibratorImpl(null)
39 {
40 }
41
42 Vibrator::~Vibrator(void)
43 {
44         if (__pVibratorImpl)
45         {
46                 delete __pVibratorImpl;
47                 __pVibratorImpl = null;
48         }
49 }
50
51 result
52 Vibrator::Construct(void)
53 {
54         result r = E_SUCCESS;
55
56         SysAssertf(__pVibratorImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
57
58         __pVibratorImpl = new (std::nothrow) _VibratorImpl();
59         SysTryReturn(NID_SYS, __pVibratorImpl != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
60
61         r = __pVibratorImpl->Construct();
62         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
63
64         return r;
65 }
66
67
68 result
69 Vibrator::Start(IntensityDurationVibrationPattern* patterns, int length, int repeatCount)
70 {
71         result r = E_SUCCESS;
72         r = _AccessController::CheckUserPrivilege(_PRV_VIBRATOR);
73         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."));
74
75         SysAssertf(__pVibratorImpl != null, "Not yet constructed. Construct() should be called before use.");
76         SysTryReturn(NID_SYS, repeatCount > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Count is out of range.");
77
78         r = __pVibratorImpl->Start(patterns, length, repeatCount);
79         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
80
81         return r;
82 }
83
84
85 result
86 Vibrator::Start(long onPeriod, long offPeriod, int count, int level)
87 {
88         result r = E_SUCCESS;
89         r = _AccessController::CheckUserPrivilege(_PRV_VIBRATOR);
90         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."));
91
92         SysAssertf(__pVibratorImpl != null, "Not yet constructed. Construct() should be called before use.");
93         SysTryReturn(NID_SYS, (onPeriod > 0) && (offPeriod >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Period is out of range.");
94         SysTryReturn(NID_SYS, count > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Count is out of range.");
95         SysTryReturn(NID_SYS, (level >= 0) && (level <= 100), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Level is out of range.");
96
97         r = __pVibratorImpl->Start(onPeriod, offPeriod, count, level);
98         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
99
100         return r;
101 }
102
103 result
104 Vibrator::Start(long milliseconds, int level)
105 {
106         result r = E_SUCCESS;
107         r = _AccessController::CheckUserPrivilege(_PRV_VIBRATOR);
108         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."));
109
110         SysAssertf(__pVibratorImpl != null, "Not yet constructed. Construct() should be called before use.");
111         SysTryReturn(NID_SYS, milliseconds > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Time is out of range.");
112         SysTryReturn(NID_SYS, (level >= 0) && (level <= 100), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Level is out of range.");
113
114         r = __pVibratorImpl->Start(milliseconds, 0, 1, level);
115         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
116
117         return r;
118 }
119
120 result
121 Vibrator::Stop(void)
122 {
123         result r = E_SUCCESS;
124         r = _AccessController::CheckUserPrivilege(_PRV_VIBRATOR);
125         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."));
126
127         SysAssertf(__pVibratorImpl != null, "Not yet constructed. Construct() should be called before use.");
128
129         r = __pVibratorImpl->Stop();
130         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
131
132         return r;
133 }
134
135 } } // Tizen::System