2 // Copyright 2015 The Android Open Source Project
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 #include "base/files/scoped_file.h"
23 #include "base/message_loop/message_loop.h"
25 namespace test_vendor_lib {
27 // Manages communications between test channel and the controller. Mirrors the
28 // HciTransport for the test channel.
29 class TestChannelTransport : public base::MessageLoopForIO::Watcher {
31 TestChannelTransport(bool enabled, int port);
33 ~TestChannelTransport() = default;
35 // Waits for a connection request from the test channel program and
36 // allocates the file descriptor to watch for run-time parameters at. This
37 // file descriptor gets stored in |fd_|.
42 // Because it imposes a different flow of work, the test channel must be
43 // actively enabled to be used. |enabled_| is set by the vendor manager.
46 // Turns the test channel off for use in circumstances where an error occurs
47 // and leaving the channel on would crash Bluetooth (e.g. if the test channel
48 // is unable to bind to its socket, Bluetooth should still start without the
52 // Sets the callback that fires when data is read in
53 // |OnFileCanReadWithoutBlocking|.
54 void RegisterCommandHandler(
55 std::function<void(const std::string&, const std::vector<std::string>&)>
59 // base::MessageLoopForIO::Watcher overrides:
60 void OnFileCanReadWithoutBlocking(int fd) override;
62 void OnFileCanWriteWithoutBlocking(int fd) override;
64 std::function<void(const std::string&, const std::vector<std::string>&)>
67 // File descriptor to watch for test hook data.
68 std::unique_ptr<base::ScopedFD> fd_;
70 // TODO(dennischeng): Get port and enabled flag from a config file.
74 DISALLOW_COPY_AND_ASSIGN(TestChannelTransport);
77 } // namespace test_vendor_lib