[aravis/af_packet: 2/5] device: make data private



commit f240916dbf7e48aaa199d1aeb6990f3073ae8a63
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sat Dec 6 18:21:14 2014 +0100

    device: make data private

 docs/reference/aravis/aravis-sections.txt |    1 +
 src/arvdevice.c                           |   31 ++++++++++++++++++----------
 src/arvdevice.h                           |    4 +-
 3 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 016b6b8..a7fdeff 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -285,6 +285,7 @@ ARV_IS_DEVICE_CLASS
 ARV_DEVICE_GET_CLASS
 <SUBSECTION Private>
 ArvDeviceClass
+ArvDevicePrivate
 ARV_DEVICE_NAME_ILLEGAL_CHARACTERS
 ARV_DEVICE_NAME_REPLACEMENT_CHARACTER
 </SECTION>
diff --git a/src/arvdevice.c b/src/arvdevice.c
index 94b0838..d09dbd1 100644
--- a/src/arvdevice.c
+++ b/src/arvdevice.c
@@ -49,6 +49,11 @@ static guint arv_device_signals[ARV_DEVICE_SIGNAL_LAST] = {0};
 
 static GObjectClass *parent_class = NULL;
 
+struct  _ArvDevicePrivate {
+       ArvDeviceStatus status;
+       char *status_message;
+};
+
 GQuark
 arv_device_error_quark (void)
 {
@@ -272,14 +277,14 @@ arv_device_get_feature (ArvDevice *device, const char *feature)
 static void
 _set_status (ArvDevice *device, ArvDeviceStatus status, const char *message)
 {
-       if (device->status == ARV_DEVICE_STATUS_SUCCESS)
+       if (device->priv->status == ARV_DEVICE_STATUS_SUCCESS)
                return;
 
        arv_warning_device ("[ArvDevice::set_status] Status changed ('%s')", message);
 
-       g_free (device->status_message);
-       device->status = status;
-       device->status_message = g_strdup (message);
+       g_free (device->priv->status_message);
+       device->priv->status = status;
+       device->priv->status_message = g_strdup (message);
 }
 
 /**
@@ -632,11 +637,11 @@ arv_device_get_status (ArvDevice *device)
        
        g_return_val_if_fail (ARV_IS_DEVICE (device), ARV_DEVICE_STATUS_UNKNOWN);
 
-       status = device->status;
+       status = device->priv->status;
        
-       g_free (device->status_message);
-       device->status = ARV_DEVICE_STATUS_SUCCESS;
-       device->status_message = NULL;
+       g_free (device->priv->status_message);
+       device->priv->status = ARV_DEVICE_STATUS_SUCCESS;
+       device->priv->status_message = NULL;
 
        return status;
 }
@@ -652,8 +657,10 @@ arv_device_emit_control_lost_signal (ArvDevice *device)
 static void
 arv_device_init (ArvDevice *device)
 {
-       device->status = ARV_DEVICE_STATUS_SUCCESS;
-       device->status_message = NULL;
+       device->priv = G_TYPE_INSTANCE_GET_PRIVATE (device, ARV_TYPE_DEVICE, ArvDevicePrivate);
+
+       device->priv->status = ARV_DEVICE_STATUS_SUCCESS;
+       device->priv->status_message = NULL;
 }
 
 static void
@@ -661,7 +668,7 @@ arv_device_finalize (GObject *object)
 {
        ArvDevice *device = ARV_DEVICE (object);
 
-       g_free (device->status_message);
+       g_free (device->priv->status_message);
 
        parent_class->finalize (object);
 }
@@ -671,6 +678,8 @@ arv_device_class_init (ArvDeviceClass *device_class)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (device_class);
 
+       g_type_class_add_private (device_class, sizeof (ArvDevicePrivate));
+
        parent_class = g_type_class_peek_parent (device_class);
 
        object_class->finalize = arv_device_finalize;
diff --git a/src/arvdevice.h b/src/arvdevice.h
index ff965b3..d172820 100644
--- a/src/arvdevice.h
+++ b/src/arvdevice.h
@@ -51,13 +51,13 @@ typedef enum {
 #define ARV_IS_DEVICE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), ARV_TYPE_DEVICE))
 #define ARV_DEVICE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj), ARV_TYPE_DEVICE, ArvDeviceClass))
 
+typedef struct _ArvDevicePrivate ArvDevicePrivate;
 typedef struct _ArvDeviceClass ArvDeviceClass;
 
 struct _ArvDevice {
        GObject object;
 
-       ArvDeviceStatus status;
-       char *status_message;
+       ArvDevicePrivate *priv;
 };
 
 struct _ArvDeviceClass {


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