2
* Copyright © 2013-2014 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
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.
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/>.
16
* Authored by: Robert Ancell <robert.ancell@canonical.com>
17
* Alexandros Frantzis <alexandros.frantzis@canonical.com>
20
#ifndef USC_ASIO_DM_CONNECTION_H_
21
#define USC_ASIO_DM_CONNECTION_H_
23
#include "dm_connection.h"
25
#include <boost/asio.hpp>
31
class AsioDMConnection : public DMConnection
35
int from_dm_fd, int to_dm_fd,
36
std::shared_ptr<DMMessageHandler> const& dm_message_handler);
39
void start() override;
42
enum class USCMessageID
47
session_connected = 3,
48
set_active_session = 4,
54
void on_read_header(const boost::system::error_code& ec);
55
void on_read_payload(const boost::system::error_code& ec);
56
void send(USCMessageID id, std::string const& body);
58
boost::asio::io_service io_service;
59
boost::asio::posix::stream_descriptor from_dm_pipe;
60
boost::asio::posix::stream_descriptor to_dm_pipe;
61
std::thread io_thread;
62
std::shared_ptr<DMMessageHandler> const dm_message_handler;
64
static size_t const size_of_header = 4;
65
unsigned char message_header_bytes[size_of_header];
66
boost::asio::streambuf message_payload_buffer;
67
std::vector<char> write_buffer;
73
#endif /* USC_ASIO_DM_CONNECTION_H_ */