TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / network / socket_connection.h
1 /*
2  * Copyright © 2012-2014 Canonical Ltd.
3  *
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,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18
19 #ifndef ANBOX_NETWORK_SOCKET_CONNECTION_H_
20 #define ANBOX_NETWORK_SOCKET_CONNECTION_H_
21
22 #include "anbox/network/connections.h"
23 #include "anbox/network/message_processor.h"
24 #include "anbox/network/message_receiver.h"
25 #include "anbox/network/message_sender.h"
26
27 #include <boost/asio.hpp>
28
29 #include <sys/types.h>
30
31 namespace anbox {
32 namespace network {
33 class SocketConnection {
34  public:
35   SocketConnection(
36       std::shared_ptr<MessageReceiver> const& message_receiver,
37       std::shared_ptr<MessageSender> const& message_sender, int id,
38       std::shared_ptr<Connections<SocketConnection>> const& connections,
39       std::shared_ptr<MessageProcessor> const& processor);
40
41   ~SocketConnection() noexcept;
42
43   void set_name(const std::string& name) { name_ = name; }
44
45   int id() const { return id_; }
46
47   void send(char const* data, size_t length);
48   void read_next_message();
49
50  private:
51   void on_read_size(const boost::system::error_code& ec,
52                     std::size_t bytes_read);
53
54   std::shared_ptr<MessageReceiver> const message_receiver_;
55   std::shared_ptr<MessageSender> const message_sender_;
56   int id_;
57   std::shared_ptr<Connections<SocketConnection>> const connections_;
58   std::shared_ptr<MessageProcessor> processor_;
59   std::array<std::uint8_t, 8192> buffer_;
60   std::string name_;
61 };
62 }  // namespace anbox
63 }  // namespace network
64
65 #endif