1 /* 2 * Copyright 2015 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 #pragma once 18 19 #include <functional> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 //#include "base/files/scoped_file.h" 25 26 namespace test_vendor_lib { 27 28 // Manages communications between test channel and the controller. Mirrors the 29 // HciTransport for the test channel. 30 class TestChannelTransport { 31 public: TestChannelTransport()32 TestChannelTransport() {} 33 ~TestChannelTransport()34 ~TestChannelTransport() {} 35 36 // Opens a port and returns the file descriptor for the socket. 37 // Returns -1 on an error. 38 int SetUp(int port); 39 40 // Closes the port (if succesfully opened in SetUp). 41 void CleanUp(); 42 43 // Waits for a connection request from the test channel program and 44 // returns the file descriptor to watch for run-time parameters. 45 // Returns -1 on an error. 46 int Accept(int listen_fd); 47 48 // Sets the callback that fires when data is read in WatchFd(). 49 void RegisterCommandHandler(const std::function<void(const std::string&, const std::vector<std::string>&)>& callback); 50 51 // Send data back to the test channel. 52 void SendResponse(int fd, const std::string&) const; 53 54 void OnCommandReady(int fd, std::function<void(void)> unwatch); 55 56 private: 57 std::function<void(const std::string&, const std::vector<std::string>&)> command_handler_; 58 59 int listen_fd_ = -1; 60 61 TestChannelTransport(const TestChannelTransport& cmdPckt) = delete; 62 TestChannelTransport& operator=(const TestChannelTransport& cmdPckt) = delete; 63 }; 64 65 } // namespace test_vendor_lib 66