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