Mir
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 #include "mir/basic_observers.h"
26 
27 #include <thread>
28 #include <mutex>
29 
30 namespace mir
31 {
32 namespace client
33 {
34 namespace rpc
35 {
36 
38  private BasicObservers<StreamTransport::Observer>
39 {
40 public:
43 
44  void on_data_available() override;
45  void on_disconnected() override;
46 };
47 
49 {
50 public:
51  StreamSocketTransport(Fd const& fd);
52  StreamSocketTransport(std::string const& socket_path);
53 
54  void register_observer(std::shared_ptr<Observer> const& observer) override;
55  void unregister_observer(std::shared_ptr<Observer> const& observer) override;
56 
57  void receive_data(void* buffer, size_t bytes_requested) override;
58  void receive_data(void* buffer, size_t bytes_requested, std::vector<Fd>& fds) override;
59  void send_message(std::vector<uint8_t> const& buffer, std::vector<mir::Fd> const& fds) override;
60 
61  Fd watch_fd() const override;
62  bool dispatch(mir::dispatch::FdEvents event) override;
63  mir::dispatch::FdEvents relevant_events() const override;
64 private:
65  Fd open_socket(std::string const& path);
66 
67  Fd const socket_fd;
68 
69  TransportObservers observers;
70 };
71 
72 }
73 }
74 }
75 
76 
77 #endif // STREAM_SOCKET_TRANSPORT_H_
All things Mir.
Definition: atomic_callback.h:25
Definition: fd.h:33
Responsible for shuttling bytes to and from the server.
Definition: stream_transport.h:68
Definition: stream_socket_transport.h:37
void receive_data(mir::Fd const &socket, void *buffer, size_t bytes_requested, std::vector< mir::Fd > &fds)
Definition: fd_socket_transmission.cpp:95
void on_data_available() override
Called by the Transport when data is available for reading.
Definition: stream_socket_transport.cpp:38
Definition: stream_socket_transport.h:48
Definition: basic_observers.h:28
uint32_t FdEvents
Definition: dispatchable.h:36
void on_disconnected() override
Called by the Transport when the connection to the server has been broken.
Definition: stream_socket_transport.cpp:43
Observer of IO status.
Definition: stream_transport.h:87

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016