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 
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 
42  void register_observer(std::shared_ptr<Observer> const& observer) override;
43  void receive_data(void* buffer, size_t bytes_requested) override;
44  void receive_data(void* buffer, size_t bytes_requested, std::vector<Fd>& fds) override;
45  void send_message(std::vector<uint8_t> const& buffer, std::vector<mir::Fd> const& fds) override;
46 
47  Fd watch_fd() const override;
48  bool dispatch(mir::dispatch::FdEvents event) override;
50 private:
51  Fd open_socket(std::string const& path);
52  void notify_data_available();
53  void notify_disconnected();
54 
55  Fd const socket_fd;
56 
57  std::mutex observer_mutex;
58  std::vector<std::shared_ptr<Observer>> observers;
59 };
60 
61 }
62 }
63 }
64 
65 
66 #endif // STREAM_SOCKET_TRANSPORT_H_
All things Mir.
Definition: buffer_stream.h:37
Definition: fd.h:33
Responsible for shuttling bytes to and from the server.
Definition: stream_transport.h:68
mir::dispatch::FdEvents relevant_events() const override
The set of file-descriptor events this Dispatchable handles.
Definition: stream_socket_transport.cpp:199
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:54
void send_message(std::vector< uint8_t > const &buffer, std::vector< mir::Fd > const &fds) override
Write message to the server.
Definition: stream_socket_transport.cpp:131
Fd watch_fd() const override
Get a poll()able file descriptor.
Definition: stream_socket_transport.cpp:167
Definition: stream_socket_transport.h:36
bool dispatch(mir::dispatch::FdEvents event) override
Dispatch one pending event.
Definition: stream_socket_transport.cpp:172
void register_observer(std::shared_ptr< Observer > const &observer) override
Definition: stream_socket_transport.cpp:48
uint32_t FdEvents
Definition: dispatchable.h:36

Copyright © 2012,2013 Canonical Ltd.
Generated on Tue Mar 24 16:15:19 UTC 2015