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 16 #ifndef HDI_DEVICE_INTELL_VOICE_MANAGER_IMPL_H 17 #define HDI_DEVICE_INTELL_VOICE_MANAGER_IMPL_H 18 19 #include <map> 20 #include <mutex> 21 #include <string> 22 23 #include "v1_0/intell_voice_engine_types.h" 24 #include "v1_0/iintell_voice_engine_manager.h" 25 #include "i_engine.h" 26 27 namespace OHOS { 28 namespace IntelligentVoice { 29 namespace Engine { 30 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineManager; 31 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineAdapter; 32 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterType; 33 using OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterDescriptor; 34 35 using GetEngineManagerHalInstFunc = IEngineManager *(*)(); 36 37 struct IntellVoiceEngineManagerPriv { 38 void *handle { nullptr }; 39 GetEngineManagerHalInstFunc getEngineManagerHalInst { nullptr }; 40 }; 41 42 class IntellVoiceEngineManagerImpl : public IIntellVoiceEngineManager { 43 public: 44 IntellVoiceEngineManagerImpl(); 45 ~IntellVoiceEngineManagerImpl(); 46 47 int32_t GetAdapterDescriptors(std::vector<IntellVoiceEngineAdapterDescriptor>& descs) override; 48 int32_t CreateAdapter(const IntellVoiceEngineAdapterDescriptor& descriptor, 49 sptr<IIntellVoiceEngineAdapter>& adapter) override; 50 int32_t ReleaseAdapter(const IntellVoiceEngineAdapterDescriptor& descriptor) override; 51 52 private: 53 int32_t LoadVendorLib(); 54 void UnloadVendorLib(); 55 56 private: 57 std::map<IntellVoiceEngineAdapterType, sptr<IIntellVoiceEngineAdapter>> adapters_; 58 std::mutex mutex_ {}; 59 IntellVoiceEngineManagerPriv engineManagerPriv_; 60 IEngineManager *inst_ = nullptr; 61 }; 62 } 63 } 64 } 65 #endif