2 * Copyright (C) 2016 Simon Fels <morphis@gravedo.de>
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef ANBOX_QEMU_ADBD_MESSAGE_PROCESSOR_H_
19 #define ANBOX_QEMU_ADBD_MESSAGE_PROCESSOR_H_
21 #include "anbox/network/message_processor.h"
22 #include "anbox/network/socket_connection.h"
23 #include "anbox/network/socket_messenger.h"
24 #include "anbox/network/tcp_socket_connector.h"
25 #include "anbox/network/tcp_socket_messenger.h"
26 #include "anbox/runtime.h"
28 #include <boost/asio.hpp>
34 class AdbMessageProcessor : public network::MessageProcessor {
37 const std::shared_ptr<Runtime> &rt,
38 const std::shared_ptr<network::SocketMessenger> &messenger);
39 ~AdbMessageProcessor();
41 bool process_data(const std::vector<std::uint8_t> &data) override;
45 waiting_for_guest_accept_command,
46 waiting_for_host_connection,
47 waiting_for_guest_start_command,
55 void wait_for_host_connection();
56 void on_host_connection(std::shared_ptr<boost::asio::basic_stream_socket<
57 boost::asio::ip::tcp>> const &socket);
58 void read_next_host_message();
59 void on_host_read_size(const boost::system::error_code &error,
60 std::size_t bytes_read);
62 std::shared_ptr<Runtime> runtime_;
63 State state_ = waiting_for_guest_accept_command;
64 std::string expected_command_;
65 std::shared_ptr<network::SocketMessenger> const messenger_;
66 std::vector<std::uint8_t> buffer_;
67 std::shared_ptr<network::TcpSocketConnector> host_connector_;
68 std::shared_ptr<network::TcpSocketMessenger> host_messenger_;
69 std::array<std::uint8_t, 8192> host_buffer_;
70 std::unique_lock<std::mutex> lock_;
72 static std::mutex active_instance_;
74 } // namespace graphics