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