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_STREAM_SOCKET_TRANSPORT_H_
19 #define ANBOX_STREAM_SOCKET_TRANSPORT_H_
21 #include "anbox/common/fd.h"
22 #include "anbox/network/socket_messenger.h"
23 #include "anbox/runtime.h"
27 #include <boost/asio.hpp>
31 class StreamSocketTransport {
36 virtual ~Observer() = default;
38 virtual void on_data_available() = 0;
39 virtual void on_disconnected() = 0;
41 Observer(Observer const&) = delete;
42 Observer& operator=(Observer const&) = delete;
45 StreamSocketTransport(const std::string& socket_path,
46 const std::shared_ptr<Runtime>& rt);
48 void register_observer(std::shared_ptr<Observer> const& observer_);
49 void unregister_observer(std::shared_ptr<Observer> const& observer_);
51 void send_message(std::vector<uint8_t> const& buffer);
52 void read_next_message();
55 void on_read_size(const boost::system::error_code& ec,
56 std::size_t bytes_read);
58 std::shared_ptr<Observer> observer_;
59 std::shared_ptr<boost::asio::local::stream_protocol::socket> socket_;
60 SocketMessenger messenger_;
62 } // namespace network
65 #endif // STREAM_SOCKET_TRANSPORT_H_