• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 AIP_NAPI_UTILS_H
17 #define AIP_NAPI_UTILS_H
18 
19 #include "i_aip_core_manager.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 
23 namespace OHOS {
24 namespace DataIntelligence {
25 class AipNapiUtils {
26 public:
27     AipNapiUtils() = default;
28     ~AipNapiUtils() = default;
29 
30     static bool LoadAlgoLibrary(const std::string &algoPath, AipCoreManagerHandle &aipMgrHandler);
31     static bool UnLoadAlgoLibrary(AipCoreManagerHandle &aipMgrHandler);
32     static IAipCoreManager *GetAlgoObj(AipCoreManagerHandle &aipMgrHandler);
33     static bool ValidateArgsType(napi_env env, napi_value *args, size_t argc,
34         const std::vector<std::string> &expectedTypes);
35     static bool TransJsToStr(napi_env env, napi_value value, std::string &str);
36     static bool TransJsToStrUnlimited(napi_env env, napi_value value, std::string &str);
37     static bool TransJsToInt32(napi_env env, napi_value value, int32_t &res);
38     static bool TransJsToDouble(napi_env env, napi_value value, double &res);
39     static bool TransJsToBool(napi_env env, napi_value value, bool &res);
40     static void CreateStringData(napi_env env, napi_value aipServiceValue, napi_value result, const std::string name,
41         std::string &content);
42     static void CreateInt32Data(napi_env env, napi_value aipServiceValue, napi_value result, const std::string name,
43         int32_t value);
44     static void CreateDoubleData(napi_env env, double value, napi_value *result);
45     static void SetInt32Property(napi_env env, napi_value targetObj, int32_t value, const char *propName);
46     static void SetPropertyName(napi_env env, napi_value targetObj, const char *propName, napi_value propValue);
47     static bool CheckModelConfig(napi_env env, napi_value value);
48 };
49 } // namespace DataIntelligence
50 } // namespace OHOS
51 #endif // AIP_NAPI_UTILS_H
52