2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FSysVibrator.cpp
20 * @brief This is the implementation file for Vibrator class.
26 #include <FSysVibrator.h>
28 #include <FBaseSysLog.h>
29 #include <FSec_AccessController.h>
30 #include <FSys_VibratorImpl.h>
32 using namespace Tizen::Base;
33 using namespace Tizen::Security;
35 namespace Tizen { namespace System
38 Vibrator::Vibrator(void)
39 : __pVibratorImpl(null)
43 Vibrator::~Vibrator(void)
47 delete __pVibratorImpl;
48 __pVibratorImpl = null;
53 Vibrator::Construct(void)
57 SysAssertf(__pVibratorImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
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.");
62 r = __pVibratorImpl->Construct();
63 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
70 Vibrator::Start(IntensityDurationVibrationPattern* patterns, int length, int repeatCount)
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."));
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.");
79 r = __pVibratorImpl->Start(patterns, length, repeatCount);
80 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
87 Vibrator::Start(long onPeriod, long offPeriod, int count, int level)
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."));
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.");
98 r = __pVibratorImpl->Start(onPeriod, offPeriod, count, level);
99 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
105 Vibrator::Start(long milliseconds, int level)
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."));
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.");
115 r = __pVibratorImpl->Start(milliseconds, 0, 1, level);
116 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
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."));
128 SysAssertf(__pVibratorImpl != null, "Not yet constructed. Construct() should be called before use.");
130 r = __pVibratorImpl->Stop();
131 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));