Mir

Merge lp:~alan-griffiths/mir/mir-server-with-add_configuration_option-chaining into lp:mir

Proposed by Alan Griffiths
Status: Rejected
Rejected by: Alan Griffiths
Proposed branch: lp:~alan-griffiths/mir/mir-server-with-add_configuration_option-chaining
Merge into: lp:mir
Prerequisite: lp:~alan-griffiths/mir/a-simpler-server-setup
Diff against target: 173 lines (+76/-30)
3 files modified
include/server/mir/server.h (+63/-23)
server-ABI-sha1sums (+1/-1)
src/server/server.cpp (+12/-6)
To merge this branch: bzr merge lp:~alan-griffiths/mir/mir-server-with-add_configuration_option-chaining
Reviewer Review Type Date Requested Status
Andreas Pokorny (community) Abstain
Alexandros Frantzis (community) Disapprove
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+238406@code.launchpad.net

Commit message

Support for chaining mir::Server::add_configuration_option()

Description of the change

Support for chaining mir::Server::add_configuration_option()

The utility vs cost of this support was contentious in the original MP, so I've separated it out for discussion.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

I think this mechanism offers very little (if anything) over just calling add_configuration_option() multiple times to deserve a place in our public API. Plus, I am not fond of this particular form of syntactic sugar ("add_configuration_option(x,y,z)(x,y,z)(x,y,z)...") anyway.

My vote is a non-blocking disapproval.

review: Disapprove
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

It comes down to whether we allow (without imposing):

    // Add choice of monitor configuration
    server.add_configuration_option(
        me::display_config_opt, me::display_config_descr, me::clone_opt_val)(
        me::display_alpha_opt, me::display_alpha_descr, me::display_alpha_off);

Or enforce:

    // Add choice of monitor configuration
    server.add_configuration_option(
        me::display_config_opt, me::display_config_descr, me::clone_opt_val);
    server.add_configuration_option(
        me::display_alpha_opt, me::display_alpha_descr, me::display_alpha_off);

We could imagine users adding even more options, but the above is real code from basic_server.cpp

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

even if somebody has a use case with a lot of configuration options he or she could do that similar to:

struct add_options
{
    mir::Server * server;
    add_options(Server* server) : server(server){}
    add_options const& operator()(std::string const& option, std::string const& description, int default_value) const
    {
         return server->add_configuration_option(option, description, default_value);
         return *this;
    }
     ....
};

not needing any further support from the mir api. Still I guess nobody will do it, since it requires probably more lines of code than one can gain with it.. So I vote for leaving it out.

review: Abstain
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> even if somebody has a use case with a lot of configuration options he or she
> could do that similar to:
>
> struct add_options
> {
> mir::Server * server;
> add_options(Server* server) : server(server){}
> add_options const& operator()(std::string const& option, std::string
> const& description, int default_value) const
> {
> return server->add_configuration_option(option, description,
> default_value);
> return *this;
> }
> ....
> };
>
> not needing any further support from the mir api. Still I guess nobody will do
> it, since it requires probably more lines of code than one can gain with it..

Your argument that any clients that wants it could do it themselves is wrong: If there is a need to do it we should do it once and every one of these client will benefit.

> So I vote for leaving it out.

OK (but your reasoning is wrong).

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

> Your argument that any clients that wants it could do it themselves is wrong:
> If there is a need to do it we should do it once and every one of these client
> will benefit.

agreed, lame argument. The thing that I left out was, that given your example the need or benefit is minimal. I believe most people will, unless we hilight its usage in big letters not even mind looking at how it has to be used.

I think you can invent or suspect a need for pretty much every imaginable feature.
So from that perspective, as the code exists and is mergeable we could simply merge it.

Unmerged revisions

1985. By Alan Griffiths

Support for chaining add_configuration_option()

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/server/mir/server.h'
2--- include/server/mir/server.h 2014-10-15 09:49:26 +0000
3+++ include/server/mir/server.h 2014-10-15 09:49:26 +0000
4@@ -74,29 +74,33 @@
5
6 /** @name Configuration options
7 * @{ */
8- /// Add user configuration option(s) to Mir's option handling.
9- /// These will be resolved during initialisation from the command line,
10- /// environment variables, a config file or the supplied default.
11- void add_configuration_option(
12- std::string const& option,
13- std::string const& description,
14- int default_value);
15-
16- /// Add user configuration option(s) to Mir's option handling.
17- /// These will be resolved during initialisation from the command line,
18- /// environment variables, a config file or the supplied default.
19- void add_configuration_option(
20- std::string const& option,
21- std::string const& description,
22- std::string const& default_value);
23-
24- /// Add user configuration option(s) to Mir's option handling.
25- /// These will be resolved during initialisation from the command line,
26- /// environment variables, a config file or the supplied default.
27- void add_configuration_option(
28- std::string const& option,
29- std::string const& description,
30- OptionType type);
31+
32+ /// Helper class to facilitate adding multiple options
33+ class ChainAddConfigurationOption;
34+
35+ /// Add user configuration option(s) to Mir's option handling.
36+ /// These will be resolved during initialisation from the command line,
37+ /// environment variables, a config file or the supplied default.
38+ auto add_configuration_option(
39+ std::string const& option,
40+ std::string const& description,
41+ int default_value) -> ChainAddConfigurationOption;
42+
43+ /// Add user configuration option(s) to Mir's option handling.
44+ /// These will be resolved during initialisation from the command line,
45+ /// environment variables, a config file or the supplied default.
46+ auto add_configuration_option(
47+ std::string const& option,
48+ std::string const& description,
49+ std::string const& default_value) -> ChainAddConfigurationOption;
50+
51+ /// Add user configuration option(s) to Mir's option handling.
52+ /// These will be resolved during initialisation from the command line,
53+ /// environment variables, a config file or the supplied default.
54+ auto add_configuration_option(
55+ std::string const& option,
56+ std::string const& description,
57+ OptionType type) -> ChainAddConfigurationOption;
58
59 /// Set a handler for any command line options Mir does not recognise.
60 /// This will be invoked if any unrecognised options are found during initialisation.
61@@ -213,5 +217,41 @@
62 struct Self;
63 std::shared_ptr<Self> const self;
64 };
65+
66+class Server::ChainAddConfigurationOption
67+{
68+public:
69+ // Yes, I know a single forwarding template would cover all three cases.
70+ // but this can give clearer error messages.
71+ auto operator()(
72+ std::string const& option,
73+ std::string const& description,
74+ int default_value) const -> ChainAddConfigurationOption
75+ {
76+ return server.add_configuration_option(option, description, default_value);
77+ }
78+
79+ auto operator()(
80+ std::string const& option,
81+ std::string const& description,
82+ std::string const& default_value) const -> ChainAddConfigurationOption
83+ {
84+ return server.add_configuration_option(option, description, default_value);
85+ }
86+
87+ auto operator()(
88+ std::string const& option,
89+ std::string const& description,
90+ OptionType type) const -> ChainAddConfigurationOption
91+ {
92+ return server.add_configuration_option(option, description, type);
93+ }
94+
95+private:
96+ friend class ::mir::Server;
97+ ChainAddConfigurationOption(Server& server) : server(server) {}
98+
99+ Server& server;
100+};
101 }
102 #endif /* SERVER_H_ */
103
104=== modified file 'server-ABI-sha1sums'
105--- server-ABI-sha1sums 2014-10-15 09:49:26 +0000
106+++ server-ABI-sha1sums 2014-10-15 09:49:26 +0000
107@@ -95,7 +95,7 @@
108 993e9f458ffc4288d304413f3fa0b1dcc95a093d include/server/mir/scene/surface_observer.h
109 7ef3e99901168cda296d74d05a979f47bf9c3ff1 include/server/mir/server_action_queue.h
110 8d83a51c278b8b71866d2178d9b6387c1f91a7d0 include/server/mir/server_configuration.h
111-5d79d4a973b597d7cc1de766bd0ef3d30b389e18 include/server/mir/server.h
112+b1c55e8baf0ba00f67adc924694718cfbf87d4ea include/server/mir/server.h
113 86098b500339bfccd07a9bed8298f75a68b18f5c include/server/mir/server_status_listener.h
114 860c04f32b60e680140148dc9dc2295de145b9c1 include/server/mir/shell/display_layout.h
115 6a2107b01feae13060d5c305804906e53c52e0be include/server/mir/shell/focus_controller.h
116
117=== modified file 'src/server/server.cpp'
118--- src/server/server.cpp 2014-10-15 09:49:26 +0000
119+++ src/server/server.cpp 2014-10-15 09:49:26 +0000
120@@ -277,10 +277,10 @@
121
122 #undef MIR_SERVER_WRAP
123
124-void mir::Server::add_configuration_option(
125+auto mir::Server::add_configuration_option(
126 std::string const& option,
127 std::string const& description,
128- int default_)
129+ int default_) -> ChainAddConfigurationOption
130 {
131 namespace po = boost::program_options;
132
133@@ -295,12 +295,14 @@
134 };
135
136 self->set_add_configuration_options(option_adder);
137+
138+ return {*this};
139 }
140
141-void mir::Server::add_configuration_option(
142+auto mir::Server::add_configuration_option(
143 std::string const& option,
144 std::string const& description,
145- std::string const& default_)
146+ std::string const& default_) -> ChainAddConfigurationOption
147 {
148 namespace po = boost::program_options;
149
150@@ -315,12 +317,14 @@
151 };
152
153 self->set_add_configuration_options(option_adder);
154+
155+ return {*this};
156 }
157
158-void mir::Server::add_configuration_option(
159+auto mir::Server::add_configuration_option(
160 std::string const& option,
161 std::string const& description,
162- OptionType type)
163+ OptionType type) -> ChainAddConfigurationOption
164 {
165 namespace po = boost::program_options;
166
167@@ -370,4 +374,6 @@
168 }
169 break;
170 }
171+
172+ return {*this};
173 }

Subscribers

People subscribed via source and target branches