Mir
configuration_option.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_CONFIGURATION_OPTION_H
18#define MIRAL_CONFIGURATION_OPTION_H
19
20#include <mir/optional_value.h>
21#include <miral/lambda_as_function.h>
22
23#include <functional>
24#include <memory>
25#include <string>
26
27namespace mir { class Server; }
28
29namespace miral
30{
31/// Add a user configuration option to Mir's option handling.
32/// By default the callback will be invoked following Mir initialisation but
33/// prior to the server starting. The value supplied to the callback will come
34/// from the command line, environment variable, config file or the default.
35///
36/// \note Except for re-ordering implied by "pre_init()" the callbacks will be
37/// invoked in the order supplied.
38/// \Remark: Renamed (from CommandLineOption) in MirAL 3.6
40{
41public:
43 std::function<void(int value)> callback,
44 std::string const& option,
45 std::string const& description,
46 int default_value);
47
49 std::function<void(double value)> callback,
50 std::string const& option,
51 std::string const& description,
52 double default_value);
53
55 std::function<void(std::string const& value)> callback,
56 std::string const& option,
57 std::string const& description,
58 std::string const& default_value);
59
61 std::function<void(std::string const& value)> callback,
62 std::string const& option,
63 std::string const& description,
64 char const* default_value);
65
67 std::function<void(bool value)> callback,
68 std::string const& option,
69 std::string const& description,
70 bool default_value);
71
73 std::function<void(mir::optional_value<int> const& value)> callback,
74 std::string const& option,
75 std::string const& description);
76
78 std::function<void(mir::optional_value<std::string> const& value)> callback,
79 std::string const& option,
80 std::string const& description);
81
83 std::function<void(mir::optional_value<bool> const& value)> callback,
84 std::string const& option,
85 std::string const& description);
86
88 std::function<void(bool is_set)> callback,
89 std::string const& option,
90 std::string const& description);
91
92 // \remark Since MirAL 3.6
93 ConfigurationOption(
94 std::function<void(std::vector<std::string> const& values)> callback,
95 std::string const& option,
96 std::string const& description);
97
98 template<typename Lambda>
100 Lambda&& callback,
101 std::string const& option,
102 std::string const& description) :
103 ConfigurationOption(lambda_as_function(std::forward<Lambda>(callback)), option, description) {}
104
105 void operator()(mir::Server& server) const;
106
107 // Call the callback *before* Mir initialization starts
109
113
114private:
115 struct Self;
116 std::shared_ptr<Self> self;
117};
118
119/**
120 * Update the option to be called back *before* Mir initialization starts
121 *
122 * \param clo the option
123 */
125}
126
127#endif //MIRAL_CONFIGURATION_OPTION_H
Definition: optional_value.h:27
Add a user configuration option to Mir's option handling. By default the callback will be invoked fol...
Definition: configuration_option.h:40
ConfigurationOption(std::function< void(bool is_set)> callback, std::string const &option, std::string const &description)
ConfigurationOption(std::function< void(std::string const &value)> callback, std::string const &option, std::string const &description, char const *default_value)
ConfigurationOption(std::function< void(bool value)> callback, std::string const &option, std::string const &description, bool default_value)
ConfigurationOption(std::function< void(mir::optional_value< bool > const &value)> callback, std::string const &option, std::string const &description)
ConfigurationOption(std::function< void(double value)> callback, std::string const &option, std::string const &description, double default_value)
ConfigurationOption(ConfigurationOption const &)
ConfigurationOption(Lambda &&callback, std::string const &option, std::string const &description)
Definition: configuration_option.h:99
ConfigurationOption(std::function< void(mir::optional_value< std::string > const &value)> callback, std::string const &option, std::string const &description)
void operator()(mir::Server &server) const
ConfigurationOption(std::function< void(mir::optional_value< int > const &value)> callback, std::string const &option, std::string const &description)
ConfigurationOption(std::function< void(int value)> callback, std::string const &option, std::string const &description, int default_value)
auto operator=(ConfigurationOption const &) -> ConfigurationOption &
friend auto pre_init(ConfigurationOption const &clo) -> ConfigurationOption
Update the option to be called back before Mir initialization starts.
ConfigurationOption(std::function< void(std::string const &value)> callback, std::string const &option, std::string const &description, std::string const &default_value)
Definition: runner.h:27
Mir Abstraction Layer.
Definition: runner.h:35

Copyright © 2012-2023 Canonical Ltd.
Generated on Tue 2 May 10:01:24 UTC 2023
This documentation is licensed under the GPL version 2 or 3.