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

Commit 61a8f203 authored by Dennis Cheng's avatar Dennis Cheng
Browse files

test_vendor_lib: Remove handlers

This upload removes the HciHandler and TestChannelHandler classes.
Removing these classes simplifies logic and also allows the
controller to do preprocessing before executing commands.

Bug: 21586676
Change-Id: I3f2711349dd2c86794538edc632b4f5f49b5169b
parent bfd19f85
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -9,11 +9,9 @@ LOCAL_SRC_FILES := \
    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/test_channel_handler.cc \
    src/test_channel_transport.cc \
    src/vendor_manager.cc \

+0 −1
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ shared_library("test_vendor_lib") {
    "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",
+14 −13
Original line number Diff line number Diff line
@@ -17,12 +17,14 @@
#pragma once

#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <unordered_map>

#include "vendor_libs/test_vendor_lib/include/hci_handler.h"
#include "vendor_libs/test_vendor_lib/include/test_channel_handler.h"
#include "vendor_libs/test_vendor_lib/include/command_packet.h"
#include "vendor_libs/test_vendor_lib/include/hci_transport.h"
#include "vendor_libs/test_vendor_lib/include/test_channel_transport.h"

namespace test_vendor_lib {

@@ -44,16 +46,15 @@ class 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 RegisterCommandsWithHandler(HciHandler& handler);
  void HandleCommand(std::unique_ptr<CommandPacket> command_packet);

  // Registers test channel command callbacks with the TestChannelHandler
  // instance so that they are fired when the corresponding command name is
  // received from the test channel.
  void RegisterCommandsWithTestChannelHandler(TestChannelHandler& handler);
  void HandleTestChannelCommand(const std::string& name,
                                const std::vector<std::string>& args);

  void RegisterHandlersWithHciTransport(HciTransport& transport);

  void RegisterHandlersWithTestChannelTransport(
      TestChannelTransport& transport);

  // Sets the callback to be used for sending events back to the HCI.
  void RegisterEventChannel(
@@ -381,11 +382,11 @@ class DualModeController {
  // command.
  std::unordered_map<std::uint16_t,
                     std::function<void(const std::vector<std::uint8_t>&)>>
      active_commands_;
      active_hci_commands_;

  std::unordered_map<std::string,
                     std::function<void(const std::vector<std::string>&)>>
      test_channel_active_commands_;
      active_test_channel_commands_;

  // Specifies the format of Inquiry Result events to be returned during the
  // Inquiry command.
+0 −69
Original line number Diff line number Diff line
//
// Copyright 2015 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.
//

#pragma once

#include <cstdint>
#include <memory>
#include <unordered_map>
#include <vector>

#include "vendor_libs/test_vendor_lib/include/command_packet.h"
#include "vendor_libs/test_vendor_lib/include/hci_transport.h"
#include "vendor_libs/test_vendor_lib/include/packet.h"

namespace test_vendor_lib {

// Dispatches packets to the appropriate controller handler. These handlers
// must be registered by controller objects in order for commands to be
// processed. Unregistered commands will perform no operations. Exposes two
// callbacks, HandleCommand() and HandleData(), to be registered with a
// HciTransport object and called when commands and data are sent by the host.
class HciHandler {
 public:
  HciHandler() = default;

  ~HciHandler() = default;

  // Callback to be fired when a command packet is received from the HCI. Takes
  // ownership of the packet and dispatches work to the controller through the
  // callback registered with the command's opcode. After the controller
  // finishes processing the command and the callback returns, the command
  // packet is destroyed.
  void HandleCommand(std::unique_ptr<CommandPacket> command_packet);

  // Creates the mapping from the opcode to the method |callback|.
  // |callback|, which is provided by the controller, will be fired when its
  // command opcode is received from the HCI.
  void RegisterControllerCommand(
      std::uint16_t opcode,
      std::function<void(const std::vector<std::uint8_t> args)> callback);

  // Sets the command and data callbacks for when packets are received from the
  // HCI.
  void RegisterHandlersWithTransport(HciTransport& transport);

 private:
  // Controller callbacks to be executed in handlers and registered in
  // RegisterControllerCommand().
  std::unordered_map<std::uint16_t,
                     std::function<void(const std::vector<std::uint8_t> args)> >
      commands_;

  DISALLOW_COPY_AND_ASSIGN(HciHandler);
};

}  // namespace test_vendor_lib
+0 −61
Original line number Diff line number Diff line
//
// Copyright 2015 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.
//

#pragma once

#include <cstdint>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "vendor_libs/test_vendor_lib/include/test_channel_transport.h"

namespace test_vendor_lib {

// Manages mappings from test channel commands to test channel callbacks
// provided by the controller. Parallels the functionality of the HciHandler for
// the test channel.
class TestChannelHandler {
 public:
  TestChannelHandler() = default;

  ~TestChannelHandler() = default;

  // Callback to be fired when a command is received from the test channel.
  void HandleTestCommand(std::string command_name,
                         std::vector<std::string> args);

  // Creates the mapping from the |command_name| to the method |callback|,
  // which is provided by the controller and will be fired when its command is
  // received from the test channel.
  void RegisterControllerCommand(
      std::string command_name,
      std::function<void(const std::vector<std::string> args)> callback);

  void RegisterHandlersWithTransport(TestChannelTransport& transport);

 private:
  // Controller callbacks to be executed in handlers and registered in
  // RegisterControllerCommand().
  std::unordered_map<std::string,
                     std::function<void(const std::vector<std::string> args)> >
      commands_;

  DISALLOW_COPY_AND_ASSIGN(TestChannelHandler);
};

}  // namespace test_vendor_lib
Loading