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));
69 Vibrator::Start(long onPeriod, long offPeriod, int count, int level)
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, (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.");
80 r = __pVibratorImpl->Start(onPeriod, offPeriod, count, level);
81 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
87 Vibrator::Start(long milliseconds, 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, 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.");
97 r = __pVibratorImpl->Start(milliseconds, 0, 1, level);
98 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));
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.");
112 r = __pVibratorImpl->Stop();
113 SysTryReturn(NID_SYS, r == E_SUCCESS, r, r, "[%s] Error is occured", GetErrorMessage(r));