commit 6ba707fca8b424c43be318974479b461cf53625d
parent 1e78ed5a7d5689319c0def9e86ec2802ed2a6073
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Wed, 25 Jul 2018 12:54:42 -0700
client: add completion for proxy property names and values
Diffstat:
2 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c
@@ -30,6 +30,8 @@
#include "agent-manager.h"
#include "dbus-proxy.h"
#include "display.h"
+#include "command.h"
+#include "properties.h"
#define IWD_SERVICE "net.connman.iwd"
#define IWD_ROOT_PATH "/"
@@ -175,6 +177,80 @@ char *proxy_property_str_completion(const struct proxy_interface_type *type,
return NULL;
}
+static char *proxy_property_completion_value_options(
+ const struct property_value_options *options,
+ const char *text, int state)
+{
+ static int index;
+ static int len;
+ const char *opt;
+
+ if (!state) {
+ index = 0;
+ len = strlen(text);
+ }
+
+ while ((opt = options[index++].value_str)) {
+ if (strncmp(opt, text, len))
+ continue;
+
+ return l_strdup(opt);
+ }
+
+ return NULL;
+}
+
+char *proxy_property_completion(
+ const struct proxy_interface_property *properties,
+ const char *text, int state)
+{
+ static size_t i;
+ static size_t j;
+ static size_t len;
+ static bool first_pass;
+ const char *name;
+
+ if (!state) {
+ j = 0;
+ first_pass = true;
+ }
+
+ while (first_pass && (name = properties[j].name)) {
+ if (!properties[j].is_read_write)
+ goto next;
+
+ if (!command_line_find_token(name, 2))
+ goto next;
+
+ if (!properties[j].options)
+ goto next;
+
+ return proxy_property_completion_value_options(
+ properties[j].options, text,
+ state);
+next:
+ j++;
+ }
+
+ if (first_pass) {
+ i = 0;
+ first_pass = false;
+ len = strlen(text);
+ }
+
+ while ((name = properties[i].name)) {
+ if (!properties[i++].is_read_write)
+ continue;
+
+ if (strncmp(name, text, len))
+ continue;
+
+ return l_strdup(name);
+ }
+
+ return NULL;
+}
+
static const struct proxy_interface_property *proxy_property_find(
const struct proxy_interface_property *types,
const char *name)
diff --git a/client/dbus-proxy.h b/client/dbus-proxy.h
@@ -23,6 +23,7 @@
#include <stdio.h>
struct proxy_interface;
+struct property_value_options;
#define IWD_ADAPTER_INTERFACE "net.connman.iwd.Adapter"
#define IWD_DEVICE_INTERFACE "net.connman.iwd.Device"
@@ -40,6 +41,7 @@ struct proxy_interface_property {
const bool is_read_write;
bool (*append)(struct l_dbus_message_builder *builder,
const char *value_str);
+ const struct property_value_options *options;
};
struct proxy_interface_type_ops {
@@ -59,6 +61,10 @@ struct proxy_interface_type {
const struct proxy_interface_type_ops *ops;
};
+char *proxy_property_completion(
+ const struct proxy_interface_property *properties,
+ const char *text, int state);
+
bool proxy_property_set(const struct proxy_interface *proxy, const char *name,
const char *value_str, l_dbus_message_func_t callback);