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