• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "mock_component_manager.h"
17 
18 #include "distributed_hardware_errno.h"
19 #include "distributed_hardware_log.h"
20 
21 namespace OHOS {
22 namespace DistributedHardware {
23 std::shared_ptr<IComponentManager> IComponentManager::componentManager_;
24 
GetOrCreateInstance()25 std::shared_ptr<IComponentManager> IComponentManager::GetOrCreateInstance()
26 {
27     if (!componentManager_) {
28         componentManager_ = std::make_shared<MockComponentManager>();
29     }
30 
31     return componentManager_;
32 }
33 
ReleaseInstance()34 void IComponentManager::ReleaseInstance()
35 {
36     componentManager_.reset();
37     componentManager_ = nullptr;
38 }
39 
CheckDemandStart(const std::string & uuid,const DHType dhType,bool & enableSource)40 int32_t ComponentManager::CheckDemandStart(const std::string &uuid, const DHType dhType, bool &enableSource)
41 {
42     enableSource = true;
43     return IComponentManager::GetOrCreateInstance()->CheckDemandStart(uuid, dhType, enableSource);
44 }
45 
ForceDisableSink(const DHDescriptor & dhDescriptor)46 int32_t ComponentManager::ForceDisableSink(const DHDescriptor &dhDescriptor)
47 {
48     return IComponentManager::GetOrCreateInstance()->ForceDisableSink(dhDescriptor);
49 }
50 
ForceDisableSource(const std::string & networkId,const DHDescriptor & dhDescriptor)51 int32_t ComponentManager::ForceDisableSource(const std::string &networkId, const DHDescriptor &dhDescriptor)
52 {
53     return IComponentManager::GetOrCreateInstance()->ForceDisableSource(networkId, dhDescriptor);
54 }
55 
EnableSink(const DHDescriptor & dhDescriptor,int32_t callingUid,int32_t callingPid)56 int32_t ComponentManager::EnableSink(const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid)
57 {
58     return IComponentManager::GetOrCreateInstance()->EnableSink(dhDescriptor, callingUid, callingPid);
59 }
60 
EnableSource(const std::string & networkId,const DHDescriptor & dhDescriptor,int32_t callingUid,int32_t callingPid)61 int32_t ComponentManager::EnableSource(const std::string &networkId,
62     const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid)
63 {
64     return IComponentManager::GetOrCreateInstance()->EnableSource(networkId, dhDescriptor, callingUid, callingPid);
65 }
66 
DisableSink(const DHDescriptor & dhDescriptor,int32_t callingUid,int32_t callingPid)67 int32_t ComponentManager::DisableSink(const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid)
68 {
69     return IComponentManager::GetOrCreateInstance()->DisableSink(dhDescriptor, callingUid, callingPid);
70 }
71 
DisableSource(const std::string & networkId,const DHDescriptor & dhDescriptor,int32_t callingUid,int32_t callingPid)72 int32_t ComponentManager::DisableSource(const std::string &networkId,
73     const DHDescriptor &dhDescriptor, int32_t callingUid, int32_t callingPid)
74 {
75     return IComponentManager::GetOrCreateInstance()->DisableSource(networkId, dhDescriptor, callingUid, callingPid);
76 }
77 
CheckSinkConfigStart(const DHType dhType,bool & enableSink)78 int32_t ComponentManager::CheckSinkConfigStart(const DHType dhType, bool &enableSink)
79 {
80     return IComponentManager::GetOrCreateInstance()->CheckSinkConfigStart(dhType, enableSink);
81 }
82 } // namespace DistributedHardware
83 } // namespace OHOS
84