• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "trigger_connector_internal_validation.h"
18 #include "trigger_connector_internal_impl.h"
19 
20 #define LOG_TAG "TriggerConnectorMgr"
21 
22 namespace OHOS {
23 namespace IntellVoiceTrigger {
24 std::unique_ptr<TriggerConnectorMgr> TriggerConnectorMgr::g_connectorMgr =
25     std::unique_ptr<TriggerConnectorMgr>(
26         new (std::nothrow) TriggerConnectorMgr(std::make_unique<TriggerConnectorInternalValidation>(
27             std::make_unique<TriggerConnectorInternalImpl>())));
28 
TriggerConnectorMgr(std::unique_ptr<IIntellVoiceTriggerConnectorInternal> delegate)29 TriggerConnectorMgr::TriggerConnectorMgr(std::unique_ptr<IIntellVoiceTriggerConnectorInternal> delegate)
30     : delegate_(std::move(delegate))
31 {}
32 
GetInstance()33 std::unique_ptr<TriggerConnectorMgr> &TriggerConnectorMgr::GetInstance()
34 {
35     return g_connectorMgr;
36 }
37 
ListConnectorModuleDescriptors()38 std::vector<TriggerConnectorModuleDesc> TriggerConnectorMgr::ListConnectorModuleDescriptors()
39 {
40     if (delegate_ == nullptr) {
41         INTELL_VOICE_LOG_ERROR("delegate_ is nullptr");
42         return {};
43     }
44 
45     return delegate_->ListModuleDescriptors();
46 }
47 
GetConnectorModule(const std::string & adapterName,std::shared_ptr<IIntellVoiceTriggerConnectorCallback> callback)48 std::shared_ptr<IIntellVoiceTriggerConnectorModule> TriggerConnectorMgr::GetConnectorModule(
49     const std::string &adapterName, std::shared_ptr<IIntellVoiceTriggerConnectorCallback> callback)
50 {
51     if (delegate_ == nullptr) {
52         INTELL_VOICE_LOG_ERROR("delegate_ is nullptr");
53         return nullptr;
54     }
55 
56     return delegate_->GetModule(adapterName, callback);
57 }
58 }  // namespace IntellVoiceTrigger
59 }  // namespace OHOS