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 namespace OHOS {
27 namespace Sensors {
28 #define EVENT_INVALID_PARAMETER (-1)
29 #define EVENT_OK 0
30 #define MAX_DATA_LEN 128
31 struct AsyncCallbackInfo {
32     napi_env env;
33     napi_async_work asyncWork;
34     napi_deferred deferred;
35     napi_ref callback[1] = { 0 };
36     int32_t sensorTypeId;
37     int32_t sensorDataLength;
38     uint32_t sensorData[MAX_DATA_LEN];
39 };
40 
41 bool IsMatchType(napi_value value, napi_valuetype type, napi_env env);
42 napi_value GetNapiInt32(int32_t number, napi_env env);
43 int32_t GetCppInt32(napi_value value, napi_env env);
44 bool GetCppBool(napi_value value, napi_env env);
45 void EmitAsyncCallbackWork(AsyncCallbackInfo *asyncCallbackInfo);
46 void EmitUvEventLoop(AsyncCallbackInfo *asyncCallbackInfo);
47 int64_t GetCppInt64(napi_value value, napi_env env);
48 napi_value NapiGetNamedProperty(napi_value jsonObject, std::string name, napi_env env);
49 napi_value GetUndefined(napi_env env);
50 } // namespace Sensors
51 } // namespace OHOS
52 #endif // MEDICAL_SENSOR_NAPI_UTILS_H