1 /*
2 * Copyright (C) 2021 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 #include <map>
17 #include <string>
18 #include <thread>
19
20 #include "bluetooth_log.h"
21 #include "napi_bluetooth_ble.h"
22 #include "napi_bluetooth_gatt_client.h"
23 #include "napi_bluetooth_gatt_server.h"
24 #include "napi_bluetooth_host.h"
25 #include "napi_bluetooth_hfp_ag.h"
26 #include "napi_bluetooth_hfp_hf.h"
27 #include "napi_bluetooth_profile.h"
28 #include "napi_bluetooth_spp_server.h"
29 #include "napi_bluetooth_a2dp_snk.h"
30 #include "napi_bluetooth_a2dp_src.h"
31 #include "napi_bluetooth_pbap_pce.h"
32 #include "napi_bluetooth_pbap_pse.h"
33 #include "napi_bluetooth_avrcp_ct.h"
34 #include "napi_bluetooth_avrcp_tg.h"
35
36 namespace OHOS {
37 namespace Bluetooth {
38 EXTERN_C_START
39 /*
40 * Module initialization function
41 */
Init(napi_env env,napi_value exports)42 static napi_value Init(napi_env env, napi_value exports)
43 {
44 napi_property_descriptor desc[] = {};
45
46 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
47
48 NapiGattServer::DefineGattServerJSClass(env);
49 NapiGattClient::DefineGattClientJSClass(env);
50 DefineBLEJSObject(env, exports);
51 DefineSppFunctions(env, exports);
52 DefineProfileFunctions(env, exports);
53 NapiHandsFreeAudioGateway::DefineHandsFreeAudioGatewayJSClass(env);
54 NapiHandsFreeUnit::DefineHandsFreeUnitJSClass(env);
55 BluetoothHostInit(env, exports);
56 NapiA2dpSink::DefineA2dpSinkJSClass(env);
57 NapiA2dpSource::DefineA2dpSourceJSClass(env);
58 NapiPbapClient::DefinePbapClientJSClass(env);
59 NapiPbapServer::DefinePbapServerJSClass(env);
60 NapiAvrcpController::DefineAvrcpControllerJSClass(env);
61 NapiAvrcpTarget::DefineAvrcpTargetJSClass(env);
62
63 DefineSystemBLEInterface(env, exports);
64
65 HILOGI("-----Init end------");
66 return exports;
67 }
68 EXTERN_C_END
69 /*
70 * Module define
71 */
72 static napi_module bluetoothModule = {.nm_version = 1,
73 .nm_flags = 0,
74 .nm_filename = NULL,
75 .nm_register_func = Init,
76 .nm_modname = "bluetooth",
77 .nm_priv = ((void *)0),
78 .reserved = {0}};
79 /*
80 * Module register function
81 */
RegisterModule(void)82 extern "C" __attribute__((constructor)) void RegisterModule(void)
83 {
84 napi_module_register(&bluetoothModule);
85 }
86 } // namespace Bluetooth
87 } // namespace OHOS