diff options
author | Michal Ratajsky <[email protected]> | 2016-01-09 20:08:32 +0100 |
---|---|---|
committer | raveit65 <[email protected]> | 2017-02-21 11:55:59 +0100 |
commit | d1deea43570dfd5bd32b7040f89cf3c971df3b9a (patch) | |
tree | efe0f391556b765477a8c35a2fe02b59a9e5220d | |
parent | cf087148400ad5510bb781db2516962b19768f4f (diff) | |
download | libmatemixer-d1deea43570dfd5bd32b7040f89cf3c971df3b9a.tar.bz2 libmatemixer-d1deea43570dfd5bd32b7040f89cf3c971df3b9a.tar.xz |
oss: Improve cleaning code and guard against incorrect use
-rw-r--r-- | backends/oss/oss-backend.c | 3 | ||||
-rw-r--r-- | backends/oss/oss-device.c | 34 | ||||
-rw-r--r-- | backends/oss/oss-device.h | 1 | ||||
-rw-r--r-- | backends/oss/oss-stream-control.c | 3 | ||||
-rw-r--r-- | backends/oss/oss-switch.c | 3 |
5 files changed, 9 insertions, 35 deletions
diff --git a/backends/oss/oss-backend.c b/backends/oss/oss-backend.c index b88dfd3..5795e7c 100644 --- a/backends/oss/oss-backend.c +++ b/backends/oss/oss-backend.c @@ -568,8 +568,7 @@ remove_device_by_list_item (OssBackend *oss, GList *item) /* Closing a device emits stream-removed signals, close after fixing the * default device to avoid re-validating default streams as they get * removed */ - if (oss_device_is_open (device) == TRUE) - oss_device_close (device); + oss_device_close (device); g_signal_handlers_disconnect_by_data (G_OBJECT (device), oss); diff --git a/backends/oss/oss-device.c b/backends/oss/oss-device.c index d408c80..582c837 100644 --- a/backends/oss/oss-device.c +++ b/backends/oss/oss-device.c @@ -170,6 +170,7 @@ struct _OssDevicePrivate GList *streams; OssStream *input; OssStream *output; + gboolean loaded; }; enum { @@ -181,7 +182,6 @@ static guint signals[N_SIGNALS] = { 0, }; static void oss_device_class_init (OssDeviceClass *klass); static void oss_device_init (OssDevice *device); -static void oss_device_dispose (GObject *object); static void oss_device_finalize (GObject *object); G_DEFINE_TYPE (OssDevice, oss_device, MATE_MIXER_TYPE_DEVICE) @@ -208,7 +208,6 @@ oss_device_class_init (OssDeviceClass *klass) MateMixerDeviceClass *device_class; object_class = G_OBJECT_CLASS (klass); - object_class->dispose = oss_device_dispose; object_class->finalize = oss_device_finalize; device_class = MATE_MIXER_DEVICE_CLASS (klass); @@ -238,25 +237,11 @@ oss_device_init (OssDevice *device) } static void -oss_device_dispose (GObject *object) -{ - OssDevice *device; - - device = OSS_DEVICE (object); - - g_clear_object (&device->priv->input); - g_clear_object (&device->priv->output); - - G_OBJECT_CLASS (oss_device_parent_class)->dispose (object); -} - -static void oss_device_finalize (GObject *object) { OssDevice *device = OSS_DEVICE (object); - if (device->priv->fd != -1) - close (device->priv->fd); + oss_device_close (device); g_free (device->priv->path); @@ -301,6 +286,7 @@ oss_device_open (OssDevice *device) gint ret; g_return_val_if_fail (OSS_IS_DEVICE (device), FALSE); + g_return_val_if_fail (device->priv->fd != -1, FALSE); g_debug ("Opening device %s (%s)", device->priv->path, @@ -337,17 +323,6 @@ fail: return FALSE; } -gboolean -oss_device_is_open (OssDevice *device) -{ - g_return_val_if_fail (OSS_IS_DEVICE (device), FALSE); - - if (device->priv->fd != -1) - return TRUE; - - return FALSE; -} - void oss_device_close (OssDevice *device) { @@ -408,6 +383,7 @@ oss_device_load (OssDevice *device) guint i; g_return_if_fail (OSS_IS_DEVICE (device)); + g_return_if_fail (device->priv->loaded == FALSE); name = mate_mixer_device_get_name (MATE_MIXER_DEVICE (device)); @@ -511,6 +487,8 @@ oss_device_load (OssDevice *device) * changed and therefore when to start the rapid polling. */ device->priv->poll_tag = create_poll_source (device, OSS_POLL_NORMAL); + + device->priv->loaded = TRUE; } const gchar * diff --git a/backends/oss/oss-device.h b/backends/oss/oss-device.h index a723f41..b2dd740 100644 --- a/backends/oss/oss-device.h +++ b/backends/oss/oss-device.h @@ -66,7 +66,6 @@ OssDevice * oss_device_new (const gchar *name, gint fd); gboolean oss_device_open (OssDevice *device); -gboolean oss_device_is_open (OssDevice *device); void oss_device_close (OssDevice *device); void oss_device_load (OssDevice *device); diff --git a/backends/oss/oss-stream-control.c b/backends/oss/oss-stream-control.c index 4ae238e..bcb73fe 100644 --- a/backends/oss/oss-stream-control.c +++ b/backends/oss/oss-stream-control.c @@ -128,8 +128,7 @@ oss_stream_control_finalize (GObject *object) control = OSS_STREAM_CONTROL (object); - if (control->priv->fd != -1) - close (control->priv->fd); + oss_stream_control_close (control); G_OBJECT_CLASS (oss_stream_control_parent_class)->finalize (object); } diff --git a/backends/oss/oss-switch.c b/backends/oss/oss-switch.c index ba07d36..87ffb90 100644 --- a/backends/oss/oss-switch.c +++ b/backends/oss/oss-switch.c @@ -93,8 +93,7 @@ oss_switch_finalize (GObject *object) swtch = OSS_SWITCH (object); - if (swtch->priv->fd != -1) - close (swtch->priv->fd); + oss_switch_close (swtch); G_OBJECT_CLASS (oss_switch_parent_class)->finalize (object); } |