+static void add_device(struct discover_client *client, struct device *device)
+{
+ client->n_devices++;
+ client->devices = talloc_realloc(client, client->devices,
+ struct device *, client->n_devices);
+
+ client->devices[client->n_devices - 1] = device;
+ talloc_steal(client, device);
+
+ client->ops.add_device(device, client->ops.cb_arg);
+}
+
+static void remove_device(struct discover_client *client, const char *id)
+{
+ struct device *device = NULL;
+ int i;
+
+ for (i = 0; i < client->n_devices; i++) {
+ if (!strcmp(client->devices[i]->id, id)) {
+ device = client->devices[i];
+ break;
+ }
+ }
+
+ 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->n_devices - i);
+ client->devices = talloc_realloc(client, client->devices,
+ struct device *, client->n_devices);
+
+}
+