Mir
server.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 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_SERVER_H_
20 #define MIR_SERVER_H_
21 
23 #include "mir_toolkit/common.h"
24 
25 #include <functional>
26 #include <memory>
27 #include <vector>
28 
29 namespace mir
30 {
31 namespace compositor { class Compositor; class DisplayBufferCompositorFactory; }
32 namespace frontend { class SessionAuthorizer; class Session; class SessionMediatorReport; }
33 namespace graphics { class Cursor; class Platform; class Display; class GLConfig; class DisplayConfigurationPolicy; class DisplayConfigurationReport; }
34 namespace input { class CompositeEventFilter; class InputDispatcher; class CursorListener; class CursorImages; class TouchVisualizer; class InputDeviceHub;}
35 namespace logging { class Logger; }
36 namespace options { class Option; }
37 namespace cookie
38 {
39 using Secret = std::vector<uint8_t>;
40 }
41 namespace shell
42 {
43 class DisplayLayout;
44 class DisplayConfigurationController;
45 class FocusController;
46 class HostLifecycleEventListener;
47 class InputTargeter;
48 class Shell;
49 }
50 namespace scene
51 {
52 class ApplicationNotRespondingDetector;
53 class BufferStreamFactory;
54 class PromptSessionListener;
55 class PromptSessionManager;
56 class SessionListener;
57 class SessionCoordinator;
58 class SurfaceCoordinator;
59 class SurfaceFactory;
60 }
61 
62 class Fd;
63 class MainLoop;
64 class ServerStatusListener;
65 
66 enum class OptionType
67 {
68  null,
69  integer,
70  string,
71  boolean
72 };
73 
75 class Server
76 {
77 public:
78  Server();
79 
83  void set_command_line(int argc, char const* argv[]);
86 
93 
96  void apply_settings();
97 
99  auto supported_pixel_formats() const -> std::vector<MirPixelFormat>;
100 
102  void run();
103 
105  void stop();
106 
108  bool exited_normally();
120  std::string const& option,
121  std::string const& description,
122  int default_value);
123 
128  std::string const& option,
129  std::string const& description,
130  std::string const& default_value);
131 
136  std::string const& option,
137  std::string const& description,
138  char const* default_value);
139 
144  std::string const& option,
145  std::string const& description,
146  bool default_value);
147 
152  std::string const& option,
153  std::string const& description,
154  OptionType type);
155 
164  std::function<void(int argc, char const* const* argv)> const& command_line_hander);
165 
170  void set_config_filename(std::string const& config_file);
171 
175  auto get_options() const -> std::shared_ptr<options::Option>;
182  void add_init_callback(std::function<void()> const& init_callback);
186 
190  void set_exception_handler(std::function<void()> const& exception_handler);
191 
194  using Terminator = std::function<void(int signal)>;
195 
200  void set_terminator(Terminator const& terminator);
201 
207  using EmergencyCleanupHandler = std::function<void()>;
208 
212  void add_emergency_cleanup(EmergencyCleanupHandler const& handler);
220  template<typename T> using Builder = std::function<std::shared_ptr<T>()>;
223 
225  void override_the_compositor(Builder<compositor::Compositor> const& compositor_builder);
226 
228  void override_the_cursor_images(Builder<input::CursorImages> const& cursor_images_builder);
229 
232  Builder<compositor::DisplayBufferCompositorFactory> const& compositor_builder);
233 
236  Builder<graphics::DisplayConfigurationReport> const& report_builder);
237 
239  void override_the_gl_config(Builder<graphics::GLConfig> const& gl_config_builder);
240 
243  Builder<shell::HostLifecycleEventListener> const& host_lifecycle_event_listener_builder);
244 
246  void override_the_input_dispatcher(Builder<input::InputDispatcher> const& input_dispatcher_builder);
247 
249  void override_the_logger(Builder<logging::Logger> const& logger_builder);
250 
252  void override_the_prompt_session_listener(Builder<scene::PromptSessionListener> const& prompt_session_listener_builder);
253 
255  void override_the_prompt_session_manager(Builder<scene::PromptSessionManager> const& prompt_session_manager_builder);
256 
258  void override_the_server_status_listener(Builder<ServerStatusListener> const& server_status_listener_builder);
259 
261  void override_the_session_authorizer(Builder<frontend::SessionAuthorizer> const& session_authorizer_builder);
262 
264  void override_the_session_listener(Builder<scene::SessionListener> const& session_listener_builder);
265 
268 
270  void override_the_shell(Builder<shell::Shell> const& wrapper);
271 
274 
277  Builder<scene::ApplicationNotRespondingDetector> const& anr_detector_builder);
278 
280  template<typename T> using Wrapper = std::function<std::shared_ptr<T>(std::shared_ptr<T> const&)>;
281 
283  void wrap_cursor(Wrapper<graphics::Cursor> const& cursor_builder);
284 
287 
291 
294 
296  void wrap_shell(Wrapper<shell::Shell> const& wrapper);
305  auto the_compositor() const -> std::shared_ptr<compositor::Compositor>;
307 
309  auto the_composite_event_filter() const -> std::shared_ptr<input::CompositeEventFilter>;
310 
312  auto the_cursor_listener() const -> std::shared_ptr<input::CursorListener>;
313 
315  auto the_cursor() const -> std::shared_ptr<graphics::Cursor>;
316 
318  auto the_focus_controller() const -> std::shared_ptr<shell::FocusController>;
319 
321  auto the_display() const -> std::shared_ptr<graphics::Display>;
322 
323  auto the_display_configuration_controller() const -> std::shared_ptr<shell::DisplayConfigurationController>;
324 
326  auto the_gl_config() const -> std::shared_ptr<graphics::GLConfig>;
327 
329  auto the_graphics_platform() const -> std::shared_ptr<graphics::Platform>;
330 
332  auto the_input_targeter() const -> std::shared_ptr<shell::InputTargeter>;
333 
335  auto the_logger() const -> std::shared_ptr<logging::Logger>;
336 
338  auto the_main_loop() const -> std::shared_ptr<MainLoop>;
339 
341  auto the_prompt_session_listener() const -> std::shared_ptr<scene::PromptSessionListener>;
342 
344  auto the_prompt_session_manager() const ->std::shared_ptr<scene::PromptSessionManager>;
345 
347  auto the_session_authorizer() const -> std::shared_ptr<frontend::SessionAuthorizer>;
348 
350  auto the_session_coordinator() const -> std::shared_ptr<scene::SessionCoordinator>;
351 
353  auto the_session_listener() const -> std::shared_ptr<scene::SessionListener>;
354 
356  auto the_shell() const -> std::shared_ptr<shell::Shell>;
357 
359  auto the_shell_display_layout() const -> std::shared_ptr<shell::DisplayLayout>;
360 
362  auto the_buffer_stream_factory() const -> std::shared_ptr<scene::BufferStreamFactory>;
363 
365  auto the_surface_factory() const -> std::shared_ptr<scene::SurfaceFactory>;
366 
368  auto the_surface_coordinator() const -> std::shared_ptr<scene::SurfaceCoordinator>;
369 
371  auto the_touch_visualizer() const -> std::shared_ptr<input::TouchVisualizer>;
372 
374  auto the_input_device_hub() const -> std::shared_ptr<input::InputDeviceHub>;
375 
378  std::shared_ptr<scene::ApplicationNotRespondingDetector>;
386  using ConnectHandler = std::function<void(std::shared_ptr<frontend::Session> const& session)>;
387 
391  auto open_client_socket() -> Fd;
392 
397  auto open_client_socket(ConnectHandler const& connect_handler) -> Fd;
398 
402  auto open_prompt_socket() -> Fd;
405 private:
406  struct ServerConfiguration;
407  struct Self;
408  std::shared_ptr<Self> const self;
409 };
410 }
411 #endif /* SERVER_H_ */
All things Mir.
Definition: atomic_callback.h:25
void add_emergency_cleanup(EmergencyCleanupHandler const &handler)
Add cleanup for abnormal terminations. handler will be called on receipt of a fatal signal after whic...
Definition: server.cpp:361
void wrap_shell(Wrapper< shell::Shell > const &wrapper)
Sets a wrapper functor for creating the shell.
auto the_session_authorizer() const -> std::shared_ptr< frontend::SessionAuthorizer >
void override_the_compositor(Builder< compositor::Compositor > const &compositor_builder)
Sets an override functor for creating the compositor.
void add_init_callback(std::function< void()> const &init_callback)
Add a callback to be invoked when the server has been initialized, but before it starts. This allows client code to get access Mir objects. If multiple callbacks are added they will be invoked in the sequence added.
Definition: server.cpp:319
auto the_input_device_hub() const -> std::shared_ptr< input::InputDeviceHub >
auto get_options() const -> std::shared_ptr< options::Option >
Returns the configuration options. This will be null before initialization starts. It will be available when the init_callback has been invoked (and thereafter until the server exits).
Definition: server.cpp:345
Customise and run a Mir server.
Definition: server.h:75
void override_the_gl_config(Builder< graphics::GLConfig > const &gl_config_builder)
Sets an override functor for creating the gl config.
auto the_gl_config() const -> std::shared_ptr< graphics::GLConfig >
auto the_graphics_platform() const -> std::shared_ptr< graphics::Platform >
void override_the_session_mediator_report(Builder< frontend::SessionMediatorReport > const &session_mediator_builder)
Sets an override functor for creating the session mediator report.
std::function< std::shared_ptr< T >(std::shared_ptr< T > const &)> Wrapper
Each of the wrap functions takes a wrapper functor of the same form.
Definition: server.h:280
void set_terminator(Terminator const &terminator)
Set handler for termination requests. terminator will be called following receipt of SIGTERM or SIGIN...
Definition: server.cpp:356
auto the_display() const -> std::shared_ptr< graphics::Display >
Definition: fd.h:33
void wrap_display_buffer_compositor_factory(Wrapper< compositor::DisplayBufferCompositorFactory > const &wrapper)
Sets a wrapper functor for creating the per-display rendering code.
mir::ModuleProperties const description
Definition: platform.cpp:189
void override_the_session_listener(Builder< scene::SessionListener > const &session_listener_builder)
Sets an override functor for creating the session listener.
std::function< void()> EmergencyCleanupHandler
Functor for processing fatal signals for any "emergency cleanup". That is: SIGQUIT, SIGABRT, SIGFPE, SIGSEGV & SIGBUS.
Definition: server.h:207
STL namespace.
auto the_composite_event_filter() const -> std::shared_ptr< input::CompositeEventFilter >
void override_the_cookie_factory(mir::cookie::Secret const &secret)
creates the CookieFactory from the given secret This secret is used to generate timestamps that can b...
Definition: server.cpp:313
std::function< std::shared_ptr< T >()> Builder
Each of the override functions takes a builder functor of the same form.
Definition: server.h:222
void override_the_server_status_listener(Builder< ServerStatusListener > const &server_status_listener_builder)
Sets an override functor for creating the status listener.
auto the_application_not_responding_detector() const -> std::shared_ptr< scene::ApplicationNotRespondingDetector >
auto the_touch_visualizer() const -> std::shared_ptr< input::TouchVisualizer >
void set_command_line(int argc, char const *argv[])
set the command line. This must remain valid while apply_settings() and run() are called...
Definition: server.cpp:306
auto the_main_loop() const -> std::shared_ptr< MainLoop >
void override_the_prompt_session_listener(Builder< scene::PromptSessionListener > const &prompt_session_listener_builder)
Sets an override functor for creating the prompt session listener.
auto the_session_listener() const -> std::shared_ptr< scene::SessionListener >
void override_the_application_not_responding_detector(Builder< scene::ApplicationNotRespondingDetector > const &anr_detector_builder)
Sets an override functor for creating the application not responding detector.
auto the_display_configuration_controller() const -> std::shared_ptr< shell::DisplayConfigurationController >
auto open_prompt_socket() -> Fd
Get a file descriptor that can be used to connect a prompt provider It can be passed to another proce...
Definition: server.cpp:446
void set_command_line_handler(std::function< void(int argc, char const *const *argv)> const &command_line_hander)
Set a handler for any command line options Mir does not recognise. This will be invoked if any unreco...
Definition: server.cpp:332
void override_the_host_lifecycle_event_listener(Builder< shell::HostLifecycleEventListener > const &host_lifecycle_event_listener_builder)
Sets an override functor for creating the host lifecycle event listener.
void override_the_window_manager_builder(shell::WindowManagerBuilder const wmb)
Sets an override functor for creating the window manager.
Definition: server.cpp:484
void apply_settings()
Applies any configuration options, hooks, or custom implementations. Must be called before calling ru...
Definition: server.cpp:377
auto the_shell() const -> std::shared_ptr< shell::Shell >
auto the_buffer_stream_factory() const -> std::shared_ptr< scene::BufferStreamFactory >
void override_the_display_configuration_report(Builder< graphics::DisplayConfigurationReport > const &report_builder)
Sets an override functor for creating the display configuration report.
void override_the_logger(Builder< logging::Logger > const &logger_builder)
Sets an override functor for creating the logger.
auto the_shell_display_layout() const -> std::shared_ptr< shell::DisplayLayout >
auto the_prompt_session_manager() const -> std::shared_ptr< scene::PromptSessionManager >
auto the_logger() const -> std::shared_ptr< logging::Logger >
Definition: main_loop.h:29
OptionType
Definition: server.h:66
auto the_compositor() const -> std::shared_ptr< compositor::Compositor >
void add_configuration_option(std::string const &option, std::string const &description, int default_value)
Add user configuration option(s) to Mir's option handling. These will be resolved during initialisati...
Definition: server.cpp:501
auto the_session_coordinator() const -> std::shared_ptr< scene::SessionCoordinator >
auto the_prompt_session_listener() const -> std::shared_ptr< scene::PromptSessionListener >
auto the_input_targeter() const -> std::shared_ptr< shell::InputTargeter >
void wrap_cursor_listener(Wrapper< input::CursorListener > const &wrapper)
Sets a wrapper functor for creating the cursor listener.
void wrap_display_configuration_policy(Wrapper< graphics::DisplayConfigurationPolicy > const &wrapper)
Sets a wrapper functor for creating the display configuration policy.
void wrap_cursor(Wrapper< graphics::Cursor > const &cursor_builder)
Sets a wrapper functor for creating the cursor.
void override_the_shell(Builder< shell::Shell > const &wrapper)
Sets an override functor for creating the shell.
auto open_client_socket() -> Fd
Get a file descriptor that can be used to connect a client It can be passed to another process...
Definition: server.cpp:438
void override_the_session_authorizer(Builder< frontend::SessionAuthorizer > const &session_authorizer_builder)
Sets an override functor for creating the session authorizer.
void set_exception_handler(std::function< void()> const &exception_handler)
Set a handler for exceptions. This is invoked in a catch (...) block and the exception can be re-thro...
Definition: server.cpp:351
auto the_cursor_listener() const -> std::shared_ptr< input::CursorListener >
std::function< void(int signal)> Terminator
Functor for processing SIGTERM or SIGINT This will not be called directly by a signal handler: arbitr...
Definition: server.h:194
std::function< void(std::shared_ptr< frontend::Session > const &session)> ConnectHandler
Definition: server.h:386
auto the_surface_coordinator() const -> std::shared_ptr< scene::SurfaceCoordinator >
auto supported_pixel_formats() const -> std::vector< MirPixelFormat >
The pixel formats that may be used when creating surfaces.
Definition: server.cpp:420
bool exited_normally()
returns true if and only if server exited normally. Otherwise false.
Definition: server.cpp:433
void run()
Run the Mir server until it exits.
Definition: server.cpp:391
void stop()
Tell the Mir server to exit.
Definition: server.cpp:425
auto the_surface_factory() const -> std::shared_ptr< scene::SurfaceFactory >
auto the_focus_controller() const -> std::shared_ptr< shell::FocusController >
void override_the_display_buffer_compositor_factory(Builder< compositor::DisplayBufferCompositorFactory > const &compositor_builder)
Sets an override functor for creating the per-display rendering code.
void override_the_input_dispatcher(Builder< input::InputDispatcher > const &input_dispatcher_builder)
Sets an override functor for creating the input dispatcher.
std::function< std::shared_ptr< WindowManager >(FocusController *focus_controller)> WindowManagerBuilder
WindowManagers are built while initializing an AbstractShell, so a builder functor is needed...
Definition: window_manager_builder.h:34
void override_the_prompt_session_manager(Builder< scene::PromptSessionManager > const &prompt_session_manager_builder)
Sets an override functor for creating the prompt session manager.
std::vector< uint8_t > Secret
Definition: cookie_factory.h:31
auto the_cursor() const -> std::shared_ptr< graphics::Cursor >
void set_config_filename(std::string const &config_file)
Set the configuration filename. This will be searched for and parsed in the standard locations...
Definition: server.cpp:339
Server()
Definition: server.cpp:294
void override_the_cursor_images(Builder< input::CursorImages > const &cursor_images_builder)
Sets an override functor for creating the cursor images.

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015