[balsa/wip/gtk4: 282/351] net-client and friends: Use G_DECLARE_*_TYPE



commit 92a269fd913c07fcd0438216a3b10506efc29cf8
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Apr 18 08:23:16 2018 -0400

    net-client and friends: Use G_DECLARE_*_TYPE

 libnetclient/net-client-pop.c  |   18 +++++-
 libnetclient/net-client-pop.h  |   30 +++-------
 libnetclient/net-client-smtp.c |   19 +++++-
 libnetclient/net-client-smtp.h |   29 +++-------
 libnetclient/net-client.c      |  127 ++++++++++++++++++++--------------------
 libnetclient/net-client.h      |   28 +++------
 6 files changed, 120 insertions(+), 131 deletions(-)
---
diff --git a/libnetclient/net-client-pop.c b/libnetclient/net-client-pop.c
index 09287d7..564e89f 100644
--- a/libnetclient/net-client-pop.c
+++ b/libnetclient/net-client-pop.c
@@ -18,6 +18,7 @@
 #include "net-client-utils.h"
 #include "net-client-pop.h"
 
+typedef struct _NetClientPopPrivate NetClientPopPrivate;
 
 struct _NetClientPopPrivate {
        NetClientCryptMode crypt_mode;
@@ -44,6 +45,17 @@ struct _NetClientPopPrivate {
 /*lint -restore */
 
 
+struct _NetClientPop {
+    NetClient parent;
+    NetClientPopPrivate *priv;
+};
+
+
+struct _NetClientPopClass {
+       NetClientClass parent;
+};
+
+
 G_DEFINE_TYPE(NetClientPop, net_client_pop, NET_CLIENT_TYPE)
 
 
@@ -392,7 +404,7 @@ net_client_pop_init(NetClientPop *self)
 static void
 net_client_pop_dispose(GObject *object)
 {
-       const NetClientPop *client = NET_CLIENT_POP(object);
+       NetClientPop *client = NET_CLIENT_POP(object);
        const GObjectClass *parent_class = G_OBJECT_CLASS(net_client_pop_parent_class);
 
        /* send the 'QUIT' command - no need to evaluate the reply or check for errors */
@@ -400,7 +412,7 @@ net_client_pop_dispose(GObject *object)
                (void) net_client_execute(NET_CLIENT(client), NULL, "QUIT", NULL);
        }
 
-       (*parent_class->dispose)(object);
+       parent_class->dispose(object);
 }
 
 
@@ -413,7 +425,7 @@ net_client_pop_finalise(GObject *object)
        g_free(client->priv->apop_banner);
        g_free(client->priv);
 
-       (*parent_class->finalize)(object);
+       parent_class->finalize(object);
 }
 
 
diff --git a/libnetclient/net-client-pop.h b/libnetclient/net-client-pop.h
index c999a31..d199f59 100644
--- a/libnetclient/net-client-pop.h
+++ b/libnetclient/net-client-pop.h
@@ -22,20 +22,17 @@
 G_BEGIN_DECLS
 
 
-#define NET_CLIENT_POP_TYPE                                    (net_client_pop_get_type())
-#define NET_CLIENT_POP(obj)                                    (G_TYPE_CHECK_INSTANCE_CAST((obj), 
NET_CLIENT_POP_TYPE, NetClientPop))
-#define NET_IS_CLIENT_POP(obj)                         (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
NET_CLIENT_POP_TYPE))
-#define NET_CLIENT_POP_CLASS(klass)                    (G_TYPE_CHECK_CLASS_CAST((klass), 
NET_CLIENT_POP_TYPE, NetClientPopClass))
-#define NET_IS_CLIENT_POP_CLASS(klass)         (G_TYPE_CHECK_CLASS_TYPE((klass), NET_CLIENT_POP_TYPE))
-#define NET_CLIENT_POP_GET_CLASS(obj)          (G_TYPE_INSTANCE_GET_CLASS((obj), NET_CLIENT_POP_TYPE, 
NetClientPopClass))
+#define NET_CLIENT_POP_TYPE net_client_pop_get_type()
 
-#define NET_CLIENT_POP_ERROR_QUARK                     (g_quark_from_static_string("net-client-pop"))
+G_DECLARE_FINAL_TYPE(NetClientPop,
+                     net_client_pop,
+                     NET,
+                     CLIENT_POP,
+                     NetClient)
+
+#define NET_CLIENT_POP_ERROR_QUARK (g_quark_from_static_string("net-client-pop"))
 
 
-typedef struct _NetClientPop NetClientPop;
-typedef struct _NetClientPopClass NetClientPopClass;
-typedef struct _NetClientPopPrivate NetClientPopPrivate;
-typedef struct _NetClientPopMessage NetClientPopMessage;
 typedef struct _NetClientPopMessageInfo NetClientPopMessageInfo;
 
 
@@ -79,17 +76,6 @@ enum _NetClientPopError {
 /** @} */
 
 
-struct _NetClientPop {
-    NetClient parent;
-    NetClientPopPrivate *priv;
-};
-
-
-struct _NetClientPopClass {
-       NetClientClass parent;
-};
-
-
 /** @brief Message information
  *
  * This structure is returned in a GList by net_client_pop_list() and contains information about on message 
in the remote mailbox.
diff --git a/libnetclient/net-client-smtp.c b/libnetclient/net-client-smtp.c
index 975492a..1b9092e 100644
--- a/libnetclient/net-client-smtp.c
+++ b/libnetclient/net-client-smtp.c
@@ -18,6 +18,8 @@
 #include "net-client-smtp.h"
 
 
+typedef struct _NetClientSmtpPrivate NetClientSmtpPrivate;
+
 struct _NetClientSmtpPrivate {
        NetClientCryptMode crypt_mode;
        guint auth_allowed[2];                  /** 0: encrypted, 1: unencrypted */
@@ -49,6 +51,17 @@ typedef struct {
 #define SMTP_DATA_BUF_SIZE                     8192U
 
 
+struct _NetClientSmtp {
+    NetClient parent;
+    NetClientSmtpPrivate *priv;
+};
+
+
+struct _NetClientSmtpClass {
+       NetClientClass parent;
+};
+
+
 G_DEFINE_TYPE(NetClientSmtp, net_client_smtp, NET_CLIENT_TYPE)
 
 
@@ -355,7 +368,7 @@ net_client_smtp_init(NetClientSmtp *self)
 static void
 net_client_smtp_dispose(GObject *object)
 {
-       const NetClientSmtp *client = NET_CLIENT_SMTP(object);
+       NetClientSmtp *client = NET_CLIENT_SMTP(object);
        const GObjectClass *parent_class = G_OBJECT_CLASS(net_client_smtp_parent_class);
 
        /* send the 'QUIT' command unless we are in 'DATA' state where the server will probably fail to reply 
- no need to evaluate the
@@ -365,7 +378,7 @@ net_client_smtp_dispose(GObject *object)
                 client->priv->data_state = TRUE;
        }
 
-       (*parent_class->dispose)(object);
+       parent_class->dispose(object);
 }
 
 
@@ -377,7 +390,7 @@ net_client_smtp_finalise(GObject *object)
 
        g_free(client->priv);
 
-       (*parent_class->finalize)(object);
+       parent_class->finalize(object);
 }
 
 
diff --git a/libnetclient/net-client-smtp.h b/libnetclient/net-client-smtp.h
index 5634c81..f7b0284 100644
--- a/libnetclient/net-client-smtp.h
+++ b/libnetclient/net-client-smtp.h
@@ -22,19 +22,17 @@
 G_BEGIN_DECLS
 
 
-#define NET_CLIENT_SMTP_TYPE                           (net_client_smtp_get_type())
-#define NET_CLIENT_SMTP(obj)                           (G_TYPE_CHECK_INSTANCE_CAST((obj), 
NET_CLIENT_SMTP_TYPE, NetClientSmtp))
-#define NET_IS_CLIENT_SMTP(obj)                                (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
NET_CLIENT_SMTP_TYPE))
-#define NET_CLIENT_SMTP_CLASS(klass)           (G_TYPE_CHECK_CLASS_CAST((klass), NET_CLIENT_SMTP_TYPE, 
NetClientSmtpClass))
-#define NET_IS_CLIENT_SMTP_CLASS(klass)                (G_TYPE_CHECK_CLASS_TYPE((klass), 
NET_CLIENT_SMTP_TYPE))
-#define NET_CLIENT_SMTP_GET_CLASS(obj)         (G_TYPE_INSTANCE_GET_CLASS((obj), NET_CLIENT_SMTP_TYPE, 
NetClientSmtpClass))
+#define NET_CLIENT_SMTP_TYPE net_client_smtp_get_type()
 
-#define NET_CLIENT_SMTP_ERROR_QUARK                    (g_quark_from_static_string("net-client-smtp"))
+G_DECLARE_FINAL_TYPE(NetClientSmtp,
+                     net_client_smtp,
+                     NET,
+                     CLIENT_SMTP,
+                     NetClient)
+
+#define NET_CLIENT_SMTP_ERROR_QUARK (g_quark_from_static_string("net-client-smtp"))
 
 
-typedef struct _NetClientSmtp NetClientSmtp;
-typedef struct _NetClientSmtpClass NetClientSmtpClass;
-typedef struct _NetClientSmtpPrivate NetClientSmtpPrivate;
 typedef struct _NetClientSmtpMessage NetClientSmtpMessage;
 typedef enum _NetClientSmtpDsnMode NetClientSmtpDsnMode;
 
@@ -73,17 +71,6 @@ enum _NetClientSmtpError {
 /** @} */
 
 
-struct _NetClientSmtp {
-    NetClient parent;
-    NetClientSmtpPrivate *priv;
-};
-
-
-struct _NetClientSmtpClass {
-       NetClientClass parent;
-};
-
-
 /** @brief Delivery Status Notification mode
  *
  * See <a href="https://tools.ietf.org/html/rfc3461";>RFC 3461</a> for a description of Delivery Status 
Notifications (DSNs).  The
diff --git a/libnetclient/net-client.c b/libnetclient/net-client.c
index 8a12c01..069095a 100644
--- a/libnetclient/net-client.c
+++ b/libnetclient/net-client.c
@@ -35,8 +35,9 @@ struct _NetClientPrivate {
 
 static guint signals[3];
 
+typedef struct _NetClientPrivate NetClientPrivate;
 
-G_DEFINE_TYPE(NetClient, net_client, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE(NetClient, net_client, G_TYPE_OBJECT)
 
 
 static void net_client_dispose(GObject *object);
@@ -48,18 +49,19 @@ NetClient *
 net_client_new(const gchar *host_and_port, guint16 default_port, gsize max_line_len)
 {
        NetClient *client;
+        NetClientPrivate *priv;
 
        g_return_val_if_fail(host_and_port != NULL, NULL);
 
        client = NET_CLIENT(g_object_new(NET_CLIENT_TYPE, NULL));
+        priv = net_client_get_instance_private(client);
 
-       if (client->priv->sock == NULL) {
-               g_object_unref(G_OBJECT(client));
-               client = NULL;
+       if (priv->sock == NULL) {
+                g_clear_object(&client);
        } else {
-               client->priv->host_and_port = g_strdup(host_and_port);
-               client->priv->default_port = default_port;
-               client->priv->max_line_len = max_line_len;
+               priv->host_and_port = g_strdup(host_and_port);
+               priv->default_port = default_port;
+               priv->max_line_len = max_line_len;
        }
 
        return client;
@@ -69,12 +71,11 @@ net_client_new(const gchar *host_and_port, guint16 default_port, gsize max_line_
 gboolean
 net_client_configure(NetClient *client, const gchar *host_and_port, guint16 default_port, gsize 
max_line_len, GError **error)
 {
-       NetClientPrivate *priv;
+       NetClientPrivate *priv = net_client_get_instance_private(client);
        gboolean result;
 
        g_return_val_if_fail(NET_IS_CLIENT(client) && (host_and_port != NULL), FALSE);
 
-       priv = client->priv;
        if (priv->plain_conn != NULL) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_CONNECTED, _("network 
client is already connected"));
                result = FALSE;
@@ -90,13 +91,14 @@ net_client_configure(NetClient *client, const gchar *host_and_port, guint16 defa
 
 
 const gchar *
-net_client_get_host(const NetClient *client)
+net_client_get_host(NetClient * client)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        const gchar *result;
 
        /*lint -e{9005}         cast'ing away const in the next statement is fine */
        if (NET_IS_CLIENT(client)) {
-               result = client->priv->host_and_port;
+               result = priv->host_and_port;
        } else {
                result = NULL;
        }
@@ -107,12 +109,11 @@ net_client_get_host(const NetClient *client)
 gboolean
 net_client_connect(NetClient *client, GError **error)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result = FALSE;
-       NetClientPrivate *priv;
 
        g_return_val_if_fail(NET_IS_CLIENT(client), FALSE);
 
-       priv = client->priv;
        if (priv->plain_conn != NULL) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_CONNECTED, _("network 
client is already connected"));
        } else {
@@ -131,22 +132,15 @@ net_client_connect(NetClient *client, GError **error)
 
 
 void
-net_client_shutdown(const NetClient *client)
+net_client_shutdown(NetClient *client)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
+
        if (NET_IS_CLIENT(client)) {
                /* note: we must unref the GDataInputStream, but *not* the GOutputStream! */
-               if (client->priv->istream != NULL) {
-                       g_object_unref(G_OBJECT(client->priv->istream));
-                       client->priv->istream = NULL;
-               }
-               if (client->priv->tls_conn != NULL) {
-                       g_object_unref(G_OBJECT(client->priv->tls_conn));
-                       client->priv->tls_conn = NULL;
-               }
-               if (client->priv->plain_conn != NULL) {
-                       g_object_unref(G_OBJECT(client->priv->plain_conn));
-                       client->priv->plain_conn = NULL;
-               }
+                g_clear_object(&priv->istream);
+                g_clear_object(&priv->tls_conn);
+                g_clear_object(&priv->plain_conn);
        }
 }
 
@@ -154,9 +148,10 @@ net_client_shutdown(const NetClient *client)
 gboolean
 net_client_is_connected(NetClient *client)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result;
 
-       if (NET_IS_CLIENT(client) && (client->priv->plain_conn != NULL)) {
+       if (NET_IS_CLIENT(client) && (priv->plain_conn != NULL)) {
                result = TRUE;
        } else {
                result = FALSE;
@@ -169,9 +164,10 @@ net_client_is_connected(NetClient *client)
 gboolean
 net_client_is_encrypted(NetClient *client)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result;
 
-       if (net_client_is_connected(client) && (client->priv->tls_conn != NULL)) {
+       if (net_client_is_connected(client) && (priv->tls_conn != NULL)) {
                result = TRUE;
        } else {
                result = FALSE;
@@ -184,24 +180,25 @@ net_client_is_encrypted(NetClient *client)
 gboolean
 net_client_read_line(NetClient *client, gchar **recv_line, GError **error)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result = FALSE;
 
        g_return_val_if_fail(NET_IS_CLIENT(client), FALSE);
 
-       if (client->priv->istream == NULL) {
+       if (priv->istream == NULL) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_NOT_CONNECTED, _("network 
client is not connected"));
        } else {
                gchar *line_buf;
                gsize length;
                GError *read_err = NULL;
 
-               line_buf = g_data_input_stream_read_line(client->priv->istream, &length, NULL, &read_err);
+               line_buf = g_data_input_stream_read_line(priv->istream, &length, NULL, &read_err);
                if (line_buf != NULL) {
                        /* check that the protocol-specific maximum line length is not exceeded */
-                       if ((client->priv->max_line_len > 0U) && (length > client->priv->max_line_len)) {
+                       if ((priv->max_line_len > 0U) && (length > priv->max_line_len)) {
                                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) 
NET_CLIENT_ERROR_LINE_TOO_LONG,
                                        _("reply length %lu exceeds the maximum allowed length %lu"),
-                                       (unsigned long) length, (unsigned long) client->priv->max_line_len);
+                                       (unsigned long) length, (unsigned long) priv->max_line_len);
                                g_free(line_buf);
                        } else {
                                g_debug("R '%s'", line_buf);
@@ -228,11 +225,12 @@ net_client_read_line(NetClient *client, gchar **recv_line, GError **error)
 gboolean
 net_client_write_buffer(NetClient *client, const gchar *buffer, gsize count, GError **error)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result;
 
        g_return_val_if_fail(NET_IS_CLIENT(client) && (buffer != NULL) && (count > 0UL), FALSE);
 
-       if (client->priv->ostream == NULL) {
+       if (priv->ostream == NULL) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_NOT_CONNECTED, _("network 
client is not connected"));
                result = FALSE;
        } else {
@@ -243,9 +241,9 @@ net_client_write_buffer(NetClient *client, const gchar *buffer, gsize count, GEr
                } else {
                        g_debug("W '%.*s'", (int) count, buffer);
                }
-               result = g_output_stream_write_all(client->priv->ostream, buffer, count, &bytes_written, 
NULL, error);
+               result = g_output_stream_write_all(priv->ostream, buffer, count, &bytes_written, NULL, error);
                if (result) {
-                       result = g_output_stream_flush(client->priv->ostream, NULL, error);
+                       result = g_output_stream_flush(priv->ostream, NULL, error);
                }
        }
 
@@ -256,6 +254,7 @@ net_client_write_buffer(NetClient *client, const gchar *buffer, gsize count, GEr
 gboolean
 net_client_vwrite_line(NetClient *client, const gchar *format, va_list args, GError **error)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result;
        GString *buffer;
 
@@ -263,7 +262,7 @@ net_client_vwrite_line(NetClient *client, const gchar *format, va_list args, GEr
 
        buffer = g_string_new(NULL);
        g_string_vprintf(buffer, format, args);
-       if ((client->priv->max_line_len > 0U) && (buffer->len > client->priv->max_line_len)) {
+       if ((priv->max_line_len > 0U) && (buffer->len > priv->max_line_len)) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_LINE_TOO_LONG, _("line too 
long"));
                result = FALSE;
        } else {
@@ -318,6 +317,7 @@ net_client_execute(NetClient *client, gchar **response, const gchar *request_fmt
 gboolean
 net_client_set_cert_from_pem(NetClient *client, const gchar *pem_data, GError **error)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result = FALSE;
        gnutls_x509_crt_t cert;
        int res;
@@ -325,10 +325,7 @@ net_client_set_cert_from_pem(NetClient *client, const gchar *pem_data, GError **
        g_return_val_if_fail(NET_IS_CLIENT(client) && (pem_data != NULL), FALSE);
 
        /* always free any existing certificate */
-       if (client->priv->certificate != NULL) {
-               g_object_unref(G_OBJECT(client->priv->certificate));
-               client->priv->certificate = NULL;
-       }
+       g_clear_object(&priv->certificate);
 
        /* load the certificate */
        res = gnutls_x509_crt_init(&cert);
@@ -397,8 +394,8 @@ net_client_set_cert_from_pem(NetClient *client, const gchar *pem_data, GError **
                                        }
 
                                        if (res == GNUTLS_E_SUCCESS) {
-                                               client->priv->certificate = 
g_tls_certificate_new_from_pem(pem_buf, -1, error);
-                                               if (client->priv->certificate != NULL) {
+                                               priv->certificate = g_tls_certificate_new_from_pem(pem_buf, 
-1, error);
+                                               if (priv->certificate != NULL) {
                                                        result = TRUE;
                                                }
                                        }
@@ -442,32 +439,33 @@ net_client_set_cert_from_file(NetClient *client, const gchar *pem_path, GError *
 gboolean
 net_client_start_tls(NetClient *client, GError **error)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
        gboolean result = FALSE;
 
        g_return_val_if_fail(NET_IS_CLIENT(client), FALSE);
 
-       if (client->priv->plain_conn == NULL) {
+       if (priv->plain_conn == NULL) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_NOT_CONNECTED, _("not 
connected"));
-       } else if (client->priv->tls_conn != NULL) {
+       } else if (priv->tls_conn != NULL) {
                g_set_error(error, NET_CLIENT_ERROR_QUARK, (gint) NET_CLIENT_ERROR_TLS_ACTIVE, _("connection 
is already encrypted"));
        } else {
-               client->priv->tls_conn = g_tls_client_connection_new(G_IO_STREAM(client->priv->plain_conn), 
NULL, error);
-               if (client->priv->tls_conn != NULL) {
-                       if (client->priv->certificate != NULL) {
-                               g_tls_connection_set_certificate(G_TLS_CONNECTION(client->priv->tls_conn), 
client->priv->certificate);
+               priv->tls_conn = g_tls_client_connection_new(G_IO_STREAM(priv->plain_conn), NULL, error);
+               if (priv->tls_conn != NULL) {
+                       if (priv->certificate != NULL) {
+                               g_tls_connection_set_certificate(G_TLS_CONNECTION(priv->tls_conn), 
priv->certificate);
                        }
-                       (void) g_signal_connect(G_OBJECT(client->priv->tls_conn), "accept-certificate", 
G_CALLBACK(cert_accept_cb), client);
-                       result = g_tls_connection_handshake(G_TLS_CONNECTION(client->priv->tls_conn), NULL, 
error);
+                       (void) g_signal_connect(G_OBJECT(priv->tls_conn), "accept-certificate", 
G_CALLBACK(cert_accept_cb), client);
+                       result = g_tls_connection_handshake(G_TLS_CONNECTION(priv->tls_conn), NULL, error);
                        if (result) {
-                               
g_filter_input_stream_set_close_base_stream(G_FILTER_INPUT_STREAM(client->priv->istream), FALSE);
-                               g_object_unref(G_OBJECT(client->priv->istream));                /* unref the 
plain connection's stream */
-                               client->priv->istream = 
g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(client->priv->tls_conn)));
-                               g_data_input_stream_set_newline_type(client->priv->istream, 
G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
-                               client->priv->ostream = 
g_io_stream_get_output_stream(G_IO_STREAM(client->priv->tls_conn));
+                               
g_filter_input_stream_set_close_base_stream(G_FILTER_INPUT_STREAM(priv->istream), FALSE);
+                               g_object_unref(G_OBJECT(priv->istream));                /* unref the plain 
connection's stream */
+                               priv->istream = 
g_data_input_stream_new(g_io_stream_get_input_stream(G_IO_STREAM(priv->tls_conn)));
+                               g_data_input_stream_set_newline_type(priv->istream, 
G_DATA_STREAM_NEWLINE_TYPE_CR_LF);
+                               priv->ostream = g_io_stream_get_output_stream(G_IO_STREAM(priv->tls_conn));
                                g_debug("connection is encrypted");
                        } else {
-                               g_object_unref(G_OBJECT(client->priv->tls_conn));
-                               client->priv->tls_conn = NULL;
+                               g_object_unref(G_OBJECT(priv->tls_conn));
+                               priv->tls_conn = NULL;
                        }
                }
        }
@@ -479,9 +477,11 @@ net_client_start_tls(NetClient *client, GError **error)
 gboolean
 net_client_set_timeout(NetClient *client, guint timeout_secs)
 {
+       NetClientPrivate *priv  = net_client_get_instance_private(client);
+
        g_return_val_if_fail(NET_IS_CLIENT(client), FALSE);
 
-       g_socket_client_set_timeout(client->priv->sock, timeout_secs);
+       g_socket_client_set_timeout(priv->sock, timeout_secs);
        return TRUE;
 }
 
@@ -507,9 +507,8 @@ net_client_class_init(NetClientClass *klass)
 static void
 net_client_init(NetClient *self)
 {
-        NetClientPrivate *priv;
+        NetClientPrivate *priv = net_client_get_instance_private(self);
 
-       self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE(self, NET_CLIENT_TYPE, NetClientPrivate);
        priv->sock = g_socket_client_new();
        if (priv->sock != NULL) {
                g_socket_client_set_timeout(priv->sock, 180U);
@@ -520,8 +519,8 @@ net_client_init(NetClient *self)
 static void
 net_client_dispose(GObject *object)
 {
-       const NetClient *client = NET_CLIENT(object);
-        NetClientPrivate *priv = client->priv;
+       NetClient *client = NET_CLIENT(object);
+        NetClientPrivate *priv = net_client_get_instance_private(client);
        const GObjectClass *parent_class = G_OBJECT_CLASS(net_client_parent_class);
 
        net_client_shutdown(client);
@@ -536,8 +535,8 @@ net_client_dispose(GObject *object)
 static void
 net_client_finalise(GObject *object)
 {
-       const NetClient *client = NET_CLIENT(object);
-        NetClientPrivate *priv = client->priv;
+       NetClient *client = NET_CLIENT(object);
+        NetClientPrivate *priv = net_client_get_instance_private(client);
        const GObjectClass *parent_class = G_OBJECT_CLASS(net_client_parent_class);
 
        g_debug("finalised connection to %s", priv->host_and_port);
diff --git a/libnetclient/net-client.h b/libnetclient/net-client.h
index e92f9b8..9fcb870 100644
--- a/libnetclient/net-client.h
+++ b/libnetclient/net-client.h
@@ -24,29 +24,21 @@
 G_BEGIN_DECLS
 
 
-#define NET_CLIENT_TYPE                                                (net_client_get_type())
-#define NET_CLIENT(obj)                                                (G_TYPE_CHECK_INSTANCE_CAST((obj), 
NET_CLIENT_TYPE, NetClient))
-#define NET_IS_CLIENT(obj)                                     (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
NET_CLIENT_TYPE))
-#define NET_CLIENT_CLASS(klass)                                (G_TYPE_CHECK_CLASS_CAST((klass), 
NET_CLIENT_TYPE, NetClientClass))
-#define NET_IS_CLIENT_CLASS(klass)                     (G_TYPE_CHECK_CLASS_TYPE((klass), NET_CLIENT_TYPE))
-#define NET_CLIENT_GET_CLASS(obj)                      (G_TYPE_INSTANCE_GET_CLASS((obj), NET_CLIENT_TYPE, 
NetClientClass))
+#define NET_CLIENT_TYPE net_client_get_type()
 
-#define NET_CLIENT_ERROR_QUARK                         (g_quark_from_static_string("net-client"))
+G_DECLARE_DERIVABLE_TYPE(NetClient,
+                         net_client,
+                         NET,
+                         CLIENT,
+                         GObject)
+
+#define NET_CLIENT_ERROR_QUARK g_quark_from_static_string("net-client")
 
 
-typedef struct _NetClient NetClient;
-typedef struct _NetClientClass NetClientClass;
-typedef struct _NetClientPrivate NetClientPrivate;
 typedef enum _NetClientError NetClientError;
 typedef enum _NetClientCryptMode NetClientCryptMode;
 
 
-struct _NetClient {
-    GObject parent;
-    NetClientPrivate *priv;
-};
-
-
 struct _NetClientClass {
     GObjectClass parent;
 };
@@ -113,7 +105,7 @@ gboolean net_client_configure(NetClient *client, const gchar *host_and_port, gui
  *
  * @note The function returns the value of @em host_and_port set by net_client_new() or 
net_client_configure().
  */
-const gchar *net_client_get_host(const NetClient *client);
+const gchar *net_client_get_host(NetClient *client);
 
 
 /** @brief Connect a network client
@@ -134,7 +126,7 @@ gboolean net_client_connect(NetClient *client, GError **error);
  * Shut down the connection.  Note that it is usually not necessary to call this function, as the connection 
will be shut down when
  * the client is destroyed by calling <tt>g_object_unref()</tt>.
  */
-void net_client_shutdown(const NetClient *client);
+void net_client_shutdown(NetClient *client);
 
 
 /** @brief Check if a network client is connected


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