sync with tizen_2.0
[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 result
69 Vibrator::Start(long onPeriod, long offPeriod, int count, int level)
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, (onPeriod > 0) && (offPeriod >= 0), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Period is out of range.");
77         SysTryReturn(NID_SYS, count > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Count is out of range.");
78         SysTryReturn(NID_SYS, (level >= 0) && (level <= 100), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Level is out of range.");
79
80         r = __pVibratorImpl->Start(onPeriod, offPeriod, count, level);
81         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
82
83         return r;
84 }
85
86 result
87 Vibrator::Start(long milliseconds, 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, milliseconds > 0, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Time 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(milliseconds, 0, 1, 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::Stop(void)
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
112         r = __pVibratorImpl->Stop();
113         SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
114
115         return r;
116 }
117
118 } } // Tizen::System