[cheese] Check for correct types in public API
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese] Check for correct types in public API
- Date: Sun, 11 Dec 2011 14:59:22 +0000 (UTC)
commit 6c8ddf357e26be4a1a41e5d13460aa87e7b9aef6
Author: David King <amigadave amigadave com>
Date: Sun Dec 11 13:08:33 2011 +0100
Check for correct types in public API
Use g_return_*_if_fail() to print critical warnings and return sensible
values if the expected type was not supplied.
libcheese/cheese-camera-device-monitor.c | 3 +-
libcheese/cheese-camera-device.c | 23 ++++++--
libcheese/cheese-camera.c | 97 +++++++++++++++++++++--------
libcheese/cheese-fileutil.c | 15 ++++-
libcheese/cheese-flash.c | 6 ++-
5 files changed, 108 insertions(+), 36 deletions(-)
---
diff --git a/libcheese/cheese-camera-device-monitor.c b/libcheese/cheese-camera-device-monitor.c
index e84b47a..9c5fd71 100644
--- a/libcheese/cheese-camera-device-monitor.c
+++ b/libcheese/cheese-camera-device-monitor.c
@@ -285,7 +285,8 @@ cheese_camera_device_monitor_coldplug (CheeseCameraDeviceMonitor *monitor)
{
GList *devices;
- g_return_if_fail (monitor->priv->client != NULL);
+ g_return_if_fail (CHEESE_IS_CAMERA_DEVICE_MONITOR (monitor)
+ || monitor->priv->client != NULL);
GST_INFO ("Probing devices with udev...");
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index 8812c76..f7951b3 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -648,7 +648,6 @@ cheese_camera_device_initable_init (GInitable *initable,
*
* Returns: a new #CheeseCameraDevice, or %NULL
*/
-
CheeseCameraDevice *
cheese_camera_device_new (const gchar *uuid,
const gchar *device_node,
@@ -669,7 +668,7 @@ cheese_camera_device_new (const gchar *uuid,
* cheese_camera_device_get_format_list:
* @device: a #CheeseCameraDevice
*
- * Get the list of #CheeseVideoFormat that the @device supports.
+ * Get the sorted list of #CheeseVideoFormat that the @device supports.
*
* Returns: (element-type Cheese.VideoFormat) (transfer container): list of
* #CheeseVideoFormat
@@ -677,6 +676,8 @@ cheese_camera_device_new (const gchar *uuid,
GList *
cheese_camera_device_get_format_list (CheeseCameraDevice *device)
{
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+
return g_list_sort (g_list_copy (device->priv->formats), compare_formats);
}
@@ -692,6 +693,8 @@ cheese_camera_device_get_format_list (CheeseCameraDevice *device)
const gchar *
cheese_camera_device_get_name (CheeseCameraDevice *device)
{
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+
return device->priv->name;
}
@@ -706,6 +709,8 @@ cheese_camera_device_get_name (CheeseCameraDevice *device)
const gchar *
cheese_camera_device_get_uuid (CheeseCameraDevice *device)
{
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+
return device->priv->uuid;
}
@@ -722,6 +727,8 @@ cheese_camera_device_get_uuid (CheeseCameraDevice *device)
const gchar *
cheese_camera_device_get_src (CheeseCameraDevice *device)
{
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+
return device->priv->src;
}
@@ -737,8 +744,9 @@ cheese_camera_device_get_src (CheeseCameraDevice *device)
const gchar *
cheese_camera_device_get_device_node (CheeseCameraDevice *device)
{
- return device->priv->device_node;
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+ return device->priv->device_node;
}
/**
@@ -754,6 +762,8 @@ cheese_camera_device_get_device_node (CheeseCameraDevice *device)
CheeseVideoFormat *
cheese_camera_device_get_best_format (CheeseCameraDevice *device)
{
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
+
CheeseVideoFormat *format = g_boxed_copy (CHEESE_TYPE_VIDEO_FORMAT,
cheese_camera_device_get_format_list (device)->data);
@@ -776,7 +786,9 @@ cheese_camera_device_get_caps_for_format (CheeseCameraDevice *device,
{
GstCaps *desired_caps;
GstCaps *subset_caps;
- guint i;
+ guint i, length;
+
+ g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
GST_INFO ("Getting caps for %dx%d", format->width, format->height);
@@ -787,7 +799,8 @@ cheese_camera_device_get_caps_for_format (CheeseCameraDevice *device,
format->height,
NULL);
- for (i = 1; i < g_strv_length (supported_formats); i++)
+ length = g_strv_length (supported_formats);
+ for (i = 1; i < length; i++)
{
gst_caps_append (desired_caps,
gst_caps_new_simple (supported_formats[i],
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index e2e2f0f..cbd9a1c 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -647,7 +647,11 @@ cheese_camera_get_num_camera_devices (CheeseCamera *camera)
CheeseCameraDevice *
cheese_camera_get_selected_device (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_val_if_fail (CHEESE_IS_CAMERA (camera), NULL);
+
+ priv = camera->priv;
if (cheese_camera_get_num_camera_devices (camera) > 0)
return CHEESE_CAMERA_DEVICE (
@@ -665,7 +669,11 @@ cheese_camera_get_selected_device (CheeseCamera *camera)
void
cheese_camera_switch_camera_device (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
/* gboolean was_recording = FALSE; */
gboolean pipeline_was_playing = FALSE;
@@ -705,10 +713,14 @@ cheese_camera_switch_camera_device (CheeseCamera *camera)
void
cheese_camera_play (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
- CheeseCameraDevice *device = g_ptr_array_index (priv->camera_devices, priv->selected_device);
- GstCaps *caps;
+ CheeseCameraPrivate *priv;
+ CheeseCameraDevice *device;
+ GstCaps *caps;
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
+ device = g_ptr_array_index (priv->camera_devices, priv->selected_device);
caps = cheese_camera_device_get_caps_for_format (device, priv->current_format);
if (gst_caps_is_empty (caps))
@@ -742,7 +754,11 @@ cheese_camera_play (CheeseCamera *camera)
void
cheese_camera_stop (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
if (priv->camerabin != NULL)
gst_element_set_state (priv->camerabin, GST_STATE_NULL);
@@ -759,9 +775,13 @@ cheese_camera_stop (CheeseCamera *camera)
static void
cheese_camera_change_effect_filter (CheeseCamera *camera, GstElement *new_filter)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
gboolean ok;
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
+
g_object_set (G_OBJECT (priv->main_valve), "drop", TRUE, NULL);
gst_element_unlink_many (priv->main_valve, priv->effect_filter,
@@ -855,6 +875,8 @@ cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect)
{
GstElement *effect_filter;
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
effect_filter = cheese_camera_element_from_effect (camera, effect);
if (effect_filter != NULL)
cheese_camera_change_effect_filter (camera, effect_filter);
@@ -870,7 +892,11 @@ cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect)
void
cheese_camera_toggle_effects_pipeline (CheeseCamera *camera, gboolean active)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
if (active)
{
@@ -895,8 +921,11 @@ cheese_camera_toggle_effects_pipeline (CheeseCamera *camera, gboolean active)
void
cheese_camera_connect_effect_texture (CheeseCamera *camera, CheeseEffect *effect, ClutterTexture *texture)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+ priv = camera->priv;
GstElement *effect_filter;
GstElement *display_element;
GstElement *display_queue;
@@ -943,7 +972,11 @@ cheese_camera_connect_effect_texture (CheeseCamera *camera, CheeseEffect *effect
void
cheese_camera_start_video_recording (CheeseCamera *camera, const gchar *filename)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
g_object_set (priv->camerabin, "mode", MODE_VIDEO, NULL);
gst_element_set_state (priv->camerabin, GST_STATE_READY);
@@ -990,9 +1023,13 @@ cheese_camera_force_stop_video_recording (gpointer data)
void
cheese_camera_stop_video_recording (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
GstState state;
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
+
gst_element_get_state (priv->camerabin, &state, NULL, 0);
if (state == GST_STATE_PLAYING)
@@ -1040,7 +1077,11 @@ cheese_camera_image_done_cb (GstElement *camerabin, const gchar *filename,
gboolean
cheese_camera_take_photo (CheeseCamera *camera, const gchar *filename)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
+
+ g_return_val_if_fail (CHEESE_IS_CAMERA (camera), FALSE);
+
+ priv = camera->priv;
if (priv->photo_handler_signal_id != 0)
{
@@ -1089,9 +1130,13 @@ cheese_camera_take_photo (CheeseCamera *camera, const gchar *filename)
gboolean
cheese_camera_take_photo_pixbuf (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
GstCaps *caps;
+ g_return_val_if_fail (CHEESE_IS_CAMERA (camera), FALSE);
+
+ priv = camera->priv;
+
if (priv->photo_handler_signal_id != 0)
{
GST_WARNING ("Still waiting for previous photo data, ignoring new request");
@@ -1387,6 +1432,7 @@ void
cheese_camera_set_device_by_device_node (CheeseCamera *camera, const gchar *file)
{
g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
g_object_set (camera, "device-node", file, NULL);
}
@@ -1401,10 +1447,7 @@ static void
cheese_camera_set_device_by_dev_uuid (CheeseCamera *camera, const gchar *uuid)
{
CheeseCameraPrivate *priv = camera->priv;
- int i;
-
- g_return_if_fail (CHEESE_IS_CAMERA (camera));
-
+ gint i;
for (i = 0; i < priv->num_camera_devices; i++)
{
@@ -1430,12 +1473,15 @@ cheese_camera_set_device_by_dev_uuid (CheeseCamera *camera, const gchar *uuid)
void
cheese_camera_setup (CheeseCamera *camera, const gchar *uuid, GError **error)
{
- CheeseCameraPrivate *priv = camera->priv;
-
+ CheeseCameraPrivate *priv;
GError *tmp_error = NULL;
GstElement *video_sink;
GstCaps *caps;
+ g_return_if_fail (CHEESE_IS_CAMERA (camera));
+
+ priv = camera->priv;
+
cheese_camera_detect_camera_devices (camera);
if (priv->num_camera_devices < 1)
@@ -1562,11 +1608,7 @@ cheese_camera_get_video_formats (CheeseCamera *camera)
static gboolean
cheese_camera_is_playing (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv;
-
- g_return_val_if_fail (CHEESE_IS_CAMERA (camera), FALSE);
-
- priv = camera->priv;
+ CheeseCameraPrivate *priv = camera->priv;
return priv->pipeline_is_playing;
}
@@ -1584,8 +1626,7 @@ cheese_camera_set_video_format (CheeseCamera *camera, CheeseVideoFormat *format)
{
CheeseCameraPrivate *priv;
- g_return_if_fail (CHEESE_IS_CAMERA (camera));
- g_return_if_fail (format != NULL);
+ g_return_if_fail (CHEESE_IS_CAMERA (camera) || format != NULL);
priv = camera->priv;
@@ -1612,10 +1653,12 @@ cheese_camera_set_video_format (CheeseCamera *camera, CheeseVideoFormat *format)
const CheeseVideoFormat *
cheese_camera_get_current_video_format (CheeseCamera *camera)
{
- CheeseCameraPrivate *priv = camera->priv;
+ CheeseCameraPrivate *priv;
g_return_val_if_fail (CHEESE_IS_CAMERA (camera), NULL);
+ priv = camera->priv;
+
return priv->current_format;
}
diff --git a/libcheese/cheese-fileutil.c b/libcheese/cheese-fileutil.c
index b613cf8..06dad01 100644
--- a/libcheese/cheese-fileutil.c
+++ b/libcheese/cheese-fileutil.c
@@ -66,6 +66,8 @@ cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil);
const gchar *
cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
{
+ g_return_val_if_fail (CHEESE_IS_FILEUTIL (fileutil), NULL);
+
return fileutil->priv->video_path;
}
@@ -80,6 +82,8 @@ cheese_fileutil_get_video_path (CheeseFileUtil *fileutil)
const gchar *
cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil)
{
+ g_return_val_if_fail (CHEESE_IS_FILEUTIL (fileutil), NULL);
+
return fileutil->priv->photo_path;
}
@@ -116,8 +120,11 @@ cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMod
gchar *filename;
GFile *file;
guint num;
+ CheeseFileUtilPrivate *priv;
- CheeseFileUtilPrivate *priv = fileutil->priv;
+ g_return_val_if_fail (CHEESE_IS_FILEUTIL (fileutil), NULL);
+
+ priv = fileutil->priv;
datetime = g_date_time_new_now_local ();
@@ -207,7 +214,11 @@ cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMod
void
cheese_fileutil_reset_burst (CheeseFileUtil *fileutil)
{
- CheeseFileUtilPrivate *priv = fileutil->priv;
+ CheeseFileUtilPrivate *priv;
+
+ g_return_if_fail (CHEESE_IS_FILEUTIL (fileutil));
+
+ priv = fileutil->priv;
priv->burst_count = 0;
priv->burst_raw_name = "";
diff --git a/libcheese/cheese-flash.c b/libcheese/cheese-flash.c
index 317c28f..de2f2bc 100644
--- a/libcheese/cheese-flash.c
+++ b/libcheese/cheese-flash.c
@@ -387,12 +387,16 @@ cheese_flash_start_fade (gpointer data)
void
cheese_flash_fire (CheeseFlash *flash)
{
- CheeseFlashPrivate *flash_priv = flash->priv;
+ CheeseFlashPrivate *flash_priv;
GtkWidget *parent;
GdkScreen *screen;
GdkRectangle rect;
int monitor;
+ g_return_if_fail (CHEESE_IS_FLASH (flash));
+
+ flash_priv = flash->priv;
+
g_return_if_fail (flash_priv->parent != NULL);
GtkWindow *flash_window = GTK_WINDOW (flash);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]