1 /*
2  * Copyright (C) 2023 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 #ifndef LOG_TAG
16 #define LOG_TAG "bt_napi_native_module_hfp"
17 #endif
18 
19 #include <map>
20 #include <string>
21 #include <thread>
22 
23 #include "bluetooth_log.h"
24 #include "napi_bluetooth_hfp_ag.h"
25 #include "napi_bluetooth_hfp_hf.h"
26 #include "hitrace_meter.h"
27 
28 namespace OHOS {
29 namespace Bluetooth {
30 EXTERN_C_START
31 /*
32  * Module initialization function
33  */
Init(napi_env env,napi_value exports)34 static napi_value Init(napi_env env, napi_value exports)
35 {
36     HITRACE_METER_NAME(HITRACE_TAG_OHOS, "hfp init");
37     HILOGD("-----Init start------");
38     napi_property_descriptor desc[] = {};
39 
40     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
41 
42     NapiHandsFreeAudioGateway::DefineHandsFreeAudioGatewayJSClass(env, exports);
43     NapiHandsFreeUnit::DefineHandsFreeUnitJSClass(env);
44 
45     HILOGD("-----Init end------");
46     return exports;
47 }
48 EXTERN_C_END
49 /*
50  * Module define
51  */
52 static napi_module bluetoothHfpModule = {.nm_version = 1,
53     .nm_flags = 0,
54     .nm_filename = NULL,
55     .nm_register_func = Init,
56     .nm_modname = "bluetooth.hfp",
57     .nm_priv = ((void *)0),
58     .reserved = {0}};
59 /*
60  * Module register function
61  */
RegisterModule(void)62 extern "C" __attribute__((constructor)) void RegisterModule(void)
63 {
64     HILOGI("Register bluetoothModule nm_modname:%{public}s", bluetoothHfpModule.nm_modname);
65     napi_module_register(&bluetoothHfpModule);
66 }
67 }  // namespace Bluetooth
68 }  // namespace OHOS
69