[balsa] Declare LibBalsaImapServer final



commit 20494f10ddd27b229e43577253c0501d27c466df
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Jun 8 11:19:49 2019 -0400

    Declare LibBalsaImapServer final
    
    Use G_DECLARE_FINAL_TYPE to declare LibBalsaImapServer
    
    The object was already private.
    
    * libbalsa/imap-server.c (libbalsa_imap_server_set_username),
    (libbalsa_imap_server_set_host), (libbalsa_imap_server_class_init),
    (libbalsa_imap_server_finalize):
    * libbalsa/imap-server.h:

 ChangeLog              | 11 +++++++++++
 libbalsa/imap-server.c | 48 +++++++-----------------------------------------
 libbalsa/imap-server.h | 21 +++++++--------------
 3 files changed, 25 insertions(+), 55 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 34f356d3a..bdfaab762 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-06-08  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Use G_DECLARE_FINAL_TYPE to declare LibBalsaImapServer
+
+       The object was already private.
+
+       * libbalsa/imap-server.c (libbalsa_imap_server_set_username),
+       (libbalsa_imap_server_set_host), (libbalsa_imap_server_class_init),
+       (libbalsa_imap_server_finalize):
+       * libbalsa/imap-server.h:
+
 2019-06-07  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Use G_DECLARE_DERIVABLE_TYPE to declare LibBalsaServer
diff --git a/libbalsa/imap-server.c b/libbalsa/imap-server.c
index 4fd1f38f2..b5ea2d98d 100644
--- a/libbalsa/imap-server.c
+++ b/libbalsa/imap-server.c
@@ -32,7 +32,6 @@
 
 #include "libbalsa.h"
 #include "libbalsa-conf.h"
-#include "server.h"
 
 #include "imap-handle.h"
 #include "imap-commands.h"
@@ -41,16 +40,14 @@
 /** wait 60 seconds for packets */
 #define IMAP_CMD_TIMEOUT (60*1000)
 
-static LibBalsaServerClass *parent_class = NULL;
-
-struct LibBalsaImapServer_ {
+struct _LibBalsaImapServer {
     LibBalsaServer server;
-    
+
     guint connection_cleanup_id;
     gchar *key;
     guint max_connections;
     gboolean offline_mode;
-    
+
     GMutex lock; /* protects the following members */
     guint used_connections;
     GList *used_handles;
@@ -64,11 +61,6 @@ struct LibBalsaImapServer_ {
     gboolean use_idle;  /**< IDLE will work: no dummy firewall on the way */
 };
 
-typedef struct LibBalsaImapServerClass_ {
-    LibBalsaServerClass parent_class;
-
-} LibBalsaImapServerClass;
-
 static void libbalsa_imap_server_class_init(LibBalsaImapServerClass * klass);
 static void libbalsa_imap_server_init(LibBalsaImapServer * server);
 static void libbalsa_imap_server_finalize(GObject * object);
@@ -102,31 +94,7 @@ static int by_last_user(gconstpointer a, gconstpointer b)
     return ((struct handle_info*)a)->last_user != b;
 }
 
-GType
-libbalsa_imap_server_get_type(void)
-{
-    static GType server_type = 0;
-
-    if (!server_type) {
-        static const GTypeInfo server_info = {
-            sizeof(LibBalsaImapServerClass),
-            NULL,               /* base_init */
-            NULL,               /* base_finalize */
-            (GClassInitFunc) libbalsa_imap_server_class_init,
-            NULL,               /* class_finalize */
-            NULL,               /* class_data */
-            sizeof(LibBalsaImapServer),
-            0,                  /* n_preallocs */
-            (GInstanceInitFunc) libbalsa_imap_server_init
-        };
-
-        server_type =
-            g_type_register_static(LIBBALSA_TYPE_SERVER, "LibBalsaImapServer",
-                                   &server_info, 0);
-    }
-
-    return server_type;
-}
+G_DEFINE_TYPE(LibBalsaImapServer, libbalsa_imap_server, LIBBALSA_TYPE_SERVER)
 
 static void libbalsa_imap_server_set_username(LibBalsaServer * server,
                                               const gchar * name)
@@ -148,7 +116,7 @@ static void libbalsa_imap_server_set_username(LibBalsaServer * server,
         g_hash_table_insert(imap_servers, imap_server->key, imap_server);
         g_mutex_unlock(&imap_servers_lock);
     }
-    (parent_class)->set_username(server, name);
+    LIBBALSA_SERVER_CLASS(libbalsa_imap_server_parent_class)->set_username(server, name);
 }
 
 static void
@@ -173,7 +141,7 @@ libbalsa_imap_server_set_host(LibBalsaServer    *server,
         g_hash_table_insert(imap_servers, imap_server->key, imap_server);
         g_mutex_unlock(&imap_servers_lock);
     }
-    (parent_class)->set_host(server, host, security);
+    LIBBALSA_SERVER_CLASS(libbalsa_imap_server_parent_class)->set_host(server, host, security);
 }
 
 static void
@@ -185,8 +153,6 @@ libbalsa_imap_server_class_init(LibBalsaImapServerClass * klass)
     object_class = G_OBJECT_CLASS(klass);
     server_class = LIBBALSA_SERVER_CLASS(klass);
 
-    parent_class = g_type_class_peek_parent(klass);
-
     object_class->finalize = libbalsa_imap_server_finalize;
 
     server_class->set_username = libbalsa_imap_server_set_username;
@@ -233,7 +199,7 @@ libbalsa_imap_server_finalize(GObject * object)
     g_mutex_clear(&imap_server->lock);
     g_free(imap_server->key); imap_server->key = NULL;
 
-    G_OBJECT_CLASS(parent_class)->finalize(object);
+    G_OBJECT_CLASS(libbalsa_imap_server_parent_class)->finalize(object);
 }
 
 
diff --git a/libbalsa/imap-server.h b/libbalsa/imap-server.h
index 27fac1eb6..88728cce5 100644
--- a/libbalsa/imap-server.h
+++ b/libbalsa/imap-server.h
@@ -21,22 +21,15 @@
 #define __IMAP_SERVER_H__
 
 #include <glib-object.h>
+#include "server.h"
 
-#define LIBBALSA_TYPE_IMAP_SERVER \
-    (libbalsa_imap_server_get_type())
-#define LIBBALSA_IMAP_SERVER(obj) \
-    (G_TYPE_CHECK_INSTANCE_CAST(obj, LIBBALSA_TYPE_IMAP_SERVER, \
-                                LibBalsaImapServer))
-#define LIBBALSA_IMAP_SERVER_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_CAST(klass, LIBBALSA_TYPE_IMAP_SERVER, \
-                             LibBalsaImapServerClass))
-#define LIBBALSA_IS_IMAP_SERVER(obj) \
-    (G_TYPE_CHECK_INSTANCE_TYPE(obj, LIBBALSA_TYPE_IMAP_SERVER))
-#define LIBBALSA_IS_IMAP_SERVER_CLASS(klass) \
-    (G_TYPE_CHECK_CLASS_TYPE(klass, LIBBALSA_TYPE_IMAP_SERVER))
+#define LIBBALSA_TYPE_IMAP_SERVER (libbalsa_imap_server_get_type())
 
-GType libbalsa_imap_server_get_type(void);
-typedef struct LibBalsaImapServer_ LibBalsaImapServer;
+G_DECLARE_FINAL_TYPE(LibBalsaImapServer,
+                     libbalsa_imap_server,
+                     LIBBALSA,
+                     IMAP_SERVER,
+                     LibBalsaServer)
 
 LibBalsaImapServer* libbalsa_imap_server_new(const gchar *username,
                                              const gchar *host);


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