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 "device/device_info.h" 17 #include "dfsu_exception.h" 18 #include "utils_log.h" 19 20 namespace OHOS { 21 namespace Storage { 22 namespace DistributedFile { 23 using namespace std; 24 DeviceInfo(const DistributedHardware::DmDeviceInfo & nodeInfo)25DeviceInfo::DeviceInfo(const DistributedHardware::DmDeviceInfo &nodeInfo) 26 { 27 cid_ = string(nodeInfo.networkId); 28 initCidFlag_ = true; 29 // convert networkId to udid 30 auto &deviceManager = DistributedHardware::DeviceManager::GetInstance(); 31 deviceManager.GetUdidByNetworkId(IDaemon::SERVICE_NAME, cid_, udid_); 32 } 33 operator =(const DistributedHardware::DmDeviceInfo & nodeInfo)34DeviceInfo &DeviceInfo::operator=(const DistributedHardware::DmDeviceInfo &nodeInfo) 35 { 36 cid_ = string(nodeInfo.networkId); 37 initCidFlag_ = true; 38 return *this; 39 } 40 DeviceInfo(const DeviceInfo & nodeInfo)41DeviceInfo::DeviceInfo(const DeviceInfo &nodeInfo) : cid_(nodeInfo.cid_), udid_(nodeInfo.udid_) 42 { 43 initCidFlag_.store(nodeInfo.initCidFlag_.load()); 44 } 45 SetCid(const string & cid)46void DeviceInfo::SetCid(const string &cid) 47 { 48 if (initCidFlag_ == false) { 49 cid_ = cid; 50 initCidFlag_ = true; 51 } else { 52 LOGI("Cid is already initialized"); 53 } 54 } 55 GetCid() const56const string &DeviceInfo::GetCid() const 57 { 58 if (initCidFlag_ == false) { 59 THROW_EXCEPTION(ERR_DEVICE_CID_UN_INIT, "cid uninitialized"); 60 } 61 return cid_; 62 } 63 } // namespace DistributedFile 64 } // namespace Storage 65 } // namespace OHOS 66