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

Commit 325485dd authored by Dennis Cheng's avatar Dennis Cheng Committed by Android Git Automerger
Browse files

am e51fbf95: test_vendor_lib: Use base::Thread

* commit 'e51fbf95':
  test_vendor_lib: Use base::Thread
parents 57788a6b e51fbf95
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5,14 +5,15 @@ include $(CLEAR_VARS)
BT_DIR := $(TOP_DIR)packages/modules/Bluetooth/system

LOCAL_SRC_FILES := \
    src/bredr_controller.cc \
    src/bt_vendor.cc \
    src/command_packet.cc \
    src/dual_mode_controller.cc \
    src/event_packet.cc \
    src/hci_handler.cc \
    src/hci_transport.cc \
    src/packet.cc \
    src/packet_stream.cc \
    src/vendor_manager.cc \

LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/include \
+1 −1
Original line number Diff line number Diff line
shared_library("test_vendor_lib") {
  sources = [
    "src/bredr_controller.cc",
    "src/bt_vendor.cc",
    "src/command_packet.cc",
    "src/dual_mode__controller.cc",
    "src/event_packet.cc",
    "src/hci_handler.cc",
    "src/hci_transport.cc",
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ class CommandPacket : public Packet {
 public:
  CommandPacket();

  ~CommandPacket() override = default;
  virtual ~CommandPacket() override = default;

  // Returns the command opcode as defined in stack/include/hcidefs.h.
  // See the Bluetooth Core Specification Version 4.2, Volume 2, Part E,
+43 −30
Original line number Diff line number Diff line
@@ -20,37 +20,37 @@
#include <vector>
#include <unordered_map>

#include "base/macros.h"
#include "vendor_libs/test_vendor_lib/include/hci_handler.h"

namespace test_vendor_lib {

// Emulates a BR/EDR controller by maintaining the link layer state machine
// detailed in the Bluetooth Core Specification Version 4.2, Volume 2, Part B,
// Section 8 (page 159). Provides actions corresponding to commands sent by the
// HCI. These actions will be registered from a single global controller
// instance as callbacks and called from the HciHandler.
// TODO(dennischeng): Should the controller implement an interface provided by
// the HciHandler and be used as a delegate (i.e. the HciHandler would hold a
// controller object) instead of registering its methods as callbacks?
class BREDRController {
// Emulates a dual mode BR/EDR + LE controller by maintaining the link layer
// state machine detailed in the Bluetooth Core Specification Version 4.2,
// Volume 6, Part B, Section 1.1 (page 30). Provides methods corresponding to
// commands sent by the HCI. These methods will be registered as callbacks from
// a controller instance with the HciHandler. To implement a new Bluetooth
// command, simply add the method declaration below, with return type void and a
// single const std::vector<std::uint8_t>& argument. After implementing the
// method, simply register it with the HciHandler using the SET_HANDLER macro in
// the controller's default constructor. Be sure to name your method after the
// corresponding Bluetooth command in the Core Specification with the prefix
// "Hci" to distinguish it as a controller command.
class DualModeController {
 public:
  // Sets all of the methods to be used as callbacks in the HciHandler.
  DualModeController();

  ~DualModeController() = default;

  // Registers command callbacks with the HciHandler instance so that they are
  // fired when the corresponding opcode is received from the HCI. For now, each
  // command must be individually registered. This allows for some flexibility
  // in which commands are made available by which controller.
  void RegisterHandlerCallbacks();

  // Functions that operate on the global controller instance. Initialize()
  // is called by the vendor library's Init() function to create the global
  // controller and must be called before Get() and CleanUp().
  // CleanUp() should be called when a call to TestVendorCleanUp() is made
  // since the global controller should live throughout the entire time the test
  // vendor library is in use.
  static BREDRController* Get();
  void RegisterCommandsWithHandler(HciHandler& handler);

  static void Initialize();

  static void CleanUp();
  // Sets the callback to be used for sending events back to the HCI.
  void RegisterEventChannel(
      std::function<void(std::unique_ptr<EventPacket>)> send_event);

  // Controller commands. For error codes, see the Bluetooth Core Specification,
  // Version 4.2, Volume 2, Part D (page 370).
@@ -318,12 +318,28 @@ class BREDRController {
  void HciInquiry(const std::vector<std::uint8_t>& args);

 private:
  // There will only be a single global instance of this class.
  BREDRController();
  // Creates a command complete event and sends it back to the HCI.
  void SendCommandComplete(uint16_t command_opcode,
                           const std::vector<uint8_t>& return_parameters) const;

  // Sends a command complete event with no return parameters. This event is
  // typically sent for commands that can be completed immediately.
  void SendCommandCompleteSuccess(uint16_t command_opcode) const;

  // The destructor can only be indirectly accessed through the static
  // CleanUp() method that destructs the global controller.
  ~BREDRController() = default;
  // Creates a command status event and sends it back to the HCI.
  void SendCommandStatus(uint16_t command_opcode) const;

  // Sends a command status event with default event parameters.
  void SendCommandStatusSuccess(uint16_t command_opcode) const;

  // Sends an inquiry response for a fake device.
  void SendInquiryResult() const;

  // Sends an extended inquiry response for a fake device.
  void SendExtendedInquiryResult() const;

  // Callback provided to send events from the controller back to the HCI.
  std::function<void(std::unique_ptr<EventPacket>)> send_event_;

  // Maintains the commands to be registered and used in the HciHandler object.
  // Keys are command opcodes and values are the callbacks to handle each
@@ -332,9 +348,6 @@ class BREDRController {
                     std::function<void(const std::vector<std::uint8_t>&)>>
      active_commands_;

  // Disallow any copies of the singleton to be made.
  DISALLOW_COPY_AND_ASSIGN(BREDRController);

  // Specifies the format of Inquiry Result events to be returned during the
  // Inquiry command.
  // 0x00: Standard Inquiry Result event format (default).
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <memory>
#include <vector>

#include "base/logging.h"
#include "vendor_libs/test_vendor_lib/include/packet.h"

namespace test_vendor_lib {
Loading