Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
9c810632
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,发现更多精彩内容 >>
提交
9c810632
编写于
9月 23, 2021
作者:
O
openharmony_ci
提交者:
Gitee
9月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
!31 implement js sendRequest for RemoteObject
Merge pull request !31 from liangshenglin1/0923
上级
72347a73
594cb879
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
275 addition
and
94 deletion
+275
-94
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
+8
-0
ipc/native/src/core/source/ipc_object_stub.cpp
ipc/native/src/core/source/ipc_object_stub.cpp
+5
-0
ipc/native/src/jni/source/ohos_rpc_remote_object.cpp
ipc/native/src/jni/source/ohos_rpc_remote_object.cpp
+14
-3
ipc/native/src/napi/include/napi_message_parcel.h
ipc/native/src/napi/include/napi_message_parcel.h
+5
-8
ipc/native/src/napi/include/napi_remote_object.h
ipc/native/src/napi/include/napi_remote_object.h
+7
-4
ipc/native/src/napi/src/napi_message_parcel.cpp
ipc/native/src/napi/src/napi_message_parcel.cpp
+31
-24
ipc/native/src/napi/src/napi_remote_object.cpp
ipc/native/src/napi/src/napi_remote_object.cpp
+205
-55
未找到文件。
interfaces/innerkits/ipc_core/include/ipc_object_stub.h
浏览文件 @
9c810632
...
...
@@ -28,6 +28,12 @@ struct RefCountNode {
class
IPCObjectStub
:
public
IRemoteObject
{
public:
enum
{
OBJECT_TYPE_NATIVE
,
OBJECT_TYPE_JAVA
,
OBJECT_TYPE_JAVASCRIPT
,
};
explicit
IPCObjectStub
(
std
::
u16string
descriptor
=
nullptr
);
~
IPCObjectStub
();
...
...
@@ -60,6 +66,8 @@ public:
virtual
int32_t
ProcessProto
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
);
virtual
int
GetObjectType
()
const
;
#ifndef CONFIG_IPC_SINGLE
int32_t
InvokerThread
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
);
...
...
ipc/native/src/core/source/ipc_object_stub.cpp
浏览文件 @
9c810632
...
...
@@ -289,6 +289,11 @@ pid_t IPCObjectStub::GetCallingUid()
return
IPCSkeleton
::
GetCallingUid
();
}
int
IPCObjectStub
::
GetObjectType
()
const
{
return
OBJECT_TYPE_NATIVE
;
}
int32_t
IPCObjectStub
::
ProcessProto
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
)
{
int
result
=
ERR_NONE
;
...
...
ipc/native/src/jni/source/ohos_rpc_remote_object.cpp
浏览文件 @
9c810632
...
...
@@ -70,6 +70,8 @@ public:
bool
CheckObjectLegality
()
const
override
;
int
GetObjectType
()
const
override
;
int
OnRemoteRequest
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
)
override
;
int
OnRemoteDump
(
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
)
override
;
...
...
@@ -160,6 +162,11 @@ bool JRemoteObject::CheckObjectLegality() const
return
true
;
}
int
JRemoteObject
::
GetObjectType
()
const
{
return
OBJECT_TYPE_JAVA
;
}
JRemoteObject
::~
JRemoteObject
()
{
JNIEnvHelper
env
;
...
...
@@ -379,9 +386,13 @@ jobject Java_ohos_rpc_getJavaRemoteObject(JNIEnv *env, const sptr<IRemoteObject>
}
if
(
target
->
CheckObjectLegality
())
{
ZLOGI
(
LABEL
,
"native Get RemoteObject"
);
auto
object
=
static_cast
<
JRemoteObject
*>
(
target
.
GetRefPtr
());
return
object
->
GetJObject
();
IPCObjectStub
*
tmp
=
static_cast
<
IPCObjectStub
*>
(
target
.
GetRefPtr
());
ZLOGW
(
LABEL
,
"object type:%{public}d"
,
tmp
->
GetObjectType
());
if
(
tmp
->
GetObjectType
()
==
IPCObjectStub
::
OBJECT_TYPE_JAVA
)
{
ZLOGW
(
LABEL
,
"native Get Java RemoteObject"
);
auto
object
=
static_cast
<
JRemoteObject
*>
(
tmp
);
return
object
->
GetJObject
();
}
}
std
::
lock_guard
<
std
::
mutex
>
lockGuard
(
g_proxyMutex_
);
...
...
ipc/native/src/napi/include/napi_message_parcel.h
浏览文件 @
9c810632
...
...
@@ -28,9 +28,8 @@ class NAPI_MessageParcel {
public:
NAPI_MessageParcel
(
napi_env
env
,
napi_value
thisVar
,
MessageParcel
*
parcel
);
virtual
~
NAPI_MessageParcel
();
MessageParcel
*
GetMessageParcel
();
std
::
shared_ptr
<
MessageParcel
>
GetMessageParcel
();
static
napi_value
Export
(
napi_env
env
,
napi_value
exports
);
static
napi_ref
GetParcelConsRef
();
private:
// Napi methods and properties
static
napi_value
JS_constructor
(
napi_env
env
,
napi_callback_info
cbinfo
);
...
...
@@ -93,14 +92,12 @@ private:
static
napi_value
JS_readCharArray
(
napi_env
env
,
napi_callback_info
cbinfo
);
static
napi_value
JS_readStringArray
(
napi_env
env
,
napi_callback_info
cbinfo
);
static
void
release
(
MessageParcel
*
parcel
);
napi_env
env_
=
nullptr
;
MessageParcel
*
nativeParcel_
=
nullptr
;
size_t
maxCapacityToWrite_
;
bool
owner
;
std
::
shared_ptr
<
MessageParcel
>
nativeParcel_
=
nullptr
;
size_t
maxCapacityToWrite_
;
};
namespace
{
napi_value
g_messageParcelConstructor
=
nullptr
;
napi_ref
g_messageParcelConsRef
=
nullptr
;
}
}
// namespace OHOS
#endif // NAPI_IPC_OHOS_MESSAGE_PARCEL_H
ipc/native/src/napi/include/napi_remote_object.h
浏览文件 @
9c810632
...
...
@@ -59,9 +59,11 @@ EXTERN_C_END
napi_value
NAPI_RemoteObject_getCallingUid
(
napi_env
env
,
napi_callback_info
info
);
napi_value
NAPI_RemoteObject_sendRequest
(
napi_env
env
,
napi_callback_info
info
);
// RemoteProxy napi methods
napi_value
SendRequestPromise
(
napi_env
env
,
sptr
<
IRemoteObject
>
target
,
uint32_t
code
,
MessageParcel
&
data
,
MessageParcel
&
reply
,
MessageOption
&
option
);
std
::
shared_ptr
<
MessageParcel
>
data
,
std
::
shared_ptr
<
MessageParcel
>
reply
,
MessageOption
&
option
);
napi_value
NAPI_RemoteProxy_sendRequest
(
napi_env
env
,
napi_callback_info
info
);
...
...
@@ -82,12 +84,13 @@ EXTERN_C_END
struct
SendRequestParam
{
sptr
<
IRemoteObject
>
target
;
uint32_t
code
;
MessageParcel
&
data
;
MessageParcel
&
reply
;
MessageOption
&
option
;
std
::
shared_ptr
<
MessageParcel
>
data
;
std
::
shared_ptr
<
MessageParcel
>
reply
;
MessageOption
&
option
;
napi_async_work
asyncWork
;
napi_deferred
deferred
;
int
errCode
;
napi_env
env
;
};
}
// namespace OHOS
#endif // NAPI_IPC_OHOS_REMOTE_OBJECT_H
\ No newline at end of file
ipc/native/src/napi/src/napi_message_parcel.cpp
浏览文件 @
9c810632
...
...
@@ -64,10 +64,10 @@ NAPI_MessageParcel::NAPI_MessageParcel(napi_env env, napi_value thisVar, Message
maxCapacityToWrite_
=
MAX_CAPACITY_TO_WRITE
;
// do NOT reference js parcel here
if
(
parcel
==
nullptr
)
{
nativeParcel_
=
new
MessageParcel
(
);
nativeParcel_
=
std
::
shared_ptr
<
MessageParcel
>
(
new
MessageParcel
()
);
owner
=
true
;
}
else
{
nativeParcel_
=
parcel
;
nativeParcel_
=
std
::
shared_ptr
<
MessageParcel
>
(
parcel
,
release
)
;
owner
=
false
;
}
}
...
...
@@ -75,14 +75,16 @@ NAPI_MessageParcel::NAPI_MessageParcel(napi_env env, napi_value thisVar, Message
NAPI_MessageParcel
::~
NAPI_MessageParcel
()
{
DBINDER_LOGI
(
"NAPI_MessageParcel::Destructor"
);
if
(
owner
)
{
delete
nativeParcel_
;
}
nativeParcel_
=
nullptr
;
env_
=
nullptr
;
}
MessageParcel
*
NAPI_MessageParcel
::
GetMessageParcel
()
void
NAPI_MessageParcel
::
release
(
MessageParcel
*
parcel
)
{
DBINDER_LOGI
(
"message parcel is created by others, do nothing"
);
}
std
::
shared_ptr
<
MessageParcel
>
NAPI_MessageParcel
::
GetMessageParcel
()
{
return
nativeParcel_
;
}
...
...
@@ -296,8 +298,8 @@ napi_value NAPI_MessageParcel::JS_writeChar(napi_env env, napi_callback_info inf
napi_value
NAPI_MessageParcel
::
JS_writeStringWithLength
(
napi_env
env
,
napi_callback_info
info
)
{
size_t
expectedArgc
=
2
;
size_t
argc
=
2
;
size_t
expectedArgc
=
2
;
napi_value
argv
[
2
]
=
{
0
};
napi_value
thisVar
=
nullptr
;
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
...
...
@@ -821,7 +823,8 @@ napi_value NAPI_MessageParcel::JS_writeSequenceable(napi_env env, napi_callback_
napi_value
funcArg
[
1
]
=
{
thisVar
};
napi_value
callResult
=
nullptr
;
bool
result
=
napi_call_function
(
env
,
thisVar
,
prop
,
1
,
funcArg
,
&
callResult
);
napi_status
status
=
napi_call_function
(
env
,
argv
[
0
],
prop
,
1
,
funcArg
,
&
callResult
);
bool
result
=
(
status
==
napi_ok
);
bool
isExceptionPending
=
false
;
napi_is_exception_pending
(
env
,
&
isExceptionPending
);
if
(
isExceptionPending
)
{
...
...
@@ -872,7 +875,8 @@ napi_value NAPI_MessageParcel::JS_writeSequenceableArray(napi_env env, napi_call
napi_value
funcArg
[
1
]
=
{
thisVar
};
napi_value
callResult
=
nullptr
;
result
=
napi_call_function
(
env
,
thisVar
,
prop
,
1
,
funcArg
,
&
callResult
);
napi_status
status
=
napi_call_function
(
env
,
element
,
prop
,
1
,
funcArg
,
&
callResult
);
result
=
(
status
==
napi_ok
);
bool
isExceptionPending
=
false
;
napi_is_exception_pending
(
env
,
&
isExceptionPending
);
...
...
@@ -1236,9 +1240,9 @@ napi_value NAPI_MessageParcel::JS_readByteArray(napi_env env, napi_callback_info
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
napiParcel
);
NAPI_ASSERT
(
env
,
napiParcel
!=
nullptr
,
"napiParcel is null"
);
uint32_t
maxB
uf
Len
=
40960
;
uint32_t
maxB
ytes
Len
=
40960
;
uint32_t
arrayBufferLength
=
napiParcel
->
nativeParcel_
->
ReadUint32
();
NAPI_ASSERT
(
env
,
arrayBufferLength
<
maxB
uf
Len
,
"byte array length too large"
);
NAPI_ASSERT
(
env
,
arrayBufferLength
<
maxB
ytes
Len
,
"byte array length too large"
);
size_t
len
=
(
arrayBufferLength
/
BYTE_SIZE_32
)
+
(
arrayBufferLength
%
BYTE_SIZE_32
==
0
?
0
:
1
);
DBINDER_LOGI
(
"messageparcel WriteBuffer typedarrayLength = %{public}d"
,
(
int
)(
len
));
...
...
@@ -1725,7 +1729,8 @@ napi_value NAPI_MessageParcel::JS_readSequenceable(napi_env env, napi_callback_i
napi_value
funcArg
[
1
]
=
{
thisVar
};
napi_value
callResult
=
nullptr
;
result
=
napi_call_function
(
env
,
thisVar
,
prop
,
1
,
funcArg
,
&
callResult
);
napi_status
status
=
napi_call_function
(
env
,
argv
[
0
],
prop
,
1
,
funcArg
,
&
callResult
);
result
=
(
status
==
napi_ok
);
}
napi_value
napiValue
=
nullptr
;
...
...
@@ -1736,9 +1741,12 @@ napi_value NAPI_MessageParcel::JS_readSequenceable(napi_env env, napi_callback_i
napi_value
NAPI_MessageParcel
::
JS_create
(
napi_env
env
,
napi_callback_info
info
)
{
// new native parcel object
napi_value
global
=
nullptr
;
napi_status
status
=
napi_get_global
(
env
,
&
global
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"get napi global failed"
);
napi_value
constructor
=
nullptr
;
napi_status
status
=
napi_get_reference_value
(
env
,
g_messageParcelConsRef
,
&
constructor
);
NAPI_ASSERT
(
env
,
constructor
!=
nullptr
,
"failed to get js MessageParcel constructor
"
);
status
=
napi_get_named_property
(
env
,
global
,
"IPCParcelConstructor_"
,
&
constructor
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"get message parcel constructor failed
"
);
napi_value
jsMessageParcel
;
status
=
napi_new_instance
(
env
,
constructor
,
0
,
nullptr
,
&
jsMessageParcel
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"failed to construct js MessageParcel"
);
...
...
@@ -1912,13 +1920,17 @@ napi_value NAPI_MessageParcel::Export(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION
(
"readCharArray"
,
NAPI_MessageParcel
::
JS_readCharArray
),
DECLARE_NAPI_FUNCTION
(
"readStringArray"
,
NAPI_MessageParcel
::
JS_readStringArray
),
};
napi_value
constructor
=
nullptr
;
napi_define_class
(
env
,
className
.
c_str
(),
className
.
length
(),
JS_constructor
,
nullptr
,
sizeof
(
properties
)
/
sizeof
(
properties
[
0
]),
properties
,
&
g_messageParcelC
onstructor
);
NAPI_ASSERT
(
env
,
g_messageParcelC
onstructor
!=
nullptr
,
"define js class MessageParcel failed"
);
napi_status
status
=
napi_set_named_property
(
env
,
exports
,
"MessageParcel"
,
g_messageParcelC
onstructor
);
sizeof
(
properties
)
/
sizeof
(
properties
[
0
]),
properties
,
&
c
onstructor
);
NAPI_ASSERT
(
env
,
c
onstructor
!=
nullptr
,
"define js class MessageParcel failed"
);
napi_status
status
=
napi_set_named_property
(
env
,
exports
,
"MessageParcel"
,
c
onstructor
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"set property MessageParcel failed"
);
status
=
napi_create_reference
(
env
,
g_messageParcelConstructor
,
1
,
&
g_messageParcelConsRef
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"create ref to js MessageParcel constructor failed"
);
napi_value
global
=
nullptr
;
status
=
napi_get_global
(
env
,
&
global
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"get napi global failed"
);
status
=
napi_set_named_property
(
env
,
global
,
"IPCParcelConstructor_"
,
constructor
);
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"set message parcel constructor failed"
);
return
exports
;
}
...
...
@@ -1949,9 +1961,4 @@ napi_value NAPI_MessageParcel::JS_constructor(napi_env env, napi_callback_info i
NAPI_ASSERT
(
env
,
status
==
napi_ok
,
"napi wrap message parcel failed"
);
return
thisVar
;
}
napi_ref
NAPI_MessageParcel
::
GetParcelConsRef
()
{
return
g_messageParcelConsRef
;
}
}
// namespace OHOS
ipc/native/src/napi/src/napi_remote_object.cpp
浏览文件 @
9c810632
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录