• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 "dm_kit.h"
17 
18 namespace OHOS {
19 namespace Sharing {
20 bool DmKit::isInited = false;
21 const std::string PKG_NAME = "sharing_framework";
22 OHOS::DistributedHardware::DmDeviceInfo DmKit::localDeviceInfo_ = {};
23 std::vector<OHOS::DistributedHardware::DmDeviceInfo> DmKit::trustedDeviceInfos_ = {};
24 
InitDeviceManager()25 void DmKit::InitDeviceManager()
26 {
27     SHARING_LOGD("trace.");
28     if (isInited) {
29         SHARING_LOGD("DmKit is already Inited.");
30         return;
31     }
32 
33     auto callback = std::make_shared<DmKitInitDMCallback>();
34     CHECK_AND_RETURN_LOG(callback != nullptr, "no memory.");
35     int32_t ret = OHOS::DistributedHardware::DeviceManager::GetInstance().InitDeviceManager(PKG_NAME, callback);
36     if (ret == 0) {
37         isInited = true;
38     }
39 
40     CHECK_AND_RETURN_LOG(ret == 0, "InitDeviceManager error ret is %{public}d.", ret);
41 }
42 
GetLocalDevicesInfo()43 OHOS::DistributedHardware::DmDeviceInfo &DmKit::GetLocalDevicesInfo()
44 {
45     SHARING_LOGD("GetLocalNetworkId.");
46     if (!isInited) {
47         SHARING_LOGE("DmKit is not Inited.");
48     }
49 
50     localDeviceInfo_ = {};
51     int32_t ret = DistributedHardware::DeviceManager::GetInstance().GetLocalDeviceInfo(PKG_NAME, localDeviceInfo_);
52     CHECK_AND_RETURN_RET_LOG(ret == 0, localDeviceInfo_, "get local deviceInfo failed.");
53 
54     return localDeviceInfo_;
55 }
56 
GetTrustedDevicesInfo()57 std::vector<OHOS::DistributedHardware::DmDeviceInfo> &DmKit::GetTrustedDevicesInfo()
58 {
59     SHARING_LOGD("trace.");
60     if (!isInited) {
61         SHARING_LOGE("DmKit is not Inited.");
62     }
63 
64     trustedDeviceInfos_.clear();
65     int32_t ret =
66         DistributedHardware::DeviceManager::GetInstance().GetTrustedDeviceList(PKG_NAME, "", trustedDeviceInfos_);
67     CHECK_AND_RETURN_RET_LOG(ret == 0, trustedDeviceInfos_, "get trusted device list failed");
68 
69     return trustedDeviceInfos_;
70 }
71 
GetIpAddrByNetworkId(const std::string & networkId)72 std::string DmKit::GetIpAddrByNetworkId(const std::string &networkId)
73 {
74     SHARING_LOGD("trace.");
75     if (!isInited) {
76         SHARING_LOGE("DmKit is not Inited.");
77     }
78 
79     std::string ipAddr = "";
80 
81     return ipAddr;
82 }
83 
84 } // namespace Sharing
85 } // namespace OHOS