• 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 
16 #define LOG_TAG "RdbDeviceManagerAdaptor"
17 
18 #include <string>
19 
20 #include "rdb_device_manager_adapter.h"
21 
22 namespace OHOS {
23 namespace DeviceManagerAdaptor {
24 using namespace OHOS::DistributedHardware;
25 constexpr int32_t DM_OK = 0;
26 constexpr int32_t DM_ERROR = -1;
RdbDeviceManagerAdaptor(const std::string & packageName)27 RdbDeviceManagerAdaptor::RdbDeviceManagerAdaptor(const std::string &packageName)
28     :packageName_(packageName)
29 {
30     Init();
31 }
32 
~RdbDeviceManagerAdaptor()33 RdbDeviceManagerAdaptor::~RdbDeviceManagerAdaptor()
34 {
35     UnInit();
36 }
37 
GetInstance(const std::string & packageName)38 RdbDeviceManagerAdaptor& RdbDeviceManagerAdaptor::GetInstance(const std::string &packageName)
39 {
40     static RdbDeviceManagerAdaptor instance(packageName);
41     return instance;
42 }
43 
Init()44 void RdbDeviceManagerAdaptor::Init()
45 {
46     auto callback = std::make_shared<InitDeviceManagerCallback>();
47     DeviceManager::GetInstance().InitDeviceManager(packageName_, callback);
48 }
49 
UnInit()50 void RdbDeviceManagerAdaptor::UnInit()
51 {
52     DeviceManager::GetInstance().UnInitDeviceManager(packageName_);
53 }
54 
GetEncryptedUuidByNetworkId(const std::string & networkId,std::string & uuid)55 int RdbDeviceManagerAdaptor::GetEncryptedUuidByNetworkId(const std::string &networkId, std::string &uuid)
56 {
57     int ret = DeviceManager::GetInstance().GetEncryptedUuidByNetworkId(packageName_, networkId, uuid);
58     if (ret != DM_OK) {
59         return DM_ERROR;
60     }
61     return DM_OK;
62 }
63 } // namespace DeviceManagerAdaptor
64 } // namespace OHOS