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

Commit 78a31e7c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove bta_closure in favor of posting messages to a message loop"

parents ee89e00a 231eec13
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ cc_defaults {
        "dm",
        "hd",
        "hh",
        "closure",
    ],
    include_dirs: [
        "packages/modules/Bluetooth/system",
@@ -51,7 +50,6 @@ cc_library_static {
        "av/bta_av_ci.cc",
        "av/bta_av_main.cc",
        "av/bta_av_ssm.cc",
        "closure/bta_closure.cc",
        "dm/bta_dm_act.cc",
        "dm/bta_dm_api.cc",
        "dm/bta_dm_cfg.cc",
@@ -118,7 +116,6 @@ cc_test {
    name: "net_test_bta",
    defaults: ["fluoride_bta_defaults"],
    srcs: [
        "test/bta_closure_test.cc",
        "test/bta_hf_client_test.cc",
    ],
    shared_libs: [
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ static_library("bta") {
    "av/bta_av_ci.cc",
    "av/bta_av_main.cc",
    "av/bta_av_ssm.cc",
    "closure/bta_closure.cc",
    "dm/bta_dm_act.cc",
    "dm/bta_dm_api.cc",
    "dm/bta_dm_cfg.cc",

system/bta/closure/bta_closure.cc

deleted100644 → 0
+0 −87
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2016 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 "base/pending_task.h"
#include "base/time/time.h"
#include "bta_closure_int.h"
#include "bta_sys.h"

using base::PendingTask;
using base::TaskQueue;
using base::TimeTicks;

namespace {

enum {
  /* these events are handled by the state machine */
  BTA_CLOSURE_EXECUTE_EVT = BTA_SYS_EVT_START(BTA_ID_CLOSURE),
};

struct tBTA_CLOSURE_EXECUTE {
  BT_HDR hdr;
  PendingTask pending_task;
};

static const tBTA_SYS_REG bta_closure_hw_reg = {bta_closure_execute, NULL};
tBTA_SYS_SENDMSG bta_closure_sys_sendmsg = NULL;

}  // namespace

/* Accept bta_sys_register, and bta_sys_sendmsg. Those parameters can be used to
 * override system methods for tests.
 */
void bta_closure_init(tBTA_SYS_REGISTER registerer, tBTA_SYS_SENDMSG sender) {
  /* register closure message handler */
  registerer(BTA_ID_CLOSURE, &bta_closure_hw_reg);
  bta_closure_sys_sendmsg = sender;
}

bool bta_closure_execute(BT_HDR* p_raw_msg) {
  if (p_raw_msg->event != BTA_CLOSURE_EXECUTE_EVT) {
    APPL_TRACE_ERROR("%s: don't know how to execute event type %d", __func__,
                     p_raw_msg->event);
    return false;
  }

  tBTA_CLOSURE_EXECUTE* p_msg = ((tBTA_CLOSURE_EXECUTE*)p_raw_msg);

  APPL_TRACE_API("%s: executing closure %s", __func__,
                 p_msg->pending_task.posted_from.ToString().c_str());
  p_msg->pending_task.task.Run();

  p_msg->pending_task.~PendingTask();
  return true;
}

/*
 * This function posts a closure for execution on the btu_bta_msg_queue. Please
 * see documentation at
 * https://www.chromium.org/developers/coding-style/important-abstractions-and-data-structures
 * for how to handle dynamic memory ownership/smart pointers with base::Owned(),
 * base::Passed(), base::ConstRef() and others.
 */
void do_in_bta_thread(const tracked_objects::Location& from_here,
                      const base::Closure& task) {
  APPL_TRACE_API("%s: posting %s", __func__, from_here.ToString().c_str());
  tBTA_CLOSURE_EXECUTE* p_msg =
      (tBTA_CLOSURE_EXECUTE*)osi_malloc(sizeof(tBTA_CLOSURE_EXECUTE));

  new (&p_msg->pending_task) PendingTask(from_here, task, TimeTicks(), true);
  p_msg->hdr.event = BTA_CLOSURE_EXECUTE_EVT;
  bta_closure_sys_sendmsg(p_msg);
}
+0 −34
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2016 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.
 *
 ******************************************************************************/

#ifndef BTA_CLOSURE_INT_H
#define BTA_CLOSURE_INT_H

#include <stdbool.h>

#include "bta/sys/bta_sys.h"
#include "bta_api.h"
#include "include/bt_trace.h"

/* Accept bta_sys_register, and bta_sys_sendmsg. Those parameters can be used to
 * override system methods for tests.
 */
void bta_closure_init(tBTA_SYS_REGISTER registerer, tBTA_SYS_SENDMSG sender);
bool bta_closure_execute(BT_HDR* p_msg);

#endif /* BTA_CLOSURE_INT_H */
+5 −1
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@
#include "bt_target.h"
#include "osi/include/alarm.h"

#include <base/logging.h>
#include <base/threading/thread.h>

/*****************************************************************************
 *  Constants and data types
 ****************************************************************************/
@@ -160,7 +163,6 @@ typedef struct {
} tBTA_SYS_HW_MSG;

typedef void (*tBTA_SYS_REGISTER)(uint8_t id, const tBTA_SYS_REG* p_reg);
typedef void (*tBTA_SYS_SENDMSG)(void* p_msg);

/*****************************************************************************
 *  Global data
@@ -221,6 +223,8 @@ extern void bta_sys_deregister(uint8_t id);
extern bool bta_sys_is_register(uint8_t id);
extern uint16_t bta_sys_get_sys_features(void);
extern void bta_sys_sendmsg(void* p_msg);
extern void do_in_bta_thread(const tracked_objects::Location& from_here,
                             const base::Closure& task);
extern void bta_sys_start_timer(alarm_t* alarm, period_ms_t interval,
                                uint16_t event, uint16_t layer_specific);
extern void bta_sys_disable(tBTA_SYS_HW_MODULE module);
Loading