Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
ba943bea
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
大约 1 年 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ba943bea
编写于
5月 18, 2022
作者:
L
liubb_0516
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ipc:add new interface of MessageParcelAppend
Signed-off-by:
N
liubb_0516
<
liubeibei8@huawei.com
>
上级
00b47491
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
212 addition
and
0 deletion
+212
-0
interfaces/innerkits/ipc_core/include/message_parcel.h
interfaces/innerkits/ipc_core/include/message_parcel.h
+1
-0
ipc/native/src/core/source/message_parcel.cpp
ipc/native/src/core/source/message_parcel.cpp
+34
-0
ipc/test/auxiliary/native/include/test_service.h
ipc/test/auxiliary/native/include/test_service.h
+2
-0
ipc/test/auxiliary/native/src/test_service.cpp
ipc/test/auxiliary/native/src/test_service.cpp
+16
-0
ipc/test/auxiliary/native/src/test_service_skeleton.cpp
ipc/test/auxiliary/native/src/test_service_skeleton.cpp
+40
-0
ipc/test/moduletest/native/common/ipc_core_module_test.cpp
ipc/test/moduletest/native/common/ipc_core_module_test.cpp
+119
-0
未找到文件。
interfaces/innerkits/ipc_core/include/message_parcel.h
浏览文件 @
ba943bea
...
...
@@ -50,6 +50,7 @@ public:
{
needCloseFd_
=
true
;
};
bool
MessageParcelAppend
(
MessageParcel
&
data
);
private:
#ifndef CONFIG_IPC_SINGLE
...
...
ipc/native/src/core/source/message_parcel.cpp
浏览文件 @
ba943bea
...
...
@@ -422,4 +422,38 @@ sptr<Ashmem> MessageParcel::ReadAshmem()
}
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
false
;
}
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
())
{
bool
res
=
WriteObjectOffset
(
writeCursorOld
+
newObjectOffsets
[
index
]);
if
(
!
res
)
{
DBINDER_LOGE
(
"parcel append write offsets failed"
);
return
false
;
}
}
else
{
DBINDER_LOGE
(
"Failed to ensure parcel capacity"
);
return
false
;
}
}
return
true
;
}
}
// namespace OHOS
ipc/test/auxiliary/native/include/test_service.h
浏览文件 @
ba943bea
...
...
@@ -46,6 +46,8 @@ public:
void
TestAsyncDumpService
()
override
;
int
TestNestingSend
(
int
sendCode
,
int
&
replyCode
)
override
;
int
TestAccessTokenID
(
int32_t
ftoken_expected
)
override
;
int
TestMessageParcelAppend
(
MessageParcel
&
dst
,
MessageParcel
&
src
)
override
;
int
TestMessageParcelAppendWithIpc
(
MessageParcel
&
dst
,
MessageParcel
&
src
,
MessageParcel
&
reply
,
bool
withObject
)
override
;
private:
int
testFd_
;
static
constexpr
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"TestService"
};
...
...
ipc/test/auxiliary/native/src/test_service.cpp
浏览文件 @
ba943bea
...
...
@@ -192,6 +192,22 @@ int TestService::TestAccessTokenID(int32_t ftoken_expected)
return
0
;
}
int
TestService
::
TestMessageParcelAppend
(
MessageParcel
&
dst
,
MessageParcel
&
src
)
{
(
void
)
dst
;
(
void
)
src
;
return
0
;
}
int
TestService
::
TestMessageParcelAppendWithIpc
(
MessageParcel
&
dst
,
MessageParcel
&
src
,
MessageParcel
&
reply
,
bool
withObject
)
{
(
void
)
dst
;
(
void
)
src
;
(
void
)
reply
;
(
void
)
withObject
;
return
0
;
}
int
TestService
::
TestFlushAsyncCalls
(
int
count
,
int
length
)
{
return
0
;
...
...
ipc/test/auxiliary/native/src/test_service_skeleton.cpp
浏览文件 @
ba943bea
...
...
@@ -426,6 +426,33 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected)
return
0
;
}
int
TestServiceProxy
::
TestMessageParcelAppend
(
MessageParcel
&
dst
,
MessageParcel
&
src
)
{
bool
res
=
dst
.
MessageParcelAppend
(
src
);
if
(
!
res
)
{
ZLOGE
(
LABEL
,
"TestMessageParcelAppend without ipc failed"
);
return
-
1
;
}
return
0
;
}
int
TestServiceProxy
::
TestMessageParcelAppendWithIpc
(
MessageParcel
&
dst
,
MessageParcel
&
src
,
MessageParcel
&
reply
,
bool
withObject
)
{
bool
res
=
dst
.
MessageParcelAppend
(
src
);
if
(
!
res
)
{
ZLOGE
(
LABEL
,
"TestMessageParcelAppend with ipc failed"
);
return
-
1
;
}
MessageOption
option
;
uint32_t
code
=
TRANS_MESSAGE_PARCEL_ADDPED
;
if
(
withObject
)
{
code
=
TRANS_MESSAGE_PARCEL_ADDPED_WITH_OBJECT
;
}
int
ret
=
Remote
()
->
SendRequest
(
code
,
dst
,
reply
,
option
);
ZLOGE
(
LABEL
,
"TestMessageParcelAppend with ipc sendrequest ret = %{public}d"
,
ret
);
return
ret
;
}
int
TestServiceProxy
::
TestFlushAsyncCalls
(
int
count
,
int
length
)
{
int
ret
;
...
...
@@ -646,6 +673,19 @@ int TestServiceStub::OnRemoteRequest(uint32_t code,
reply
.
WriteInt32
(
ftoken
);
break
;
}
case
TRANS_MESSAGE_PARCEL_ADDPED
:
{
reply
.
WriteInt32
(
data
.
ReadInt32
());
reply
.
WriteInt32
(
data
.
ReadInt32
());
reply
.
WriteString
(
data
.
ReadString
());
break
;
}
case
TRANS_MESSAGE_PARCEL_ADDPED_WITH_OBJECT
:
{
reply
.
WriteInt32
(
data
.
ReadInt32
());
reply
.
WriteInt32
(
data
.
ReadInt32
());
reply
.
WriteString
(
data
.
ReadString
());
reply
.
WriteRemoteObject
(
data
.
ReadRemoteObject
());
break
;
}
default:
ret
=
IPCObjectStub
::
OnRemoteRequest
(
code
,
data
,
reply
,
option
);
break
;
...
...
ipc/test/moduletest/native/common/ipc_core_module_test.cpp
浏览文件 @
ba943bea
...
...
@@ -27,6 +27,8 @@
#include "system_ability_definition.h"
#include "ipc_object_proxy.h"
#include "foo_service.h"
#include "log_tags.h"
using
namespace
testing
::
ext
;
...
...
@@ -562,6 +564,7 @@ HWTEST_F(IPCNativeFrameworkTest, function_test_018, TestSize.Level1)
}
}
#ifndef CONFIG_STANDARD_SYSTEM
/**
* @tc.name: function_test_019
...
...
@@ -738,3 +741,119 @@ HWTEST_F(IPCNativeFrameworkTest, function_test_024, TestSize.Level1)
thread
->
join
();
}
}
/**
* @tc.name: function_test_025
* @tc.desc: Test messageparcel append in same process
* @tc.type: FUNC
* @tc.require: AR000H0FUK
*/
HWTEST_F
(
IPCNativeFrameworkTest
,
function_test_025
,
TestSize
.
Level1
)
{
IPCTestHelper
helper
;
bool
res
=
helper
.
StartTestApp
(
IPCTestHelper
::
IPC_TEST_SERVER
);
ASSERT_TRUE
(
res
);
auto
saMgr
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
ASSERT_TRUE
(
saMgr
!=
nullptr
);
sptr
<
IRemoteObject
>
object
=
saMgr
->
GetSystemAbility
(
IPC_TEST_SERVICE
);
ASSERT_TRUE
(
object
!=
nullptr
);
sptr
<
ITestService
>
testService
=
iface_cast
<
ITestService
>
(
object
);
ASSERT_TRUE
(
testService
!=
nullptr
);
MessageParcel
dstParcel
,
srcParcel
;
int
ret
=
testService
->
TestMessageParcelAppend
(
dstParcel
,
srcParcel
);
EXPECT_EQ
(
ret
,
-
1
);
const
int32_t
num
=
5767168
;
dstParcel
.
WriteInt32
(
num
);
srcParcel
.
WriteInt32
(
num
);
const
std
::
string
strwrite1
=
"test for write string padded**********************************************************##################"
;
srcParcel
.
WriteString
(
strwrite1
);
sptr
<
FooStub
>
fooCallback
=
new
FooStub
();
srcParcel
.
WriteRemoteObject
(
fooCallback
->
AsObject
());
ret
=
testService
->
TestMessageParcelAppend
(
dstParcel
,
srcParcel
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
num
,
dstParcel
.
ReadInt32
());
EXPECT_EQ
(
num
,
dstParcel
.
ReadInt32
());
EXPECT_EQ
(
strwrite1
,
dstParcel
.
ReadString
());
res
=
dstParcel
.
ReadRemoteObject
();
ASSERT_TRUE
(
res
);
}
/**
* @tc.name: function_test_026
* @tc.desc: Test messageparcel append with ipc
* @tc.type: FUNC
* @tc.require: AR000H0FUK
*/
HWTEST_F
(
IPCNativeFrameworkTest
,
function_test_026
,
TestSize
.
Level1
)
{
IPCTestHelper
helper
;
bool
res
=
helper
.
StartTestApp
(
IPCTestHelper
::
IPC_TEST_SERVER
);
ASSERT_TRUE
(
res
);
auto
saMgr
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
ASSERT_TRUE
(
saMgr
!=
nullptr
);
sptr
<
IRemoteObject
>
object
=
saMgr
->
GetSystemAbility
(
IPC_TEST_SERVICE
);
ASSERT_TRUE
(
object
!=
nullptr
);
sptr
<
ITestService
>
testService
=
iface_cast
<
ITestService
>
(
object
);
ASSERT_TRUE
(
testService
!=
nullptr
);
MessageParcel
dstParcel
,
srcParcel
,
reply
;
const
int32_t
num
=
5767168
;
dstParcel
.
WriteInt32
(
num
);
srcParcel
.
WriteInt32
(
num
);
const
std
::
string
strwrite1
=
"test for write string padded**********************************************************##################"
;
srcParcel
.
WriteString
(
strwrite1
);
int
ret
=
testService
->
TestMessageParcelAppendWithIpc
(
dstParcel
,
srcParcel
,
reply
,
false
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
num
,
reply
.
ReadInt32
());
EXPECT_EQ
(
num
,
reply
.
ReadInt32
());
EXPECT_EQ
(
strwrite1
,
reply
.
ReadString
());
}
/**
* @tc.name: function_test_027
* @tc.desc: Test messageparcel append with ipc
* @tc.type: FUNC
* @tc.require: AR000H0FUK
*/
HWTEST_F
(
IPCNativeFrameworkTest
,
function_test_027
,
TestSize
.
Level1
)
{
IPCTestHelper
helper
;
bool
res
=
helper
.
StartTestApp
(
IPCTestHelper
::
IPC_TEST_SERVER
);
ASSERT_TRUE
(
res
);
auto
saMgr
=
SystemAbilityManagerClient
::
GetInstance
().
GetSystemAbilityManager
();
ASSERT_TRUE
(
saMgr
!=
nullptr
);
sptr
<
IRemoteObject
>
object
=
saMgr
->
GetSystemAbility
(
IPC_TEST_SERVICE
);
ASSERT_TRUE
(
object
!=
nullptr
);
sptr
<
ITestService
>
testService
=
iface_cast
<
ITestService
>
(
object
);
ASSERT_TRUE
(
testService
!=
nullptr
);
MessageParcel
dstParcel
,
srcParcel
,
reply
;
const
int32_t
num
=
5767168
;
dstParcel
.
WriteInt32
(
num
);
srcParcel
.
WriteInt32
(
num
);
const
std
::
string
strwrite1
=
"test for write string padded**********************************************************##################"
;
srcParcel
.
WriteString
(
strwrite1
);
sptr
<
FooStub
>
fooCallback
=
new
FooStub
();
srcParcel
.
WriteRemoteObject
(
fooCallback
->
AsObject
());
int
ret
=
testService
->
TestMessageParcelAppendWithIpc
(
dstParcel
,
srcParcel
,
reply
,
true
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
num
,
reply
.
ReadInt32
());
EXPECT_EQ
(
num
,
reply
.
ReadInt32
());
EXPECT_EQ
(
strwrite1
,
reply
.
ReadString
());
res
=
reply
.
ReadRemoteObject
();
ASSERT_TRUE
(
res
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录