代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony/deviceprofile_device_info_manager 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
DeviceProfile是设备硬件能力和系统软件特征的管理器,典型的Profile有设备类型、设备名称、设备OS类型、OS版本号等。DeviceProfile提供快速访问本地和远端设备Profile的能力,是发起分布式业务的基础。主要功能如下:
DeviceProfile模块组成如下图所示:
DeviceProfile主要代码目录结构如下:
├── interfaces
│ └── innerkits
│ └── distributeddeviceprofile // innerkits接口
├── ohos.build
├── sa_profile // said声明文件
│ ├── 6001.xml
│ └── BUILD.gn
└── services
└── distributeddeviceprofile
├── BUILD.gn
├── include
│ ├── authority // 权限校验
│ ├── contentsensor // CS数据采集头文件
│ ├── dbstorage // 数据库操作头文件
│ ├── devicemanager // 设备管理头文件
│ └── subscribemanager // 订阅管理头文件
├── src
│ ├── authority // 权限校验
│ ├── contentsensor // CS数据采集实现
│ ├── dbstorage // 数据库操作实现
│ ├── devicemanager // 设备管理实现
│ └── subscribemanager // 订阅管理实现
└── test // 测试用例
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
deviceId | std::string | 是 | 查询指定设备的profile,空值表示查询本地 |
serviceId | std::string | 是 | 查询的service id |
profile | ServiceCharacteristicProfile | 是 | 返回值 |
// 声明返回值
ServiceCharacteristicProfile profile;
// 执行查询接口GetDeviceProfile
DistributedDeviceProfileClient::GetInstance().GetDeviceProfile(deviceId, serviceId, profile);
std::string jsonData = profile.GetCharacteristicProfileJson();
result.append("jsonData:" + jsonData + "\n");
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
profile | ServiceCharacteristicProfile | 是 | 需要插入的profile信息 |
// 声明并填充插入数据
ServiceCharacteristicProfile profile;
profile.SetServiceId(serviceId);
profile.SetServiceType(serviceType);
nlohmann::json j;
j["testVersion"] = "3.0.0";
j["testApiLevel"] = API_LEVEL;
profile.SetCharacteristicProfileJson(j.dump());
// 执行插入接口PutDeviceProfile
DistributedDeviceProfileClient::GetInstance().PutDeviceProfile(profile);
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
serviceId | std::string | 是 | 删除特定serviceid的记录 |
// 声明并填充插入数据
std::string serviceId = "test";
// DeleteDeviceProfile
DistributedDeviceProfileClient::GetInstance().DeleteDeviceProfile(serviceId);
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
syncOption | SyncOption | 是 | 指定同步范围和模式 |
syncCb | IProfileEventCallback | 是 | 同步结果回调 |
// 定义同步模式和范围
SyncOptions syncOption;
syncOption.SetSyncMode((OHOS::DeviceProfile::SyncMode)atoi(mode.c_str()));
for (const auto& deviceId : deviceIds) {
syncOption.AddDevice(deviceId);
}
// 执行同步接口
DistributedDeviceProfileClient::GetInstance().SyncDeviceProfile(syncOption,
std::make_shared<ProfileEventCallback>());
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
subscribeInfos | SubscribeInfo | 是 | 指定订阅的事件类型 |
eventCb | IProfileEventCallback | 是 | 订阅事件回调 |
failedEvents | ProfileEvent | 是 | 失败事件 |
auto callback = std::make_shared<ProfileEventCallback>();
std::list<SubscribeInfo> subscribeInfos;
// 订阅EVENT_PROFILE_CHANGED事件
ExtraInfo extraInfo;
extraInfo["deviceId"] = deviceId;
extraInfo["serviceIds"] = serviceIds;
SubscribeInfo changeEventInfo;
changeEventInfo.profileEvent = ProfileEvent::EVENT_PROFILE_CHANGED;
changeEventInfo.extraInfo = std::move(extraInfo);
subscribeInfos.emplace_back(changeEventInfo);
// 订阅EVENT_SYNC_COMPLETED事件
SubscribeInfo syncEventInfo;
syncEventInfo.profileEvent = ProfileEvent::EVENT_SYNC_COMPLETED;
subscribeInfos.emplace_back(syncEventInfo);
// 执行订阅接口
std::list<ProfileEvent> failedEvents;
DistributedDeviceProfileClient::GetInstance().SubscribeProfileEvents(subscribeInfos,
callback, failedEvents);
// 解除订阅
std::list<ProfileEvent> profileEvents;
profileEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED);
DistributedDeviceProfileClient::GetInstance().UnsubscribeProfileEvents(profileEvents,
callback, failedEvents);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。