[gnome-builder/wip/libide] libide: add ide_device_manager_get_device()



commit 39738d9ccc7d9f3a0597abdddb79f14f241387e2
Author: Christian Hergert <christian hergert me>
Date:   Fri Feb 27 18:48:03 2015 -0800

    libide: add ide_device_manager_get_device()
    
    Helper function to get a device by id.

 libide/ide-device-manager.c |   32 ++++++++++++++++++++++++++++++++
 libide/ide-device-manager.h |    2 ++
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-device-manager.c b/libide/ide-device-manager.c
index 0afdf7d..a478227 100644
--- a/libide/ide-device-manager.c
+++ b/libide/ide-device-manager.c
@@ -320,3 +320,35 @@ ide_device_manager_init (IdeDeviceManager *self)
   priv->devices = g_ptr_array_new_with_free_func (g_object_unref);
   priv->providers = g_ptr_array_new_with_free_func (g_object_unref);
 }
+
+/**
+ * ide_device_manager_get_device:
+ * @device_id: The device identifier string.
+ *
+ * Fetches the first device that matches the device identifier @device_id.
+ *
+ * Returns: (transfer none): An #IdeDevice or %NULL.
+ */
+IdeDevice *
+ide_device_manager_get_device (IdeDeviceManager *self,
+                               const gchar      *device_id)
+{
+  IdeDeviceManagerPrivate *priv = ide_device_manager_get_instance_private (self);
+  gsize i;
+
+  g_return_val_if_fail (IDE_IS_DEVICE_MANAGER (self), NULL);
+
+  for (i = 0; i < priv->devices->len; i++)
+    {
+      IdeDevice *device;
+      const gchar *id;
+
+      device = g_ptr_array_index (priv->devices, i);
+      id = ide_device_get_id (device);
+
+      if (0 == g_strcmp0 (id, device_id))
+        return device;
+    }
+
+  return NULL;
+}
diff --git a/libide/ide-device-manager.h b/libide/ide-device-manager.h
index dbe4e0c..7016711 100644
--- a/libide/ide-device-manager.h
+++ b/libide/ide-device-manager.h
@@ -39,6 +39,8 @@ GPtrArray *ide_device_manager_get_devices     (IdeDeviceManager  *self);
 gboolean   ide_device_manager_get_settled     (IdeDeviceManager  *self);
 void       ide_device_manager_remove_provider (IdeDeviceManager  *self,
                                                IdeDeviceProvider *provider);
+IdeDevice *ide_device_manager_get_device      (IdeDeviceManager  *self,
+                                               const gchar       *device_id);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]