Mir
runner.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016-2019 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 2 or 3 as
6  * 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 
17 #ifndef MIRAL_RUNNER_H
18 #define MIRAL_RUNNER_H
19 
20 #include "mir/optional_value.h"
21 
22 #include <functional>
23 #include <initializer_list>
24 #include <memory>
25 
26 namespace mir { class Server; }
27 
28 /** Mir Abstraction Layer.
29  * A thin, hopefully ABI stable, layer over the Mir libraries exposing only
30  * those abstractions needed to write a shell. One day this may inspire a core
31  * Mir library.
32  */
33 namespace miral
34 {
35 
36 /// Runner for applying initialization options to Mir.
37 class MirRunner
38 {
39 public:
40  MirRunner(int argc, char const* argv[]);
41  MirRunner(int argc, char const* argv[], char const* config_file);
43 
44  /// Add a callback to be invoked when the server has started,
45  /// If multiple callbacks are added they will be invoked in the sequence added.
46  void add_start_callback(std::function<void()> const& start_callback);
47 
48  /// Add a callback to be invoked when the server is about to stop,
49  /// If multiple callbacks are added they will be invoked in the reverse sequence added.
50  void add_stop_callback(std::function<void()> const& stop_callback);
51 
52  /// Set a handler for exceptions caught in run_with().
53  /// run_with() invokes handler() in catch (...) blocks before returning EXIT_FAILURE.
54  /// Hence the exception can be re-thrown to retrieve type information.
55  /// The default action is to call mir::report_exception(std::cerr)
56  void set_exception_handler(std::function<void()> const& handler);
57 
58  /// Apply the supplied initialization options and run the Mir server.
59  /// @returns EXIT_SUCCESS or EXIT_FAILURE according to whether the server ran successfully
60  /// \note blocks until the Mir server exits
61  auto run_with(std::initializer_list<std::function<void(::mir::Server&)>> options) -> int;
62 
63  /// Tell the Mir server to exit
64  void stop();
65 
66  /// Name of the .config file.
67  /// The .config file is located via the XDG Base Directory Specification:
68  /// $XDG_CONFIG_HOME or $HOME/.config followed by $XDG_CONFIG_DIRS
69  /// Config file entries are long form (e.g. "x11-output=1200x720")
70  /// \remark Since MirAL 2.4
71  auto config_file() const -> std::string;
72 
73  /// Name of the .display configuration file.
74  /// The .display file is located via the XDG Base Directory Specification:
75  /// $XDG_CONFIG_HOME or $HOME/.config followed by $XDG_CONFIG_DIRS
76  /// Config file entries are long form (e.g. "x11-output=1200x720")
77  /// \remark Since MirAL 2.4
78  auto display_config_file() const -> std::string;
79 
80  /// Get the Wayland endpoint name (if any) usable as a $WAYLAND_DISPLAY value
81  /// \remark Since MirAL 2.8
82  auto wayland_display() const -> mir::optional_value<std::string>;
83 
84  /// Get the X11 socket name (if any) usable as a $DISPLAY value
85  /// \remark Since MirAL 2.8
86  auto x11_display() const -> mir::optional_value<std::string>;
87 
88 private:
89  MirRunner(MirRunner const&) = delete;
90  MirRunner& operator=(MirRunner const&) = delete;
91  struct Self;
92  std::unique_ptr<Self> const self;
93 };
94 }
95 
96 #endif //MIRAL_RUNNER_H

Copyright © 2012-2022 Canonical Ltd.
Generated on Fri Aug 26 13:27:37 UTC 2022
This documentation is licensed under the GPL version 2 or 3.