Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
2133da38
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,发现更多精彩内容 >>
未验证
提交
2133da38
编写于
5月 24, 2022
作者:
O
openharmony_ci
提交者:
Gitee
5月 24, 2022
浏览文件
操作
浏览文件
下载
差异文件
!260 ipc:add new interface of MessageParcelAppend
Merge pull request !260 from liubb_0516/master
上级
0766dbb6
86d709c4
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
288 addition
and
0 deletion
+288
-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
+72
-0
ipc/test/auxiliary/native/include/test_service.h
ipc/test/auxiliary/native/include/test_service.h
+3
-0
ipc/test/auxiliary/native/include/test_service_skeleton.h
ipc/test/auxiliary/native/include/test_service_skeleton.h
+8
-0
ipc/test/auxiliary/native/src/test_service.cpp
ipc/test/auxiliary/native/src/test_service.cpp
+17
-0
ipc/test/auxiliary/native/src/test_service_skeleton.cpp
ipc/test/auxiliary/native/src/test_service_skeleton.cpp
+42
-0
ipc/test/moduletest/native/common/ipc_core_module_test.cpp
ipc/test/moduletest/native/common/ipc_core_module_test.cpp
+145
-0
未找到文件。
interfaces/innerkits/ipc_core/include/message_parcel.h
浏览文件 @
2133da38
...
...
@@ -50,6 +50,7 @@ public:
{
needCloseFd_
=
true
;
};
bool
Append
(
MessageParcel
&
data
);
private:
#ifndef CONFIG_IPC_SINGLE
...
...
ipc/native/src/core/source/message_parcel.cpp
浏览文件 @
2133da38
...
...
@@ -37,12 +37,44 @@ namespace OHOS {
#define TITLE __PRETTY_FUNCTION__
#endif
#ifdef CONFIG_IPC_SINGLE
using
namespace
IPC_SINGLE
;
#endif
static
constexpr
OHOS
::
HiviewDFX
::
HiLogLabel
LOG_LABEL
=
{
LOG_CORE
,
LOG_ID_RPC
,
"MessageParcel"
};
#define DBINDER_LOGE(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Error(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
#define DBINDER_LOGI(fmt, args...) \
(void)OHOS::HiviewDFX::HiLog::Info(LOG_LABEL, "%{public}s %{public}d: " fmt, TITLE, __LINE__, ##args)
void
AcquireObject
(
flat_binder_object
*
flat
,
const
void
*
cookie
)
{
switch
(
flat
->
hdr
.
type
)
{
case
BINDER_TYPE_BINDER
:
if
(
flat
->
binder
)
{
reinterpret_cast
<
IRemoteObject
*>
(
flat
->
cookie
)
->
IncStrongRef
(
cookie
);
}
break
;
case
BINDER_TYPE_HANDLE
:
{
IPCProcessSkeleton
*
current
=
IPCProcessSkeleton
::
GetCurrent
();
IRemoteObject
*
remoteObject
=
nullptr
;
if
(
current
!=
nullptr
)
{
remoteObject
=
current
->
QueryObject
(
current
->
MakeHandleDescriptor
(
flat
->
handle
));
}
if
(
remoteObject
!=
nullptr
)
{
remoteObject
->
IncStrongRef
(
cookie
);
}
break
;
}
case
BINDER_TYPE_FD
:
flat
->
handle
=
dup
(
flat
->
handle
);
break
;
default:
DBINDER_LOGE
(
"binder object type is invalid."
);
break
;
}
}
MessageParcel
::
MessageParcel
()
:
Parcel
(),
writeRawDataFd_
(
-
1
),
...
...
@@ -422,4 +454,44 @@ sptr<Ashmem> MessageParcel::ReadAshmem()
}
return
new
(
std
::
nothrow
)
Ashmem
(
fd
,
size
);
}
bool
MessageParcel
::
Append
(
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
(
"failed to append data with writebuffer."
);
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
];
if
(
!
WriteObjectOffset
(
offset
))
{
DBINDER_LOGE
(
"failed to write object offset"
);
return
false
;
}
flat_binder_object
*
flat
=
reinterpret_cast
<
flat_binder_object
*>
(
this
->
GetData
()
+
offset
);
if
(
flat
==
nullptr
)
{
DBINDER_LOGE
(
"flat binder object is nullptr"
);
return
false
;
}
AcquireObject
(
flat
,
this
);
}
else
{
DBINDER_LOGE
(
"Failed to ensure parcel capacity"
);
return
false
;
}
}
return
true
;
}
}
// namespace OHOS
ipc/test/auxiliary/native/include/test_service.h
浏览文件 @
2133da38
...
...
@@ -46,6 +46,9 @@ 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/include/test_service_skeleton.h
浏览文件 @
2133da38
...
...
@@ -47,6 +47,8 @@ public:
TRANS_ID_ASYNC_DUMP_SERVICE
=
16
,
TRANS_ID_NESTING_SEND
=
17
,
TRANS_ID_ACCESS_TOKENID
=
18
,
TRANS_MESSAGE_PARCEL_ADDPED
=
19
,
TRANS_MESSAGE_PARCEL_ADDPED_WITH_OBJECT
=
20
,
};
public:
virtual
int
TestSyncTransaction
(
int
data
,
int
&
reply
,
int
delayTime
=
0
)
=
0
;
...
...
@@ -67,6 +69,9 @@ public:
virtual
void
TestAsyncDumpService
()
=
0
;
virtual
int
TestNestingSend
(
int
sendCode
,
int
&
replyCode
)
=
0
;
virtual
int
TestAccessTokenID
(
int32_t
ftoken_expected
)
=
0
;
virtual
int
TestMessageParcelAppend
(
MessageParcel
&
dst
,
MessageParcel
&
src
)
=
0
;
virtual
int
TestMessageParcelAppendWithIpc
(
MessageParcel
&
dst
,
MessageParcel
&
src
,
MessageParcel
&
reply
,
bool
withObject
)
=
0
;
public:
DECLARE_INTERFACE_DESCRIPTOR
(
u"test.ipc.ITestService"
);
};
...
...
@@ -105,6 +110,9 @@ 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:
static
inline
BrokerDelegator
<
TestServiceProxy
>
delegator_
;
static
constexpr
HiviewDFX
::
HiLogLabel
LABEL
=
{
LOG_CORE
,
LOG_ID_IPC
,
"TestServiceProxy"
};
...
...
ipc/test/auxiliary/native/src/test_service.cpp
浏览文件 @
2133da38
...
...
@@ -192,6 +192,23 @@ 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
浏览文件 @
2133da38
...
...
@@ -426,6 +426,34 @@ int TestServiceProxy::TestAccessTokenID(int32_t ftoken_expected)
return
0
;
}
int
TestServiceProxy
::
TestMessageParcelAppend
(
MessageParcel
&
dst
,
MessageParcel
&
src
)
{
bool
res
=
dst
.
Append
(
src
);
if
(
!
res
)
{
ZLOGE
(
LABEL
,
"message parcel append without ipc failed"
);
return
-
1
;
}
return
0
;
}
int
TestServiceProxy
::
TestMessageParcelAppendWithIpc
(
MessageParcel
&
dst
,
MessageParcel
&
src
,
MessageParcel
&
reply
,
bool
withObject
)
{
bool
res
=
dst
.
Append
(
src
);
if
(
!
res
)
{
ZLOGE
(
LABEL
,
"message parcel append 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 +674,20 @@ 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
());
reply
.
WriteFileDescriptor
(
data
.
ReadFileDescriptor
());
break
;
}
default:
ret
=
IPCObjectStub
::
OnRemoteRequest
(
code
,
data
,
reply
,
option
);
break
;
...
...
ipc/test/moduletest/native/common/ipc_core_module_test.cpp
浏览文件 @
2133da38
...
...
@@ -27,6 +27,9 @@
#include "system_ability_definition.h"
#include "ipc_object_proxy.h"
#include "directory_ex.h"
#include "foo_service.h"
#include "log_tags.h"
using
namespace
testing
::
ext
;
...
...
@@ -738,3 +741,145 @@ 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
,
0
);
const
int32_t
num
=
5767168
;
const
std
::
string
strwrite1
=
"test for write string padded**********************************************************##################"
;
dstParcel
.
WriteInt32
(
num
);
dstParcel
.
WriteString
(
strwrite1
);
srcParcel
.
WriteInt32
(
num
);
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
(
strwrite1
,
dstParcel
.
ReadString
());
EXPECT_EQ
(
num
,
dstParcel
.
ReadInt32
());
EXPECT_EQ
(
strwrite1
,
dstParcel
.
ReadString
());
res
=
dstParcel
.
ReadRemoteObject
();
ASSERT_TRUE
(
res
);
ret
=
testService
->
TestMessageParcelAppend
(
srcParcel
,
dstParcel
);
EXPECT_EQ
(
ret
,
0
);
EXPECT_EQ
(
num
,
srcParcel
.
ReadInt32
());
EXPECT_EQ
(
strwrite1
,
srcParcel
.
ReadString
());
res
=
srcParcel
.
ReadRemoteObject
();
ASSERT_TRUE
(
res
);
EXPECT_EQ
(
num
,
srcParcel
.
ReadInt32
());
EXPECT_EQ
(
strwrite1
,
srcParcel
.
ReadString
());
}
/**
* @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
());
const
std
::
string
dirpath
=
"/data/test_dir"
;
res
=
ForceCreateDirectory
(
dirpath
);
ASSERT_TRUE
(
res
);
string
filename
=
dirpath
+
"/test.txt"
;
int
fd
=
open
(
filename
.
c_str
(),
O_RDWR
|
O_CREAT
|
O_TRUNC
,
S_IRUSR
|
S_IWUSR
);
EXPECT_GT
(
fd
,
0
);
res
=
srcParcel
.
WriteFileDescriptor
(
fd
);
// write fd
ASSERT_TRUE
(
res
);
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
);
res
=
reply
.
ReadFileDescriptor
();
ASSERT_TRUE
(
res
);
RemoveFile
(
filename
);
ForceRemoveDirectory
(
dirpath
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录