• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #include "nadatatypes.h"
17 #include "nodeapi.h"
18 
createTctNADataTypeInstance(napi_env env)19 napi_value createTctNADataTypeInstance(napi_env env)
20 {
21     napi_status status;
22     napi_value instance;
23 
24     OH_LOG_Print(LOG_APP, LOG_INFO, GLOBAL_RESMGR, "basesample", "Add in");
25 
26     status = napi_create_object(env, &instance);
27     if (status != napi_ok) {
28         napi_throw_error(env, nullptr, "Failed to create object");
29         return nullptr;
30     }
31 
32     napi_value pname;
33     status = napi_create_string_utf8(env, "tct_datatypes", strlen("tct_datatypes"), &pname);
34     if (status != napi_ok) {
35         napi_throw_error(env, nullptr, "Invalid argument: name must be a string");
36         return nullptr;
37     }
38 
39     status = napi_set_named_property(env, instance, "name", pname);
40     if (status != napi_ok) {
41         napi_throw_error(env, nullptr, "Failed to set property");
42         return nullptr;
43     }
44 
45     napi_property_descriptor properties[] = {
46         {"testNapiStatus", nullptr, testNapiStatus, nullptr, nullptr, nullptr, napi_default, nullptr},
47         {"testExterrinfo", nullptr, testNapiExterrinfo, nullptr, nullptr, nullptr, napi_default, nullptr},
48         {"testNapiEnv", nullptr, testNapiEnv, nullptr, nullptr, nullptr, napi_default, nullptr},
49         {"testNapiValue", nullptr, testNapiValue, nullptr, nullptr, nullptr, napi_default, nullptr},
50         {"testNapiThreadsafefunc", nullptr, setThreadsafefunc, nullptr, nullptr, nullptr, napi_default, nullptr},
51         {"testNapiThreadsafefuncrel", nullptr, setThreadsafefuncrel, nullptr, nullptr, nullptr, napi_default, nullptr},
52         {"testNapiThreadsafefuncall", nullptr, setThreadsafefuncall, nullptr, nullptr, nullptr, napi_default, nullptr},
53         {"cjson_version", nullptr, cJSONVersion, nullptr, nullptr, nullptr, napi_default, nullptr},
54     };
55 
56     status = napi_define_properties(env, instance, sizeof(properties) / sizeof(napi_property_descriptor), properties);
57     if (status != napi_ok) {
58         napi_throw_error(env, nullptr, "Failed to define properties");
59         return nullptr;
60     }
61     return instance;
62 }