[libsoup] Use G_DEFINE_INTERFACE and G_DEFINE_BOXED_TYPE



commit 0d0b2f7717f88c8e837399548bfa2ebfc12c8587
Author: Dan Winship <danw gnome org>
Date:   Wed Jul 4 12:44:37 2012 -0400

    Use G_DEFINE_INTERFACE and G_DEFINE_BOXED_TYPE

 libsoup/soup-cookie.c             |   15 +--------------
 libsoup/soup-date.c               |   15 +--------------
 libsoup/soup-message-body.c       |   30 ++----------------------------
 libsoup/soup-message-headers.c    |   15 +--------------
 libsoup/soup-multipart.c          |   15 +--------------
 libsoup/soup-password-manager.c   |   24 ++++++------------------
 libsoup/soup-proxy-resolver.c     |   27 +++++----------------------
 libsoup/soup-proxy-uri-resolver.c |   21 ++++-----------------
 libsoup/soup-server.c             |   15 +--------------
 libsoup/soup-session-feature.c    |   24 +++---------------------
 libsoup/soup-uri.c                |   16 +---------------
 libsoup/soup-value-utils.c        |   18 +++---------------
 12 files changed, 29 insertions(+), 206 deletions(-)
---
diff --git a/libsoup/soup-cookie.c b/libsoup/soup-cookie.c
index f148afa..7d6b583 100755
--- a/libsoup/soup-cookie.c
+++ b/libsoup/soup-cookie.c
@@ -74,20 +74,7 @@
  * Since: 2.24
  **/
 
-GType
-soup_cookie_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupCookie"),
-			(GBoxedCopyFunc) soup_cookie_copy,
-			(GBoxedFreeFunc) soup_cookie_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupCookie, soup_cookie, soup_cookie_copy, soup_cookie_free)
 
 /**
  * soup_cookie_copy:
diff --git a/libsoup/soup-date.c b/libsoup/soup-date.c
index a8a32e9..cf338e5 100644
--- a/libsoup/soup-date.c
+++ b/libsoup/soup-date.c
@@ -88,20 +88,7 @@ days_in_month (int month, int year)
 		return nonleap_days_in_month[month];
 }
 
-GType
-soup_date_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupDate"),
-			(GBoxedCopyFunc) soup_date_copy,
-			(GBoxedFreeFunc) soup_date_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupDate, soup_date, soup_date_copy, soup_date_free)
 
 static void
 soup_date_fixup (SoupDate *date)
diff --git a/libsoup/soup-message-body.c b/libsoup/soup-message-body.c
index cfcc0bc..6cff98d 100644
--- a/libsoup/soup-message-body.c
+++ b/libsoup/soup-message-body.c
@@ -328,20 +328,7 @@ soup_buffer_get_as_bytes (SoupBuffer *buffer)
 					   copy);
 }
 
-GType
-soup_buffer_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupBuffer"),
-			(GBoxedCopyFunc) soup_buffer_copy,
-			(GBoxedFreeFunc) soup_buffer_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupBuffer, soup_buffer, soup_buffer_copy, soup_buffer_free)
 
 
 /**
@@ -753,17 +740,4 @@ soup_message_body_free (SoupMessageBody *body)
 	}
 }
 
-GType
-soup_message_body_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupMessageBody"),
-			(GBoxedCopyFunc) soup_message_body_copy,
-			(GBoxedFreeFunc) soup_message_body_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupMessageBody, soup_message_body, soup_message_body_copy, soup_message_body_free)
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 60033e1..eb50034 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -108,20 +108,7 @@ soup_message_headers_free (SoupMessageHeaders *hdrs)
 	}
 }
 
-GType
-soup_message_headers_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupMessageHeaders"),
-			(GBoxedCopyFunc) soup_message_headers_copy,
-			(GBoxedFreeFunc) soup_message_headers_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupMessageHeaders, soup_message_headers, soup_message_headers_copy, soup_message_headers_free)
 
 /**
  * soup_message_headers_clear:
diff --git a/libsoup/soup-multipart.c b/libsoup/soup-multipart.c
index 6469490..a88281f 100644
--- a/libsoup/soup-multipart.c
+++ b/libsoup/soup-multipart.c
@@ -488,17 +488,4 @@ soup_multipart_copy (SoupMultipart *multipart)
 	return copy;
 }
 
-GType
-soup_multipart_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupMultipart"),
-			(GBoxedCopyFunc) soup_multipart_copy,
-			(GBoxedFreeFunc) soup_multipart_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupMultipart, soup_multipart, soup_multipart_copy, soup_multipart_free)
diff --git a/libsoup/soup-password-manager.c b/libsoup/soup-password-manager.c
index 5f629ee..fed0156 100644
--- a/libsoup/soup-password-manager.c
+++ b/libsoup/soup-password-manager.c
@@ -14,25 +14,13 @@
 #include "soup-password-manager.h"
 #include "soup-session-feature.h"
 
-GType
-soup_password_manager_get_type (void)
+G_DEFINE_INTERFACE_WITH_CODE (SoupPasswordManager, soup_password_manager, G_TYPE_OBJECT,
+			      g_type_interface_add_prerequisite (g_define_type_id, SOUP_TYPE_SESSION_FEATURE);
+			      )
+
+static void
+soup_password_manager_default_init (SoupPasswordManagerInterface *iface)
 {
-  static volatile gsize g_define_type_id__volatile = 0;
-  if (g_once_init_enter (&g_define_type_id__volatile))
-    {
-      GType g_define_type_id =
-        g_type_register_static_simple (G_TYPE_INTERFACE,
-                                       g_intern_static_string ("SoupPasswordManager"),
-                                       sizeof (SoupPasswordManagerInterface),
-                                       (GClassInitFunc)NULL,
-                                       0,
-                                       (GInstanceInitFunc)NULL,
-                                       (GTypeFlags) 0);
-      g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT);
-      g_type_interface_add_prerequisite (g_define_type_id, SOUP_TYPE_SESSION_FEATURE);
-      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
-    }
-  return g_define_type_id__volatile;
 }
 
 /**
diff --git a/libsoup/soup-proxy-resolver.c b/libsoup/soup-proxy-resolver.c
index 837a1f7..ca60411 100644
--- a/libsoup/soup-proxy-resolver.c
+++ b/libsoup/soup-proxy-resolver.c
@@ -16,29 +16,12 @@
 #include "soup-session-feature.h"
 #include "soup-uri.h"
 
-static void soup_proxy_resolver_interface_init (GTypeInterface *iface);
+static void soup_proxy_resolver_default_init (SoupProxyResolverInterface *iface);
 static void soup_proxy_resolver_uri_resolver_interface_init (SoupProxyURIResolverInterface *uri_resolver_interface);
 
-GType
-soup_proxy_resolver_get_type (void)
-{
-  static volatile gsize g_define_type_id__volatile = 0;
-  if (g_once_init_enter (&g_define_type_id__volatile))
-    {
-      GType g_define_type_id =
-        g_type_register_static_simple (G_TYPE_INTERFACE,
-                                       g_intern_static_string ("SoupProxyResolver"),
-                                       sizeof (SoupProxyResolverInterface),
-                                       (GClassInitFunc)soup_proxy_resolver_interface_init,
-                                       0,
-                                       (GInstanceInitFunc)NULL,
-                                       (GTypeFlags) 0);
-      g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT);
-      g_type_interface_add_prerequisite (g_define_type_id, SOUP_TYPE_SESSION_FEATURE);
-      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
-    }
-  return g_define_type_id__volatile;
-}
+G_DEFINE_INTERFACE_WITH_CODE (SoupProxyResolver, soup_proxy_resolver, G_TYPE_OBJECT,
+			      g_type_interface_add_prerequisite (g_define_type_id, SOUP_TYPE_SESSION_FEATURE);
+			      )
 
 static void
 proxy_resolver_interface_check (gpointer func_data, gpointer g_iface)
@@ -63,7 +46,7 @@ proxy_resolver_interface_check (gpointer func_data, gpointer g_iface)
 
 
 static void
-soup_proxy_resolver_interface_init (GTypeInterface *iface)
+soup_proxy_resolver_default_init (SoupProxyResolverInterface *iface)
 {
 	/* Add an interface_check where we can kludgily add the
 	 * SoupProxyURIResolver interface to all SoupProxyResolvers.
diff --git a/libsoup/soup-proxy-uri-resolver.c b/libsoup/soup-proxy-uri-resolver.c
index 556ba78..01f4f4f 100644
--- a/libsoup/soup-proxy-uri-resolver.c
+++ b/libsoup/soup-proxy-uri-resolver.c
@@ -12,24 +12,11 @@
 #include "soup-proxy-uri-resolver.h"
 #include "soup-session-feature.h"
 
-GType
-soup_proxy_uri_resolver_get_type (void)
+G_DEFINE_INTERFACE (SoupProxyURIResolver, soup_proxy_uri_resolver, G_TYPE_OBJECT)
+
+static void
+soup_proxy_uri_resolver_default_init (SoupProxyURIResolverInterface *iface)
 {
-  static volatile gsize g_define_type_id__volatile = 0;
-  if (g_once_init_enter (&g_define_type_id__volatile))
-    {
-      GType g_define_type_id =
-        g_type_register_static_simple (G_TYPE_INTERFACE,
-                                       g_intern_static_string ("SoupProxyURIResolver"),
-                                       sizeof (SoupProxyURIResolverInterface),
-                                       (GClassInitFunc)NULL,
-                                       0,
-                                       (GInstanceInitFunc)NULL,
-                                       (GTypeFlags) 0);
-      g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT);
-      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
-    }
-  return g_define_type_id__volatile;
 }
 
 /**
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index 8ba0eaa..e6a7711 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -1137,20 +1137,7 @@ soup_server_get_async_context (SoupServer *server)
  * also be of use in some situations (eg, tracking when multiple
  * requests are made on the same connection).
  **/
-GType
-soup_client_context_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupClientContext"),
-			(GBoxedCopyFunc) soup_client_context_ref,
-			(GBoxedFreeFunc) soup_client_context_unref);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupClientContext, soup_client_context, soup_client_context_ref, soup_client_context_unref)
 
 /**
  * soup_client_context_get_socket:
diff --git a/libsoup/soup-session-feature.c b/libsoup/soup-session-feature.c
index f572a3a..e7fe453 100644
--- a/libsoup/soup-session-feature.c
+++ b/libsoup/soup-session-feature.c
@@ -51,33 +51,15 @@
  * Since: 2.24
  **/
 
-static void soup_session_feature_interface_init (SoupSessionFeatureInterface *interface);
+static void soup_session_feature_default_init (SoupSessionFeatureInterface *interface);
 
 static void attach (SoupSessionFeature *feature, SoupSession *session);
 static void detach (SoupSessionFeature *feature, SoupSession *session);
 
-GType
-soup_session_feature_get_type (void)
-{
-  static volatile gsize g_define_type_id__volatile = 0;
-  if (g_once_init_enter (&g_define_type_id__volatile))
-    {
-      GType g_define_type_id =
-        g_type_register_static_simple (G_TYPE_INTERFACE,
-                                       g_intern_static_string ("SoupSessionFeature"),
-                                       sizeof (SoupSessionFeatureInterface),
-                                       (GClassInitFunc)soup_session_feature_interface_init,
-                                       0,
-                                       (GInstanceInitFunc)NULL,
-                                       (GTypeFlags) 0);
-      g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_OBJECT);
-      g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
-    }
-  return g_define_type_id__volatile;
-}
+G_DEFINE_INTERFACE (SoupSessionFeature, soup_session_feature, G_TYPE_OBJECT)
 
 static void
-soup_session_feature_interface_init (SoupSessionFeatureInterface *interface)
+soup_session_feature_default_init (SoupSessionFeatureInterface *interface)
 {
 	interface->attach = attach;
 	interface->detach = detach;
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 24cd6b0..c2fc434 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -1220,18 +1220,4 @@ soup_uri_host_equal (gconstpointer v1, gconstpointer v2)
 	return g_ascii_strcasecmp (one->host, two->host) == 0;
 }
 
-
-GType
-soup_uri_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupURI"),
-			(GBoxedCopyFunc) soup_uri_copy,
-			(GBoxedFreeFunc) soup_uri_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+G_DEFINE_BOXED_TYPE (SoupURI, soup_uri, soup_uri_copy, soup_uri_free)
diff --git a/libsoup/soup-value-utils.c b/libsoup/soup-value-utils.c
index 41f8c92..d9f6bdc 100644
--- a/libsoup/soup-value-utils.c
+++ b/libsoup/soup-value-utils.c
@@ -482,20 +482,8 @@ soup_byte_array_free (GByteArray *ba)
 /**
  * SOUP_TYPE_BYTE_ARRAY:
  *
- * glib does not define a #GType for #GByteArray, so libsoup
+ * glib did not used to define a #GType for #GByteArray, so libsoup
  * defines this one itself.
  **/
-GType
-soup_byte_array_get_type (void)
-{
-	static volatile gsize type_volatile = 0;
-
-	if (g_once_init_enter (&type_volatile)) {
-		GType type = g_boxed_type_register_static (
-			g_intern_static_string ("SoupByteArray"),
-			(GBoxedCopyFunc) soup_byte_array_copy,
-			(GBoxedFreeFunc) soup_byte_array_free);
-		g_once_init_leave (&type_volatile, type);
-	}
-	return type_volatile;
-}
+typedef GByteArray SoupByteArray;
+G_DEFINE_BOXED_TYPE (SoupByteArray, soup_byte_array, soup_byte_array_copy, soup_byte_array_free)



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