Mir
session_mediator.h
Go to the documentation of this file.
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 MIR_FRONTEND_SESSION_MEDIATOR_H_
20 #define MIR_FRONTEND_SESSION_MEDIATOR_H_
21 
22 #include "display_server.h"
26 #include "mir_toolkit/common.h"
27 #include "surface_tracker.h"
28 
29 #include <functional>
30 #include <memory>
31 #include <mutex>
32 #include <vector>
33 
34 namespace mir
35 {
36 namespace graphics
37 {
38 class Buffer;
39 class Display;
40 class GraphicBufferAllocator;
41 }
42 namespace input
43 {
44 class CursorImages;
45 }
46 
47 namespace scene
48 {
49 class CoordinateTranslator;
50 }
51 
54 namespace frontend
55 {
56 class ClientBufferTracker;
57 class Shell;
58 class Session;
59 class Surface;
60 class MessageResourceCache;
61 class SessionMediatorReport;
62 class EventSink;
63 class DisplayChanger;
64 class Screencast;
65 class PromptSession;
66 
67 // SessionMediator relays requests from the client process into the server.
68 class SessionMediator : public detail::DisplayServer, public mir::protobuf::Debug
69 {
70 public:
71 
73  std::shared_ptr<Shell> const& shell,
74  std::shared_ptr<graphics::PlatformIpcOperations> const& ipc_operations,
75  std::shared_ptr<frontend::DisplayChanger> const& display_changer,
76  std::vector<MirPixelFormat> const& surface_pixel_formats,
77  std::shared_ptr<SessionMediatorReport> const& report,
78  std::shared_ptr<EventSink> const& event_sink,
79  std::shared_ptr<MessageResourceCache> const& resource_cache,
80  std::shared_ptr<Screencast> const& screencast,
81  ConnectionContext const& connection_context,
82  std::shared_ptr<input::CursorImages> const& cursor_images,
83  std::shared_ptr<scene::CoordinateTranslator> const& translator);
84 
85  ~SessionMediator() noexcept;
86 
87  void client_pid(int pid) override;
88 
89  /* Platform independent requests */
90  void connect(::google::protobuf::RpcController* controller,
91  const ::mir::protobuf::ConnectParameters* request,
92  ::mir::protobuf::Connection* response,
93  ::google::protobuf::Closure* done) override;
94 
95  void create_surface(google::protobuf::RpcController* controller,
96  const mir::protobuf::SurfaceParameters* request,
97  mir::protobuf::Surface* response,
98  google::protobuf::Closure* done) override;
99 
100  void next_buffer(
101  google::protobuf::RpcController* controller,
102  mir::protobuf::SurfaceId const* request,
103  mir::protobuf::Buffer* response,
104  google::protobuf::Closure* done) override;
105 
106  void exchange_buffer(
107  google::protobuf::RpcController* controller,
108  mir::protobuf::BufferRequest const* request,
109  mir::protobuf::Buffer* response,
110  google::protobuf::Closure* done) override;
111 
112  void release_surface(google::protobuf::RpcController* controller,
114  mir::protobuf::Void*,
115  google::protobuf::Closure* done) override;
116 
117  void disconnect(google::protobuf::RpcController* controller,
118  const mir::protobuf::Void* request,
119  mir::protobuf::Void* response,
120  google::protobuf::Closure* done) override;
121 
122  void configure_surface(google::protobuf::RpcController* controller,
123  const mir::protobuf::SurfaceSetting*,
124  mir::protobuf::SurfaceSetting*,
125  google::protobuf::Closure* done) override;
126 
127  void configure_display(::google::protobuf::RpcController* controller,
128  const ::mir::protobuf::DisplayConfiguration* request,
129  ::mir::protobuf::DisplayConfiguration* response,
130  ::google::protobuf::Closure* done) override;
131 
132  void create_screencast(google::protobuf::RpcController*,
133  const mir::protobuf::ScreencastParameters*,
134  mir::protobuf::Screencast*,
135  google::protobuf::Closure* done) override;
136 
137  void release_screencast(google::protobuf::RpcController*,
138  const mir::protobuf::ScreencastId*,
139  mir::protobuf::Void*,
140  google::protobuf::Closure* done) override;
141 
142  void screencast_buffer(google::protobuf::RpcController*,
143  const mir::protobuf::ScreencastId*,
144  mir::protobuf::Buffer*,
145  google::protobuf::Closure* done) override;
146 
147  void configure_cursor(google::protobuf::RpcController*,
148  mir::protobuf::CursorSetting const*,
149  mir::protobuf::Void*,
150  google::protobuf::Closure* done) override;
151 
152  void start_prompt_session(::google::protobuf::RpcController* controller,
153  const ::mir::protobuf::PromptSessionParameters* request,
154  ::mir::protobuf::Void* response,
155  ::google::protobuf::Closure* done) override;
156 
157  void stop_prompt_session(::google::protobuf::RpcController* controller,
158  const ::mir::protobuf::Void* request,
159  ::mir::protobuf::Void* response,
160  ::google::protobuf::Closure* done) override;
161 
162  /* Platform specific requests */
163  void drm_auth_magic(google::protobuf::RpcController* controller,
164  const mir::protobuf::DRMMagic* request,
165  mir::protobuf::DRMAuthMagicStatus* response,
166  google::protobuf::Closure* done) override;
167 
168  void platform_operation(
169  google::protobuf::RpcController* /*controller*/,
170  mir::protobuf::PlatformOperationMessage const* request,
171  mir::protobuf::PlatformOperationMessage* response,
172  google::protobuf::Closure* done) override;
173 
175  ::google::protobuf::RpcController* controller,
176  ::mir::protobuf::SocketFDRequest const* parameters,
177  ::mir::protobuf::SocketFD* response,
178  ::google::protobuf::Closure* done) override;
179 
180  // TODO: Split this into a separate thing
182  ::google::protobuf::RpcController* controller,
183  ::mir::protobuf::CoordinateTranslationRequest const* request,
184  ::mir::protobuf::CoordinateTranslationResponse* response,
185  ::google::protobuf::Closure *done) override;
186 
187 private:
188  void pack_protobuf_buffer(protobuf::Buffer& protobuf_buffer,
189  graphics::Buffer* graphics_buffer,
190  graphics::BufferIpcMsgType msg_type);
191 
192  void advance_buffer(
193  SurfaceId surf_id,
194  Surface& surface,
195  graphics::Buffer* old_buffer,
196  std::unique_lock<std::mutex>& lock,
197  std::function<void(graphics::Buffer*, graphics::BufferIpcMsgType)> complete);
198 
199  virtual std::function<void(std::shared_ptr<Session> const&)> prompt_session_connect_handler() const;
200 
201  pid_t client_pid_;
202  std::shared_ptr<Shell> const shell;
203  std::shared_ptr<graphics::PlatformIpcOperations> const ipc_operations;
204 
205  std::vector<MirPixelFormat> const surface_pixel_formats;
206 
207  std::shared_ptr<frontend::DisplayChanger> const display_changer;
208  std::shared_ptr<SessionMediatorReport> const report;
209  std::shared_ptr<EventSink> const event_sink;
210  std::shared_ptr<MessageResourceCache> const resource_cache;
211  std::shared_ptr<Screencast> const screencast;
212  ConnectionContext const connection_context;
213  std::shared_ptr<input::CursorImages> const cursor_images;
214  std::shared_ptr<scene::CoordinateTranslator> const translator;
215 
216  SurfaceTracker surface_tracker;
217 
218  std::mutex session_mutex;
219  std::weak_ptr<Session> weak_session;
220  std::weak_ptr<PromptSession> weak_prompt_session;
221 };
222 
223 }
224 }
225 
226 #endif /* MIR_FRONTEND_SESSION_MEDIATOR_H_ */
All things Mir.
Definition: buffer_stream.h:37
IntWrapper< detail::SessionsSurfaceIdTag > SurfaceId
Definition: surface_id.h:29
void new_fds_for_prompt_providers(::google::protobuf::RpcController *controller,::mir::protobuf::SocketFDRequest const *parameters,::mir::protobuf::SocketFD *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:562
void release_surface(google::protobuf::RpcController *controller, const mir::protobuf::SurfaceId *, mir::protobuf::Void *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:330
void platform_operation(google::protobuf::RpcController *, mir::protobuf::PlatformOperationMessage const *request, mir::protobuf::PlatformOperationMessage *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:654
void configure_surface(google::protobuf::RpcController *controller, const mir::protobuf::SurfaceSetting *, mir::protobuf::SurfaceSetting *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:379
BufferIpcMsgType
Definition: platform_ipc_operations.h:29
void configure_display(::google::protobuf::RpcController *controller, const ::mir::protobuf::DisplayConfiguration *request,::mir::protobuf::DisplayConfiguration *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:411
void next_buffer(google::protobuf::RpcController *controller, mir::protobuf::SurfaceId const *request, mir::protobuf::Buffer *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:274
void release_screencast(google::protobuf::RpcController *, const mir::protobuf::ScreencastId *, mir::protobuf::Void *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:487
void disconnect(google::protobuf::RpcController *controller, const mir::protobuf::Void *request, mir::protobuf::Void *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:356
void translate_surface_to_screen(::google::protobuf::RpcController *controller,::mir::protobuf::CoordinateTranslationRequest const *request,::mir::protobuf::CoordinateTranslationResponse *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:594
Definition: session_mediator.h:68
void drm_auth_magic(google::protobuf::RpcController *controller, const mir::protobuf::DRMMagic *request, mir::protobuf::DRMAuthMagicStatus *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:620
void client_pid(int pid) override
Definition: session_mediator.cpp:110
~SessionMediator() noexcept
Definition: session_mediator.cpp:101
void stop_prompt_session(::google::protobuf::RpcController *controller, const ::mir::protobuf::Void *request,::mir::protobuf::Void *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:715
void create_surface(google::protobuf::RpcController *controller, const mir::protobuf::SurfaceParameters *request, mir::protobuf::Surface *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:178
void configure_cursor(google::protobuf::RpcController *, mir::protobuf::CursorSetting const *, mir::protobuf::Void *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:530
Definition: connection_context.h:32
Definition: surface_tracker.h:39
Definition: int_wrapper.h:27
void connect(::google::protobuf::RpcController *controller, const ::mir::protobuf::ConnectParameters *request,::mir::protobuf::Connection *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:115
Definition: surface.h:40
void screencast_buffer(google::protobuf::RpcController *, const mir::protobuf::ScreencastId *, mir::protobuf::Buffer *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:499
Definition: buffer.h:34
void create_screencast(google::protobuf::RpcController *, const mir::protobuf::ScreencastParameters *, mir::protobuf::Screencast *, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:457
void exchange_buffer(google::protobuf::RpcController *controller, mir::protobuf::BufferRequest const *request, mir::protobuf::Buffer *response, google::protobuf::Closure *done) override
Definition: session_mediator.cpp:301
void start_prompt_session(::google::protobuf::RpcController *controller, const ::mir::protobuf::PromptSessionParameters *request,::mir::protobuf::Void *response,::google::protobuf::Closure *done) override
Definition: session_mediator.cpp:689
Definition: display_server.h:30
SessionMediator(std::shared_ptr< Shell > const &shell, std::shared_ptr< graphics::PlatformIpcOperations > const &ipc_operations, std::shared_ptr< frontend::DisplayChanger > const &display_changer, std::vector< MirPixelFormat > const &surface_pixel_formats, std::shared_ptr< SessionMediatorReport > const &report, std::shared_ptr< EventSink > const &event_sink, std::shared_ptr< MessageResourceCache > const &resource_cache, std::shared_ptr< Screencast > const &screencast, ConnectionContext const &connection_context, std::shared_ptr< input::CursorImages > const &cursor_images, std::shared_ptr< scene::CoordinateTranslator > const &translator)
Definition: session_mediator.cpp:73

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