[cheese] Improved CheeseCameraDeviceMonitor::added signal



commit 054a929303468353537442b4ba77590449c90a73
Author: Patricia Santana Cruz <patriciasantanacruz gmail com>
Date:   Fri Oct 28 17:38:24 2011 +0200

    Improved CheeseCameraDeviceMonitor::added signal
    
    CheeseCameraDeviceMonitor:added has now a CheeseCameraDevice argument.
    CheeseCameraDeviceMonitor is also now a member of CheeseCamera.

 libcheese/cheese-camera-device-monitor.c |   34 ++++++++++++++++++------
 libcheese/cheese-camera-device-monitor.h |   10 +++----
 libcheese/cheese-camera.c                |   41 +++++++++++-------------------
 libcheese/cheese-marshal.list            |    1 -
 4 files changed, 44 insertions(+), 42 deletions(-)
---
diff --git a/libcheese/cheese-camera-device-monitor.c b/libcheese/cheese-camera-device-monitor.c
index 39f3b8a..2c6b696 100644
--- a/libcheese/cheese-camera-device-monitor.c
+++ b/libcheese/cheese-camera-device-monitor.c
@@ -102,15 +102,16 @@ cheese_camera_device_monitor_error_quark (void)
 }
 
 #ifdef HAVE_UDEV
-static void
-cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
-                                    GUdevDevice               *udevice)
+
+CheeseCameraDevice*
+cheese_camera_device_monitor_set_up_device(GUdevDevice *udevice)
 {
   const char *device_file;
   const char *product_name;
   const char *vendor;
   const char *product;
   const char *bus;
+  GError      *error = NULL;
   gint        vendor_id   = 0;
   gint        product_id  = 0;
   gint        v4l_version = 0;
@@ -181,11 +182,26 @@ cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
     g_assert_not_reached ();
   }
 
-  g_signal_emit (monitor, monitor_signals[ADDED], 0,
-                 devpath,
+  CheeseCameraDevice *device = cheese_camera_device_new (devpath,
+                                                         device_file,
+                                                         product_name,
+                                                         v4l_version,
+                                                         &error);
+
+  if (device == NULL)
+    GST_WARNING ("Device initialization for %s failed: %s ",
                  device_file,
-                 product_name,
-                 v4l_version);
+                 (error != NULL) ? error->message : "Unknown reason");
+
+  return device;
+}
+
+static void
+cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
+                                    GUdevDevice               *udevice)
+{
+  CheeseCameraDevice *device = cheese_camera_device_monitor_set_up_device (udevice);
+  g_signal_emit (monitor, monitor_signals[ADDED], 0, device);
 }
 
 static void
@@ -360,8 +376,8 @@ cheese_camera_device_monitor_class_init (CheeseCameraDeviceMonitorClass *klass)
                                          G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                                          G_STRUCT_OFFSET (CheeseCameraDeviceMonitorClass, added),
                                          NULL, NULL,
-                                         cheese_marshal_VOID__STRING_STRING_STRING_INT,
-                                         G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
+                                         g_cclosure_marshal_VOID__OBJECT,
+                                         G_TYPE_NONE, 1, G_TYPE_OBJECT);
 
   /**
    * CheeseCameraDeviceMonitor::removed:
diff --git a/libcheese/cheese-camera-device-monitor.h b/libcheese/cheese-camera-device-monitor.h
index 0a5f3be..88e9d47 100644
--- a/libcheese/cheese-camera-device-monitor.h
+++ b/libcheese/cheese-camera-device-monitor.h
@@ -25,6 +25,7 @@
 
 #include <glib-object.h>
 #include <gst/interfaces/xoverlay.h>
+#include "cheese-camera-device.h"
 
 G_BEGIN_DECLS
 
@@ -63,12 +64,9 @@ struct _CheeseCameraDeviceMonitorClass
   GObjectClass parent_class;
 
   /*< public >*/
-  void (*added)(CheeseCameraDeviceMonitor *camera,
-                const char                *id,
-                const char                *device_file,
-                const char                *product_name,
-                int                        api_version);
-  void (*removed)(CheeseCameraDeviceMonitor *camera, const char *id);
+  void (*added)(CheeseCameraDeviceMonitor *monitor,
+                CheeseCameraDevice        *device);
+  void (*removed)(CheeseCameraDeviceMonitor *monitor, const char *id);
 };
 
 GType                      cheese_camera_device_monitor_get_type (void) G_GNUC_CONST;
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index a818970..36eb69b 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -101,6 +101,8 @@ typedef struct
   CheeseVideoFormat *current_format;
 
   guint eos_timeout_id;
+
+  CheeseCameraDeviceMonitor *monitor;
 } CheeseCameraPrivate;
 
 enum
@@ -244,46 +246,29 @@ cheese_camera_bus_message_cb (GstBus *bus, GstMessage *message, CheeseCamera *ca
 
 static void
 cheese_camera_add_device (CheeseCameraDeviceMonitor *monitor,
-                          const gchar               *id,
-                          const gchar               *device_file,
-                          const gchar               *product_name,
-                          gint                       api_version,
+			  CheeseCameraDevice        *device,
                           CheeseCamera              *camera)
 {
   CheeseCameraPrivate *priv  = CHEESE_CAMERA_GET_PRIVATE (camera);
-  GError              *error = NULL;
-
-  CheeseCameraDevice *device = cheese_camera_device_new (id,
-                                                         device_file,
-                                                         product_name,
-                                                         api_version,
-                                                         &error);
-
-  if (device == NULL)
-    GST_WARNING ("Device initialization for %s failed: %s ",
-                 device_file,
-                 (error != NULL) ? error->message : "Unknown reason");
-  else
-  {
-    g_ptr_array_add (priv->camera_devices, device);
-    priv->num_camera_devices++;
-  }
+
+  g_debug("%s", "added\n");
+  g_ptr_array_add (priv->camera_devices, device);
+  priv->num_camera_devices++;
 }
 
 static void
 cheese_camera_detect_camera_devices (CheeseCamera *camera)
 {
   CheeseCameraPrivate       *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
-  CheeseCameraDeviceMonitor *monitor;
 
   priv->num_camera_devices = 0;
   priv->camera_devices     = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 
-  monitor = cheese_camera_device_monitor_new ();
-  g_signal_connect (G_OBJECT (monitor), "added",
+  priv->monitor = cheese_camera_device_monitor_new ();
+  g_signal_connect (G_OBJECT (priv->monitor), "added",
                     G_CALLBACK (cheese_camera_add_device), camera);
-  cheese_camera_device_monitor_coldplug (monitor);
-  g_object_unref (monitor);
+
+  cheese_camera_device_monitor_coldplug (priv->monitor);
 }
 
 static gboolean
@@ -960,6 +945,9 @@ cheese_camera_finalize (GObject *object)
   /* Free CheeseCameraDevice array */
   g_ptr_array_free (priv->camera_devices, TRUE);
 
+  if (priv->monitor != NULL)
+    g_object_unref (priv->monitor);
+
   G_OBJECT_CLASS (cheese_camera_parent_class)->finalize (object);
 }
 
@@ -1096,6 +1084,7 @@ cheese_camera_init (CheeseCamera *camera)
   priv->device_name             = NULL;
   priv->photo_handler_signal_id = 0;
   priv->current_format          = NULL;
+  priv->monitor                 = NULL;
 }
 
 /**
diff --git a/libcheese/cheese-marshal.list b/libcheese/cheese-marshal.list
index 7013605..e69de29 100644
--- a/libcheese/cheese-marshal.list
+++ b/libcheese/cheese-marshal.list
@@ -1 +0,0 @@
-VOID:STRING,STRING,STRING,INT



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