From bb33c5db8c4b8744c79ad72eaddcc568ef296df1 Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Wed, 10 Apr 2019 15:58:20 -0700 Subject: [PATCH] client: Add 'Yes', 'No' property type support This property type will be used for the argument completion among the properties that require Yes or No value. --- client/properties.c | 20 ++++++++++++++++++++ client/properties.h | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/client/properties.c b/client/properties.c index 65737b3c..8838f4f0 100644 --- a/client/properties.c +++ b/client/properties.c @@ -29,6 +29,7 @@ #include "properties.h" const char *properties_on_off_opts[3] = { "on", "off", NULL }; +const char *properties_yes_no_opts[3] = { "yes", "no", NULL }; bool properties_builder_append_on_off_variant( struct l_dbus_message_builder *builder, @@ -48,3 +49,22 @@ bool properties_builder_append_on_off_variant( return l_dbus_message_builder_append_basic(builder, 'b', &value); } + +bool properties_builder_append_yes_no_variant( + struct l_dbus_message_builder *builder, + const char *value_str) +{ + bool value; + + if (!builder || !value_str) + return false; + + if (!strcmp(value_str, "yes")) + value = true; + else if (!strcmp(value_str, "no")) + value = false; + else + return false; + + return l_dbus_message_builder_append_basic(builder, 'b', &value); +} diff --git a/client/properties.h b/client/properties.h index 935dcfc0..eaf26127 100644 --- a/client/properties.h +++ b/client/properties.h @@ -21,7 +21,12 @@ */ const char *properties_on_off_opts[3]; +const char *properties_yes_no_opts[3]; bool properties_builder_append_on_off_variant( struct l_dbus_message_builder *builder, const char *value_str); + +bool properties_builder_append_yes_no_variant( + struct l_dbus_message_builder *builder, + const char *value_str);