Openharmony 5.0.3蓝牙开启流程

流程伪代码:
所在文件:foundation/communication/bluetooth/frameworks/js/napi/src/access/napi_bluetooth_access.cpp
napi_value NapiAccess::EnableBluetooth(napi_env env, napi_callback_info info)
{
int32_t ret = host->EnableBle();
}
所在文件:foundation/communication/bluetooth/frameworks/inner/src/bluetooth_host.cpp
int BluetoothHost::EnableBle()
{
return pimpl->switchModule_->ProcessBluetoothSwitchEvent(BluetoothSwitchEvent::ENABLE_BLUETOOTH);
}
所在文件:foundation/communication/bluetooth/frameworks/inner/src/bluetooth_switch_module.cpp
int BluetoothSwitchModule::ProcessBluetoothSwitchEvent(BluetoothSwitchEvent event)
{
switch (event) {
case BluetoothSwitchEvent::ENABLE_BLUETOOTH:
return ProcessEnableBluetoothEvent();
}
所在文件:foundation/communication/bluetooth/frameworks/inner/src/bluetooth_switch_module.cpp
int BluetoothSwitchModule::ProcessEnableBluetoothEvent(void)
{
return ProcessBluetoothSwitchAction(
[this]() { return switchAction_->EnableBluetooth(); },
BluetoothSwitchEvent::ENABLE_BLUETOOTH);
}
所在文件:foundation/communication/bluetooth/frameworks/inner/src/bluetooth_host.cpp
int EnableBluetooth(void) override
{
return proxy->EnableBle();
}
所在文件:foundation/communication/bluetooth/frameworks/inner/ipc/src/bluetooth_host_proxy.cpp
int32_t BluetoothHostProxy::EnableBle()
{
int32_t error = InnerTransact(BluetoothHostInterfaceCode::BT_ENABLE_BLE, option, data, reply);
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/ipc/src/bluetooth_host_stub.cpp
int32_t BluetoothHostStub::EnableBleInner(MessageParcel &data, MessageParcel &reply)
{
int32_t result = EnableBle();
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/service/src/common/adapter_manager.cpp
bool AdapterManager::Enable(const BTTransport transport) const
{
if (GetState(transport) == BTStateID::STATE_TURN_OFF) {
pimpl->dispatcher_->PostTask(std::bind(&AdapterManager::impl::ProcessMessage, pimpl.get(), transport, msg));
}
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/service/src/common/adapter_manager.cpp
void AdapterManager::impl::ProcessMessage(const BTTransport transport, const utility::Message &msg)
{
std::lock_guard<std::recursive_mutex> lock(syncMutex_);
if (transport == ADAPTER_BREDR && classicAdapter_ && classicAdapter_->stateMachine) {
classicAdapter_->stateMachine->ProcessMessage(msg);
return;
}
if (transport == ADAPTER_BLE && bleAdapter_ && bleAdapter_->stateMachine) {
bleAdapter_->stateMachine->ProcessMessage(msg);
return;
}
LOG_ERROR("%{public}s transport(%{public}d) failed", __PRETTY_FUNCTION__, transport);
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/service/src/util/state_machine.cpp
bool StateMachine::ProcessMessage(const Message &msg) const
{
State *current = current_;
if (current == nullptr) {
return false;
} else {
while (!current->Dispatch(msg)) {
current = current->parent_;
if (current == nullptr) {
return false;
}
}
}
return true;
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/service/src/common/adapter_state_machine.cpp
void AdapterTurningOnState::Entry()
{
adapter_.GetContext()->Enable();
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/service/src/ble/ble_adapter.cpp
void BleAdapter::Enable()
{
GetDispatcher()->PostTask(std::bind(&BleAdapter::EnableTask, this));
}
所在文件:foundation/communication/bluetooth_servic/services/bluetooth/service/src/ble/ble_adapter.cpp
bool BleAdapter::EnableTask()
{
bool ret = (BTM_Enable(LE_CONTROLLER) == BT_SUCCESS);
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/stack/src/btm/btm.c
int BTM_Enable(int controller)
{
if (g_currentMode == MODE_NONE) {
result = BtmEnableLeAndSharedModules();
}
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/stack/src/btm/btm.c
static int BtmEnableLeAndSharedModules()
{
int result = HCI_Initialize();
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/stack/src/hci/hci.c
int HCI_Initialize()
{
do {
g_hdiLib = LoadHdiLib();
if (g_hdiLib == NULL) {
result = BT_OPERATION_FAILED;
break;
}
HciInitFailure();
HciInitCmd();
HciInitEvent();
HciInitAcl();
HciVendorInit();
g_hciTxThread = ThreadCreate("HciTx");
if (g_hciTxThread == NULL) {
result = BT_OPERATION_FAILED;
break;
}
result = HciInitQueue();
if (result != BT_SUCCESS) {
break;
}
result = HciInitHal();
} while (0);
}
所在文件:foundation/communication/bluetooth_service/services/bluetooth/stack/src/hci/hci.c
NO_SANITIZE("cfi") static int HciInitHal()
{
int ret = g_hdiLib->hdiInit(&g_hdiCallacks);
}
所在文件:foundation/communication/bluetooth_service/services/Bluetooth/hardware/src/bluetooth_hdi.cpp
int HdiInit(BtHciCallbacks *callbacks)
{
int32_t result = iBtHci->Init(g_bluetoothHciCallbacks);
}
所在文件: drivers/peripheral/bluetooth/hci/hdi_service/hci_interface_impl.cpp
int32_t HciInterfaceImpl::Init(const sptr<IHciCallback>& callbackObj)
{
bool result = VendorInterface::GetInstance()->Initialize(
[callbackObj](bool status) { callbackObj->OnInited(status ? BtStatus::SUCCESS : BtStatus::INITIAL_ERROR); },
callback);
}
所在文件:drivers/peripheral/bluetooth/hci/hdi_service/implement/vendor_interface.cpp
bool VendorInterface::Initialize(
InitializeCompleteCallback initializeCompleteCallback, const ReceiveCallback &receiveCallback)
{
vendorHandle_ = dlopen(BT_VENDOR_NAME, RTLD_NOW);
}
此后调用蓝牙的libbt_vendor.z.so加载蓝牙驱动
更多推荐
所有评论(0)