• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., 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 
16 #ifndef HIVIEWDFX_NAPI_HITRACE_UTIL_H
17 #define HIVIEWDFX_NAPI_HITRACE_UTIL_H
18 
19 #include <functional>
20 
21 #include "hitrace/trace.h"
22 #include "napi/native_api.h"
23 #include "napi/native_node_api.h"
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 constexpr int NAPI_VALUE_STRING_LEN = 10240;
28 class NapiHitraceUtil {
29 public:
30     static bool CheckValueTypeValidity(const napi_env env, const napi_value& jsObj,
31         const napi_valuetype typeName);
32     static void CreateHiTraceIdJsObject(const napi_env env, HiTraceId& traceId,
33         napi_value& valueObject);
34     static void TransHiTraceIdJsObjectToNative(const napi_env env, HiTraceId& traceId,
35         const napi_value& valueObject);
36     static void EnableTraceIdObjectFlag(const napi_env env, HiTraceId& traceId, napi_value& traceIdObject);
37 
38 private:
39     static void SetPropertyInt32(const napi_env env, napi_value& object,
40         const std::string& propertyName, uint32_t value);
41     static void SetPropertyInt64(const napi_env env, napi_value& object,
42         const std::string& propertyName, uint64_t value);
43     static void SetPropertyBigInt64(const napi_env env, napi_value& object,
44         const std::string& propertyName, uint64_t value);
45     static uint32_t GetPropertyInt32(const napi_env env, const napi_value& object,
46         const std::string& propertyName);
47     static uint64_t GetPropertyInt64(const napi_env env, const napi_value& object,
48         const std::string& propertyName);
49     static uint64_t GetPropertyBigInt64(const napi_env env, const napi_value& object,
50         const std::string& propertyName);
51 };
52 } // namespace HiviewDFX
53 } // namespace OHOS
54 
55 #endif // HIVIEWDFX_NAPI_HITRACE_UTIL_H
56