1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef VIBRATOR_THREAD_H 17 #define VIBRATOR_THREAD_H 18 19 #include <thread> 20 21 #include "thread_ex.h" 22 23 #include "vibrator_hdi_connection.h" 24 25 namespace OHOS { 26 namespace Sensors { 27 class VibratorThread : public Thread { 28 public: 29 void UpdateVibratorEffect(const VibrateInfo &vibrateInfo); 30 VibrateInfo GetCurrentVibrateInfo(); 31 void SetExitStatus(bool status); 32 void WakeUp(); 33 34 protected: 35 virtual bool Run(); 36 37 private: 38 int32_t PlayOnce(const VibrateInfo &info); 39 int32_t PlayEffect(const VibrateInfo &info); 40 int32_t PlayCustomByHdHptic(const VibrateInfo &info); 41 void HandleMultipleVibrations(); 42 #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR 43 int32_t PlayCustomByCompositeEffect(const VibrateInfo &info); 44 int32_t PlayCompositeEffect(const VibrateInfo &info, const HdfCompositeEffect &hdfCompositeEffect); 45 #endif // HDF_DRIVERS_INTERFACE_VIBRATOR 46 std::mutex currentVibrationMutex_; 47 VibrateInfo currentVibration_; 48 std::mutex vibrateMutex_; 49 std::condition_variable cv_; 50 std::atomic<bool> exitFlag_ = false; 51 }; 52 #define VibratorDevice VibratorHdiConnection::GetInstance() 53 } // namespace Sensors 54 } // namespace OHOS 55 #endif // VIBRATOR_THREAD_H