[librest/wip/teuf/gtask: 9/28] rest-proxy: Use G_DEFINE_TYPE_WITH_PRIVATE



commit e7b3ed2cc407d34a3e35d59f3c13d68c9e682c0d
Author: Timm Bäder <mail baedert org>
Date:   Sat Apr 23 13:13:01 2016 +0200

    rest-proxy: Use G_DEFINE_TYPE_WITH_PRIVATE

 configure.ac       |    2 +-
 rest/oauth-proxy.c |   10 +++++-----
 rest/rest-proxy.c  |   35 +++++++++++------------------------
 3 files changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 10afad8..4d92dfc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,7 +40,7 @@ AM_PROG_CC_C_O
 LT_PREREQ([2.2.6])
 LT_INIT([disable-static])
 
-PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.36)
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.38)
 PKG_CHECK_MODULES(SOUP, libsoup-2.4)
 PKG_CHECK_MODULES(XML, libxml-2.0)
 PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
diff --git a/rest/oauth-proxy.c b/rest/oauth-proxy.c
index cd76a41..1ad597b 100644
--- a/rest/oauth-proxy.c
+++ b/rest/oauth-proxy.c
@@ -263,11 +263,11 @@ oauth_proxy_new (const char *consumer_key,
  */
 RestProxy *
 oauth_proxy_new_with_token (const char *consumer_key,
-                 const char *consumer_secret,
-                 const char *token,
-                 const char *token_secret,
-                 const gchar *url_format,
-                 gboolean binding_required)
+                            const char *consumer_secret,
+                            const char *token,
+                            const char *token_secret,
+                            const gchar *url_format,
+                            gboolean binding_required)
 {
   return g_object_new (OAUTH_TYPE_PROXY,
                        "consumer-key", consumer_key,
diff --git a/rest/rest-proxy.c b/rest/rest-proxy.c
index 0342892..d79d204 100644
--- a/rest/rest-proxy.c
+++ b/rest/rest-proxy.c
@@ -33,10 +33,8 @@
 #include "rest-proxy.h"
 #include "rest-private.h"
 
-G_DEFINE_TYPE (RestProxy, rest_proxy, G_TYPE_OBJECT)
 
-#define GET_PRIVATE(o) \
-  (G_TYPE_INSTANCE_GET_PRIVATE ((o), REST_TYPE_PROXY, RestProxyPrivate))
+#define GET_PRIVATE(o) rest_proxy_get_instance_private(REST_PROXY(o))
 
 typedef struct _RestProxyPrivate RestProxyPrivate;
 
@@ -53,6 +51,9 @@ struct _RestProxyPrivate {
   char *ssl_ca_file;
 };
 
+
+G_DEFINE_TYPE_WITH_PRIVATE (RestProxy, rest_proxy, G_TYPE_OBJECT)
+
 enum
 {
   PROP0 = 0,
@@ -279,8 +280,6 @@ rest_proxy_class_init (RestProxyClass *klass)
 
   _rest_setup_debugging ();
 
-  g_type_class_add_private (klass, sizeof (RestProxyPrivate));
-
   object_class->get_property = rest_proxy_get_property;
   object_class->set_property = rest_proxy_set_property;
   object_class->dispose = rest_proxy_dispose;
@@ -532,12 +531,10 @@ rest_proxy_set_user_agent (RestProxy  *proxy,
 const gchar *
 rest_proxy_get_user_agent (RestProxy *proxy)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_val_if_fail (REST_IS_PROXY (proxy), NULL);
 
-  priv = GET_PRIVATE (proxy);
-
   return priv->user_agent;
 }
 
@@ -566,10 +563,9 @@ rest_proxy_get_user_agent (RestProxy *proxy)
 void
 rest_proxy_add_soup_feature (RestProxy *proxy, SoupSessionFeature *feature)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_if_fail (REST_IS_PROXY(proxy));
-  priv = GET_PRIVATE (proxy);
   g_return_if_fail (priv->session != NULL);
 
   soup_session_add_feature (priv->session, feature);
@@ -606,24 +602,20 @@ rest_proxy_new_call (RestProxy *proxy)
 gboolean
 _rest_proxy_get_binding_required (RestProxy *proxy)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_val_if_fail (REST_IS_PROXY (proxy), FALSE);
 
-  priv = GET_PRIVATE (proxy);
-
   return priv->binding_required;
 }
 
 const gchar *
 _rest_proxy_get_bound_url (RestProxy *proxy)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_val_if_fail (REST_IS_PROXY (proxy), NULL);
 
-  priv = GET_PRIVATE (proxy);
-
   if (!priv->url && !priv->binding_required)
   {
     priv->url = g_strdup (priv->url_format);
@@ -704,13 +696,11 @@ _rest_proxy_queue_message (RestProxy   *proxy,
                            SoupSessionCallback callback,
                            gpointer user_data)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_if_fail (REST_IS_PROXY (proxy));
   g_return_if_fail (SOUP_IS_MESSAGE (message));
 
-  priv = GET_PRIVATE (proxy);
-
   soup_session_queue_message (priv->session,
                               message,
                               callback,
@@ -721,12 +711,11 @@ void
 _rest_proxy_cancel_message (RestProxy   *proxy,
                             SoupMessage *message)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_if_fail (REST_IS_PROXY (proxy));
   g_return_if_fail (SOUP_IS_MESSAGE (message));
 
-  priv = GET_PRIVATE (proxy);
   soup_session_cancel_message (priv->session,
                                message,
                                SOUP_STATUS_CANCELLED);
@@ -736,12 +725,10 @@ guint
 _rest_proxy_send_message (RestProxy   *proxy,
                           SoupMessage *message)
 {
-  RestProxyPrivate *priv;
+  RestProxyPrivate *priv = GET_PRIVATE (proxy);
 
   g_return_val_if_fail (REST_IS_PROXY (proxy), 0);
   g_return_val_if_fail (SOUP_IS_MESSAGE (message), 0);
 
-  priv = GET_PRIVATE (proxy);
-
   return soup_session_send_message (priv->session, message);
 }


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