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

Copyright © 2012-2023 Canonical Ltd.
Generated on Wed Feb 1 16:59:23 UTC 2023
This documentation is licensed under the GPL version 2 or 3.