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
=== modified file 'include/server/mir/server.h'
--- include/server/mir/server.h 2014-10-15 09:49:26 +0000
+++ include/server/mir/server.h 2014-10-15 09:49:26 +0000
@@ -74,29 +74,33 @@
7474
75/** @name Configuration options75/** @name Configuration options
76 * @{ */76 * @{ */
77 /// Add user configuration option(s) to Mir's option handling.77
78 /// These will be resolved during initialisation from the command line,78 /// Helper class to facilitate adding multiple options
79 /// environment variables, a config file or the supplied default.79 class ChainAddConfigurationOption;
80 void add_configuration_option(80
81 std::string const& option,81 /// Add user configuration option(s) to Mir's option handling.
82 std::string const& description,82 /// These will be resolved during initialisation from the command line,
83 int default_value);83 /// environment variables, a config file or the supplied default.
8484 auto add_configuration_option(
85 /// Add user configuration option(s) to Mir's option handling.85 std::string const& option,
86 /// These will be resolved during initialisation from the command line,86 std::string const& description,
87 /// environment variables, a config file or the supplied default.87 int default_value) -> ChainAddConfigurationOption;
88 void add_configuration_option(88
89 std::string const& option,89 /// Add user configuration option(s) to Mir's option handling.
90 std::string const& description,90 /// These will be resolved during initialisation from the command line,
91 std::string const& default_value);91 /// environment variables, a config file or the supplied default.
9292 auto add_configuration_option(
93 /// Add user configuration option(s) to Mir's option handling.93 std::string const& option,
94 /// These will be resolved during initialisation from the command line,94 std::string const& description,
95 /// environment variables, a config file or the supplied default.95 std::string const& default_value) -> ChainAddConfigurationOption;
96 void add_configuration_option(96
97 std::string const& option,97 /// Add user configuration option(s) to Mir's option handling.
98 std::string const& description,98 /// These will be resolved during initialisation from the command line,
99 OptionType type);99 /// environment variables, a config file or the supplied default.
100 auto add_configuration_option(
101 std::string const& option,
102 std::string const& description,
103 OptionType type) -> ChainAddConfigurationOption;
100104
101 /// Set a handler for any command line options Mir does not recognise.105 /// Set a handler for any command line options Mir does not recognise.
102 /// This will be invoked if any unrecognised options are found during initialisation.106 /// This will be invoked if any unrecognised options are found during initialisation.
@@ -213,5 +217,41 @@
213 struct Self;217 struct Self;
214 std::shared_ptr<Self> const self;218 std::shared_ptr<Self> const self;
215};219};
220
221class Server::ChainAddConfigurationOption
222{
223public:
224 // Yes, I know a single forwarding template would cover all three cases.
225 // but this can give clearer error messages.
226 auto operator()(
227 std::string const& option,
228 std::string const& description,
229 int default_value) const -> ChainAddConfigurationOption
230 {
231 return server.add_configuration_option(option, description, default_value);
232 }
233
234 auto operator()(
235 std::string const& option,
236 std::string const& description,
237 std::string const& default_value) const -> ChainAddConfigurationOption
238 {
239 return server.add_configuration_option(option, description, default_value);
240 }
241
242 auto operator()(
243 std::string const& option,
244 std::string const& description,
245 OptionType type) const -> ChainAddConfigurationOption
246 {
247 return server.add_configuration_option(option, description, type);
248 }
249
250private:
251 friend class ::mir::Server;
252 ChainAddConfigurationOption(Server& server) : server(server) {}
253
254 Server& server;
255};
216}256}
217#endif /* SERVER_H_ */257#endif /* SERVER_H_ */
218258
=== modified file 'server-ABI-sha1sums'
--- server-ABI-sha1sums 2014-10-15 09:49:26 +0000
+++ server-ABI-sha1sums 2014-10-15 09:49:26 +0000
@@ -95,7 +95,7 @@
95993e9f458ffc4288d304413f3fa0b1dcc95a093d include/server/mir/scene/surface_observer.h95993e9f458ffc4288d304413f3fa0b1dcc95a093d include/server/mir/scene/surface_observer.h
967ef3e99901168cda296d74d05a979f47bf9c3ff1 include/server/mir/server_action_queue.h967ef3e99901168cda296d74d05a979f47bf9c3ff1 include/server/mir/server_action_queue.h
978d83a51c278b8b71866d2178d9b6387c1f91a7d0 include/server/mir/server_configuration.h978d83a51c278b8b71866d2178d9b6387c1f91a7d0 include/server/mir/server_configuration.h
985d79d4a973b597d7cc1de766bd0ef3d30b389e18 include/server/mir/server.h98b1c55e8baf0ba00f67adc924694718cfbf87d4ea include/server/mir/server.h
9986098b500339bfccd07a9bed8298f75a68b18f5c include/server/mir/server_status_listener.h9986098b500339bfccd07a9bed8298f75a68b18f5c include/server/mir/server_status_listener.h
100860c04f32b60e680140148dc9dc2295de145b9c1 include/server/mir/shell/display_layout.h100860c04f32b60e680140148dc9dc2295de145b9c1 include/server/mir/shell/display_layout.h
1016a2107b01feae13060d5c305804906e53c52e0be include/server/mir/shell/focus_controller.h1016a2107b01feae13060d5c305804906e53c52e0be include/server/mir/shell/focus_controller.h
102102
=== modified file 'src/server/server.cpp'
--- src/server/server.cpp 2014-10-15 09:49:26 +0000
+++ src/server/server.cpp 2014-10-15 09:49:26 +0000
@@ -277,10 +277,10 @@
277277
278#undef MIR_SERVER_WRAP278#undef MIR_SERVER_WRAP
279279
280void mir::Server::add_configuration_option(280auto mir::Server::add_configuration_option(
281 std::string const& option,281 std::string const& option,
282 std::string const& description,282 std::string const& description,
283 int default_)283 int default_) -> ChainAddConfigurationOption
284{284{
285 namespace po = boost::program_options;285 namespace po = boost::program_options;
286286
@@ -295,12 +295,14 @@
295 };295 };
296296
297 self->set_add_configuration_options(option_adder);297 self->set_add_configuration_options(option_adder);
298
299 return {*this};
298}300}
299301
300void mir::Server::add_configuration_option(302auto mir::Server::add_configuration_option(
301 std::string const& option,303 std::string const& option,
302 std::string const& description,304 std::string const& description,
303 std::string const& default_)305 std::string const& default_) -> ChainAddConfigurationOption
304{306{
305 namespace po = boost::program_options;307 namespace po = boost::program_options;
306308
@@ -315,12 +317,14 @@
315 };317 };
316318
317 self->set_add_configuration_options(option_adder);319 self->set_add_configuration_options(option_adder);
320
321 return {*this};
318}322}
319323
320void mir::Server::add_configuration_option(324auto mir::Server::add_configuration_option(
321 std::string const& option,325 std::string const& option,
322 std::string const& description,326 std::string const& description,
323 OptionType type)327 OptionType type) -> ChainAddConfigurationOption
324{328{
325 namespace po = boost::program_options;329 namespace po = boost::program_options;
326330
@@ -370,4 +374,6 @@
370 }374 }
371 break;375 break;
372 }376 }
377
378 return {*this};
373}379}

Subscribers

People subscribed via source and target branches