• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "ark_communication_provider.h"
17 #include "log_print.h"
18 
19 #undef LOG_TAG
20 #define LOG_TAG "ArkCommunicationProvider"
21 
22 namespace OHOS {
23 namespace AppDistributedKv {
Init()24 CommunicationProvider &ArkCommunicationProvider::Init()
25 {
26     static ArkCommunicationProvider instance;
27     if (instance.isInited) {
28         return instance;
29     }
30     ZLOGI("begin");
31     std::lock_guard<std::mutex> lock(mutex_);
32     if (!instance.isInited) {
33         instance.Initialize();
34     }
35     instance.isInited = true;
36     ZLOGI("normal end");
37     return instance;
38 }
ArkCommunicationProvider()39 ArkCommunicationProvider::ArkCommunicationProvider()
40     : CommunicationProviderImpl(appPipeMgrImpl_)
41 {
42 }
43 
GetLocalDevice() const44 DeviceInfo ArkCommunicationProvider::GetLocalDevice() const
45 {
46     if (deviceQuery_ == nullptr) {
47         return CommunicationProviderImpl::GetLocalDevice();
48     }
49     return deviceQuery_->GetLocalDevice();
50 }
51 
GetRemoteDevices() const52 std::vector<DeviceInfo> ArkCommunicationProvider::GetRemoteDevices() const
53 {
54     if (deviceQuery_ == nullptr) {
55         return CommunicationProviderImpl::GetRemoteDevices();
56     }
57     return deviceQuery_->GetRemoteDevices();
58 }
59 
GetDeviceInfo(const std::string & networkId) const60 DeviceInfo ArkCommunicationProvider::GetDeviceInfo(const std::string &networkId) const
61 {
62     if (deviceQuery_ == nullptr) {
63         return CommunicationProviderImpl::GetDeviceInfo(networkId);
64     }
65     return deviceQuery_->GetDeviceInfo(networkId);
66 }
67 
SetDeviceQuery(std::shared_ptr<IDeviceQuery> deviceQuery)68 void ArkCommunicationProvider::SetDeviceQuery(std::shared_ptr<IDeviceQuery> deviceQuery)
69 {
70     ZLOGI("set device query");
71     deviceQuery_ = deviceQuery;
72 }
73 }  // namespace AppDistributedKv
74 }  // namespace OHOS
75