X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=ui%2Fcommon%2Fdiscover-client.c;h=6b991b14791a8b85beb3cfe5f19ab98a2d1a9593;hp=47c57cb11bc69d49e69467cbe0b259e8c07069c5;hb=dcab4e022083fecf221bebf9d6cdbb30b4b33c4d;hpb=e48a0d17214a832cfcc42d937a26a4bbf732c25a diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c index 47c57cb..6b991b1 100644 --- a/ui/common/discover-client.c +++ b/ui/common/discover-client.c @@ -10,7 +10,7 @@ #include #include -#include +#include #include "ui/common/discover-client.h" #include "pb-protocol/pb-protocol.h" @@ -33,7 +33,7 @@ static int discover_client_destructor(void *arg) } struct discover_client* discover_client_init( - const struct discover_client_ops *ops) + const struct discover_client_ops *ops, void *cb_arg) { struct discover_client *client; struct sockaddr_un addr; @@ -43,6 +43,7 @@ struct discover_client* discover_client_init( return NULL; memcpy(&client->ops, ops, sizeof(client->ops)); + client->ops.cb_arg = cb_arg; client->fd = socket(AF_UNIX, SOCK_STREAM, 0); if (!client->fd < 0) { @@ -107,10 +108,6 @@ static void remove_device(struct discover_client *client, const char *id) if (!device) return; - client->ops.remove_device(device, client->ops.cb_arg); - - talloc_free(device); - /* remove the device from the client's device array */ client->n_devices--; memmove(&client->devices[i], &client->devices[i+1], @@ -118,6 +115,10 @@ static void remove_device(struct discover_client *client, const char *id) client->devices = talloc_realloc(client, client->devices, struct device *, client->n_devices); + /* notify the UI */ + client->ops.remove_device(device, client->ops.cb_arg); + + talloc_free(device); } int discover_client_process(struct discover_client *client) @@ -156,3 +157,18 @@ int discover_client_process(struct discover_client *client) return 0; } + +/* accessors for discovered devices */ +int discover_client_device_count(struct discover_client *client) +{ + return client->n_devices; +} + +struct device *discover_client_get_device(struct discover_client *client, + int index) +{ + if (index < 0 || index >= client->n_devices) + return NULL; + + return client->devices[index]; +}