提交 8a3c869d 编写于 作者: L liubb_0516

move messageparcelappend to utils parcel

Signed-off-by: Nliubb_0516 <liubeibei8@huawei.com>
上级 a5633443
...@@ -50,7 +50,6 @@ public: ...@@ -50,7 +50,6 @@ public:
{ {
needCloseFd_ = true; needCloseFd_ = true;
}; };
bool MessageParcelAppend(MessageParcel &data);
private: private:
#ifndef CONFIG_IPC_SINGLE #ifndef CONFIG_IPC_SINGLE
......
...@@ -422,43 +422,4 @@ sptr<Ashmem> MessageParcel::ReadAshmem() ...@@ -422,43 +422,4 @@ sptr<Ashmem> MessageParcel::ReadAshmem()
} }
return new (std::nothrow) Ashmem(fd, size); return new (std::nothrow) Ashmem(fd, size);
} }
bool MessageParcel::MessageParcelAppend(MessageParcel &data)
{
size_t dataSize = data.GetDataSize();
if (dataSize == 0) {
DBINDER_LOGE("no data to append");
return true;
}
uintptr_t dataPtr = data.GetData();
size_t writeCursorOld = this->GetWritePosition();
if (!WriteBuffer(reinterpret_cast<void *>(dataPtr), dataSize)) {
DBINDER_LOGE("data append write buffer failed");
return false;
}
size_t objectSize = data.GetOffsetsSize();
if (objectSize == 0) {
return true;
}
binder_size_t objectOffsets = data.GetObjectOffsets();
auto *newObjectOffsets = reinterpret_cast<binder_size_t *>(objectOffsets);
for (size_t index = 0; index < objectSize; index++) {
if (EnsureObjectsCapacity()) {
size_t offset = writeCursorOld + newObjectOffsets[index];
bool res = WriteObjectOffset(offset);
if (!res) {
DBINDER_LOGE("parcel append write offsets failed");
return false;
}
flat_binder_object *flat = reinterpret_cast<flat_binder_object *>(this->GetData() + offset);
if (flat->hdr.type == BINDER_TYPE_FD) {
flat->handle = dup(flat->handle);
}
} else {
DBINDER_LOGE("Failed to ensure parcel capacity");
return false;
}
}
return true;
}
} // namespace OHOS } // namespace OHOS
...@@ -428,7 +428,7 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected) ...@@ -428,7 +428,7 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected)
int TestServiceProxy::TestMessageParcelAppend(MessageParcel &dst, MessageParcel &src) int TestServiceProxy::TestMessageParcelAppend(MessageParcel &dst, MessageParcel &src)
{ {
bool res = dst.MessageParcelAppend(src); bool res = dst.ParcelAppend(src);
if (!res) { if (!res) {
ZLOGE(LABEL, "TestMessageParcelAppend without ipc failed"); ZLOGE(LABEL, "TestMessageParcelAppend without ipc failed");
return -1; return -1;
...@@ -439,7 +439,7 @@ int TestServiceProxy::TestMessageParcelAppend(MessageParcel &dst, MessageParcel ...@@ -439,7 +439,7 @@ int TestServiceProxy::TestMessageParcelAppend(MessageParcel &dst, MessageParcel
int TestServiceProxy::TestMessageParcelAppendWithIpc(MessageParcel &dst, MessageParcel &src, int TestServiceProxy::TestMessageParcelAppendWithIpc(MessageParcel &dst, MessageParcel &src,
MessageParcel &reply, bool withObject) MessageParcel &reply, bool withObject)
{ {
bool res = dst.MessageParcelAppend(src); bool res = dst.ParcelAppend(src);
if (!res) { if (!res) {
ZLOGE(LABEL, "TestMessageParcelAppend with ipc failed"); ZLOGE(LABEL, "TestMessageParcelAppend with ipc failed");
return -1; return -1;
...@@ -685,6 +685,7 @@ int TestServiceStub::OnRemoteRequest(uint32_t code, ...@@ -685,6 +685,7 @@ int TestServiceStub::OnRemoteRequest(uint32_t code,
reply.WriteInt32(data.ReadInt32()); reply.WriteInt32(data.ReadInt32());
reply.WriteString(data.ReadString()); reply.WriteString(data.ReadString());
reply.WriteRemoteObject(data.ReadRemoteObject()); reply.WriteRemoteObject(data.ReadRemoteObject());
reply.WriteFileDescriptor(data.ReadFileDescriptor());
break; break;
} }
default: default:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册