mirror of
https://gitee.com/openharmony/communication_ipc
synced 2024-11-23 07:50:24 +00:00
!845 fix: 代码整改 优化判断条件;变量初始化;小驼峰命名
Merge pull request !845 from jialinbo/master
This commit is contained in:
commit
277100370e
@ -92,10 +92,6 @@ int32_t InvokerListenThread(ProxyObject *proxyObject, const char *localDeviceID,
|
||||
if (current->sessionName == NULL) {
|
||||
return ERR_FAILED;
|
||||
}
|
||||
if (sessionNameLen == 0 || sessionNameLen > SERVICENAME_LENGTH) {
|
||||
RPC_LOG_ERROR("sessionNameLen invalid");
|
||||
return ERR_FAILED;
|
||||
}
|
||||
if (strcpy_s(current->sessionName, sessionNameLen + 1, proxyObject->sessionName) != EOK) {
|
||||
free(current->sessionName);
|
||||
return ERR_FAILED;
|
||||
|
@ -145,13 +145,13 @@ static napi_value NapiOhosRpcMessageOptionSetWaittime(napi_env env, napi_callbac
|
||||
napi_valuetype valueType = napi_null;
|
||||
napi_typeof(env, argv[ARGV_INDEX_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[ARGV_INDEX_0], &waittime);
|
||||
int32_t waitTime = 0;
|
||||
napi_status status = napi_get_value_int32(env, argv[ARGV_INDEX_0], &waitTime);
|
||||
NAPI_ASSERT(env, status == napi_ok, "failed to get int32 value");
|
||||
MessageOption *option = nullptr;
|
||||
napi_unwrap(env, thisVar, (void **)&option);
|
||||
NAPI_ASSERT(env, option != nullptr, "failed to get native message option");
|
||||
option->SetWaitTime(waittime);
|
||||
option->SetWaitTime(waitTime);
|
||||
napi_value result = nullptr;
|
||||
napi_get_undefined(env, &result);
|
||||
return result;
|
||||
@ -165,10 +165,10 @@ static napi_value NAPIMessageOption_JS_Constructor(napi_env env, napi_callback_i
|
||||
napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
|
||||
|
||||
int flags = 0;
|
||||
int waittime = 0;
|
||||
int waitTime = 0;
|
||||
if (argc == 0) {
|
||||
flags = MessageOption::TF_SYNC;
|
||||
waittime = MessageOption::TF_WAIT_TIME;
|
||||
waitTime = MessageOption::TF_WAIT_TIME;
|
||||
} else if (argc == 1) {
|
||||
napi_valuetype valueType;
|
||||
napi_typeof(env, argv[ARGV_INDEX_0], &valueType);
|
||||
@ -182,7 +182,7 @@ static napi_value NAPIMessageOption_JS_Constructor(napi_env env, napi_callback_i
|
||||
napi_get_value_int32(env, argv[ARGV_INDEX_0], &jsFlags);
|
||||
flags = jsFlags == 0 ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC;
|
||||
}
|
||||
waittime = MessageOption::TF_WAIT_TIME;
|
||||
waitTime = MessageOption::TF_WAIT_TIME;
|
||||
} else {
|
||||
napi_valuetype valueType = napi_null;
|
||||
napi_typeof(env, argv[ARGV_INDEX_0], &valueType);
|
||||
@ -191,13 +191,13 @@ static napi_value NAPIMessageOption_JS_Constructor(napi_env env, napi_callback_i
|
||||
NAPI_ASSERT(env, valueType == napi_number, "type mismatch for parameter 2");
|
||||
int32_t jsFlags = 0;
|
||||
napi_get_value_int32(env, argv[ARGV_INDEX_0], &jsFlags);
|
||||
int32_t jsWaittime = 0;
|
||||
napi_get_value_int32(env, argv[ARGV_INDEX_1], &jsWaittime);
|
||||
int32_t jsWaitTime = 0;
|
||||
napi_get_value_int32(env, argv[ARGV_INDEX_1], &jsWaitTime);
|
||||
flags = jsFlags == 0 ? MessageOption::TF_SYNC : MessageOption::TF_ASYNC;
|
||||
waittime = jsWaittime;
|
||||
waitTime = jsWaitTime;
|
||||
}
|
||||
|
||||
auto messageOption = new MessageOption(flags, waittime);
|
||||
auto messageOption = new MessageOption(flags, waitTime);
|
||||
// connect native message option to js thisVar
|
||||
napi_status status = napi_wrap(
|
||||
env, thisVar, messageOption,
|
||||
|
@ -139,7 +139,7 @@ napi_value NAPIAshmem::Create(napi_env env, napi_callback_info info)
|
||||
size_t argcAshmem = 2;
|
||||
napi_value argv[ARGV_LENGTH_2] = { 0 };
|
||||
napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr);
|
||||
if (!(argc == argcExistingAshmem || argc == argcAshmem)) {
|
||||
if ((argc != argcExistingAshmem) && (argc != argcAshmem)) {
|
||||
ZLOGE(LOG_LABEL, "requires 1 or 2 parameter");
|
||||
return napiErr.ThrowError(env, OHOS::errorDesc::CHECK_PARAM_ERROR);
|
||||
}
|
||||
@ -231,7 +231,7 @@ napi_value NAPIAshmem::GetAshmemFromExisting(napi_env env, napi_callback_info in
|
||||
}
|
||||
int32_t fd = napiAshmem->GetAshmem()->GetAshmemFd();
|
||||
uint32_t size = (uint32_t)(napiAshmem->GetAshmem()->GetAshmemSize());
|
||||
if (!((fd > 0) && (size > 0))) {
|
||||
if (fd <= 0 || size <= 0) {
|
||||
ZLOGE(LOG_LABEL, "fd <= 0 or size <= 0");
|
||||
return nullptr;
|
||||
}
|
||||
@ -428,17 +428,17 @@ napi_value NAPIAshmem::ReadFromAshmem(napi_env env, napi_callback_info info)
|
||||
napi_value arrayBuffer = nullptr;
|
||||
void *arrayBufferPtr = nullptr;
|
||||
napi_create_arraybuffer(env, size, &arrayBufferPtr, &arrayBuffer);
|
||||
napi_value typedarray = nullptr;
|
||||
napi_create_typedarray(env, napi_int32_array, size / BYTE_SIZE_32, arrayBuffer, 0, &typedarray);
|
||||
napi_value typedArray = nullptr;
|
||||
napi_create_typedarray(env, napi_int32_array, size / BYTE_SIZE_32, arrayBuffer, 0, &typedArray);
|
||||
bool isTypedArray = false;
|
||||
napi_is_typedarray(env, typedarray, &isTypedArray);
|
||||
napi_is_typedarray(env, typedArray, &isTypedArray);
|
||||
NAPI_ASSERT(env, isTypedArray == true, "create TypedArray failed");
|
||||
if (size == 0) {
|
||||
return typedarray;
|
||||
return typedArray;
|
||||
}
|
||||
errno_t status = memcpy_s(arrayBufferPtr, size, result, size);
|
||||
NAPI_ASSERT(env, status == EOK, "memcpy_s is failed");
|
||||
return typedarray;
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
napi_value NAPIAshmem::ReadAshmem(napi_env env, napi_callback_info info)
|
||||
@ -496,24 +496,24 @@ napi_value NAPIAshmem::TransferByteToJsData(napi_env env, uint32_t size, const v
|
||||
napi_value arrayBuffer = nullptr;
|
||||
void *arrayBufferPtr = nullptr;
|
||||
napi_create_arraybuffer(env, size, &arrayBufferPtr, &arrayBuffer);
|
||||
napi_value typedarray = nullptr;
|
||||
napi_create_typedarray(env, napi_int32_array, size / BYTE_SIZE_32, arrayBuffer, 0, &typedarray);
|
||||
napi_value typedArray = nullptr;
|
||||
napi_create_typedarray(env, napi_int32_array, size / BYTE_SIZE_32, arrayBuffer, 0, &typedArray);
|
||||
bool isTypedArray = false;
|
||||
napi_is_typedarray(env, typedarray, &isTypedArray);
|
||||
napi_is_typedarray(env, typedArray, &isTypedArray);
|
||||
NAPI_ASSERT(env, isTypedArray == true, "create TypedArray failed");
|
||||
if (isTypedArray == false) {
|
||||
if (!isTypedArray) {
|
||||
ZLOGE(LOG_LABEL, "napiAshmem is null");
|
||||
return napiErr.ThrowError(env, OHOS::errorDesc::READ_FROM_ASHMEM_ERROR);
|
||||
}
|
||||
if (size == 0) {
|
||||
return typedarray;
|
||||
return typedArray;
|
||||
}
|
||||
errno_t status = memcpy_s(arrayBufferPtr, size, result, size);
|
||||
if (status != EOK) {
|
||||
ZLOGE(LOG_LABEL, "memcpy_s is failed");
|
||||
return napiErr.ThrowError(env, OHOS::errorDesc::READ_FROM_ASHMEM_ERROR);
|
||||
}
|
||||
return typedarray;
|
||||
return typedArray;
|
||||
}
|
||||
|
||||
napi_value NAPIAshmem::SetProtection(napi_env env, napi_callback_info info)
|
||||
@ -656,7 +656,7 @@ napi_value NAPIAshmem::WriteAshmem(napi_env env, napi_callback_info info)
|
||||
for (size_t i = 0; i < arrayLength; i++) {
|
||||
bool hasElement = false;
|
||||
napi_has_element(env, argv[ARGV_INDEX_0], i, &hasElement);
|
||||
if (hasElement == false) {
|
||||
if (!hasElement) {
|
||||
ZLOGE(LOG_LABEL, "parameter check error");
|
||||
return napiErr.ThrowError(env, OHOS::errorDesc::CHECK_PARAM_ERROR);
|
||||
}
|
||||
@ -703,7 +703,7 @@ napi_value NAPIAshmem::CheckWriteAshmemParams(napi_env env, size_t argc, napi_va
|
||||
}
|
||||
bool isArray = false;
|
||||
napi_is_array(env, argv[ARGV_INDEX_0], &isArray);
|
||||
if (isArray == false) {
|
||||
if (!isArray) {
|
||||
ZLOGE(LOG_LABEL, "type mismatch for parameter 1");
|
||||
return napiErr.ThrowError(env, OHOS::errorDesc::CHECK_PARAM_ERROR);
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ static int32_t ProcessProto(uint32_t code, IpcIo *data, IpcIo *reply, MessageOpt
|
||||
|
||||
static int32_t DBinderRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption *option)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t ret = -1;
|
||||
switch (code) {
|
||||
case GET_PROTO_INFO: {
|
||||
ret = ProcessProto(code, data, reply, option);
|
||||
@ -110,7 +110,6 @@ static int32_t DBinderRemoteRequest(uint32_t code, IpcIo *data, IpcIo *reply, Me
|
||||
}
|
||||
default: {
|
||||
RPC_LOG_ERROR("unknown dbinder code %u", code);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user