dms and aafwk decoupling

Signed-off-by: majiajun <864428661@qq.com>
Change-Id: I590edef2a56a08c9d8efc4f7685b722e5d10251b
This commit is contained in:
majiajun 2022-01-15 05:02:18 -08:00
parent 4d481700a1
commit f858bbbba9
17 changed files with 99 additions and 40 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ohos/distributedschedule_dms_fwk",
"description": "支持跨设备组件的启动和调用;支持分布式任务迁移;支持全局任务快照信息的实时获取能力。",
"description": "distributed ability manager service",
"version": "3.1",
"license": "Apache License 2.0",
"repository": "https://gitee.com/openharmony/distributedschedule_dms_fwk",
@ -45,10 +45,6 @@
"name": "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
"header": {
"header_files": [
"caller_info.h",
"distributed_sched_interface.h",
"distributed_sched_proxy.h",
"mission/distributed_mission_info.h",
"uri.h"
],
"header_base": "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include"

View File

@ -20,6 +20,7 @@
#include "ability_info.h"
#include "caller_info.h"
#include "iremote_broker.h"
#include "mission_info.h"
#include "mission/distributed_mission_info.h"
#include "mission_snapshot.h"
#include "ohos/aafwk/content/want.h"
@ -64,7 +65,7 @@ public:
virtual int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) = 0;
virtual int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) = 0;
virtual int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos) = 0;
std::vector<AAFwk::MissionInfo>& missionInfos) = 0;
virtual int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId,
const uint8_t* byteStream, size_t len) = 0;
virtual int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) = 0;

View File

@ -51,7 +51,7 @@ public:
int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos) override;
std::vector<AAFwk::MissionInfo>& missionInfos) override;
int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId,
const uint8_t* byteStream, size_t len) override;
int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) override;

View File

@ -76,7 +76,7 @@ public:
int32_t uid, const std::string& sourceDeviceId) override;
int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override;
int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos) override;
std::vector<AAFwk::MissionInfo>& missionInfos) override;
int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId,
const uint8_t* byteStream, size_t len) override;
int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) override;

View File

@ -57,8 +57,8 @@ struct DstbMissionInfo : public Parcelable {
static DstbMissionInfo* Unmarshalling(Parcel& parcel);
std::string ToString() const;
static bool ReadMissionInfoVectorFromParcel(Parcel& parcel, std::vector<DstbMissionInfo> &missionInfos);
static bool WriteMissionInfoVectorFromParcel(Parcel& parcel, const std::vector<DstbMissionInfo> &missionInfos);
static bool ReadDstbMissionInfosFromParcel(Parcel& parcel, std::vector<DstbMissionInfo>& missionInfos);
static bool WriteDstbMissionInfosToParcel(Parcel& parcel, const std::vector<DstbMissionInfo>& missionInfos);
};
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -23,6 +23,7 @@
#include "common_event_manager.h"
#include "distributed_data_storage.h"
#include "distributed_mission_change_listener.h"
#include "distributed_mission_info.h"
#include "distributed_sched_interface.h"
#include "event_handler.h"
#include "single_instance.h"
@ -73,7 +74,7 @@ class DistributedSchedMissionManager {
public:
void Init();
int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos);
std::vector<AAFwk::MissionInfo>& missionInfos);
int32_t InitDataStorage();
int32_t StopDataStorage();
int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId,

View File

@ -30,6 +30,8 @@ public:
std::vector<DstbMissionInfo>& dstbMissionInfos);
static int32_t ConvertToMissionInfos(std::vector<DstbMissionInfo>& dstbMissionInfos,
std::vector<AAFwk::MissionInfo>& missionInfos);
static bool ReadMissionInfosFromParcel(Parcel& parcel, std::vector<AAFwk::MissionInfo>& missionInfos);
static bool WriteMissionInfosToParcel(Parcel& parcel, const std::vector<AAFwk::MissionInfo>& missionInfos);
};
}
}

View File

@ -244,7 +244,7 @@ int32_t DistributedSchedAdapter::RegisterMissionListener(const sptr<DstbMissionC
return ERR_OK;
}
int32_t DistributedSchedAdapter::UnRegisterMissionListener(const sptr<DstbMissionChangeListener> &listener)
int32_t DistributedSchedAdapter::UnRegisterMissionListener(const sptr<DstbMissionChangeListener>& listener)
{
if (listener == nullptr) {
HILOGE("listener is null");

View File

@ -325,7 +325,7 @@ int32_t DistributedSchedProxy::StartSyncMissionsFromRemote(const CallerInfo& cal
}
int32_t version = reply.ReadInt32();
HILOGD("version : %{public}d", version);
return DstbMissionInfo::ReadMissionInfoVectorFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
return DstbMissionInfo::ReadDstbMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
}
int32_t DistributedSchedProxy::StopSyncRemoteMissions(const std::string& devId)
@ -409,7 +409,7 @@ int32_t DistributedSchedProxy::UnRegisterMissionListener(const std::u16string& d
}
int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos)
std::vector<AAFwk::MissionInfo>& missionInfos)
{
HILOGI("called");
sptr<IRemoteObject> remote = Remote();
@ -431,7 +431,7 @@ int32_t DistributedSchedProxy::GetMissionInfos(const std::string& deviceId, int3
HILOGW("sendRequest fail, error: %{public}d", ret);
return ret;
}
return DstbMissionInfo::ReadMissionInfoVectorFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
return MissionInfoConverter::ReadMissionInfosFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
}
int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
@ -449,7 +449,7 @@ int32_t DistributedSchedProxy::NotifyMissionsChangedFromRemote(const std::vector
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, Int32, callerInfo.dmsVersion);
if (!DstbMissionInfo::WriteMissionInfoVectorFromParcel(data, missionInfos)) {
if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(data, missionInfos)) {
return ERR_FLATTEN_OBJECT;
}
PARCEL_WRITE_HELPER(data, String, callerInfo.sourceDeviceId);

View File

@ -1045,7 +1045,7 @@ void DistributedSchedService::DumpElementLocked(const std::list<AppExecFwk::Elem
}
int32_t DistributedSchedService::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos)
std::vector<MissionInfo>& missionInfos)
{
return DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceId, numMissions, missionInfos);
}

View File

@ -25,6 +25,7 @@
#include "ipc_skeleton.h"
#include "message_parcel.h"
#include "mission/distributed_sched_mission_manager.h"
#include "mission/mission_info_converter.h"
#include "mission/snapshot_converter.h"
#include "parcel_helper.h"
@ -361,13 +362,13 @@ int32_t DistributedSchedStub::GetMissionInfosInner(MessageParcel& data, MessageP
int32_t numMissions = 0;
PARCEL_READ_HELPER(data, Int32, numMissions);
std::vector<DstbMissionInfo> missionInfos;
int result = GetMissionInfos(Str16ToStr8(deviceId), numMissions, missionInfos);
std::vector<MissionInfo> missionInfos;
int32_t result = GetMissionInfos(Str16ToStr8(deviceId), numMissions, missionInfos);
HILOGI("result = %{public}d", result);
if (result == ERR_NONE) {
return DstbMissionInfo::WriteMissionInfoVectorFromParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
result = MissionInfoConverter::WriteMissionInfosToParcel(reply, missionInfos) ? ERR_NONE : ERR_FLATTEN_OBJECT;
}
return ERR_NULL_OBJECT;
return result;
}
int32_t DistributedSchedStub::GetRemoteSnapshotInfoInner(MessageParcel& data, MessageParcel& reply)
@ -485,7 +486,7 @@ int32_t DistributedSchedStub::StartSyncMissionsFromRemoteInner(MessageParcel& da
if (!reply.WriteInt32(VERSION)) {
return ERR_FLATTEN_OBJECT;
}
if (!DstbMissionInfo::WriteMissionInfoVectorFromParcel(reply, missionInfos)) {
if (!DstbMissionInfo::WriteDstbMissionInfosToParcel(reply, missionInfos)) {
HILOGE("write mission info failed!");
return ERR_FLATTEN_OBJECT;
}
@ -545,7 +546,7 @@ int32_t DistributedSchedStub::NotifyMissionsChangedFromRemoteInner(MessageParcel
int32_t version = data.ReadInt32();
HILOGD("version is %{public}d", version);
std::vector<DstbMissionInfo> missionInfos;
if (!DstbMissionInfo::ReadMissionInfoVectorFromParcel(data, missionInfos)) {
if (!DstbMissionInfo::ReadDstbMissionInfosFromParcel(data, missionInfos)) {
return ERR_FLATTEN_OBJECT;
}
CallerInfo callerInfo;

View File

@ -100,13 +100,13 @@ bool DstbMissionInfo::Marshalling(Parcel& parcel) const
return true;
}
bool DstbMissionInfo::ReadMissionInfoVectorFromParcel(Parcel& parcel,
std::vector<DstbMissionInfo> &missionInfos)
bool DstbMissionInfo::ReadDstbMissionInfosFromParcel(Parcel& parcel,
std::vector<DstbMissionInfo>& missionInfos)
{
int32_t empty = parcel.ReadInt32();
if (empty == VALUE_OBJECT) {
int32_t len = parcel.ReadInt32();
HILOGD("ReadMissionInfoVectorFromParcel::readLength is:%{public}d", len);
HILOGD("ReadDstbMissionInfosFromParcel::readLength is:%{public}d", len);
if (len < 0) {
return false;
}
@ -127,12 +127,12 @@ bool DstbMissionInfo::ReadMissionInfoVectorFromParcel(Parcel& parcel,
}
}
HILOGI("read ReadMissionInfoVectorFromParcel end. info size is:%{public}zu", missionInfos.size());
HILOGI("read ReadDstbMissionInfosFromParcel end. info size is:%{public}zu", missionInfos.size());
return true;
}
bool DstbMissionInfo::WriteMissionInfoVectorFromParcel(Parcel& parcel,
const std::vector<DstbMissionInfo> &missionInfos)
bool DstbMissionInfo::WriteDstbMissionInfosToParcel(Parcel& parcel,
const std::vector<DstbMissionInfo>& missionInfos)
{
size_t size = missionInfos.size();
if (size == 0) {

View File

@ -27,6 +27,7 @@
#include "iservice_registry.h"
#include "mission/mission_changed_notify.h"
#include "mission/mission_constant.h"
#include "mission/mission_info_converter.h"
#include "mission/snapshot_converter.h"
#include "nlohmann/json.hpp"
#include "string_ex.h"
@ -71,7 +72,7 @@ void DistributedSchedMissionManager::Init()
}
int32_t DistributedSchedMissionManager::GetMissionInfos(const std::string& deviceId,
int32_t numMissions, std::vector<DstbMissionInfo>& missionInfos)
int32_t numMissions, std::vector<AAFwk::MissionInfo>& missionInfos)
{
HILOGI("start!");
if (!AllowMissionUid(IPCSkeleton::GetCallingUid())) {
@ -85,8 +86,13 @@ int32_t DistributedSchedMissionManager::GetMissionInfos(const std::string& devic
HILOGE("numMissions is illegal! numMissions:%{public}d", numMissions);
return INVALID_PARAMETERS_ERR;
}
return FetchCachedRemoteMissions(deviceId, numMissions, missionInfos);
std::vector<DstbMissionInfo> dstbMissionInfos;
int32_t ret = FetchCachedRemoteMissions(deviceId, numMissions, dstbMissionInfos);
if (ret != ERR_OK) {
HILOGE("FetchCachedRemoteMissions failed, ret = %{public}d", ret);
return ret;
}
return MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos);
}
sptr<IDistributedSched> DistributedSchedMissionManager::GetRemoteDms(const std::string& deviceId)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Copyright (c) 2021-2022 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
@ -15,12 +15,17 @@
#include "mission/mission_info_converter.h"
#include "adapter/adapter_constant.h"
#include "dtbschedmgr_log.h"
#include "parcel_helper.h"
using namespace std;
namespace OHOS {
namespace DistributedSchedule {
using namespace Constants::Adapter;
namespace {
const std::string TAG = "MissionInfoConverter";
}
int32_t MissionInfoConverter::ConvertToDstbMissionInfos(std::vector<AAFwk::MissionInfo>& missionInfos,
std::vector<DstbMissionInfo>& dstbMissionInfos)
{
@ -59,5 +64,53 @@ int32_t MissionInfoConverter::ConvertToMissionInfos(std::vector<DstbMissionInfo>
}
return ERR_OK;
}
bool MissionInfoConverter::ReadMissionInfosFromParcel(Parcel& parcel,
std::vector<AAFwk::MissionInfo>& missionInfos)
{
int32_t empty = parcel.ReadInt32();
if (empty == VALUE_OBJECT) {
int32_t len = parcel.ReadInt32();
HILOGD("ReadMissionInfosFromParcel::readLength is:%{public}d", len);
if (len < 0) {
return false;
}
size_t size = static_cast<size_t>(len);
if ((size > parcel.GetReadableBytes()) || (missionInfos.max_size() < size)) {
HILOGE("Failed to read MissionInfo vector, size = %{public}zu", size);
return false;
}
missionInfos.clear();
for (size_t i = 0; i < size; i++) {
AAFwk::MissionInfo *ptr = parcel.ReadParcelable<AAFwk::MissionInfo>();
if (ptr == nullptr) {
HILOGW("read MissionInfo failed");
return false;
}
missionInfos.emplace_back(*ptr);
delete ptr;
}
}
HILOGI("ReadMissionInfosFromParcel end. info size is:%{public}zu", missionInfos.size());
return true;
}
bool MissionInfoConverter::WriteMissionInfosToParcel(Parcel& parcel,
const std::vector<AAFwk::MissionInfo>& missionInfos)
{
size_t size = missionInfos.size();
if (size == 0) {
PARCEL_WRITE_HELPER_RET(parcel, Int32, VALUE_NULL, false);
return true;
}
PARCEL_WRITE_HELPER_RET(parcel, Int32, VALUE_OBJECT, false);
PARCEL_WRITE_HELPER_RET(parcel, Int32, size, false);
for (auto& info : missionInfos) {
PARCEL_WRITE_HELPER_RET(parcel, Parcelable, &info, false);
}
return true;
}
}
}

View File

@ -93,7 +93,7 @@ sptr<IDistributedSched> DMSMissionManagerTest::GetDms()
*/
HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo001, TestSize.Level1)
{
std::vector<DstbMissionInfo> infos;
std::vector<AAFwk::MissionInfo> infos;
auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(DEVICE_ID, 0, infos);
EXPECT_TRUE(ret != ERR_NONE);
@ -122,7 +122,7 @@ HWTEST_F(DMSMissionManagerTest, testGetRemoteMissionInfo002, TestSize.Level1)
if (proxy == nullptr) {
return;
}
std::vector<DstbMissionInfo> infos;
std::vector<AAFwk::MissionInfo> infos;
auto ret = proxy->GetMissionInfos(DEVICE_ID, 0, infos);
EXPECT_TRUE(ret != ERR_NONE);
@ -151,7 +151,6 @@ HWTEST_F(DMSMissionManagerTest, testStartSyncRemoteMissions001, TestSize.Level1)
if (proxy == nullptr) {
return;
}
std::vector<DstbMissionInfo> infos;
auto ret = proxy->StartSyncRemoteMissions(DEVICE_ID, false, 0);
EXPECT_TRUE(ret != ERR_NONE);
@ -191,7 +190,7 @@ HWTEST_F(DMSMissionManagerTest, testGetMissionInfos001, TestSize.Level1)
{
std::string deviceid = DEVICE_ID;
int32_t numMissions = NUM_MISSIONS;
std::vector<DstbMissionInfo> missionInfos;
std::vector<AAFwk::MissionInfo> missionInfos;
auto ret = DistributedSchedMissionManager::GetInstance().GetMissionInfos(deviceid, numMissions, missionInfos);
EXPECT_TRUE(ret != ERR_NONE);

View File

@ -145,7 +145,7 @@ int32_t MockDistributedSched::GetOsdSwitchValueFromRemote()
}
int32_t MockDistributedSched::GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos)
std::vector<MissionInfo>& missionInfos)
{
return ERR_NONE;
}

View File

@ -50,7 +50,7 @@ public:
int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
std::vector<DstbMissionInfo>& missionInfos) override;
std::vector<AAFwk::MissionInfo>& missionInfos) override;
int32_t StoreSnapshotInfo(const std::string& deviceId, int32_t missionId,
const uint8_t* byteStream, size_t len) override;
int32_t RemoveSnapshotInfo(const std::string& deviceId, int32_t missionId) override;