1 /* 2 * Copyright (c) 2022 Chipsea Technologies (Shenzhen) Corp., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef MEDICAL_SENSOR_NAPI_UTILS_H 16 #define MEDICAL_SENSOR_NAPI_UTILS_H 17 18 #include <uv.h> 19 #include <iostream> 20 21 #include "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 24 #include "medical_native_impl.h" 25 26 #define EVENT_INVALID_PARAMETER (-1) 27 #define EVENT_OK 0 28 #define MAX_DATA_LEN 128 29 struct AsyncCallbackInfo { 30 napi_env env; 31 napi_async_work asyncWork; 32 napi_deferred deferred; 33 napi_ref callback[1] = { 0 }; 34 int32_t sensorTypeId; 35 int32_t sensorDataLength; 36 uint32_t sensorData[MAX_DATA_LEN]; 37 }; 38 39 bool IsMatchType(napi_value value, napi_valuetype type, napi_env env); 40 napi_value GetNapiInt32(int32_t number, napi_env env); 41 int32_t GetCppInt32(napi_value value, napi_env env); 42 bool GetCppBool(napi_value value, napi_env env); 43 void EmitAsyncCallbackWork(AsyncCallbackInfo *async_callback_info); 44 void EmitUvEventLoop(AsyncCallbackInfo *async_callback_info); 45 int64_t GetCppInt64(napi_value value, napi_env env); 46 napi_value NapiGetNamedProperty(napi_value jsonObject, std::string name, napi_env env); 47 napi_value GetUndefined(napi_env env); 48 #endif // MEDICAL_SENSOR_NAPI_UTILS_H