diff --git a/ipc/native/src/napi/include/napi_message_option.h b/ipc/native/src/napi/include/napi_message_option.h index bbdaa7321faab9ef1d69853fd1cd0160e1b9bec8..83377334340cf8ecdd515f5bfaa2bf331fd8ad4e 100644 --- a/ipc/native/src/napi/include/napi_message_option.h +++ b/ipc/native/src/napi/include/napi_message_option.h @@ -32,6 +32,16 @@ napi_value NapiOhosRpcMessageOptionGetFlags(napi_env env, napi_callback_info inf */ napi_value NapiOhosRpcMessageOptionSetFlags(napi_env env, napi_callback_info info); +/* + * Get async to ohos.rpc.MessageOption + */ +napi_value NapiOhosRpcMessageOptionIsAsync(napi_env env, napi_callback_info info); + +/* + * Set async to ohos.rpc.MessageOption + */ +napi_value NapiOhosRpcMessageOptionSetAsync(napi_env env, napi_callback_info info); + /* * Get wait time field from ohos.rpc.MessageOption. */ diff --git a/ipc/native/src/napi/include/napi_message_sequence.h b/ipc/native/src/napi/include/napi_message_sequence.h index e96b36e9c0030fe98cd2585194dcf805eddf3b74..36e5f8fbd6be7b2835eeb09e1d95562f0c6183da 100644 --- a/ipc/native/src/napi/include/napi_message_sequence.h +++ b/ipc/native/src/napi/include/napi_message_sequence.h @@ -61,7 +61,7 @@ private: 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_writeString(napi_env env, napi_callback_info cbinfo); - static napi_value JS_writeSequenceable(napi_env env, napi_callback_info cbinfo); + static napi_value JS_writeParcelable(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); @@ -71,7 +71,7 @@ private: 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_writeParcelableArray(napi_env env, napi_callback_info cbinfo); static napi_value JS_writeRemoteObjectArray(napi_env env, napi_callback_info cbinfo); static napi_value JS_readByte(napi_env env, napi_callback_info cbinfo); @@ -83,7 +83,7 @@ private: 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_readParcelable(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); @@ -93,7 +93,7 @@ private: 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); - static napi_value JS_readSequenceableArray(napi_env env, napi_callback_info cbinfo); + static napi_value JS_readParcelableArray(napi_env env, napi_callback_info cbinfo); static napi_value JS_readRemoteObjectArray(napi_env env, napi_callback_info cbinfo); static napi_value JS_CloseFileDescriptor(napi_env env, napi_callback_info info); @@ -114,10 +114,10 @@ private: static napi_value JS_checkWriteArrayArgs(napi_env env, size_t argc, napi_value* argv, uint32_t &arrayLength); static napi_value JS_checkWriteStringArrayElement(napi_env env, napi_value* argv, size_t &index, size_t &bufferSize, napi_value &element); - static napi_value JS_writeSequenceableArrayCallJsFunc(napi_env env, napi_value &element, napi_value &thisVar); + static napi_value JS_writeParcelableArrayCallJsFunc(napi_env env, napi_value &element, napi_value &thisVar); static napi_value JS_checkReadArrayArgs(napi_env env, napi_callback_info info, size_t &argc, napi_value &thisVar, napi_value* argv); - static napi_value JS_readSequenceableArrayCallJsFunc(napi_env env, napi_value &element, napi_value &thisVar); + static napi_value JS_readParcelableArrayCallJsFunc(napi_env env, napi_value &element, napi_value &thisVar); static napi_value JS_checkWriteRawDataArgs(napi_env env, size_t argc, napi_value* argv); napi_env env_ = nullptr; diff --git a/ipc/native/src/napi/src/napi_message_option.cpp b/ipc/native/src/napi/src/napi_message_option.cpp index 1eca782dfb67e4383ae35a26846f81e8ba8f4abf..171e057d43e478ec973673427ff5f1955a207a1e 100644 --- a/ipc/native/src/napi/src/napi_message_option.cpp +++ b/ipc/native/src/napi/src/napi_message_option.cpp @@ -61,6 +61,49 @@ napi_value NapiOhosRpcMessageOptionSetFlags(napi_env env, napi_callback_info inf return result; } +/* + * Get async to ohos.rpc.MessageOption + */ +napi_value NapiOhosRpcMessageOptionIsAsync(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_unwrap(env, thisVar, (void **)&option); + NAPI_ASSERT(env, option != nullptr, "failed to get native message option"); + int flags = option->GetFlags(); + napi_value result = nullptr; + napi_status status = napi_get_boolean(env, flags != 0 ? true : false, &result); + NAPI_ASSERT(env, status == napi_ok, "failed to create boolean value"); + return result; +} + +/* + * Set async to ohos.rpc.MessageOption + */ +napi_value NapiOhosRpcMessageOptionSetAsync(napi_env env, napi_callback_info info) +{ + napi_value thisVar = nullptr; + 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_null; + napi_typeof(env, argv[0], &valueType); + NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 1"); + bool flags = false; + napi_status status = napi_get_value_bool(env, argv[0], &flags); + NAPI_ASSERT(env, status == napi_ok, "failed to get boolean value"); + MessageOption *option = nullptr; + napi_unwrap(env, thisVar, (void **)&option); + NAPI_ASSERT(env, option != nullptr, "failed to get native message option"); + option->SetFlags(static_cast (flags)); + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + /* * Get wait time field from ohos.rpc.MessageOption. */ diff --git a/ipc/native/src/napi/src/napi_message_sequence.cpp b/ipc/native/src/napi/src/napi_message_sequence.cpp index 3b1326976c19e2601b3733b92abb7458ba3bd08f..5b5547cc60318d41fad6a984b42030c220aa006b 100644 --- a/ipc/native/src/napi/src/napi_message_sequence.cpp +++ b/ipc/native/src/napi/src/napi_message_sequence.cpp @@ -995,7 +995,7 @@ napi_value NAPI_MessageSequence::JS_writeStringArray(napi_env env, napi_callback return napiValue; } -napi_value NAPI_MessageSequence::JS_writeSequenceable(napi_env env, napi_callback_info info) +napi_value NAPI_MessageSequence::JS_writeParcelable(napi_env env, napi_callback_info info) { napi_value result = nullptr; napi_get_undefined(env, &result); @@ -1043,7 +1043,7 @@ napi_value NAPI_MessageSequence::JS_writeSequenceable(napi_env env, napi_callbac return napiErr.ThrowError(env, errorDesc::WRITE_DATA_TO_MESSAGE_SEQUENCE_ERROR); } -napi_value NAPI_MessageSequence::JS_writeSequenceableArrayCallJsFunc(napi_env env, +napi_value NAPI_MessageSequence::JS_writeParcelableArrayCallJsFunc(napi_env env, napi_value &element, napi_value &thisVar) { @@ -1067,7 +1067,7 @@ napi_value NAPI_MessageSequence::JS_writeSequenceableArrayCallJsFunc(napi_env en return retValue; } -napi_value NAPI_MessageSequence::JS_writeSequenceableArray(napi_env env, napi_callback_info info) +napi_value NAPI_MessageSequence::JS_writeParcelableArray(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value argv[ARGV_INDEX_1] = { 0 }; @@ -1110,7 +1110,7 @@ napi_value NAPI_MessageSequence::JS_writeSequenceableArray(napi_env env, napi_ca } else { napiSequence->nativeParcel_->WriteInt32(1); } - napi_value callResult = JS_writeSequenceableArrayCallJsFunc(env, element, thisVar); + napi_value callResult = JS_writeParcelableArrayCallJsFunc(env, element, thisVar); if (callResult == nullptr) { ZLOGE(LOG_LABEL, "call mashalling failed, element index: %{public}zu", i); napiSequence->nativeParcel_->RewindWrite(pos); @@ -2120,7 +2120,7 @@ napi_value NAPI_MessageSequence::JS_readStringArray(napi_env env, napi_callback_ return result; } -napi_value NAPI_MessageSequence::JS_readSequenceableArrayCallJsFunc(napi_env env, +napi_value NAPI_MessageSequence::JS_readParcelableArrayCallJsFunc(napi_env env, napi_value &element, napi_value &thisVar) { @@ -2142,7 +2142,7 @@ napi_value NAPI_MessageSequence::JS_readSequenceableArrayCallJsFunc(napi_env env return retValue; } -napi_value NAPI_MessageSequence::JS_readSequenceableArray(napi_env env, napi_callback_info info) +napi_value NAPI_MessageSequence::JS_readParcelableArray(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value thisVar = nullptr; @@ -2181,7 +2181,7 @@ napi_value NAPI_MessageSequence::JS_readSequenceableArray(napi_env env, napi_cal } napi_value element = nullptr; napi_get_element(env, argv[ARGV_INDEX_0], i, &element); - napi_value callJsFuncResult = JS_readSequenceableArrayCallJsFunc(env, element, thisVar); + napi_value callJsFuncResult = JS_readParcelableArrayCallJsFunc(env, element, thisVar); if (callJsFuncResult == nullptr) { ZLOGE(LOG_LABEL, "call unmarshalling failed, element index: %{public}d", i); return callJsFuncResult; @@ -2243,7 +2243,7 @@ napi_value NAPI_MessageSequence::JS_readRemoteObjectArray(napi_env env, napi_cal return result; } -napi_value NAPI_MessageSequence::JS_readSequenceable(napi_env env, napi_callback_info info) +napi_value NAPI_MessageSequence::JS_readParcelable(napi_env env, napi_callback_info info) { size_t argc = 1; napi_value argv[ARGV_INDEX_1] = {0}; @@ -2823,7 +2823,7 @@ napi_value NAPI_MessageSequence::Export(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("writeBoolean", NAPI_MessageSequence::JS_writeBoolean), DECLARE_NAPI_FUNCTION("writeChar", NAPI_MessageSequence::JS_writeChar), DECLARE_NAPI_FUNCTION("writeString", NAPI_MessageSequence::JS_writeString), - DECLARE_NAPI_FUNCTION("writeSequenceable", NAPI_MessageSequence::JS_writeSequenceable), + DECLARE_NAPI_FUNCTION("writeParcelable", NAPI_MessageSequence::JS_writeParcelable), DECLARE_NAPI_FUNCTION("writeByteArray", NAPI_MessageSequence::JS_writeByteArray), DECLARE_NAPI_FUNCTION("writeShortArray", NAPI_MessageSequence::JS_writeShortArray), DECLARE_NAPI_FUNCTION("writeIntArray", NAPI_MessageSequence::JS_writeIntArray), @@ -2833,7 +2833,7 @@ napi_value NAPI_MessageSequence::Export(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("writeBooleanArray", NAPI_MessageSequence::JS_writeBooleanArray), DECLARE_NAPI_FUNCTION("writeCharArray", NAPI_MessageSequence::JS_writeCharArray), DECLARE_NAPI_FUNCTION("writeStringArray", NAPI_MessageSequence::JS_writeStringArray), - DECLARE_NAPI_FUNCTION("writeSequenceableArray", NAPI_MessageSequence::JS_writeSequenceableArray), + DECLARE_NAPI_FUNCTION("writeParcelableArray", NAPI_MessageSequence::JS_writeParcelableArray), DECLARE_NAPI_FUNCTION("writeRemoteObjectArray", NAPI_MessageSequence::JS_writeRemoteObjectArray), DECLARE_NAPI_FUNCTION("readByte", NAPI_MessageSequence::JS_readByte), DECLARE_NAPI_FUNCTION("readShort", NAPI_MessageSequence::JS_readShort), @@ -2844,7 +2844,7 @@ napi_value NAPI_MessageSequence::Export(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("readBoolean", NAPI_MessageSequence::JS_readBoolean), DECLARE_NAPI_FUNCTION("readChar", NAPI_MessageSequence::JS_readChar), DECLARE_NAPI_FUNCTION("readString", NAPI_MessageSequence::JS_readString), - DECLARE_NAPI_FUNCTION("readSequenceable", NAPI_MessageSequence::JS_readSequenceable), + DECLARE_NAPI_FUNCTION("readParcelable", NAPI_MessageSequence::JS_readParcelable), DECLARE_NAPI_FUNCTION("readByteArray", NAPI_MessageSequence::JS_readByteArray), DECLARE_NAPI_FUNCTION("readShortArray", NAPI_MessageSequence::JS_readShortArray), DECLARE_NAPI_FUNCTION("readIntArray", NAPI_MessageSequence::JS_readIntArray), @@ -2854,7 +2854,7 @@ napi_value NAPI_MessageSequence::Export(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("readBooleanArray", NAPI_MessageSequence::JS_readBooleanArray), DECLARE_NAPI_FUNCTION("readCharArray", NAPI_MessageSequence::JS_readCharArray), DECLARE_NAPI_FUNCTION("readStringArray", NAPI_MessageSequence::JS_readStringArray), - DECLARE_NAPI_FUNCTION("readSequenceableArray", NAPI_MessageSequence::JS_readSequenceableArray), + DECLARE_NAPI_FUNCTION("readParcelableArray", NAPI_MessageSequence::JS_readParcelableArray), DECLARE_NAPI_FUNCTION("readRemoteObjectArray", NAPI_MessageSequence::JS_readRemoteObjectArray), DECLARE_NAPI_STATIC_FUNCTION("closeFileDescriptor", NAPI_MessageSequence::JS_CloseFileDescriptor), DECLARE_NAPI_STATIC_FUNCTION("dupFileDescriptor", NAPI_MessageSequence::JS_DupFileDescriptor), diff --git a/ipc/native/src/napi/src/napi_remote_object.cpp b/ipc/native/src/napi/src/napi_remote_object.cpp index 4548339fa379825b30ae32e241b0814118c7cec9..8c871df381bb1874bb28d886c25c80880eac376c 100644 --- a/ipc/native/src/napi/src/napi_remote_object.cpp +++ b/ipc/native/src/napi/src/napi_remote_object.cpp @@ -1854,10 +1854,16 @@ napi_value NAPIMessageOption_JS_Constructor(napi_env env, napi_callback_info inf } else if (argc == 1) { napi_valuetype valueType; napi_typeof(env, argv[0], &valueType); - NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 1"); - int32_t jsFlags = 0; - napi_get_value_int32(env, argv[0], &jsFlags); - flags = jsFlags; + NAPI_ASSERT(env, valueType == napi_number || valueType == napi_boolean, "type mismatch for parameter 1"); + if (valueType == napi_boolean) { + bool jsBoolFlags = false; + napi_get_value_bool(env, argv[0], &jsBoolFlags); + flags = jsBoolFlags ? MessageOption::TF_ASYNC : MessageOption::TF_SYNC; + } else { + int32_t jsFlags = 0; + napi_get_value_int32(env, argv[0], &jsFlags); + flags = jsFlags == 0 ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC; + } waittime = MessageOption::TF_WAIT_TIME; } else { napi_valuetype valueType = napi_null; @@ -1869,7 +1875,7 @@ napi_value NAPIMessageOption_JS_Constructor(napi_env env, napi_callback_info inf napi_get_value_int32(env, argv[0], &jsFlags); int32_t jsWaittime = 0; napi_get_value_int32(env, argv[1], &jsWaittime); - flags = jsFlags; + flags = jsFlags == 0 ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC; waittime = jsWaittime; } @@ -1904,6 +1910,8 @@ napi_value NAPIMessageOptionExport(napi_env env, napi_value exports) napi_property_descriptor properties[] = { DECLARE_NAPI_FUNCTION("getFlags", NapiOhosRpcMessageOptionGetFlags), DECLARE_NAPI_FUNCTION("setFlags", NapiOhosRpcMessageOptionSetFlags), + DECLARE_NAPI_FUNCTION("isAsync", NapiOhosRpcMessageOptionIsAsync), + DECLARE_NAPI_FUNCTION("setAsync", NapiOhosRpcMessageOptionSetAsync), DECLARE_NAPI_FUNCTION("getWaitTime", NapiOhosRpcMessageOptionGetWaittime), DECLARE_NAPI_FUNCTION("setWaitTime", NapiOhosRpcMessageOptionSetWaittime), DECLARE_NAPI_STATIC_PROPERTY("TF_SYNC", tfSync),