client: Device show cmd

This commit is contained in:
Tim Kourt 2017-04-17 09:50:10 -07:00 committed by Denis Kenzior
parent b3772259b5
commit 0ada918031
3 changed files with 79 additions and 0 deletions

View File

@ -138,6 +138,35 @@ struct proxy_interface *proxy_interface_find(const char *interface,
return NULL;
}
struct l_queue *proxy_interface_find_all(const char *interface,
proxy_property_match_func_t function,
const void *value)
{
const struct l_queue_entry *entry;
struct l_queue *match = NULL;
if (!interface || !function || !value)
return NULL;
for (entry = l_queue_get_entries(proxy_interfaces); entry;
entry = entry->next) {
struct proxy_interface *proxy = entry->data;
if (!interface_match_by_type_name(proxy->type, interface))
continue;
if (!function(proxy->data, value))
continue;
if (!match)
match = l_queue_new();
l_queue_push_tail(match, proxy);
}
return match;
}
static struct l_queue *proxy_interface_find_by_path(const char *path)
{
const struct l_queue_entry *entry;

View File

@ -30,6 +30,8 @@ struct proxy_interface;
#define IWD_NETWORK_INTERFACE "net.connman.iwd.Network"
#define IWD_WSC_INTERFACE "net.connman.iwd.WiFiSimpleConfiguration"
typedef bool (*proxy_property_match_func_t) (const void *a, const void *b);
struct proxy_interface_property {
const char *name;
const char *type;
@ -58,6 +60,10 @@ struct proxy_interface_type {
struct proxy_interface *proxy_interface_find(const char *interface,
const char *path);
struct l_queue *proxy_interface_find_all(const char *interface,
proxy_property_match_func_t function,
const void *value);
void *proxy_interface_get_data(const struct proxy_interface *proxy);
const char *proxy_interface_get_interface(const struct proxy_interface *proxy);
const char *proxy_interface_get_identity_str(

View File

@ -43,6 +43,10 @@ struct device {
const struct proxy_interface *wsc;
};
static void display_device(const struct device *device)
{
}
static const void *get_name(const void *data)
{
const struct device *device = data;
@ -236,8 +240,48 @@ static struct proxy_interface_type device_interface_type = {
.ops = &device_ops,
};
static bool match_by_name(const void *a, const void *b)
{
const struct device *device = a;
const char *name = b;
return !strcmp(device->name, name);
}
static const struct proxy_interface *get_device_proxy_by_name(
const char *device_name)
{
struct l_queue *match;
struct proxy_interface *proxy = NULL;
if (!device_name)
return NULL;
match = proxy_interface_find_all(device_interface_type.interface,
match_by_name, device_name);
if (l_queue_length(match))
proxy = l_queue_pop_head(match);
else
display("Device %s not found", device_name);
l_queue_destroy(match, NULL);
return proxy;
}
static void cmd_show(const char *device_name, char *args)
{
struct device *device;
const struct proxy_interface *proxy =
get_device_proxy_by_name(device_name);
if (!proxy)
return;
device = proxy_interface_get_data(proxy);
display_device(device);
}
static void cmd_scan(const char *device_name, char *args)