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