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#include "hitrace_meter.h" 41namespace OHOS { 42namespace Bluetooth { 43EXTERN_C_START 44/* 45 * Module initialization function 46 */ 47static napi_value Init(napi_env env, napi_value exports) 48{ 49#ifdef ENABLE_NAPI_BLUETOOTH_MANAGER 50 HITRACE_METER_NAME(HITRACE_TAG_OHOS, "bluetoothManager init"); 51#else 52 HITRACE_METER_NAME(HITRACE_TAG_OHOS, "bluetooth init"); 53#endif 54 HILOGD("-----Init start------"); 55 napi_property_descriptor desc[] = {}; 56 57 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); 58 59 NapiGattServer::DefineGattServerJSClass(env); 60 NapiGattClient::DefineGattClientJSClass(env); 61 DefineBLEJSObject(env, exports); 62 DefineSppFunctions(env, exports); 63 NapiProfile::DefineProfileFunctions(env, exports); 64 NapiHandsFreeAudioGateway::DefineHandsFreeAudioGatewayJSClass(env, exports); 65 NapiHandsFreeUnit::DefineHandsFreeUnitJSClass(env); 66 67 NapiAccess::DefineAccessJSFunction(env, exports); 68 DefineConnectionFunctions(env, exports); 69 NapiConstant::DefineJSConstant(env, exports); 70 71 BluetoothHostInit(env, exports); 72 NapiA2dpSink::DefineA2dpSinkJSClass(env); 73 NapiA2dpSource::DefineA2dpSourceJSClass(env, exports); 74 NapiAvrcpController::DefineAvrcpControllerJSClass(env); 75 NapiAvrcpTarget::DefineAvrcpTargetJSClass(env); 76 NapiBluetoothHidHost::DefineHidHostJSClass(env, exports); 77 NapiBluetoothPan::DefinePanJSClass(env, exports); 78 DefineSystemBLEInterface(env, exports); 79 80 HILOGD("-----Init end------"); 81 return exports; 82} 83EXTERN_C_END 84/* 85 * Module define 86 */ 87static 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 */ 101extern "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