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 #include "trigger_connector_mgr.h"
16 #include "intell_voice_log.h"
17 #include "intell_voice_service_manager.h"
18 #include "trigger_connector_internal_validation.h"
19 #include "trigger_connector_internal_impl.h"
20
21 #define LOG_TAG "TriggerConnectorMgr"
22
23 namespace OHOS {
24 namespace IntellVoiceTrigger {
25 std::unique_ptr<TriggerConnectorMgr> TriggerConnectorMgr::g_connectorMgr =
26 std::unique_ptr<TriggerConnectorMgr>(
27 new (std::nothrow) TriggerConnectorMgr(std::make_unique<TriggerConnectorInternalValidation>(
__anon4bf46ebb0102(const IntellVoiceTriggerAdapterDsecriptor &desc) 28 std::make_unique<TriggerConnectorInternalImpl>([](const IntellVoiceTriggerAdapterDsecriptor &desc) {
29 TriggerConnectorMgr::OnTriggerConnectServiceStart(desc);
30 }))));
31
TriggerConnectorMgr(std::unique_ptr<IIntellVoiceTriggerConnectorInternal> delegate)32 TriggerConnectorMgr::TriggerConnectorMgr(std::unique_ptr<IIntellVoiceTriggerConnectorInternal> delegate)
33 : delegate_(std::move(delegate))
34 {}
35
GetInstance()36 std::unique_ptr<TriggerConnectorMgr> &TriggerConnectorMgr::GetInstance()
37 {
38 return g_connectorMgr;
39 }
40
ListConnectorModuleDescriptors()41 std::vector<TriggerConnectorModuleDesc> TriggerConnectorMgr::ListConnectorModuleDescriptors()
42 {
43 if (delegate_ == nullptr) {
44 INTELL_VOICE_LOG_ERROR("delegate_ is nullptr");
45 return {};
46 }
47
48 return delegate_->ListModuleDescriptors();
49 }
50
GetConnectorModule(const std::string & adapterName,std::shared_ptr<IIntellVoiceTriggerConnectorCallback> callback)51 std::shared_ptr<IIntellVoiceTriggerConnectorModule> TriggerConnectorMgr::GetConnectorModule(
52 const std::string &adapterName, std::shared_ptr<IIntellVoiceTriggerConnectorCallback> callback)
53 {
54 if (delegate_ == nullptr) {
55 INTELL_VOICE_LOG_ERROR("delegate_ is nullptr");
56 return nullptr;
57 }
58
59 return delegate_->GetModule(adapterName, callback);
60 }
61
OnTriggerConnectServiceStart(const IntellVoiceTriggerAdapterDsecriptor & desc)62 void TriggerConnectorMgr::OnTriggerConnectServiceStart(const IntellVoiceTriggerAdapterDsecriptor &desc)
63 {
64 INTELL_VOICE_LOG_INFO("enter, adapter name:%{public}s", desc.adapterName.c_str());
65 const auto &manager = OHOS::IntellVoiceEngine::IntellVoiceServiceManager::GetInstance();
66 if (manager != nullptr) {
67 manager->OnTriggerConnectServiceStart();
68 }
69 }
70 } // namespace IntellVoiceTrigger
71 } // namespace OHOS