1 /* 2 * Copyright (c) 2024 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 "dm_adapter.h" 17 #include "distributed_device_profile_constants.h" 18 #include "distributed_device_profile_errors.h" 19 #include "distributed_device_profile_log.h" 20 21 namespace OHOS { 22 namespace DistributedDeviceProfile { 23 namespace { 24 const std::string TAG = "DMAdapter"; 25 } 26 27 IMPLEMENT_SINGLE_INSTANCE(DMAdapter); 28 Init()29int32_t DMAdapter::Init() 30 { 31 HILOGI("call!"); 32 int32_t errCode = DP_SUCCESS; 33 { 34 std::lock_guard<std::mutex> autoLock(deviceStateCallbackMutex_); 35 if (deviceStateCallback_ == nullptr) { 36 deviceStateCallback_ = std::make_shared<DpDeviceStateCallback>(); 37 } 38 errCode = DistributedHardware::DeviceManager::GetInstance() 39 .RegisterDevStateCallback(DP_PKG_NAME, "", deviceStateCallback_); 40 } 41 HILOGI("RegisterDevStateCallback errCode = %{public}d", errCode); 42 return errCode; 43 } 44 UnInit()45int32_t DMAdapter::UnInit() 46 { 47 HILOGI("call!"); 48 int32_t errCode = DP_SUCCESS; 49 { 50 std::lock_guard<std::mutex> autoLock(deviceStateCallbackMutex_); 51 if (deviceStateCallback_ != nullptr) { 52 errCode = DistributedHardware::DeviceManager::GetInstance().UnRegisterDevStateCallback(DP_PKG_NAME); 53 deviceStateCallback_ = nullptr; 54 } 55 } 56 HILOGI("UnRegisterDevStateCallback errCode = %{public}d", errCode); 57 return errCode; 58 } 59 ReInit()60int32_t DMAdapter::ReInit() 61 { 62 HILOGI("call!"); 63 UnInit(); 64 return Init(); 65 } 66 OnDeviceOnline(const DistributedHardware::DmDeviceInfo & deviceInfo)67void DMAdapter::DpDeviceStateCallback::OnDeviceOnline(const DistributedHardware::DmDeviceInfo &deviceInfo) 68 { 69 HILOGI("call!"); 70 } 71 OnDeviceOffline(const DistributedHardware::DmDeviceInfo & deviceInfo)72void DMAdapter::DpDeviceStateCallback::OnDeviceOffline(const DistributedHardware::DmDeviceInfo &deviceInfo) 73 { 74 HILOGI("call!"); 75 } 76 OnDeviceChanged(const DistributedHardware::DmDeviceInfo & deviceInfo)77void DMAdapter::DpDeviceStateCallback::OnDeviceChanged(const DistributedHardware::DmDeviceInfo &deviceInfo) 78 { 79 HILOGI("call!"); 80 } 81 OnDeviceReady(const DistributedHardware::DmDeviceInfo & deviceInfo)82void DMAdapter::DpDeviceStateCallback::OnDeviceReady(const DistributedHardware::DmDeviceInfo &deviceInfo) 83 { 84 HILOGI("call!"); 85 } 86 } // namespace DistributedDeviceProfile 87 } // namespace OHOS