Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
41d59528
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,发现更多精彩内容 >>
提交
41d59528
编写于
10月 20, 2021
作者:
O
openharmony_ci
提交者:
Gitee
10月 20, 2021
浏览文件
操作
浏览文件
下载
差异文件
!43 fix ipc js interfaces bug
Merge pull request !43 from liangshenglin1/1020lts
上级
1f8af948
25fd4715
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
514 addition
and
248 deletion
+514
-248
interfaces/kits/js/napi/rpc.js
interfaces/kits/js/napi/rpc.js
+161
-132
ipc/native/src/napi/include/napi_remote_object.h
ipc/native/src/napi/include/napi_remote_object.h
+4
-0
ipc/native/src/napi/src/napi_message_option.cpp
ipc/native/src/napi/src/napi_message_option.cpp
+7
-7
ipc/native/src/napi/src/napi_message_parcel.cpp
ipc/native/src/napi/src/napi_message_parcel.cpp
+59
-60
ipc/native/src/napi/src/napi_remote_object.cpp
ipc/native/src/napi/src/napi_remote_object.cpp
+283
-49
未找到文件。
interfaces/kits/js/napi/rpc.js
浏览文件 @
41d59528
...
...
@@ -15,26 +15,57 @@
const
rpcSo
=
requireInternal
(
"
rpc
"
);
const
EXC_INSECURITY
=
-
1
;
const
EXC_ILLEGAL_ARGUMENT
=
-
3
;
const
EXC_NULL_POINTER
=
-
4
;
const
EXC_ILLEGAL_STATE
=
-
5
;
const
EXC_UNSUPPORTED_OPERATION
=
-
7
;
const
EXC_INDEX_OUTOF_BOUNDS
=
-
10
;
const
EXC_NEGATIVE_ARRAY_SIZE
=
-
11
;
const
EXC_ARRAY_STORE
=
-
12
;
const
EXC_CLASS_CAST
=
-
13
;
const
EXC_PARCEL_CAPACITY_ERROR
=
-
14
;
const
EXC_REMOTE_TRANSACTION_FAILED
=
-
200
;
let
MessageParcel
=
rpcSo
.
MessageParcel
;
let
IPCSkeleton
=
rpcSo
.
IPCSkeleton
;
let
RemoteObject
=
rpcSo
.
RemoteObject
;
let
NAPIMessageParcel
=
rpcSo
.
MessageParcel
;
let
NAPIIPCSkeleton
=
rpcSo
.
IPCSkeleton
;
let
NAPIRemoteObject
=
rpcSo
.
RemoteObject
;
let
RemoteProxy
=
rpcSo
.
RemoteProxy
;
let
MessageOption
=
rpcSo
.
MessageOption
;
class
RemoteObject
extends
NAPIRemoteObject
{
constructor
(
descriptor
)
{
if
(
typeof
descriptor
===
'
string
'
&&
descriptor
.
length
>
0
)
{
super
(
descriptor
,
descriptor
.
length
);
this
.
descriptor
=
descriptor
;
}
else
{
throw
new
NullPointerException
(
"
invalid descriptor
"
);
}
}
addDeathRecipient
(
recipient
,
flags
)
{
return
false
;
}
removeDeathRecipient
(
recipient
,
flags
)
{
return
false
;
}
isObjectDead
()
{
return
false
;
}
attachLocalInterface
(
localInterface
,
descriptor
)
{
this
.
descriptor
=
descriptor
;
this
.
interface
=
localInterface
;
}
queryLocalInterface
(
descriptor
)
{
if
(
this
.
descriptor
===
descriptor
)
{
return
this
.
interface
;
}
return
null
;
}
}
class
IPCSkeleton
extends
NAPIIPCSkeleton
{
static
setCallingIdentity
(
identity
)
{
if
(
typeof
identity
===
'
string
'
)
{
return
NAPIIPCSkeleton
.
setCallingIdentity
(
identity
,
identity
.
length
);
}
return
false
;
}
}
class
Exception
{
message
;
constructor
(
msg
)
{
this
.
message
=
msg
;
}
...
...
@@ -57,101 +88,110 @@ class RemoteException extends Exception {}
class
ParcelException
extends
Exception
{}
class
RuntimeException
extends
Exception
{}
MessageParcel
.
prototype
.
createException
=
function
(
code
,
msg
)
{
switch
(
code
)
{
case
EXC_INSECURITY
:
{
return
new
SecurityException
(
msg
);
}
case
EXC_ILLEGAL_ARGUMENT
:
{
return
new
IllegalArgumentException
(
msg
);
}
case
EXC_NULL_POINTER
:
{
return
new
NullPointerException
(
msg
);
}
case
EXC_ILLEGAL_STATE
:
{
return
new
IllegalStateException
(
msg
);
}
case
EXC_UNSUPPORTED_OPERATION
:
{
return
new
UnsupportedOperationException
(
msg
);
}
case
EXC_INDEX_OUTOF_BOUNDS
:
{
return
new
IndexOutOfBoundsException
(
msg
);
}
case
EXC_NEGATIVE_ARRAY_SIZE
:
{
return
new
NegativeArraySizeException
(
msg
);
}
case
EXC_ARRAY_STORE
:
{
return
new
ArrayStoreException
(
msg
);
}
case
EXC_CLASS_CAST
:
{
return
new
ClassCastException
(
msg
);
}
case
EXC_REMOTE_TRANSACTION_FAILED
:
{
return
new
RemoteException
(
msg
);
}
case
EXC_PARCEL_CAPACITY_ERROR
:
{
return
new
ParcelException
(
msg
);
}
default
:
{
return
new
RuntimeException
(
"
Unknown exception code:
"
+
code
+
"
msg
"
+
msg
);
class
MessageParcel
extends
NAPIMessageParcel
{
static
EXC_INSECURITY
=
-
1
;
static
EXC_ILLEGAL_ARGUMENT
=
-
3
;
static
EXC_NULL_POINTER
=
-
4
;
static
EXC_ILLEGAL_STATE
=
-
5
;
static
EXC_UNSUPPORTED_OPERATION
=
-
7
;
static
EXC_INDEX_OUTOF_BOUNDS
=
-
10
;
static
EXC_NEGATIVE_ARRAY_SIZE
=
-
11
;
static
EXC_ARRAY_STORE
=
-
12
;
static
EXC_CLASS_CAST
=
-
13
;
static
EXC_PARCEL_CAPACITY_ERROR
=
-
14
;
static
EXC_REMOTE_TRANSACTION_FAILED
=
-
200
;
createException
(
code
,
msg
)
{
switch
(
code
)
{
case
MessageParcel
.
EXC_INSECURITY
:
{
return
new
SecurityException
(
msg
);
}
case
MessageParcel
.
EXC_ILLEGAL_ARGUMENT
:
{
return
new
IllegalArgumentException
(
msg
);
}
case
MessageParcel
.
EXC_NULL_POINTER
:
{
return
new
NullPointerException
(
msg
);
}
case
MessageParcel
.
EXC_ILLEGAL_STATE
:
{
return
new
IllegalStateException
(
msg
);
}
case
MessageParcel
.
EXC_UNSUPPORTED_OPERATION
:
{
return
new
UnsupportedOperationException
(
msg
);
}
case
MessageParcel
.
EXC_INDEX_OUTOF_BOUNDS
:
{
return
new
IndexOutOfBoundsException
(
msg
);
}
case
MessageParcel
.
EXC_NEGATIVE_ARRAY_SIZE
:
{
return
new
NegativeArraySizeException
(
msg
);
}
case
MessageParcel
.
EXC_ARRAY_STORE
:
{
return
new
ArrayStoreException
(
msg
);
}
case
MessageParcel
.
EXC_CLASS_CAST
:
{
return
new
ClassCastException
(
msg
);
}
case
MessageParcel
.
EXC_REMOTE_TRANSACTION_FAILED
:
{
return
new
RemoteException
(
msg
);
}
case
MessageParcel
.
EXC_PARCEL_CAPACITY_ERROR
:
{
return
new
ParcelException
(
msg
);
}
default
:
{
return
new
RuntimeException
(
"
Unknown exception code:
"
+
code
+
"
msg
"
+
msg
);
}
}
}
}
MessageParcel
.
prototype
.
writeException
=
function
(
exception
)
{
let
code
=
0
;
if
(
exception
instanceof
SecurityException
)
{
code
=
EXC_INSECURITY
;
}
else
if
(
exception
instanceof
IllegalArgumentException
)
{
code
=
EXC_ILLEGAL_ARGUMENT
;
}
else
if
(
exception
instanceof
NullPointerException
)
{
code
=
EXC_NULL_POINTER
;
}
else
if
(
exception
instanceof
IllegalStateException
)
{
code
=
EXC_ILLEGAL_STATE
;
}
else
if
(
exception
instanceof
UnsupportedOperationException
)
{
code
=
EXC_UNSUPPORTED_OPERATION
;
}
else
if
(
exception
instanceof
IndexOutOfBoundsException
)
{
code
=
EXC_INDEX_OUTOF_BOUNDS
;
}
else
if
(
exception
instanceof
NegativeArraySizeException
)
{
code
=
EXC_NEGATIVE_ARRAY_SIZE
;
}
else
if
(
exception
instanceof
ArrayStoreException
)
{
code
=
EXC_ARRAY_STORE
;
}
else
if
(
exception
instanceof
ClassCastException
)
{
code
=
EXC_CLASS_CAST
;
}
else
if
(
exception
instanceof
RemoteException
)
{
code
=
EXC_REMOTE_TRANSACTION_FAILED
;
}
else
if
(
exception
instanceof
ParcelException
)
{
code
=
EXC_PARCEL_CAPACITY_ERROR
;
}
else
{
code
=
0
;
}
this
.
writeInt
(
code
);
if
(
code
===
0
)
{
if
(
exception
instanceof
RuntimeException
)
{
writeException
(
exception
)
{
let
code
=
0
;
if
(
exception
instanceof
SecurityException
)
{
code
=
MessageParcel
.
EXC_INSECURITY
;
}
else
if
(
exception
instanceof
IllegalArgumentException
)
{
code
=
MessageParcel
.
EXC_ILLEGAL_ARGUMENT
;
}
else
if
(
exception
instanceof
NullPointerException
)
{
code
=
MessageParcel
.
EXC_NULL_POINTER
;
}
else
if
(
exception
instanceof
IllegalStateException
)
{
code
=
MessageParcel
.
EXC_ILLEGAL_STATE
;
}
else
if
(
exception
instanceof
UnsupportedOperationException
)
{
code
=
MessageParcel
.
EXC_UNSUPPORTED_OPERATION
;
}
else
if
(
exception
instanceof
IndexOutOfBoundsException
)
{
code
=
MessageParcel
.
EXC_INDEX_OUTOF_BOUNDS
;
}
else
if
(
exception
instanceof
NegativeArraySizeException
)
{
code
=
MessageParcel
.
EXC_NEGATIVE_ARRAY_SIZE
;
}
else
if
(
exception
instanceof
ArrayStoreException
)
{
code
=
MessageParcel
.
EXC_ARRAY_STORE
;
}
else
if
(
exception
instanceof
ClassCastException
)
{
code
=
MessageParcel
.
EXC_CLASS_CAST
;
}
else
if
(
exception
instanceof
RemoteException
)
{
code
=
MessageParcel
.
EXC_REMOTE_TRANSACTION_FAILED
;
}
else
if
(
exception
instanceof
ParcelException
)
{
code
=
MessageParcel
.
EXC_PARCEL_CAPACITY_ERROR
;
}
else
{
code
=
0
;
}
this
.
writeInt
(
code
);
if
(
code
===
0
)
{
throw
new
RuntimeException
(
exception
.
getMessage
());
}
th
row
new
RuntimeException
(
exception
.
getMessage
());
}
th
is
.
writeString
(
exception
.
getMessage
());
}
this
.
writeString
(
exception
.
getMessage
());
}
MessageParcel
.
prototype
.
writeNoException
=
func
tion
()
{
this
.
writeInt
(
0
);
}
writeNoExcep
tion
()
{
this
.
writeInt
(
0
);
}
MessageParcel
.
prototype
.
readException
=
func
tion
()
{
let
code
=
this
.
readInt
();
readExcep
tion
()
{
let
code
=
this
.
readInt
();
if
(
code
===
0
)
{
return
;
}
let
msg
=
this
.
readString
();
let
exception
=
this
.
createException
(
code
,
msg
);
return
exception
;
}
throw
exception
;
}
MessageParcel
.
prototype
.
createRemoteObjectArray
=
function
()
{
let
num
=
this
.
readInt
();
createRemoteObjectArray
()
{
let
num
=
this
.
readInt
();
if
(
num
<=
0
)
{
return
null
;
}
...
...
@@ -160,46 +200,35 @@ MessageParcel.prototype.createRemoteObjectArray = function() {
list
[
i
]
=
this
.
readRemoteObject
();
}
return
list
;
}
MessageParcel
.
prototype
.
writeRemoteObjectArray
=
function
(
objects
)
{
if
(
objects
===
null
||
objects
.
length
<=
0
)
{
this
.
writeInt
(
-
1
);
return
false
;
}
let
num
=
objects
.
length
;
this
.
writeInt
(
num
);
for
(
let
i
=
0
;
i
<
num
;
i
++
)
{
this
.
writeRemoteObject
(
objects
[
i
]);
}
return
true
;
}
MessageParcel
.
prototype
.
readRemoteObjectArray
=
function
(
objects
)
{
if
(
objects
===
null
)
{
return
;
}
writeRemoteObjectArray
(
objects
)
{
if
(
objects
===
null
||
objects
.
length
<=
0
)
{
this
.
writeInt
(
-
1
);
return
false
;
}
let
num
=
this
.
readInt
()
;
if
(
num
!==
objects
.
length
)
{
return
;
}
for
(
let
i
=
0
;
i
<
num
;
i
++
)
{
objects
[
i
]
=
this
.
readRemoteObject
()
;
let
num
=
objects
.
length
;
this
.
writeInt
(
num
);
for
(
let
i
=
0
;
i
<
num
;
i
++
)
{
this
.
writeRemoteObject
(
objects
[
i
]);
}
return
true
;
}
}
RemoteObject
.
prototype
.
addDeathRecipient
=
function
(
recipient
,
flags
)
{
return
false
;
}
RemoteObject
.
prototype
.
removeDeathRecipient
=
function
(
recipient
,
flags
)
{
return
false
;
}
readRemoteObjectArray
(
objects
)
{
if
(
objects
===
null
)
{
return
;
}
RemoteObject
.
prototype
.
isObjectDead
=
function
()
{
return
false
;
let
num
=
this
.
readInt
();
if
(
num
!==
objects
.
length
)
{
return
;
}
for
(
let
i
=
0
;
i
<
num
;
i
++
)
{
objects
[
i
]
=
this
.
readRemoteObject
();
}
}
}
export
default
{
...
...
ipc/native/src/napi/include/napi_remote_object.h
浏览文件 @
41d59528
...
...
@@ -55,6 +55,8 @@ EXTERN_C_END
napi_value
NAPI_IPCSkeleton_setCallingIdentity
(
napi_env
env
,
napi_callback_info
info
);
// RemoteObject napi methods
napi_value
NAPI_RemoteObject_getInterfaceDescriptor
(
napi_env
env
,
napi_callback_info
info
);
napi_value
NAPI_RemoteObject_getCallingPid
(
napi_env
env
,
napi_callback_info
info
);
napi_value
NAPI_RemoteObject_getCallingUid
(
napi_env
env
,
napi_callback_info
info
);
...
...
@@ -67,6 +69,8 @@ EXTERN_C_END
napi_value
NAPI_RemoteProxy_sendRequest
(
napi_env
env
,
napi_callback_info
info
);
napi_value
NAPI_RemoteProxy_queryLocalInterface
(
napi_env
env
,
napi_callback_info
info
);
napi_value
NAPI_RemoteProxy_addDeathRecipient
(
napi_env
env
,
napi_callback_info
info
);
napi_value
NAPI_RemoteProxy_removeDeathRecipient
(
napi_env
env
,
napi_callback_info
info
);
...
...
ipc/native/src/napi/src/napi_message_option.cpp
浏览文件 @
41d59528
...
...
@@ -42,11 +42,11 @@ napi_value NapiOhosRpcMessageOptionGetFlags(napi_env env, napi_callback_info inf
napi_value
NapiOhosRpcMessageOptionSetFlags
(
napi_env
env
,
napi_callback_info
info
)
{
napi_value
thisVar
=
nullptr
;
size_t
argc
;
size_t
argc
=
1
;
napi_value
argv
[
1
]
=
{
0
};
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
NAPI_ASSERT
(
env
,
thisVar
!=
nullptr
,
"failed to get js message option object"
);
napi_valuetype
valueType
;
NAPI_ASSERT
(
env
,
thisVar
!=
nullptr
&&
argv
[
0
]
!=
nullptr
,
"failed to get js message option object"
);
napi_valuetype
valueType
=
napi_null
;
napi_typeof
(
env
,
argv
[
0
],
&
valueType
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 1"
);
int32_t
flags
=
0
;
...
...
@@ -85,11 +85,11 @@ napi_value NapiOhosRpcMessageOptionGetWaittime(napi_env env, napi_callback_info
napi_value
NapiOhosRpcMessageOptionSetWaittime
(
napi_env
env
,
napi_callback_info
info
)
{
napi_value
thisVar
=
nullptr
;
size_t
argc
;
size_t
argc
=
1
;
napi_value
argv
[
1
]
=
{
0
};
napi_get_cb_info
(
env
,
info
,
&
argc
,
argv
,
&
thisVar
,
nullptr
);
NAPI_ASSERT
(
env
,
thisVar
!=
nullptr
,
"failed to get js message option object"
);
napi_valuetype
valueType
;
NAPI_ASSERT
(
env
,
thisVar
!=
nullptr
&&
argv
[
0
]
!=
nullptr
,
"failed to get js message option object"
);
napi_valuetype
valueType
=
napi_null
;
napi_typeof
(
env
,
argv
[
0
],
&
valueType
);
NAPI_ASSERT
(
env
,
valueType
==
napi_number
,
"type mismatch for parameter 1"
);
int32_t
waittime
=
0
;
...
...
@@ -98,7 +98,7 @@ napi_value NapiOhosRpcMessageOptionSetWaittime(napi_env env, napi_callback_info
MessageOption
*
option
=
nullptr
;
status
=
napi_unwrap
(
env
,
thisVar
,
(
void
**
)
&
option
);
NAPI_ASSERT
(
env
,
option
!=
nullptr
,
"failed to get native message option"
);
option
->
Set
Flags
(
waittime
);
option
->
Set
WaitTime
(
waittime
);
napi_value
result
=
nullptr
;
napi_get_undefined
(
env
,
&
result
);
return
result
;
...
...
ipc/native/src/napi/src/napi_message_parcel.cpp
浏览文件 @
41d59528
此差异已折叠。
点击以展开。
ipc/native/src/napi/src/napi_remote_object.cpp
浏览文件 @
41d59528
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录