2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file FSysVibrator.cpp
19 * @brief This is the implementation file for Vibrator class.
25 #include <FSysVibrator.h>
27 #include <FBaseSysLog.h>
28 #include <FSec_AccessController.h>
29 #include <FSys_VibratorImpl.h>
31 using namespace Tizen::Base;
32 using namespace Tizen::Security;
34 namespace Tizen { namespace System
37 Vibrator::Vibrator(void)
38 : __pVibratorImpl(null)
42 Vibrator::~Vibrator(void)
46 delete __pVibratorImpl;
47 __pVibratorImpl = null;
52 Vibrator::Construct(void)
56 SysAssertf(__pVibratorImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
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.");
61 r = __pVibratorImpl->Construct();
62 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
69 Vibrator::Start(IntensityDurationVibrationPattern* patterns, int length, int repeatCount)
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."));
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.");
78 r = __pVibratorImpl->Start(patterns, length, repeatCount);
79 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
86 Vibrator::Start(long onPeriod, long offPeriod, int count, int level)
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."));
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.");
97 r = __pVibratorImpl->Start(onPeriod, offPeriod, count, level);
98 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
104 Vibrator::Start(long milliseconds, int level)
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."));
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.");
114 r = __pVibratorImpl->Start(milliseconds, 0, 1, level);
115 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
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."));
127 SysAssertf(__pVibratorImpl != null, "Not yet constructed. Construct() should be called before use.");
129 r = __pVibratorImpl->Stop();
130 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));