summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegis Merlino <regis.merlino@intel.com>2013-02-28 14:21:31 +0100
committerRegis Merlino <regis.merlino@intel.com>2013-02-28 14:21:31 +0100
commit5e745dd775fc9b51167167cd596d638f83c5e43b (patch)
treede0f3ff5b4d428ab38f1d96c8c65ef586224feb9
parentc81ad4b7251310ed61c8e2d04498ce8586b527f2 (diff)
downloaddleyna-core-5e745dd775fc9b51167167cd596d638f83c5e43b.tar.gz
[Service] Add gupnp service-task utility
Signed-off-by: Regis Merlino <regis.merlino@intel.com>
-rw-r--r--Makefile.am6
-rw-r--r--configure.ac1
-rw-r--r--dleyna-core-1.0.pc.in2
-rw-r--r--src/service-task.c130
-rw-r--r--src/service-task.h63
5 files changed, 200 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index 7424011..d38a4cd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -6,6 +6,7 @@ DLEYNA_CORE_VERSION = 1:0:0
AM_CFLAGS = $(GLIB_CFLAGS) \
$(GIO_CFLAGS) \
+ $(GUPNP_CFLAGS) \
-include config.h \
-DSYS_CONFIG_DIR="\"$(sysconfdir)\"" \
-DCONNECTOR_DIR="\"$(connectordir)\""
@@ -20,6 +21,7 @@ libdleyna_coreinc_HEADERS = src/connector.h \
src/error.h \
src/log.h \
src/main-loop.h \
+ src/service-task.h \
src/settings.h \
src/task-atom.h \
src/task-processor.h
@@ -33,11 +35,13 @@ libdleyna_core_1_0_la_SOURCES = $(libdleyna_coreinc_HEADERS) \
src/error.c \
src/log.c \
src/main-loop.c \
+ src/service-task.c \
src/settings.c \
src/task-processor.c
libdleyna_core_1_0_la_LIBADD = $(GLIB_LIBS) \
- $(GIO_LIBS)
+ $(GIO_LIBS) \
+ $(GUPNP_LIBS)
MAINTAINERCLEANFILES = Makefile.in \
aclocal.m4 \
diff --git a/configure.ac b/configure.ac
index 7e950ca..bf048d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -38,6 +38,7 @@ LT_LANG([C])
PKG_PROG_PKG_CONFIG(0.16)
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.28])
PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.28])
+PKG_CHECK_MODULES([GUPNP], [gupnp-1.0 >= 0.19.1])
# Checks for header files.
AC_CHECK_HEADERS([stdlib.h string.h syslog.h])
diff --git a/dleyna-core-1.0.pc.in b/dleyna-core-1.0.pc.in
index 36ed961..966a8e1 100644
--- a/dleyna-core-1.0.pc.in
+++ b/dleyna-core-1.0.pc.in
@@ -8,5 +8,5 @@ Name: @PACKAGE@
Description: UPnP & DLNA core library
Libs: -L${libdir} -ldleyna-core-1.0
Cflags: -I${includedir}/dleyna-1.0
-Requires: glib-2.0 gio-2.0 gmodule-2.0
+Requires: glib-2.0 gio-2.0 gmodule-2.0 gupnp-1.0
Version: @VERSION@
diff --git a/src/service-task.c b/src/service-task.c
new file mode 100644
index 0000000..f2d3817
--- /dev/null
+++ b/src/service-task.c
@@ -0,0 +1,130 @@
+/*
+ * dLeyna
+ *
+ * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Ludovic Ferrandis <ludovic.ferrandis@intel.com>
+ * Regis Merlino <regis.merlino@intel.com>
+ *
+ */
+
+#include "log.h"
+#include "service-task.h"
+#include "task-processor.h"
+
+struct dleyna_service_task_t_ {
+ dleyna_task_atom_t base; /* pseudo inheritance - MUST be first field */
+ GUPnPServiceProxyActionCallback callback;
+ GUPnPServiceProxyAction *p_action;
+ GDestroyNotify free_func;
+ gpointer user_data;
+ dleyna_service_task_action t_action;
+ GUPnPServiceProxy *proxy;
+};
+
+const char *dleyna_service_task_create_source(void)
+{
+ static unsigned int cpt = 1;
+ static char source[20];
+
+ g_snprintf(source, 20, "source-%d", cpt);
+ cpt++;
+
+ return source;
+}
+
+void dleyna_service_task_add(const dleyna_task_queue_key_t *queue_id,
+ dleyna_service_task_action action,
+ GUPnPServiceProxy *proxy,
+ GUPnPServiceProxyActionCallback action_cb,
+ GDestroyNotify free_func,
+ gpointer cb_user_data)
+{
+ dleyna_service_task_t *task;
+
+ task = g_new0(dleyna_service_task_t, 1);
+
+ task->t_action = action;
+ task->callback = action_cb;
+ task->free_func = free_func;
+ task->user_data = cb_user_data;
+ task->proxy = proxy;
+
+ if (proxy != NULL)
+ g_object_add_weak_pointer((G_OBJECT(proxy)),
+ (gpointer *)&task->proxy);
+
+ dleyna_task_queue_add_task(queue_id, &task->base);
+}
+
+void dleyna_service_task_begin_action_cb(GUPnPServiceProxy *proxy,
+ GUPnPServiceProxyAction *action,
+ gpointer user_data)
+{
+ dleyna_service_task_t *task = (dleyna_service_task_t *)user_data;
+
+ task->p_action = NULL;
+ task->callback(proxy, action, task->user_data);
+
+ dleyna_task_queue_task_completed(task->base.queue_id);
+}
+
+void dleyna_service_task_process_cb(dleyna_task_atom_t *atom,
+ gpointer user_data)
+{
+ gboolean failed = FALSE;
+ dleyna_service_task_t *task = (dleyna_service_task_t *)atom;
+
+ task->p_action = task->t_action(task, task->proxy, &failed);
+
+ if (failed)
+ dleyna_task_processor_cancel_queue(task->base.queue_id);
+ else if (!task->p_action)
+ dleyna_task_queue_task_completed(task->base.queue_id);
+}
+
+void dleyna_service_task_cancel_cb(dleyna_task_atom_t *atom, gpointer user_data)
+{
+ dleyna_service_task_t *task = (dleyna_service_task_t *)atom;
+
+ if (task->p_action) {
+ if (task->proxy)
+ gupnp_service_proxy_cancel_action(task->proxy,
+ task->p_action);
+ task->p_action = NULL;
+
+ dleyna_task_queue_task_completed(task->base.queue_id);
+ }
+}
+
+void dleyna_service_task_delete_cb(dleyna_task_atom_t *atom, gpointer user_data)
+{
+ dleyna_service_task_t *task = (dleyna_service_task_t *)atom;
+
+ if (task->free_func != NULL)
+ task->free_func(task->user_data);
+
+ if (task->proxy != NULL)
+ g_object_remove_weak_pointer((G_OBJECT(task->proxy)),
+ (gpointer *)&task->proxy);
+
+ g_free(task);
+}
+
+gpointer *dleyna_service_task_get_user_data(dleyna_service_task_t *task)
+{
+ return task->user_data;
+}
diff --git a/src/service-task.h b/src/service-task.h
new file mode 100644
index 0000000..1129324
--- /dev/null
+++ b/src/service-task.h
@@ -0,0 +1,63 @@
+/*
+ * dLeyna
+ *
+ * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU Lesser General Public License,
+ * version 2.1, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Ludovic Ferrandis <ludovic.ferrandis@intel.com>
+ * Regis Merlino <regis.merlino@intel.com>
+ *
+ */
+
+#ifndef DLEYNA_SERVICE_TASK_H__
+#define DLEYNA_SERVICE_TASK_H__
+
+#include <glib.h>
+#include <libgupnp/gupnp-service-proxy.h>
+
+#include "task-atom.h"
+
+typedef struct dleyna_service_task_t_ dleyna_service_task_t;
+
+typedef GUPnPServiceProxyAction *(*dleyna_service_task_action)
+ (dleyna_service_task_t *task,
+ GUPnPServiceProxy *proxy,
+ gboolean *failed);
+
+const char *dleyna_service_task_create_source(void);
+
+void dleyna_service_task_add(const dleyna_task_queue_key_t *queue_id,
+ dleyna_service_task_action action,
+ GUPnPServiceProxy *proxy,
+ GUPnPServiceProxyActionCallback action_cb,
+ GDestroyNotify free_func,
+ gpointer cb_user_data);
+
+void dleyna_service_task_begin_action_cb(GUPnPServiceProxy *proxy,
+ GUPnPServiceProxyAction *action,
+ gpointer user_data);
+
+void dleyna_service_task_process_cb(dleyna_task_atom_t *atom,
+ gpointer user_data);
+
+void dleyna_service_task_cancel_cb(dleyna_task_atom_t *atom,
+ gpointer user_data);
+
+void dleyna_service_task_delete_cb(dleyna_task_atom_t *atom,
+ gpointer user_data);
+
+gpointer *dleyna_service_task_get_user_data(dleyna_service_task_t *task);
+
+#endif /* DLEYNA_SERVICE_TASK_H__ */