提交 8032720b 编写于 作者: L liangshenglin1

implement ipc js interfaces

Signed-off-by: Nliangshenglin1 <liangshenglin1@huawei.com>
上级 fc8fa9f1
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
SUBSYSTEM_DIR = "//foundation/communication/ipc"
base_output_path = get_label_info(":rpc_js", "target_out_dir")
ipc_js_obj_path = base_output_path + "/rpc.o"
gen_js_obj("rpc_js") {
input = "//foundation/communication/ipc/interfaces/kits/js/napi/rpc.js"
output = ipc_js_obj_path
}
config("rpc_public_config") {
visibility = [ ":*" ]
include_dirs = [ "$SUBSYSTEM_DIR/ipc/native/src/napi/include" ]
}
ohos_shared_library("rpc") {
include_dirs = [
"$SUBSYSTEM_DIR/utils/include",
"//foundation/ace/napi/interfaces/kits",
"//utils/system/safwk/native/include",
]
public_configs = [ ":rpc_public_config" ]
sources = [
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_message_option.cpp",
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_message_parcel.cpp",
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_remote_object.cpp",
"$SUBSYSTEM_DIR/ipc/native/src/napi/src/napi_rpc_native_module.cpp",
]
deps = [
":rpc_js",
"//foundation/ace/napi:ace_napi",
"//third_party/libuv:uv_static",
"//utils/native/base:utils",
]
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
"samgr_L2:samgr_proxy",
]
relative_install_dir = "module"
subsystem_name = "communication"
part_name = "ipc_js"
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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 RemoteProxy = rpcSo.RemoteProxy;
let MessageOption = rpcSo.MessageOption;
class Exception {
message;
constructor(msg) {
this.message = msg;
}
getMessage() {
return this.message;
}
}
class NullPointerException extends Exception {}
class SecurityException extends Exception {}
class IllegalArgumentException extends Exception {}
class IllegalStateException extends Exception {}
class UnsupportedOperationException extends Exception {}
class IndexOutOfBoundsException extends Exception {}
class NegativeArraySizeException extends Exception {}
class ArrayStoreException extends Exception {}
class ClassCastException extends Exception {}
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);
}
}
}
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) {
throw new RuntimeException(exception.getMessage());
}
throw new RuntimeException(exception.getMessage());
}
this.writeString(exception.getMessage());
}
MessageParcel.prototype.writeNoException = function() {
this.writeInt(0);
}
MessageParcel.prototype.readException = function() {
let code = this.readInt();
if (code === 0) {
return;
}
let msg = this.readString();
let exception = this.createException(code, msg);
return exception;
}
MessageParcel.prototype.createRemoteObjectArray = function() {
let num = this.readInt();
if (num <= 0) {
return null;
}
let list = new Array(num);
for (let i = 0; i < num; i++) {
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;
}
let num = this.readInt();
if (num !== objects.length) {
return;
}
for (let i = 0; i < num; i ++) {
objects[i] = this.readRemoteObject();
}
}
RemoteObject.prototype.addDeathRecipient = function(recipient, flags) {
return false;
}
RemoteObject.prototype.removeDeathRecipient = function(recipient, flags) {
return false;
}
RemoteObject.prototype.isObjectDead = function() {
return false;
}
export default {
MessageParcel: MessageParcel,
IPCSkeleton: IPCSkeleton,
RemoteObject: RemoteObject,
RemoteProxy: RemoteProxy,
MessageOption: MessageOption,
NullPointerException: NullPointerException,
SecurityException: SecurityException,
IllegalArgumentException: IllegalArgumentException,
IllegalStateException: IllegalStateException,
UnsupportedOperationException: UnsupportedOperationException,
IndexOutOfBoundsException: IndexOutOfBoundsException,
NegativeArraySizeException: NegativeArraySizeException,
ArrayStoreException: ArrayStoreException,
ClassCastException: ClassCastException,
RemoteException: RemoteException,
ParcelException: ParcelException,
RuntimeException: RuntimeException
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NAPI_IPC_OHOS_MESSAGE_OPTION_H
#define NAPI_IPC_OHOS_MESSAGE_OPTION_H
#include "message_option.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
namespace OHOS {
/*
* Get flags field from ohos.rpc.MessageOption.
*/
napi_value NapiOhosRpcMessageOptionGetFlags(napi_env env, napi_callback_info info);
/*
* Set flags to ohos.rpc.MessageOption
*/
napi_value NapiOhosRpcMessageOptionSetFlags(napi_env env, napi_callback_info info);
/*
* Get wait time field from ohos.rpc.MessageOption.
*/
napi_value NapiOhosRpcMessageOptionGetWaittime(napi_env env, napi_callback_info info);
/*
* Set wait time to ohos.rpc.MessageOption
*/
napi_value NapiOhosRpcMessageOptionSetWaittime(napi_env env, napi_callback_info info);
} // namespace OHOS
#endif // NAPI_IPC_OHOS_MESSAGE_OPTION_H
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NAPI_IPC_OHOS_MESSAGE_PARCEL_H
#define NAPI_IPC_OHOS_MESSAGE_PARCEL_H
#include "ipc_skeleton.h"
#include "message_parcel.h"
#include "napi/native_api.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
#include "securec.h"
namespace OHOS {
class NAPI_MessageParcel {
public:
NAPI_MessageParcel(napi_env env, napi_value thisVar, MessageParcel *parcel);
virtual ~NAPI_MessageParcel();
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);
static napi_value JS_create(napi_env env, napi_callback_info cbinfo);
static napi_value JS_reclaim(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeRemoteObject(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readRemoteObject(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeInterfaceToken(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readInterfaceToken(napi_env env, napi_callback_info cbinfo);
static napi_value JS_getSize(napi_env env, napi_callback_info cbinfo);
static napi_value JS_getCapacity(napi_env env, napi_callback_info cbinfo);
static napi_value JS_setSize(napi_env env, napi_callback_info cbinfo);
static napi_value JS_setCapacity(napi_env env, napi_callback_info cbinfo);
static napi_value JS_getWritableBytes(napi_env env, napi_callback_info cbinfo);
static napi_value JS_getReadableBytes(napi_env env, napi_callback_info cbinfo);
static napi_value JS_getReadPosition(napi_env env, napi_callback_info cbinfo);
static napi_value JS_getWritePosition(napi_env env, napi_callback_info cbinfo);
static napi_value JS_rewindWrite(napi_env env, napi_callback_info cbinfo);
static napi_value JS_rewindRead(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeByte(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeShort(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeInt(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeLong(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeFloat(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeDouble(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeBoolean(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeChar(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeStringWithLength(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeString(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeSequenceable(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeByteArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeShortArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeIntArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeLongArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeFloatArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeDoubleArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeBooleanArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeCharArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeStringArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_writeSequenceableArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readByte(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readShort(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readInt(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readLong(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readFloat(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readDouble(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readBoolean(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readChar(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readString(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readSequenceable(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readByteArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readShortArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readIntArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readLongArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readFloatArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readDoubleArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readBooleanArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readCharArray(napi_env env, napi_callback_info cbinfo);
static napi_value JS_readStringArray(napi_env env, napi_callback_info cbinfo);
napi_env env_ = nullptr;
MessageParcel *nativeParcel_ = nullptr;
size_t maxCapacityToWrite_;
bool owner;
};
namespace {
napi_value g_messageParcelConstructor = nullptr;
napi_ref g_messageParcelConsRef = nullptr;
}
} // namespace OHOS
#endif // NAPI_IPC_OHOS_MESSAGE_PARCEL_H
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NAPI_IPC_OHOS_REMOTE_OBJECT_H
#define NAPI_IPC_OHOS_REMOTE_OBJECT_H
#include "iremote_object.h"
#include "iservice_registry.h"
#include "napi/native_common.h"
#include "napi/native_node_api.h"
#include "refbase.h"
#include "system_ability_manager_proxy.h"
namespace OHOS {
EXTERN_C_START
napi_value NAPIIPCSkeletonExport(napi_env env, napi_value exports);
napi_value NAPIRemoteProxyExport(napi_env env, napi_value exports);
napi_value NAPIRemoteObjectExport(napi_env env, napi_value exports);
napi_value NAPIMessageOptionExport(napi_env env, napi_value exports);
EXTERN_C_END
// IPCSkeleton napi methods
napi_value NAPI_IPCSkeleton_getSystemAbility(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_addSystemAbility(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_getContextObject(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_getCallingPid(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_getCallingUid(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_getCallingDeviceID(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_getLocalDeviceID(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_isLocalCalling(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_flushCommands(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_resetCallingIdentity(napi_env env, napi_callback_info info);
napi_value NAPI_IPCSkeleton_setCallingIdentity(napi_env env, napi_callback_info info);
// RemoteObject napi methods
napi_value NAPI_RemoteObject_getCallingPid(napi_env env, napi_callback_info info);
napi_value NAPI_RemoteObject_getCallingUid(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);
napi_value NAPI_RemoteProxy_sendRequest(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);
napi_value NAPI_RemoteProxy_getInterfaceDescriptor(napi_env env, napi_callback_info info);
napi_value NAPI_RemoteProxy_isObjectDead(napi_env env, napi_callback_info info);
napi_value NAPI_RemoteProxy_getHandle(napi_env env, napi_callback_info info);
sptr<IRemoteObject> NAPI_ohos_rpc_getNativeRemoteObject(napi_env env, napi_value object);
napi_value NAPI_ohos_rpc_CreateJsRemoteObject(napi_env env, const sptr<IRemoteObject> target);
struct SendRequestParam {
sptr<IRemoteObject> target;
uint32_t code;
MessageParcel &data;
MessageParcel &reply;
MessageOption &option;
napi_async_work asyncWork;
napi_deferred deferred;
int errCode;
};
} // namespace OHOS
#endif // NAPI_IPC_OHOS_REMOTE_OBJECT_H
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "napi_message_option.h"
#include "ipc_debug.h"
#include "log_tags.h"
namespace OHOS {
/*
* Get flags field from ohos.rpc.MessageOption.
*/
napi_value NapiOhosRpcMessageOptionGetFlags(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
NAPI_ASSERT(env, thisVar != nullptr, "failed to get js message option object");
MessageOption *option = nullptr;
napi_status status = napi_unwrap(env, thisVar, (void **)&option);
NAPI_ASSERT(env, option != nullptr, "failed to get native message option");
int flags = option->GetFlags();
napi_value result = nullptr;
status = napi_create_int32(env, flags, &result);
NAPI_ASSERT(env, status == napi_ok, "failed to create int32 value");
return result;
}
/*
* Set flags to ohos.rpc.MessageOption
*/
napi_value NapiOhosRpcMessageOptionSetFlags(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
size_t argc;
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_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 1");
int32_t flags = 0;
napi_status status = napi_get_value_int32(env, argv[0], &flags);
NAPI_ASSERT(env, status == napi_ok, "failed to get int32 value");
MessageOption *option = nullptr;
status = napi_unwrap(env, thisVar, (void **)&option);
NAPI_ASSERT(env, option != nullptr, "failed to get native message option");
option->SetFlags(flags);
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
/*
* Get wait time field from ohos.rpc.MessageOption.
*/
napi_value NapiOhosRpcMessageOptionGetWaittime(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
napi_get_cb_info(env, info, nullptr, nullptr, &thisVar, nullptr);
NAPI_ASSERT(env, thisVar != nullptr, "failed to get js message option object");
MessageOption *option = nullptr;
napi_status status = napi_unwrap(env, thisVar, (void **)&option);
NAPI_ASSERT(env, option != nullptr, "failed to get native message option");
int flags = option->GetWaitTime();
napi_value result = nullptr;
status = napi_create_int32(env, flags, &result);
NAPI_ASSERT(env, status == napi_ok, "failed to create int32 value");
return result;
}
/*
* Set wait time to ohos.rpc.MessageOption
*/
napi_value NapiOhosRpcMessageOptionSetWaittime(napi_env env, napi_callback_info info)
{
napi_value thisVar = nullptr;
size_t argc;
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_typeof(env, argv[0], &valueType);
NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 1");
int32_t waittime = 0;
napi_status status = napi_get_value_int32(env, argv[0], &waittime);
NAPI_ASSERT(env, status == napi_ok, "failed to get int32 value");
MessageOption *option = nullptr;
status = napi_unwrap(env, thisVar, (void **)&option);
NAPI_ASSERT(env, option != nullptr, "failed to get native message option");
option->SetFlags(waittime);
napi_value result = nullptr;
napi_get_undefined(env, &result);
return result;
}
} // namespace OHOS
\ No newline at end of file
此差异已折叠。
此差异已折叠。
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <unistd.h>
#include "hilog/log.h"
#include "log_tags.h"
#include "napi_message_parcel.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "napi_remote_object.h"
extern const char _binary_rpc_js_start[];
extern const char _binary_rpc_js_end[];
namespace OHOS {
EXTERN_C_START
static napi_value rpcExport(napi_env env, napi_value exports)
{
NAPI_MessageParcel::Export(env, exports);
NAPIIPCSkeletonExport(env, exports);
NAPIRemoteObjectExport(env, exports);
NAPIRemoteProxyExport(env, exports);
NAPIMessageOptionExport(env, exports);
return exports;
}
EXTERN_C_END
extern "C" __attribute__((visibility("default"))) void NAPI_rpc_GetJSCode(const char **buf, int *bufLen)
{
if (buf != nullptr) {
*buf = _binary_rpc_js_start;
}
if (bufLen != nullptr) {
*bufLen = _binary_rpc_js_end - _binary_rpc_js_start;
}
}
static napi_module RPCModule_ = {
.nm_version = 1,
.nm_flags = 0,
.nm_filename = nullptr,
.nm_register_func = rpcExport,
.nm_modname = "rpc",
.nm_priv = ((void*)0),
.reserved = { 0 }
};
/*
* Module register function
*/
extern "C" __attribute__((constructor)) void RegisterModule(void)
{
napi_module_register(&RPCModule_);
}
} // namesapce OHOS
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册