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 
22 #include "mir_toolkit/common.h"
23 
24 #include <functional>
25 #include <memory>
26 #include <vector>
27 
28 namespace mir
29 {
30 namespace compositor { class Compositor; class DisplayBufferCompositorFactory; }
31 namespace frontend { class SessionAuthorizer; class Session; class SessionMediatorReport; }
32 namespace graphics { class Platform; class Display; class GLConfig; class DisplayConfigurationPolicy; }
33 namespace input { class CompositeEventFilter; class InputDispatcher; class CursorListener; class TouchVisualizer; }
34 namespace logging { class Logger; }
35 namespace options { class Option; }
36 namespace shell
37 {
38 class DisplayLayout;
39 class FocusController;
40 class HostLifecycleEventListener;
41 class InputTargeter;
42 class Shell;
43 }
44 namespace scene
45 {
46 class PlacementStrategy;
47 class PromptSessionListener;
48 class PromptSessionManager;
49 class SessionListener;
50 class SessionCoordinator;
51 class SurfaceConfigurator;
52 class SurfaceCoordinator;
53 }
54 
55 class Fd;
56 class MainLoop;
57 class ServerStatusListener;
58 
59 enum class OptionType
60 {
61  null,
62  integer,
63  string,
64  boolean
65 };
66 
68 class Server
69 {
70 public:
71  Server();
72 
76  void set_command_line(int argc, char const* argv[]);
79 
82  void apply_settings();
83 
85  auto supported_pixel_formats() const -> std::vector<MirPixelFormat>;
86 
88  void run();
89 
91  void stop();
92 
94  bool exited_normally();
106  std::string const& option,
107  std::string const& description,
108  int default_value);
109 
114  std::string const& option,
115  std::string const& description,
116  std::string const& default_value);
117 
122  std::string const& option,
123  std::string const& description,
124  char const* default_value);
125 
130  std::string const& option,
131  std::string const& description,
132  bool default_value);
133 
138  std::string const& option,
139  std::string const& description,
140  OptionType type);
141 
150  std::function<void(int argc, char const* const* argv)> const& command_line_hander);
151 
156  void set_config_filename(std::string const& config_file);
157 
161  auto get_options() const -> std::shared_ptr<options::Option>;
168  void add_init_callback(std::function<void()> const& init_callback);
172 
176  void set_exception_handler(std::function<void()> const& exception_handler);
177 
180  using Terminator = std::function<void(int signal)>;
181 
186  void set_terminator(Terminator const& terminator);
187 
193  using EmergencyCleanupHandler = std::function<void()>;
194 
198  void add_emergency_cleanup(EmergencyCleanupHandler const& handler);
206  template<typename T> using Builder = std::function<std::shared_ptr<T>()>;
209 
211  void override_the_compositor(Builder<compositor::Compositor> const& compositor_builder);
212 
215  Builder<compositor::DisplayBufferCompositorFactory> const& compositor_builder);
216 
218  void override_the_gl_config(Builder<graphics::GLConfig> const& gl_config_builder);
219 
222  Builder<shell::HostLifecycleEventListener> const& host_lifecycle_event_listener_builder);
223 
225  void override_the_input_dispatcher(Builder<input::InputDispatcher> const& input_dispatcher_builder);
226 
228  void override_the_logger(Builder<logging::Logger> const& logger_builder);
229 
231  void override_the_placement_strategy(Builder<scene::PlacementStrategy> const& placement_strategy_builder);
232 
234  void override_the_prompt_session_listener(Builder<scene::PromptSessionListener> const& prompt_session_listener_builder);
235 
237  void override_the_prompt_session_manager(Builder<scene::PromptSessionManager> const& prompt_session_manager_builder);
238 
240  void override_the_server_status_listener(Builder<ServerStatusListener> const& server_status_listener_builder);
241 
243  void override_the_session_authorizer(Builder<frontend::SessionAuthorizer> const& session_authorizer_builder);
244 
246  void override_the_session_listener(Builder<scene::SessionListener> const& session_listener_builder);
247 
250 
252  void override_the_shell(Builder<shell::Shell> const& wrapper);
253 
255  void override_the_surface_configurator(Builder<scene::SurfaceConfigurator> const& surface_configurator_builder);
256 
258  template<typename T> using Wrapper = std::function<std::shared_ptr<T>(std::shared_ptr<T> const&)>;
259 
262 
266 
269 
271  void wrap_shell(Wrapper<shell::Shell> const& wrapper);
280  auto the_compositor() const -> std::shared_ptr<compositor::Compositor>;
282 
284  auto the_composite_event_filter() const -> std::shared_ptr<input::CompositeEventFilter>;
285 
287  auto the_cursor_listener() const -> std::shared_ptr<input::CursorListener>;
288 
290  auto the_focus_controller() const -> std::shared_ptr<shell::FocusController>;
291 
293  auto the_display() const -> std::shared_ptr<graphics::Display>;
294 
296  auto the_gl_config() const -> std::shared_ptr<graphics::GLConfig>;
297 
299  auto the_graphics_platform() const -> std::shared_ptr<graphics::Platform>;
300 
302  auto the_input_targeter() const -> std::shared_ptr<shell::InputTargeter>;
303 
305  auto the_logger() const -> std::shared_ptr<logging::Logger>;
306 
308  auto the_main_loop() const -> std::shared_ptr<MainLoop>;
309 
311  auto the_prompt_session_listener() const -> std::shared_ptr<scene::PromptSessionListener>;
312 
314  auto the_prompt_session_manager() const ->std::shared_ptr<scene::PromptSessionManager>;
315 
317  auto the_session_authorizer() const -> std::shared_ptr<frontend::SessionAuthorizer>;
318 
320  auto the_session_coordinator() const -> std::shared_ptr<scene::SessionCoordinator>;
321 
323  auto the_session_listener() const -> std::shared_ptr<scene::SessionListener>;
324 
326  auto the_shell() const -> std::shared_ptr<shell::Shell>;
327 
329  auto the_shell_display_layout() const -> std::shared_ptr<shell::DisplayLayout>;
330 
332  auto the_surface_configurator() const -> std::shared_ptr<scene::SurfaceConfigurator>;
333 
335  auto the_surface_coordinator() const -> std::shared_ptr<scene::SurfaceCoordinator>;
336 
338  auto the_touch_visualizer() const -> std::shared_ptr<input::TouchVisualizer>;
346  using ConnectHandler = std::function<void(std::shared_ptr<frontend::Session> const& session)>;
347 
351  auto open_client_socket() -> Fd;
352 
357  auto open_client_socket(ConnectHandler const& connect_handler) -> Fd;
358 
362  auto open_prompt_socket() -> Fd;
364 private:
365  struct ServerConfiguration;
366  struct Self;
367  std::shared_ptr<Self> const self;
368 };
369 }
370 #endif /* SERVER_H_ */
All things Mir.
Definition: buffer_stream.h:37
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:329
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:287
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:313
Customise and run a Mir server.
Definition: server.h:68
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:258
void set_terminator(Terminator const &terminator)
Set handler for termination requests. terminator will be called following receipt of SIGTERM or SIGIN...
Definition: server.cpp:324
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:180
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:193
STL namespace.
auto the_composite_event_filter() const -> std::shared_ptr< input::CompositeEventFilter >
std::function< std::shared_ptr< T >()> Builder
Each of the override functions takes a builder functor of the same form.
Definition: server.h:208
void override_the_server_status_listener(Builder< ServerStatusListener > const &server_status_listener_builder)
Sets an override functor for creating the status listener.
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:280
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 >
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:414
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:300
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 apply_settings()
Applies any configuration options, hooks, or custom implementations. Must be called before calling ru...
Definition: server.cpp:345
auto the_shell() const -> std::shared_ptr< shell::Shell >
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:59
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:463
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 override_the_shell(Builder< shell::Shell > const &wrapper)
Sets an override functor for creating the shell.
void override_the_surface_configurator(Builder< scene::SurfaceConfigurator > const &surface_configurator_builder)
Sets an override functor for creating the surface configurator.
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:406
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:319
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:180
std::function< void(std::shared_ptr< frontend::Session > const &session)> ConnectHandler
Definition: server.h:346
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:388
bool exited_normally()
returns true if and only if server exited normally. Otherwise false.
Definition: server.cpp:401
void run()
Run the Mir server until it exits.
Definition: server.cpp:359
void stop()
Tell the Mir server to exit.
Definition: server.cpp:393
MirSurfaceType type
Definition: mir_surface.h:448
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.
void override_the_prompt_session_manager(Builder< scene::PromptSessionManager > const &prompt_session_manager_builder)
Sets an override functor for creating the prompt session manager.
auto the_surface_configurator() const -> std::shared_ptr< scene::SurfaceConfigurator >
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:307
void override_the_placement_strategy(Builder< scene::PlacementStrategy > const &placement_strategy_builder)
Sets an override functor for creating the placement strategy.
Server()
Definition: server.cpp:268

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