Use G_DEFINE_INTERFACE and G_DEFINE_BOXED_TYPE
authorDan Winship <danw@gnome.org>
Wed, 4 Jul 2012 16:44:37 +0000 (12:44 -0400)
committerDan Winship <danw@gnome.org>
Fri, 13 Jul 2012 18:18:36 +0000 (14:18 -0400)
12 files changed:
libsoup/soup-cookie.c
libsoup/soup-date.c
libsoup/soup-message-body.c
libsoup/soup-message-headers.c
libsoup/soup-multipart.c
libsoup/soup-password-manager.c
libsoup/soup-proxy-resolver.c
libsoup/soup-proxy-uri-resolver.c
libsoup/soup-server.c
libsoup/soup-session-feature.c
libsoup/soup-uri.c
libsoup/soup-value-utils.c

index f148afa..7d6b583 100755 (executable)
  * 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:
index a8a32e9..cf338e5 100644 (file)
@@ -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)
index cfcc0bc..6cff98d 100644 (file)
@@ -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)
index 60033e1..eb50034 100644 (file)
@@ -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:
index 6469490..a88281f 100644 (file)
@@ -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)
index 5f629ee..fed0156 100644 (file)
 #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;
 }
 
 /**
index 837a1f7..ca60411 100644 (file)
 #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.
index 556ba78..01f4f4f 100644 (file)
 #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;
 }
 
 /**
index 8ba0eaa..e6a7711 100644 (file)
@@ -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:
index f572a3a..e7fe453 100644 (file)
  * 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;
index 24cd6b0..c2fc434 100644 (file)
@@ -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)
index 41f8c92..d9f6bdc 100644 (file)
@@ -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)