Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
stream_socket_transport.h
Go to the documentation of this file.
1 /*
2  * Copyright © 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 Lesser 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
17  */
18 
19 
20 #ifndef STREAM_SOCKET_TRANSPORT_H_
21 #define STREAM_SOCKET_TRANSPORT_H_
22 
23 #include "stream_transport.h"
24 #include "mir/fd.h"
25 
26 #include <thread>
27 #include <mutex>
28 
29 namespace mir
30 {
31 namespace client
32 {
33 namespace rpc
34 {
35 
37 {
38 public:
39  StreamSocketTransport(Fd const& fd);
40  StreamSocketTransport(std::string const& socket_path);
41  ~StreamSocketTransport() override;
42 
43  void register_observer(std::shared_ptr<Observer> const& observer) override;
44  void receive_data(void* buffer, size_t bytes_requested) override;
45  void receive_data(void* buffer, size_t bytes_requested, std::vector<Fd>& fds) override;
46  void send_data(const std::vector<uint8_t> &buffer) override;
47 
48 private:
49  void init();
50  Fd open_socket(std::string const& path);
51  void notify_data_available();
52  void notify_disconnected();
53 
54  std::thread io_service_thread;
55  Fd const socket_fd;
56  Fd shutdown_fd;
57 
58  std::mutex observer_mutex;
59  std::vector<std::shared_ptr<Observer>> observers;
60 };
61 
62 }
63 }
64 }
65 
66 
67 #endif // STREAM_SOCKET_TRANSPORT_H_
All things Mir.
Definition: aging_buffer.h:24
void send_data(const std::vector< uint8_t > &buffer) override
Write data to the server.
Definition: stream_socket_transport.cpp:143
Definition: fd.h:33
Responsible for shuttling bytes to and from the server.
Definition: stream_transport.h:67
StreamSocketTransport(Fd const &fd)
Definition: stream_socket_transport.cpp:38
void receive_data(void *buffer, size_t bytes_requested) override
Read data from the server.
Definition: stream_socket_transport.cpp:66
Definition: stream_socket_transport.h:36
void register_observer(std::shared_ptr< Observer > const &observer) override
Definition: stream_socket_transport.cpp:60
~StreamSocketTransport() override
Definition: stream_socket_transport.cpp:49

Copyright © 2012,2013 Canonical Ltd.
Generated on Fri Oct 10 14:07:14 UTC 2014