mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-27 00:20:44 +00:00
fix: code duplication
Signed-off-by: z00838083 <zhuhuixuan@huawei.com>
This commit is contained in:
parent
59e45473d2
commit
45c65c0aa7
@ -892,10 +892,10 @@ napi_value JsContinuationManager::GenerateBusinessError(const napi_env &env, int
|
||||
{
|
||||
napi_value code = nullptr;
|
||||
napi_create_int32(env, errCode, &code);
|
||||
napi_value msg = nullptr;
|
||||
napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &msg);
|
||||
napi_value message = nullptr;
|
||||
napi_create_string_utf8(env, errMsg.c_str(), NAPI_AUTO_LENGTH, &message);
|
||||
napi_value businessError = nullptr;
|
||||
napi_create_error(env, nullptr, msg, &businessError);
|
||||
napi_create_error(env, nullptr, message, &businessError);
|
||||
napi_set_named_property(env, businessError, CODE_KEY_NAME.c_str(), code);
|
||||
return businessError;
|
||||
}
|
||||
|
@ -143,12 +143,12 @@ bool DistributedOperation::operator==(const DistributedOperation& other) const
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t entitiesCount = entities_.size();
|
||||
size_t dEntitiesCount = entities_.size();
|
||||
size_t otherEntitiesCount = other.entities_.size();
|
||||
if (entitiesCount != otherEntitiesCount) {
|
||||
if (dEntitiesCount != otherEntitiesCount) {
|
||||
return false;
|
||||
} else {
|
||||
for (size_t i = 0; i < entitiesCount; i++) {
|
||||
for (size_t i = 0; i < dEntitiesCount; i++) {
|
||||
if (entities_[i] != other.entities_[i]) {
|
||||
return false;
|
||||
}
|
||||
@ -187,8 +187,8 @@ bool DistributedOperation::Marshalling(Parcel& parcel) const
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, entities_);
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, flags_);
|
||||
|
||||
Uri uri("");
|
||||
if (uri_ == uri) {
|
||||
Uri dUri("");
|
||||
if (uri_ == dUri) {
|
||||
WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, VALUE_NULL);
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
@ -214,33 +214,33 @@ DistributedOperation* DistributedOperation::Unmarshalling(Parcel& parcel)
|
||||
|
||||
bool DistributedOperation::ReadFromParcel(Parcel& parcel)
|
||||
{
|
||||
std::u16string readString16;
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, readString16);
|
||||
abilityName_ = Str16ToStr8(readString16);
|
||||
readString16.clear();
|
||||
std::u16string dReadString16;
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, dReadString16);
|
||||
abilityName_ = Str16ToStr8(dReadString16);
|
||||
dReadString16.clear();
|
||||
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, readString16);
|
||||
action_ = Str16ToStr8(readString16);
|
||||
readString16.clear();
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, dReadString16);
|
||||
action_ = Str16ToStr8(dReadString16);
|
||||
dReadString16.clear();
|
||||
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, readString16);
|
||||
bundleName_ = Str16ToStr8(readString16);
|
||||
readString16.clear();
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, dReadString16);
|
||||
bundleName_ = Str16ToStr8(dReadString16);
|
||||
dReadString16.clear();
|
||||
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, readString16);
|
||||
deviceId_ = Str16ToStr8(readString16);
|
||||
readString16.clear();
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, dReadString16);
|
||||
deviceId_ = Str16ToStr8(dReadString16);
|
||||
dReadString16.clear();
|
||||
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(StringVector, parcel, &entities_);
|
||||
READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, flags_);
|
||||
|
||||
// uri_
|
||||
int32_t empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
int32_t value = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty == VALUE_OBJECT) {
|
||||
if (value == VALUE_OBJECT) {
|
||||
auto uri = parcel.ReadParcelable<Uri>();
|
||||
if (uri != nullptr) {
|
||||
uri_ = *uri;
|
||||
|
@ -71,16 +71,16 @@ DistributedOperationBuilder& DistributedOperationBuilder::WithUri(const Uri& uri
|
||||
|
||||
std::shared_ptr<DistributedOperation> DistributedOperationBuilder::build()
|
||||
{
|
||||
std::shared_ptr<DistributedOperation> operation = std::make_shared<DistributedOperation>();
|
||||
operation->abilityName_ = abilityName_;
|
||||
operation->bundleName_ = bundleName_;
|
||||
operation->deviceId_ = deviceId_;
|
||||
operation->action_ = action_;
|
||||
operation->entities_ = entities_;
|
||||
operation->flags_ = flags_;
|
||||
operation->uri_ = uri_;
|
||||
std::shared_ptr<DistributedOperation> dOperation = std::make_shared<DistributedOperation>();
|
||||
dOperation->abilityName_ = abilityName_;
|
||||
dOperation->bundleName_ = bundleName_;
|
||||
dOperation->deviceId_ = deviceId_;
|
||||
dOperation->action_ = action_;
|
||||
dOperation->entities_ = entities_;
|
||||
dOperation->flags_ = flags_;
|
||||
dOperation->uri_ = uri_;
|
||||
|
||||
return operation;
|
||||
return dOperation;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021-2023 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
|
||||
@ -259,9 +259,9 @@ DistributedWant& DistributedWant::FormatType(const std::string& type)
|
||||
|
||||
Uri DistributedWant::GetLowerCaseScheme(const Uri& uri)
|
||||
{
|
||||
std::string strUri = const_cast<Uri&>(uri).ToString();
|
||||
std::string dStrUri = const_cast<Uri&>(uri).ToString();
|
||||
std::string schemeStr = const_cast<Uri&>(uri).GetScheme();
|
||||
if (strUri.empty() || schemeStr.empty()) {
|
||||
if (dStrUri.empty() || schemeStr.empty()) {
|
||||
return uri;
|
||||
}
|
||||
|
||||
@ -274,12 +274,12 @@ Uri DistributedWant::GetLowerCaseScheme(const Uri& uri)
|
||||
return uri;
|
||||
}
|
||||
|
||||
std::size_t pos = strUri.find_first_of(schemeStr, 0);
|
||||
std::size_t pos = dStrUri.find_first_of(schemeStr, 0);
|
||||
if (pos != std::string::npos) {
|
||||
strUri.replace(pos, schemeStr.length(), lowSchemeStr);
|
||||
dStrUri.replace(pos, schemeStr.length(), lowSchemeStr);
|
||||
}
|
||||
|
||||
return Uri(strUri);
|
||||
return Uri(dStrUri);
|
||||
}
|
||||
|
||||
DistributedWant& DistributedWant::FormatUriAndType(const Uri& uri, const std::string& type)
|
||||
@ -289,18 +289,19 @@ DistributedWant& DistributedWant::FormatUriAndType(const Uri& uri, const std::st
|
||||
|
||||
std::string DistributedWant::FormatMimeType(const std::string& mimeType)
|
||||
{
|
||||
std::string strMimeType = mimeType;
|
||||
strMimeType.erase(std::remove(strMimeType.begin(), strMimeType.end(), ' '), strMimeType.end());
|
||||
std::transform(
|
||||
strMimeType.begin(), strMimeType.end(), strMimeType.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
std::string dStrMimeType = mimeType;
|
||||
dStrMimeType.erase(std::remove(dStrMimeType.begin(), dStrMimeType.end(), ' '), dStrMimeType.end());
|
||||
std::transform(dStrMimeType.begin(), dStrMimeType.end(), dStrMimeType.begin(), [](unsigned char c) {
|
||||
return std::tolower(c);
|
||||
});
|
||||
|
||||
std::size_t pos = 0;
|
||||
std::size_t begin = 0;
|
||||
pos = strMimeType.find_first_of(";", begin);
|
||||
pos = dStrMimeType.find_first_of(";", begin);
|
||||
if (pos != std::string::npos) {
|
||||
strMimeType = strMimeType.substr(begin, pos - begin);
|
||||
dStrMimeType = dStrMimeType.substr(begin, pos - begin);
|
||||
}
|
||||
return strMimeType;
|
||||
return dStrMimeType;
|
||||
}
|
||||
|
||||
std::string DistributedWant::GetAction() const
|
||||
@ -996,9 +997,9 @@ void DistributedWant::GenerateUriString(std::string& uriString) const
|
||||
if (GetUriString().length() > 0) {
|
||||
uriString += "uri=" + Encode(GetUriString()) + ";";
|
||||
}
|
||||
for (auto entity : operation_.GetEntities()) {
|
||||
if (entity.length() > 0) {
|
||||
uriString += "entity=" + Encode(entity) + ";";
|
||||
for (auto dEntity : operation_.GetEntities()) {
|
||||
if (dEntity.length() > 0) {
|
||||
uriString += "entity=" + Encode(dEntity) + ";";
|
||||
}
|
||||
}
|
||||
if (operation_.GetDeviceId().length() > 0) {
|
||||
@ -1013,8 +1014,8 @@ void DistributedWant::GenerateUriString(std::string& uriString) const
|
||||
if (operation_.GetFlags() != 0) {
|
||||
uriString += "flag=";
|
||||
char buf[HEX_STRING_BUF_LEN] {0};
|
||||
int len = snprintf_s(buf, HEX_STRING_BUF_LEN, HEX_STRING_BUF_LEN - 1, "0x%08x", operation_.GetFlags());
|
||||
if (len == HEX_STRING_LEN) {
|
||||
int lenth = snprintf_s(buf, HEX_STRING_BUF_LEN, HEX_STRING_BUF_LEN - 1, "0x%08x", operation_.GetFlags());
|
||||
if (lenth == HEX_STRING_LEN) {
|
||||
std::string flag = buf;
|
||||
uriString += Encode(flag);
|
||||
uriString += ";";
|
||||
@ -1112,14 +1113,17 @@ bool DistributedWant::MarshallingWriteUri(Parcel& parcel) const
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteString16(Str8ToStr16(GetUriString()))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteString16(Str8ToStr16(GetUriString()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1147,9 +1151,9 @@ bool DistributedWant::MarshallingWriteEntities(Parcel& parcel) const
|
||||
|
||||
bool DistributedWant::MarshallingWriteElement(Parcel& parcel) const
|
||||
{
|
||||
ElementName emptyElement;
|
||||
ElementName empty;
|
||||
ElementName element = GetElement();
|
||||
if (element == emptyElement) {
|
||||
if (element == empty) {
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
@ -1170,13 +1174,15 @@ bool DistributedWant::MarshallingWriteParameters(Parcel& parcel) const
|
||||
if (!parcel.WriteInt32(VALUE_NULL)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteParcelable(¶meters_)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(VALUE_OBJECT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteParcelable(¶meters_)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -1226,11 +1232,11 @@ DistributedWant* DistributedWant::Unmarshalling(Parcel& parcel)
|
||||
|
||||
bool DistributedWant::ReadUriFromParcel(Parcel& parcel)
|
||||
{
|
||||
int empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
int value = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
if (empty == VALUE_OBJECT) {
|
||||
if (value == VALUE_OBJECT) {
|
||||
SetUri(Str16ToStr8(parcel.ReadString16()));
|
||||
}
|
||||
return true;
|
||||
@ -1240,11 +1246,11 @@ bool DistributedWant::ReadEntitiesFromParcel(Parcel& parcel)
|
||||
{
|
||||
std::vector<std::string> entities;
|
||||
std::vector<std::u16string> entityU16;
|
||||
int empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
int value = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
if (empty == VALUE_OBJECT) {
|
||||
if (value == VALUE_OBJECT) {
|
||||
if (!parcel.ReadString16Vector(&entityU16)) {
|
||||
return false;
|
||||
}
|
||||
@ -1258,11 +1264,11 @@ bool DistributedWant::ReadEntitiesFromParcel(Parcel& parcel)
|
||||
|
||||
bool DistributedWant::ReadElementFromParcel(Parcel& parcel)
|
||||
{
|
||||
int empty = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(empty)) {
|
||||
int value = VALUE_NULL;
|
||||
if (!parcel.ReadInt32(value)) {
|
||||
return false;
|
||||
}
|
||||
if (empty == VALUE_OBJECT) {
|
||||
if (value == VALUE_OBJECT) {
|
||||
auto element = parcel.ReadParcelable<ElementName>();
|
||||
if (element != nullptr) {
|
||||
SetElement(*element);
|
||||
@ -1327,37 +1333,37 @@ bool DistributedWant::ReadFromParcel(Parcel& parcel)
|
||||
bool DistributedWant::ParseUriInternal(const std::string& content, ElementName& element, DistributedWant& want)
|
||||
{
|
||||
static constexpr int TYPE_TAG_SIZE = 2;
|
||||
std::string prop;
|
||||
std::string dProp;
|
||||
std::string value;
|
||||
|
||||
if (content.empty() || content[0] == '=') {
|
||||
return true;
|
||||
}
|
||||
if (!ParseContent(content, prop, value)) {
|
||||
if (!ParseContent(content, dProp, value)) {
|
||||
return false;
|
||||
}
|
||||
if (value.empty()) {
|
||||
return true;
|
||||
}
|
||||
if (prop == "action") {
|
||||
if (dProp == "action") {
|
||||
want.SetAction(value);
|
||||
} else if (prop == "entity") {
|
||||
} else if (dProp == "entity") {
|
||||
want.AddEntity(value);
|
||||
} else if (prop == "flag") {
|
||||
} else if (dProp == "flag") {
|
||||
if (!ParseFlag(value, want)) {
|
||||
return false;
|
||||
}
|
||||
} else if (prop == "device") {
|
||||
} else if (dProp == "device") {
|
||||
element.SetDeviceID(value);
|
||||
} else if (prop == "bundle") {
|
||||
} else if (dProp == "bundle") {
|
||||
element.SetBundleName(value);
|
||||
} else if (prop == "ability") {
|
||||
} else if (dProp == "ability") {
|
||||
element.SetAbilityName(value);
|
||||
} else if (prop == "package") {
|
||||
} else if (dProp == "package") {
|
||||
want.SetBundle(Decode(value));
|
||||
} else if (prop.length() > TYPE_TAG_SIZE) {
|
||||
std::string key = prop.substr(TYPE_TAG_SIZE);
|
||||
if (!DistributedWant::CheckAndSetParameters(want, key, prop, value)) {
|
||||
} else if (dProp.length() > TYPE_TAG_SIZE) {
|
||||
std::string key = dProp.substr(TYPE_TAG_SIZE);
|
||||
if (!DistributedWant::CheckAndSetParameters(want, key, dProp, value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1366,11 +1372,11 @@ bool DistributedWant::ParseUriInternal(const std::string& content, ElementName&
|
||||
|
||||
bool DistributedWant::ParseContent(const std::string& content, std::string& prop, std::string& value)
|
||||
{
|
||||
std::size_t pos = content.find("=");
|
||||
if (pos != std::string::npos) {
|
||||
std::string subString = content.substr(0, pos);
|
||||
std::size_t dPos = content.find("=");
|
||||
if (dPos != std::string::npos) {
|
||||
std::string subString = content.substr(0, dPos);
|
||||
prop = Decode(subString);
|
||||
subString = content.substr(pos + 1, content.length() - pos - 1);
|
||||
subString = content.substr(dPos + 1, content.length() - dPos - 1);
|
||||
value = Decode(subString);
|
||||
return true;
|
||||
}
|
||||
@ -1379,20 +1385,20 @@ bool DistributedWant::ParseContent(const std::string& content, std::string& prop
|
||||
|
||||
bool DistributedWant::ParseFlag(const std::string& content, DistributedWant& want)
|
||||
{
|
||||
std::string contentLower = LowerStr(content);
|
||||
std::string dContentLower = LowerStr(content);
|
||||
std::string prefix = "0x";
|
||||
if (!contentLower.empty()) {
|
||||
if (contentLower.find(prefix) != 0) {
|
||||
if (!dContentLower.empty()) {
|
||||
if (dContentLower.find(prefix) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::size_t i = prefix.length(); i < contentLower.length(); i++) {
|
||||
if (!isxdigit(contentLower[i])) {
|
||||
for (std::size_t i = prefix.length(); i < dContentLower.length(); i++) {
|
||||
if (!isxdigit(dContentLower[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int base = 16; // hex string
|
||||
unsigned int flag = std::stoul(contentLower, nullptr, base);
|
||||
unsigned int flag = std::stoul(dContentLower, nullptr, base);
|
||||
want.SetFlags(flag);
|
||||
}
|
||||
return true;
|
||||
@ -1400,54 +1406,54 @@ bool DistributedWant::ParseFlag(const std::string& content, DistributedWant& wan
|
||||
|
||||
std::string DistributedWant::Decode(const std::string& str)
|
||||
{
|
||||
std::string decode;
|
||||
std::string dDecode;
|
||||
for (std::size_t i = 0; i < str.length();) {
|
||||
if (str[i] == '\\') {
|
||||
if (++i >= str.length()) {
|
||||
decode += "\\";
|
||||
dDecode += "\\";
|
||||
break;
|
||||
}
|
||||
if (str[i] == '\\') {
|
||||
decode += "\\";
|
||||
dDecode += "\\";
|
||||
i++;
|
||||
} else if (str[i] == '0') {
|
||||
if (str.compare(i, OCT_EQUALSTO.length(), OCT_EQUALSTO) == 0) {
|
||||
decode += "=";
|
||||
dDecode += "=";
|
||||
i += OCT_EQUALSTO.length();
|
||||
} else if (str.compare(i, OCT_SEMICOLON.length(), OCT_SEMICOLON) == 0) {
|
||||
decode += ";";
|
||||
dDecode += ";";
|
||||
i += OCT_SEMICOLON.length();
|
||||
} else {
|
||||
decode += "\\" + str.substr(i, 1);
|
||||
dDecode += "\\" + str.substr(i, 1);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
decode += "\\" + str.substr(i, 1);
|
||||
dDecode += "\\" + str.substr(i, 1);
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
decode += str[i];
|
||||
dDecode += str[i];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return decode;
|
||||
return dDecode;
|
||||
}
|
||||
|
||||
std::string DistributedWant::Encode(const std::string& str)
|
||||
{
|
||||
std::string encode;
|
||||
std::string dEncode;
|
||||
for (std::size_t i = 0; i < str.length(); i++) {
|
||||
if (str[i] == '\\') {
|
||||
encode += "\\\\";
|
||||
dEncode += "\\\\";
|
||||
} else if (str[i] == '=') {
|
||||
encode += "\\" + OCT_EQUALSTO;
|
||||
dEncode += "\\" + OCT_EQUALSTO;
|
||||
} else if (str[i] == ';') {
|
||||
encode += "\\" + OCT_SEMICOLON;
|
||||
dEncode += "\\" + OCT_SEMICOLON;
|
||||
} else {
|
||||
encode += str[i];
|
||||
dEncode += str[i];
|
||||
}
|
||||
}
|
||||
return encode;
|
||||
return dEncode;
|
||||
}
|
||||
|
||||
bool DistributedWant::CheckAndSetParameters(DistributedWant& want, const std::string& key,
|
||||
@ -1531,10 +1537,10 @@ nlohmann::json DistributedWant::ToJson() const
|
||||
DistributedWantParamWrapper wrapper(parameters_);
|
||||
std::string parametersString = wrapper.ToString();
|
||||
|
||||
nlohmann::json entitiesJson;
|
||||
nlohmann::json dEntitiesJson;
|
||||
std::vector<std::string> entities = GetEntities();
|
||||
for (auto entity : entities) {
|
||||
entitiesJson.emplace_back(entity);
|
||||
dEntitiesJson.emplace_back(entity);
|
||||
}
|
||||
|
||||
nlohmann::json wantJson = nlohmann::json {
|
||||
@ -1546,7 +1552,7 @@ nlohmann::json DistributedWant::ToJson() const
|
||||
{"flags", GetFlags()},
|
||||
{"action", GetAction()},
|
||||
{"parameters", parametersString},
|
||||
{"entities", entitiesJson},
|
||||
{"entities", dEntitiesJson},
|
||||
};
|
||||
return wantJson;
|
||||
}
|
||||
|
@ -432,8 +432,8 @@ bool DistributedWantParams::WriteToParcelWantParams(Parcel& parcel, sptr<IInterf
|
||||
{
|
||||
DistributedWantParams value = DistributedWantParamWrapper::Unbox(IDistributedWantParams::Query(o));
|
||||
|
||||
auto type = value.GetParam(TYPE_PROPERTY);
|
||||
AAFwk::IString *typeP = AAFwk::IString::Query(type);
|
||||
auto dType = value.GetParam(TYPE_PROPERTY);
|
||||
AAFwk::IString *typeP = AAFwk::IString::Query(dType);
|
||||
if (typeP != nullptr) {
|
||||
std::string typeValue = AAFwk::String::Unbox(typeP);
|
||||
if (typeValue == FD) {
|
||||
@ -457,8 +457,8 @@ bool DistributedWantParams::WriteToParcelFD(Parcel& parcel, const DistributedWan
|
||||
return false;
|
||||
}
|
||||
|
||||
auto fdWrap = value.GetParam(VALUE_PROPERTY);
|
||||
AAFwk::IInteger *fdIWrap = AAFwk::IInteger::Query(fdWrap);
|
||||
auto dFdWrap = value.GetParam(VALUE_PROPERTY);
|
||||
AAFwk::IInteger *fdIWrap = AAFwk::IInteger::Query(dFdWrap);
|
||||
if (fdIWrap != nullptr) {
|
||||
int fd = AAFwk::Integer::Unbox(fdIWrap);
|
||||
auto messageParcel = static_cast<MessageParcel*>(&parcel);
|
||||
@ -478,8 +478,8 @@ bool DistributedWantParams::WriteToParcelRemoteObject(Parcel& parcel, const Dist
|
||||
return false;
|
||||
}
|
||||
|
||||
auto remoteObjectWrap = value.GetParam(VALUE_PROPERTY);
|
||||
AAFwk::IRemoteObjectWrap *remoteObjectIWrap = AAFwk::IRemoteObjectWrap::Query(remoteObjectWrap);
|
||||
auto remoteObjWrap = value.GetParam(VALUE_PROPERTY);
|
||||
AAFwk::IRemoteObjectWrap *remoteObjectIWrap = AAFwk::IRemoteObjectWrap::Query(remoteObjWrap);
|
||||
if (remoteObjectIWrap != nullptr) {
|
||||
auto remoteObject = AAFwk::RemoteObjectWrap::UnBox(remoteObjectIWrap);
|
||||
auto messageParcel = static_cast<MessageParcel*>(&parcel);
|
||||
@ -590,12 +590,12 @@ bool DistributedWantParams::WriteMarshalling(Parcel& parcel, sptr<IInterface>& o
|
||||
|
||||
bool DistributedWantParams::DoMarshalling(Parcel& parcel) const
|
||||
{
|
||||
size_t size = params_.size();
|
||||
size_t dSize = params_.size();
|
||||
if (!cachedUnsupportedData_.empty()) {
|
||||
size += cachedUnsupportedData_.size();
|
||||
dSize += cachedUnsupportedData_.size();
|
||||
}
|
||||
|
||||
if (!parcel.WriteInt32(size)) {
|
||||
if (!parcel.WriteInt32(dSize)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -614,21 +614,21 @@ bool DistributedWantParams::DoMarshalling(Parcel& parcel) const
|
||||
}
|
||||
|
||||
if (!cachedUnsupportedData_.empty()) {
|
||||
for (const DistributedUnsupportedData& data : cachedUnsupportedData_) {
|
||||
if (!parcel.WriteString16(data.key)) {
|
||||
for (const DistributedUnsupportedData& dData : cachedUnsupportedData_) {
|
||||
if (!parcel.WriteString16(dData.key)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(data.type)) {
|
||||
if (!parcel.WriteInt32(dData.type)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteInt32(data.size)) {
|
||||
if (!parcel.WriteInt32(dData.size)) {
|
||||
return false;
|
||||
}
|
||||
// Corresponding to Parcel#writeByteArray() in Java.
|
||||
if (!parcel.WriteInt32(data.size)) {
|
||||
if (!parcel.WriteInt32(dData.size)) {
|
||||
return false;
|
||||
}
|
||||
if (!parcel.WriteBuffer(data.buffer, data.size)) {
|
||||
if (!parcel.WriteBuffer(dData.buffer, dData.size)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -675,23 +675,23 @@ static void SetNewArray(const AAFwk::InterfaceID& id, AAFwk::IArray* orgIArray,
|
||||
if (orgIArray == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::vector<T1> array;
|
||||
auto func = [&array](AAFwk::IInterface* object) {
|
||||
std::vector<T1> dArray;
|
||||
auto func = [&dArray](AAFwk::IInterface* object) {
|
||||
if (object != nullptr) {
|
||||
T3* value = T3::Query(object);
|
||||
if (value != nullptr) {
|
||||
array.push_back(T2::Unbox(value));
|
||||
dArray.push_back(T2::Unbox(value));
|
||||
}
|
||||
}
|
||||
};
|
||||
AAFwk::Array::ForEach(orgIArray, func);
|
||||
|
||||
typename std::vector<T1>::size_type size = array.size();
|
||||
typename std::vector<T1>::size_type size = dArray.size();
|
||||
if (size > 0) {
|
||||
ao = new (std::nothrow) AAFwk::Array(size, id);
|
||||
if (ao != nullptr) {
|
||||
for (typename std::vector<T1>::size_type i = 0; i < size; i++) {
|
||||
ao->Set(i, T2::Box(array[i]));
|
||||
ao->Set(i, T2::Box(dArray[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1183,19 +1183,19 @@ bool DistributedWantParams::ReadUnsupportedData(Parcel& parcel, const std::strin
|
||||
return false;
|
||||
}
|
||||
|
||||
DistributedUnsupportedData data;
|
||||
data.key = Str8ToStr16(key);
|
||||
data.type = type;
|
||||
data.size = bufferSize;
|
||||
data.buffer = new (std::nothrow) uint8_t[bufferSize];
|
||||
if (data.buffer == nullptr) {
|
||||
DistributedUnsupportedData dData;
|
||||
dData.key = Str8ToStr16(key);
|
||||
dData.type = type;
|
||||
dData.size = bufferSize;
|
||||
dData.buffer = new (std::nothrow) uint8_t[bufferSize];
|
||||
if (dData.buffer == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (memcpy_s(data.buffer, bufferSize, bufferP, bufferSize) != EOK) {
|
||||
if (memcpy_s(dData.buffer, bufferSize, bufferP, bufferSize) != EOK) {
|
||||
return false;
|
||||
}
|
||||
cachedUnsupportedData_.emplace_back(std::move(data));
|
||||
cachedUnsupportedData_.emplace_back(std::move(dData));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1240,9 +1240,9 @@ bool DistributedWantParams::ReadFromParcelParam(Parcel& parcel, const std::strin
|
||||
if (!ReadArrayToParcel(parcel, type, ao)) {
|
||||
return false;
|
||||
}
|
||||
sptr<IInterface> intf = ao;
|
||||
if (intf) {
|
||||
SetParam(key, intf);
|
||||
sptr<IInterface> dIntf = ao;
|
||||
if (dIntf) {
|
||||
SetParam(key, dIntf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ std::string DistributedWantParamWrapper::ToString()
|
||||
if (wantParams_.Size() != 0) {
|
||||
result += "{";
|
||||
for (auto it : wantParams_.GetParams()) {
|
||||
int typeId = DistributedWantParams::GetDataType(it.second);
|
||||
result = result + "\"" + it.first + "\":{\"" + std::to_string(typeId) + "\":";
|
||||
int dTypeId = DistributedWantParams::GetDataType(it.second);
|
||||
result = result + "\"" + it.first + "\":{\"" + std::to_string(dTypeId) + "\":";
|
||||
if (IDistributedWantParams::Query(it.second) != nullptr) {
|
||||
result = result +
|
||||
static_cast<DistributedWantParamWrapper*>(IDistributedWantParams::Query(it.second))->ToString();
|
||||
} else {
|
||||
result = result + "\"" + DistributedWantParams::GetStringByType(it.second, typeId) + "\"";
|
||||
result = result + "\"" + DistributedWantParams::GetStringByType(it.second, dTypeId) + "\"";
|
||||
}
|
||||
if (it == *wantParams_.GetParams().rbegin()) {
|
||||
result += "}";
|
||||
@ -97,15 +97,15 @@ bool DistributedWantParamWrapper::ValidateStr(const std::string& str)
|
||||
if (count(str.begin(), str.end(), '{') != count(str.begin(), str.end(), '}')) {
|
||||
return false;
|
||||
}
|
||||
int count = 0;
|
||||
int counter = 0;
|
||||
for (auto it : str) {
|
||||
if (it == '{') {
|
||||
count++;
|
||||
counter++;
|
||||
}
|
||||
if (it == '}') {
|
||||
count--;
|
||||
counter--;
|
||||
}
|
||||
if (count < 0) {
|
||||
if (counter < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -116,10 +116,10 @@ sptr<IDistributedWantParams> DistributedWantParamWrapper::Parse(const std::strin
|
||||
{
|
||||
DistributedWantParams wantParams;
|
||||
if (ValidateStr(str)) {
|
||||
std::string key = "";
|
||||
std::string strKey = "";
|
||||
int typeId = 0;
|
||||
for (size_t strnum = 0; strnum < str.size(); strnum++) {
|
||||
if (str[strnum] == '{' && key != "" && typeId == DistributedWantParams::VALUE_TYPE_WANTPARAMS) {
|
||||
if (str[strnum] == '{' && strKey != "" && typeId == DistributedWantParams::VALUE_TYPE_WANTPARAMS) {
|
||||
size_t num;
|
||||
int count = 0;
|
||||
for (num = strnum; num < str.size(); num++) {
|
||||
@ -132,14 +132,14 @@ sptr<IDistributedWantParams> DistributedWantParamWrapper::Parse(const std::strin
|
||||
break;
|
||||
}
|
||||
}
|
||||
wantParams.SetParam(key, DistributedWantParamWrapper::Parse(str.substr(strnum, num - strnum + 1)));
|
||||
key = "";
|
||||
wantParams.SetParam(strKey, DistributedWantParamWrapper::Parse(str.substr(strnum, num - strnum + 1)));
|
||||
strKey = "";
|
||||
typeId = 0;
|
||||
strnum = num + 1;
|
||||
} else if (str[strnum] == '"') {
|
||||
if (key == "") {
|
||||
if (strKey == "") {
|
||||
strnum++;
|
||||
key = str.substr(strnum, str.find('"', strnum) - strnum);
|
||||
strKey = str.substr(strnum, str.find('"', strnum) - strnum);
|
||||
strnum = str.find('"', strnum);
|
||||
} else if (typeId == 0) {
|
||||
strnum++;
|
||||
@ -150,12 +150,12 @@ sptr<IDistributedWantParams> DistributedWantParamWrapper::Parse(const std::strin
|
||||
strnum = str.find('"', strnum);
|
||||
} else {
|
||||
strnum++;
|
||||
wantParams.SetParam(key,
|
||||
wantParams.SetParam(strKey,
|
||||
DistributedWantParams::GetInterfaceByType(typeId,
|
||||
str.substr(strnum, str.find('"', strnum) - strnum)));
|
||||
strnum = str.find('"', strnum);
|
||||
typeId = 0;
|
||||
key = "";
|
||||
strKey = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -174,14 +174,14 @@ DistributedWantParams DistributedWantParamWrapper::ParseWantParams(const std::st
|
||||
for (size_t strnum = 0; strnum < str.size(); strnum++) {
|
||||
if (str[strnum] == '{' && key != "" && typeId == DistributedWantParams::VALUE_TYPE_WANTPARAMS) {
|
||||
size_t num;
|
||||
int count = 0;
|
||||
int counter = 0;
|
||||
for (num = strnum; num < str.size(); num++) {
|
||||
if (str[num] == '{') {
|
||||
count++;
|
||||
counter++;
|
||||
} else if (str[num] == '}') {
|
||||
count--;
|
||||
counter--;
|
||||
}
|
||||
if (count == 0) {
|
||||
if (counter == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -57,9 +57,9 @@ int32_t DistributedSchedProxy::StartRemoteAbility(const OHOS::AAFwk::Want& want,
|
||||
PARCEL_WRITE_HELPER(data, Int32, callerUid);
|
||||
PARCEL_WRITE_HELPER(data, Int32, requestCode);
|
||||
PARCEL_WRITE_HELPER(data, Uint32, accessToken);
|
||||
MessageParcel reply;
|
||||
MessageParcel msgReply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_REMOTE_ABILITY),
|
||||
data, reply);
|
||||
data, msgReply);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedProxy::StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
|
||||
@ -148,8 +148,8 @@ int32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, c
|
||||
PARCEL_WRITE_HELPER(data, Int32, missionId);
|
||||
PARCEL_WRITE_HELPER(data, RemoteObject, callback);
|
||||
PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
|
||||
MessageParcel reply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION), data, reply);
|
||||
MessageParcel msgReply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION), data, msgReply);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
|
||||
@ -173,9 +173,9 @@ int32_t DistributedSchedProxy::ContinueMission(const std::string& srcDeviceId, c
|
||||
PARCEL_WRITE_HELPER(data, String, bundleName);
|
||||
PARCEL_WRITE_HELPER(data, RemoteObject, callback);
|
||||
PARCEL_WRITE_HELPER(data, Parcelable, &wantParams);
|
||||
MessageParcel reply;
|
||||
MessageParcel msgReply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::CONTINUE_MISSION_OF_BUNDLENAME),
|
||||
data, reply);
|
||||
data, msgReply);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
|
||||
@ -195,8 +195,9 @@ int32_t DistributedSchedProxy::StartContinuation(const OHOS::AAFwk::Want& want,
|
||||
PARCEL_WRITE_HELPER(data, Int32, callerUid);
|
||||
PARCEL_WRITE_HELPER(data, Int32, status);
|
||||
PARCEL_WRITE_HELPER(data, Uint32, accessToken);
|
||||
MessageParcel reply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION), data, reply);
|
||||
MessageParcel msgReply;
|
||||
PARCEL_TRANSACT_SYNC_RET_INT(remote, static_cast<uint32_t>(IDSchedInterfaceCode::START_CONTINUATION),
|
||||
data, msgReply);
|
||||
}
|
||||
|
||||
void DistributedSchedProxy::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess)
|
||||
|
Loading…
Reference in New Issue
Block a user