1 /* 2 * Copyright (c) 2023 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 #ifndef INTELL_VOICE_TRIGGER_MANAGER_H 16 #define INTELL_VOICE_TRIGGER_MANAGER_H 17 18 #include <map> 19 #include <memory> 20 #include <mutex> 21 #include "trigger_base_type.h" 22 23 namespace OHOS { 24 namespace IntellVoiceTrigger { 25 class TriggerService; 26 class TriggerDetector; 27 28 class TriggerManager { 29 public: 30 TriggerManager(); 31 ~TriggerManager(); 32 33 void UpdateModel(std::vector<uint8_t> buffer, int32_t uuid, TriggerModelType type); 34 void DeleteModel(int32_t uuid); 35 bool IsModelExist(int32_t uuid); 36 std::shared_ptr<GenericTriggerModel> GetModel(int32_t uuid); 37 void CreateDetector(int32_t uuid, std::function<void()> onDetected); 38 void ReleaseTriggerDetector(int32_t uuid); 39 int32_t StartDetection(int32_t uuid); 40 void StopDetection(int32_t uuid); 41 int32_t SetParameter(const std::string &key, const std::string &value); 42 std::string GetParameter(const std::string &key); 43 void OnServiceStart(); 44 void OnServiceStop(); 45 void OnTelephonyStateRegistryServiceChange(bool isAdded); 46 void OnAudioDistributedServiceChange(bool isAdded); 47 void OnAudioPolicyServiceChange(bool isAdded); 48 void OnPowerManagerServiceChange(bool isAdded); 49 50 private: 51 void AttachTelephonyObserver(); 52 void DetachTelephonyObserver(); 53 void AttachAudioCaptureListener(); 54 void DetachAudioCaptureListener(); 55 void AttachAudioRendererEventListener(); 56 void DetachAudioRendererEventListener(); 57 void AttachHibernateObserver(); 58 void DetachHibernateObserver(); 59 60 private: 61 std::mutex detectorMutex_; //这个锁回头看看有没有必要删掉 62 std::map<int32_t, std::shared_ptr<TriggerDetector>> detectors_; 63 std::shared_ptr<TriggerService> service_ = nullptr; 64 }; 65 } // namespace IntellVoiceTrigger 66 } // namespace OHOS 67 #endif