[gupnp/wip/phako/new-api: 7/17] service-proxy: Move Action into its own file



commit 7411cb31f1f09d3f2f38a1209133fcd41b585fb0
Author: Jens Georg <mail jensge org>
Date:   Fri Dec 14 23:14:58 2018 +0100

    service-proxy: Move Action into its own file

 libgupnp/gupnp-service-proxy-action-private.h | 33 ++++++++++++
 libgupnp/gupnp-service-proxy-action.c         | 72 +++++++++++++++++++++++++++
 libgupnp/gupnp-service-proxy-private.h        | 14 ++++++
 libgupnp/gupnp-service-proxy.c                | 64 ++----------------------
 libgupnp/meson.build                          |  1 +
 5 files changed, 123 insertions(+), 61 deletions(-)
---
diff --git a/libgupnp/gupnp-service-proxy-action-private.h b/libgupnp/gupnp-service-proxy-action-private.h
new file mode 100644
index 0000000..2eda5a4
--- /dev/null
+++ b/libgupnp/gupnp-service-proxy-action-private.h
@@ -0,0 +1,33 @@
+#ifndef GUPNP_SERVICE_PROXY_ACTION_H
+#define GUPNP_SERVICE_PROXY_ACTION_H
+
+G_BEGIN_DECLS
+
+struct _GUPnPServiceProxyAction {
+        volatile gint ref_count;
+        GUPnPServiceProxy *proxy;
+        char *action_name;
+
+        SoupMessage *msg;
+        GString *msg_str;
+
+        GUPnPServiceProxyActionCallback callback;
+        gpointer user_data;
+
+        GError *error;    /* If non-NULL, description of error that
+                             occurred when preparing message */
+};
+
+G_GNUC_INTERNAL GUPnPServiceProxyAction *
+gupnp_service_proxy_action_new (const char *action);
+
+G_GNUC_INTERNAL GUPnPServiceProxyAction *
+gupnp_service_proxy_action_ref (GUPnPServiceProxyAction *action);
+
+G_GNUC_INTERNAL void
+gupnp_service_proxy_action_unref (GUPnPServiceProxyAction *action);
+
+
+G_END_DECLS
+
+#endif /* GUPNP_SERVICE_PROXY_ACTION_H */
diff --git a/libgupnp/gupnp-service-proxy-action.c b/libgupnp/gupnp-service-proxy-action.c
new file mode 100644
index 0000000..b932277
--- /dev/null
+++ b/libgupnp/gupnp-service-proxy-action.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd.
+ *
+ * Author: Jorn Baayen <jorn openedhand com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gupnp-service-proxy.h"
+#include "gupnp-service-proxy-private.h"
+#include "gupnp-service-proxy-action-private.h"
+
+GUPnPServiceProxyAction *
+gupnp_service_proxy_action_new (const char *action) {
+        GUPnPServiceProxyAction *ret;
+
+        ret = g_slice_new (GUPnPServiceProxyAction);
+        ret->ref_count = 1;
+
+        return ret;
+}
+
+GUPnPServiceProxyAction *
+gupnp_service_proxy_action_ref (GUPnPServiceProxyAction *action)
+{
+        g_return_val_if_fail (action, NULL);
+        g_return_val_if_fail (action->ref_count > 0, NULL);
+
+        g_atomic_int_inc (&action->ref_count);
+
+        return action;
+}
+
+void
+gupnp_service_proxy_action_unref (GUPnPServiceProxyAction *action)
+{
+
+        g_return_if_fail (action);
+        g_return_if_fail (action->ref_count > 0);
+
+
+        if (g_atomic_int_dec_and_test (&action->ref_count)) {
+                if (action->proxy != NULL) {
+                        g_object_remove_weak_pointer (G_OBJECT (action->proxy),
+                                                      (gpointer *)&(action->proxy));
+                        gupnp_service_proxy_remove_action (action->proxy, action);
+                }
+
+                if (action->msg != NULL)
+                        g_object_unref (action->msg);
+
+                g_slice_free (GUPnPServiceProxyAction, action);
+        }
+}
+
+G_DEFINE_BOXED_TYPE (GUPnPServiceProxyAction,
+                     gupnp_service_proxy_action,
+                     gupnp_service_proxy_action_ref,
+                     gupnp_service_proxy_action_unref)
diff --git a/libgupnp/gupnp-service-proxy-private.h b/libgupnp/gupnp-service-proxy-private.h
new file mode 100644
index 0000000..ae07d08
--- /dev/null
+++ b/libgupnp/gupnp-service-proxy-private.h
@@ -0,0 +1,14 @@
+#ifndef GUPNP_SERVICE_PROXY_PRIVATE_H
+#define GUPNP_SERVICE_PROXY_PRIVATE_H
+
+#include "gupnp-service-proxy.h"
+
+G_BEGIN_DECLS
+
+G_GNUC_INTERNAL void
+gupnp_service_proxy_remove_action (GUPnPServiceProxy       *proxy,
+                                   GUPnPServiceProxyAction *action);
+
+G_END_DECLS
+
+#endif /* GUPNP_SERVICE_PROXY_ACTION_H */
diff --git a/libgupnp/gupnp-service-proxy.c b/libgupnp/gupnp-service-proxy.c
index 58b8b1e..987dc0c 100644
--- a/libgupnp/gupnp-service-proxy.c
+++ b/libgupnp/gupnp-service-proxy.c
@@ -35,6 +35,7 @@
 #include <errno.h>
 
 #include "gupnp-service-proxy.h"
+#include "gupnp-service-proxy-action-private.h"
 #include "gupnp-context-private.h"
 #include "gupnp-error.h"
 #include "gupnp-error-private.h"
@@ -81,20 +82,6 @@ enum {
 
 static guint signals[LAST_SIGNAL];
 
-struct _GUPnPServiceProxyAction {
-        volatile gint ref_count;
-        GUPnPServiceProxy *proxy;
-
-        SoupMessage *msg;
-        GString *msg_str;
-
-        GUPnPServiceProxyActionCallback callback;
-        gpointer user_data;
-
-        GError *error;    /* If non-NULL, description of error that
-                             occurred when preparing message */
-};
-
 typedef struct {
         GType type;       /* type of the variable this notification is for */
 
@@ -124,13 +111,7 @@ subscribe (GUPnPServiceProxy *proxy);
 static void
 unsubscribe (GUPnPServiceProxy *proxy);
 
-static GUPnPServiceProxyAction *
-gupnp_service_proxy_action_ref (GUPnPServiceProxyAction *action);
-
-static void
-gupnp_service_proxy_action_unref (GUPnPServiceProxyAction *action);
-
-static void
+void
 gupnp_service_proxy_remove_action (GUPnPServiceProxy       *proxy,
                                    GUPnPServiceProxyAction *action)
 {
@@ -142,44 +123,6 @@ gupnp_service_proxy_remove_action (GUPnPServiceProxy       *proxy,
                                                action);
 }
 
-static GUPnPServiceProxyAction *
-gupnp_service_proxy_action_ref (GUPnPServiceProxyAction *action)
-{
-        g_return_val_if_fail (action, NULL);
-        g_return_val_if_fail (action->ref_count > 0, NULL);
-
-        g_atomic_int_inc (&action->ref_count);
-
-        return action;
-}
-
-static void
-gupnp_service_proxy_action_unref (GUPnPServiceProxyAction *action)
-{
-
-        g_return_if_fail (action);
-        g_return_if_fail (action->ref_count > 0);
-
-
-        if (g_atomic_int_dec_and_test (&action->ref_count)) {
-                if (action->proxy != NULL) {
-                        g_object_remove_weak_pointer (G_OBJECT (action->proxy),
-                                                      (gpointer *)&(action->proxy));
-                        gupnp_service_proxy_remove_action (action->proxy, action);
-                }
-
-                if (action->msg != NULL)
-                        g_object_unref (action->msg);
-
-                g_slice_free (GUPnPServiceProxyAction, action);
-        }
-}
-
-G_DEFINE_BOXED_TYPE (GUPnPServiceProxyAction,
-                     gupnp_service_proxy_action,
-                     gupnp_service_proxy_action_ref,
-                     gupnp_service_proxy_action_unref)
-
 static void
 callback_data_free (CallbackData *data)
 {
@@ -811,8 +754,7 @@ begin_action_msg (GUPnPServiceProxy              *proxy,
         priv = gupnp_service_proxy_get_instance_private (proxy);
 
         /* Create action structure */
-        ret = g_slice_new (GUPnPServiceProxyAction);
-        ret->ref_count = 1;
+        ret = gupnp_service_proxy_action_new (action);
 
         ret->proxy = proxy;
         g_object_add_weak_pointer (G_OBJECT (proxy), (gpointer *)&(ret->proxy));
diff --git a/libgupnp/meson.build b/libgupnp/meson.build
index 3dfd28a..b832acb 100644
--- a/libgupnp/meson.build
+++ b/libgupnp/meson.build
@@ -80,6 +80,7 @@ sources = files(
     'gupnp-service-info.c',
     'gupnp-service-introspection.c',
     'gupnp-service-proxy.c',
+    'gupnp-service-proxy-action.c',
     'gupnp-simple-context-manager.c',
     'gupnp-types.c',
     'gupnp-white-list.c',


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