From 6bb41ae0956a48006b40ed46ed5a6d251cf192b4 Mon Sep 17 00:00:00 2001 From: BrainL Date: Mon, 3 Feb 2025 14:24:31 +0800 Subject: [PATCH] =?UTF-8?q?dfs=5Fservice=20IDL=E5=8C=96=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: BrainL Change-Id: Icd924bcefde2cf35e4a3fab7d72ca6824d73be22 --- interfaces/inner_kits/native_cpp/BUILD.gn | 2 + .../native_cpp/include/dm_device_info.h | 118 +++++++++++++ .../native_cpp/src/dm_device_info.cpp | 162 ++++++++++++++++++ 3 files changed, 282 insertions(+) create mode 100644 interfaces/inner_kits/native_cpp/src/dm_device_info.cpp diff --git a/interfaces/inner_kits/native_cpp/BUILD.gn b/interfaces/inner_kits/native_cpp/BUILD.gn index 1012479b..583e1b32 100644 --- a/interfaces/inner_kits/native_cpp/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/BUILD.gn @@ -96,6 +96,7 @@ if (defined(ohos_lite)) { "${common_path}/src/dm_anonymous.cpp", "${devicemanager_path}/radar/src/lite/dm_radar_helper.cpp", "src/device_manager.cpp", + "src/dm_device_info.cpp", "src/device_manager_impl.cpp", "src/ipc/ipc_client_proxy.cpp", "src/ipc/lite/ipc_client_manager.cpp", @@ -169,6 +170,7 @@ if (defined(ohos_lite)) { "${common_path}/src/ipc/standard/ipc_model_codec.cpp", "${devicemanager_path}/radar/src/dm_radar_helper.cpp", "src/device_manager.cpp", + "src/dm_device_info.cpp", "src/device_manager_impl.cpp", "src/ipc/ipc_client_proxy.cpp", "src/ipc/standard/dm_service_load.cpp", diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 00d087fc..542ee8f1 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -21,6 +21,7 @@ #include #include "dm_app_image_info.h" +#include "parcel.h" #define DM_MAX_DEVICE_ID_LEN (97) #define DM_MAX_DEVICE_NAME_LEN (129) @@ -413,6 +414,123 @@ typedef struct DmNotifyKey { notifyUserId == other.notifyUserId && udid < other.udid); } } DmNotifyKey; + +struct DmDeviceInfoExt : public Parcelable +{ + + /** + * Device Id of the device. + */ + char deviceId[DM_MAX_DEVICE_ID_LEN] = {0}; + /** + * Device name of the device. + */ + char deviceName[DM_MAX_DEVICE_NAME_LEN] = {0}; + /** + * Device type of the device. + */ + uint16_t deviceTypeId; + /** + * NetworkId of the device. + */ + char networkId[DM_MAX_DEVICE_ID_LEN] = {0}; + /** + * The distance of discovered device, in centimeter(cm). + */ + int32_t range; + /** + * NetworkType of the device. + */ + int32_t networkType; + /** + * Device authentication form. + */ + int32_t authForm; + /** + * Extra data of the device. + * include json keys: "CONN_ADDR_TYPE", "BR_MAC_", "BLE_MAC", "WIFI_IP", "WIFI_PORT", "CUSTOM_DATA" + */ + std::string extraData; + + DmDeviceInfoExt() {} + + DmDeviceInfoExt(const DmDeviceInfo &devInfo) + { + strncpy(deviceId, devInfo.deviceId, DM_MAX_DEVICE_ID_LEN - 1); + deviceId[DM_MAX_DEVICE_ID_LEN - 1] = '\0'; // 纭繚瀛楃涓蹭互 '\0' 缁撳熬 + + strncpy(deviceName, devInfo.deviceName, DM_MAX_DEVICE_NAME_LEN - 1); + deviceName[DM_MAX_DEVICE_NAME_LEN - 1] = '\0'; // 纭繚瀛楃涓蹭互 '\0' 缁撳熬 + + strncpy(networkId, devInfo.networkId, DM_MAX_DEVICE_ID_LEN - 1); + networkId[DM_MAX_DEVICE_ID_LEN - 1] = '\0'; // 纭繚瀛楃涓蹭互 '\0' 缁撳熬 + + deviceTypeId = devInfo.deviceTypeId; + range = devInfo.range; + networkType = devInfo.networkType; + authForm = static_cast(devInfo.authForm); + extraData = devInfo.extraData; + } + + DmDeviceInfo ConvertToDmDeviceInfo() + { + DmDeviceInfo dmDeviceInfo; + + strncpy(dmDeviceInfo.deviceId, deviceId, DM_MAX_DEVICE_ID_LEN - 1); + dmDeviceInfo.deviceId[DM_MAX_DEVICE_ID_LEN - 1] = '\0'; + + strncpy(dmDeviceInfo.deviceName, deviceName, DM_MAX_DEVICE_NAME_LEN - 1); + dmDeviceInfo.deviceName[DM_MAX_DEVICE_NAME_LEN - 1] = '\0'; + + strncpy(dmDeviceInfo.networkId, networkId, DM_MAX_DEVICE_ID_LEN - 1); + dmDeviceInfo.networkId[DM_MAX_DEVICE_ID_LEN - 1] = '\0'; + + dmDeviceInfo.deviceTypeId = deviceTypeId; + dmDeviceInfo.range = range; + dmDeviceInfo.networkType = networkType; + dmDeviceInfo.authForm = static_cast(authForm); + dmDeviceInfo.extraData = extraData; + + return dmDeviceInfo; + } + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmDeviceInfoExt *Unmarshalling(Parcel &parcel); +}; + +struct PeerTargetIdExt : public PeerTargetId, public Parcelable { + + using PeerTargetId::PeerTargetId; + + PeerTargetIdExt(const PeerTargetId& peerTargetId) : PeerTargetId(peerTargetId) {} + + virtual bool Marshalling(Parcel &parcel) const override; + + static PeerTargetIdExt *Unmarshalling(Parcel &parcel); +}; + +struct DmAccessCallerExt : public DmAccessCaller, public Parcelable { + + using DmAccessCaller::DmAccessCaller; + + DmAccessCallerExt(const DmAccessCaller& dmAccessCaller) : DmAccessCaller(dmAccessCaller) {} + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmAccessCallerExt *Unmarshalling(Parcel &parcel); +}; + +struct DmAccessCalleeExt : public DmAccessCallee, public Parcelable { + + using DmAccessCallee::DmAccessCallee; + + DmAccessCalleeExt(const DmAccessCallee& dmAccessCallee) : DmAccessCallee(dmAccessCallee) {} + + virtual bool Marshalling(Parcel &parcel) const override; + + static DmAccessCalleeExt *Unmarshalling(Parcel &parcel); +}; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_DEVICE_INFO_H \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp new file mode 100644 index 00000000..a6f0a4e9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/src/dm_device_info.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "dm_device_info.h" + +#include "dm_log.h" +#include "dm_constants.h" + +#define DM_MAX_DEVICE_ID_LEN (97) +#define DM_MAX_DEVICE_NAME_LEN (129) + +namespace OHOS { +namespace DistributedHardware { +bool DmDeviceInfoExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + std::string deviceIdStr(deviceId); + bRet = (bRet && parcel.WriteString(deviceIdStr)); + std::string deviceNameStr(deviceName); + bRet = (bRet && parcel.WriteString(deviceNameStr)); + bRet = (bRet && parcel.WriteUint16(deviceTypeId)); + std::string networkIdStr(networkId); + bRet = (bRet && parcel.WriteString(networkIdStr)); + bRet = (bRet && parcel.WriteInt32(range)); + bRet = (bRet && parcel.WriteInt32(networkType)); + bRet = (bRet && parcel.WriteInt32(authForm)); + bRet = (bRet && parcel.WriteString(extraData)); + return bRet; +} + +DmDeviceInfoExt *DmDeviceInfoExt::Unmarshalling(Parcel &parcel) +{ + DmDeviceInfoExt *deviceInfoExt = new (std::nothrow) DmDeviceInfoExt(); + if (deviceInfoExt == nullptr) { + LOGE("Create DmDeviceInfoExt failed"); + return nullptr; + } + std::string deviceIdStr = parcel.ReadString(); + if (strcpy_s(deviceInfoExt->deviceId, deviceIdStr.size() + 1, deviceIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceId failed!"); + delete deviceInfoExt; + return nullptr; + } + std::string deviceNameStr = parcel.ReadString(); + if (strcpy_s(deviceInfoExt->deviceName, deviceNameStr.size() + 1, deviceNameStr.c_str()) != DM_OK) { + LOGE("strcpy_s deviceName failed!"); + delete deviceInfoExt; + return nullptr; + } + deviceInfoExt->deviceTypeId = parcel.ReadUint16(); + std::string networkIdStr = parcel.ReadString(); + if (strcpy_s(deviceInfoExt->networkId, networkIdStr.size() + 1, networkIdStr.c_str()) != DM_OK) { + LOGE("strcpy_s networkId failed!"); + delete deviceInfoExt; + return nullptr; + } + deviceInfoExt->range = parcel.ReadInt32(); + deviceInfoExt->networkType = parcel.ReadInt32(); + deviceInfoExt->authForm = static_cast(parcel.ReadInt32()); + deviceInfoExt->extraData = parcel.ReadString(); + return deviceInfoExt; +} + +bool PeerTargetIdExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(deviceId)); + bRet = (bRet && parcel.WriteString(brMac)); + bRet = (bRet && parcel.WriteString(bleMac)); + bRet = (bRet && parcel.WriteString(wifiIp)); + bRet = (bRet && parcel.WriteUint16(wifiPort)); + return bRet; +} + +PeerTargetIdExt *PeerTargetIdExt::Unmarshalling(Parcel &parcel) +{ + PeerTargetIdExt *targetIdExt = new (std::nothrow) PeerTargetIdExt(); + if (targetIdExt == nullptr) { + LOGE("Create PeerTargetIdExt failed"); + return nullptr; + } + targetIdExt->deviceId = parcel.ReadString(); + targetIdExt->brMac = parcel.ReadString(); + targetIdExt->bleMac = parcel.ReadString(); + targetIdExt->wifiIp = parcel.ReadString(); + targetIdExt->wifiPort = parcel.ReadUint16(); + return targetIdExt; +} + +bool DmAccessCallerExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(accountId)); + bRet = (bRet && parcel.WriteString(pkgName)); + bRet = (bRet && parcel.WriteString(networkId)); + bRet = (bRet && parcel.WriteInt32(userId)); + bRet = (bRet && parcel.WriteUint64(tokenId)); + bRet = (bRet && parcel.WriteString(extra)); + return bRet; +} + +DmAccessCallerExt *DmAccessCallerExt::Unmarshalling(Parcel &parcel) +{ + DmAccessCallerExt *callerExt = new (std::nothrow) DmAccessCallerExt(); + if (callerExt == nullptr) { + LOGE("Create DmAccessCallerExt failed"); + return nullptr; + } + callerExt->accountId = parcel.ReadString(); + callerExt->pkgName = parcel.ReadString(); + callerExt->networkId = parcel.ReadString(); + callerExt->userId = parcel.ReadInt32(); + callerExt->tokenId = parcel.ReadUint64(); + callerExt->extra = parcel.ReadString(); + return callerExt; +} + +bool DmAccessCalleeExt::Marshalling(Parcel &parcel) const +{ + bool bRet = true; + bRet = (bRet && parcel.WriteString(accountId)); + bRet = (bRet && parcel.WriteString(networkId)); + bRet = (bRet && parcel.WriteString(peerId)); + bRet = (bRet && parcel.WriteInt32(userId)); + bRet = (bRet && parcel.WriteString(extra)); + return bRet; +} + +DmAccessCalleeExt *DmAccessCalleeExt::Unmarshalling(Parcel &parcel) +{ + DmAccessCalleeExt *calleeExt = new (std::nothrow) DmAccessCalleeExt(); + if (calleeExt == nullptr) { + LOGE("Create DmAccessCallerExt failed"); + return nullptr; + } + calleeExt->accountId = parcel.ReadString(); + calleeExt->networkId = parcel.ReadString(); + calleeExt->peerId = parcel.ReadString(); + calleeExt->userId = parcel.ReadInt32(); + calleeExt->extra = parcel.ReadString(); + + return calleeExt; +} + +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file -- Gitee