#include <asm/byteorder.h>
#include <talloc/talloc.h>
-#include <log.h>
+#include <log/log.h>
#include "ui/common/discover-client.h"
#include "pb-protocol/pb-protocol.h"
}
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;
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) {
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],
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)
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];
+}