Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f81cac87 authored by Chris Manton's avatar Chris Manton
Browse files

IA2: Split btu event and btu task

hci event handling and main thread tasks are
unrelated and should be separated.

Bug: 301776146
Test: m .

Change-Id: I63ae8debf53ab6a0ae618202e10958b541644336
parent 2d26aa40
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -233,6 +233,7 @@ cc_library_static {
        "btm/btm_sco_hci.cc",
        "btm/btm_sco_hci.cc",
        "btm/btm_sco_hfp_hal.cc",
        "btm/btm_sco_hfp_hal.cc",
        "btm/btm_sec.cc",
        "btm/btm_sec.cc",
        "btu/btu_event.cc",
        "btu/btu_hcif.cc",
        "btu/btu_hcif.cc",
        "btu/btu_task.cc",
        "btu/btu_task.cc",
        "eatt/eatt.cc",
        "eatt/eatt.cc",
@@ -1711,6 +1712,7 @@ cc_test {
        ":TestMockStackL2cap",
        ":TestMockStackL2cap",
        ":TestMockStackMetrics",
        ":TestMockStackMetrics",
        ":TestMockStackSmp",
        ":TestMockStackSmp",
        "btu/btu_event.cc",
        "btu/btu_hcif.cc",
        "btu/btu_hcif.cc",
        "btu/btu_task.cc",
        "btu/btu_task.cc",
        "test/stack_btu_test.cc",
        "test/stack_btu_test.cc",
+1 −0
Original line number Original line Diff line number Diff line
@@ -128,6 +128,7 @@ source_set("stack") {
    "btm/btm_sec.cc",
    "btm/btm_sec.cc",
    "btm/hfp_msbc_encoder.cc",
    "btm/hfp_msbc_encoder.cc",
    "btm/hfp_msbc_decoder.cc",
    "btm/hfp_msbc_decoder.cc",
    "btu/btu_event.cc",
    "btu/btu_hcif.cc",
    "btu/btu_hcif.cc",
    "btu/btu_task.cc",
    "btu/btu_task.cc",
    "eatt/eatt.cc",
    "eatt/eatt.cc",
+44 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "btm_iso_api.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/btu_hcif.h"

using bluetooth::hci::IsoManager;

/* Define BTU storage area */
uint8_t btu_trace_level = HCI_INITIAL_TRACE_LEVEL;

void btu_hci_msg_process(BT_HDR* p_msg) {
  /* Determine the input message type. */
  switch (p_msg->event & BT_EVT_MASK) {
    case BT_EVT_TO_BTU_HCI_EVT:
      btu_hcif_process_event((uint8_t)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
      osi_free(p_msg);
      break;

    case BT_EVT_TO_BTU_HCI_ISO:
      IsoManager::GetInstance()->HandleIsoData(p_msg);
      osi_free(p_msg);
      break;

    default:
      osi_free(p_msg);
      break;
  }
}
+2 −37
Original line number Original line Diff line number Diff line
@@ -22,51 +22,16 @@
#include <base/logging.h>
#include <base/logging.h>
#include <base/run_loop.h>
#include <base/run_loop.h>
#include <base/threading/thread.h>
#include <base/threading/thread.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


#include "bta/sys/bta_sys.h"
#include "btcore/include/module.h"
#include "btif/include/btif_common.h"
#include "btm_iso_api.h"
#include "common/message_loop_thread.h"
#include "common/message_loop_thread.h"
#include "osi/include/allocator.h"
#include "include/hardware/bluetooth.h"
#include "osi/include/log.h"
#include "os/log.h"
#include "osi/include/osi.h"
#include "stack/include/acl_hci_link_interface.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/btu.h"
#include "stack/include/btu.h"
#include "stack/include/btu_hcif.h"


using bluetooth::common::MessageLoopThread;
using bluetooth::common::MessageLoopThread;
using bluetooth::hci::IsoManager;

/* Define BTU storage area */
uint8_t btu_trace_level = HCI_INITIAL_TRACE_LEVEL;


static MessageLoopThread main_thread("bt_main_thread");
static MessageLoopThread main_thread("bt_main_thread");


void btu_hci_msg_process(BT_HDR* p_msg) {
  /* Determine the input message type. */
  switch (p_msg->event & BT_EVT_MASK) {
    case BT_EVT_TO_BTU_HCI_EVT:
      btu_hcif_process_event((uint8_t)(p_msg->event & BT_SUB_EVT_MASK), p_msg);
      osi_free(p_msg);
      break;

    case BT_EVT_TO_BTU_HCI_ISO:
      IsoManager::GetInstance()->HandleIsoData(p_msg);
      osi_free(p_msg);
      break;

    default:
      osi_free(p_msg);
      break;
  }
}

bluetooth::common::MessageLoopThread* get_main_thread() { return &main_thread; }
bluetooth::common::MessageLoopThread* get_main_thread() { return &main_thread; }


bt_status_t do_in_main_thread(const base::Location& from_here,
bt_status_t do_in_main_thread(const base::Location& from_here,
+1 −20
Original line number Original line Diff line number Diff line
@@ -27,30 +27,11 @@
#ifndef BTU_H
#ifndef BTU_H
#define BTU_H
#define BTU_H


#include <base/functional/callback.h>
#include <base/location.h>
#include <base/threading/thread.h>

#include <cstdint>
#include <cstdint>


#include "bt_target.h"
#include "stack/include/btu_task.h"
#include "common/message_loop_thread.h"
#include "osi/include/alarm.h"


/* Global BTU data */
/* Global BTU data */
extern uint8_t btu_trace_level;
extern uint8_t btu_trace_level;


/* Functions provided by btu_task.cc
 ***********************************
*/
bluetooth::common::MessageLoopThread* get_main_thread();
bt_status_t do_in_main_thread(const base::Location& from_here,
                              base::OnceClosure task);
bt_status_t do_in_main_thread_delayed(const base::Location& from_here,
                                      base::OnceClosure task,
                                      const base::TimeDelta& delay);

using BtMainClosure = std::function<void()>;
void post_on_bt_main(BtMainClosure closure);

#endif
#endif
Loading