• 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 #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_avrcp_ct.h"
32 #include "napi_bluetooth_avrcp_tg.h"
33 #include "napi_bluetooth_hid_host.h"
34 #include "napi_bluetooth_pan.h"
35 #include "napi_bluetooth_opp.h"
36 
37 #include "access/napi_bluetooth_access.h"
38 #include "connection/napi_bluetooth_connection.h"
39 #include "constant/napi_bluetooth_constant.h"
40 
41 namespace OHOS {
42 namespace Bluetooth {
43 EXTERN_C_START
44 /*
45  * Module initialization function
46  */
Init(napi_env env,napi_value exports)47 static napi_value Init(napi_env env, napi_value exports)
48 {
49     HILOGD("-----Init start------");
50     napi_property_descriptor desc[] = {};
51 
52     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
53 
54     NapiGattServer::DefineGattServerJSClass(env);
55     NapiGattClient::DefineGattClientJSClass(env);
56     DefineBLEJSObject(env, exports);
57     DefineSppFunctions(env, exports);
58     NapiProfile::DefineProfileFunctions(env, exports);
59     NapiHandsFreeAudioGateway::DefineHandsFreeAudioGatewayJSClass(env, exports);
60     NapiHandsFreeUnit::DefineHandsFreeUnitJSClass(env);
61 
62     NapiAccess::DefineAccessJSFunction(env, exports);
63     DefineConnectionFunctions(env, exports);
64     NapiConstant::DefineJSConstant(env, exports);
65 
66     BluetoothHostInit(env, exports);
67     NapiA2dpSink::DefineA2dpSinkJSClass(env);
68     NapiA2dpSource::DefineA2dpSourceJSClass(env, exports);
69     NapiAvrcpController::DefineAvrcpControllerJSClass(env);
70     NapiAvrcpTarget::DefineAvrcpTargetJSClass(env);
71     NapiBluetoothHidHost::DefineHidHostJSClass(env, exports);
72     NapiBluetoothPan::DefinePanJSClass(env, exports);
73     NapiBluetoothOpp::DefineOppJSClass(env);
74     DefineSystemBLEInterface(env, exports);
75 
76     HILOGD("-----Init end------");
77     return exports;
78 }
79 EXTERN_C_END
80 /*
81  * Module define
82  */
83 static napi_module bluetoothModule = {.nm_version = 1,
84     .nm_flags = 0,
85     .nm_filename = NULL,
86     .nm_register_func = Init,
87 #ifdef ENABLE_NAPI_BLUETOOTH_MANAGER
88     .nm_modname = "bluetoothManager",
89 #else
90     .nm_modname = "bluetooth",
91 #endif
92     .nm_priv = ((void *)0),
93     .reserved = {0}};
94 /*
95  * Module register function
96  */
RegisterModule(void)97 extern "C" __attribute__((constructor)) void RegisterModule(void)
98 {
99     HILOGI("Register bluetoothModule nm_modname:%{public}s", bluetoothModule.nm_modname);
100     napi_module_register(&bluetoothModule);
101 }
102 }  // namespace Bluetooth
103 }  // namespace OHOS
104