Update dLeyna to v0.2.1
[profile/ivi/dLeyna.git] / dleyna-renderer / libdleyna / renderer / async.c
1 /*
2  * dLeyna
3  *
4  * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU Lesser General Public License,
8  * version 2.1, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
13  * for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Mark Ryan <mark.d.ryan@intel.com>
20  *
21  */
22
23 #include <libdleyna/core/error.h>
24 #include <libdleyna/core/log.h>
25
26 #include "async.h"
27
28 void dlr_async_task_delete(dlr_async_task_t *task)
29 {
30         if (task->free_private)
31                 task->free_private(task->private);
32         if (task->cancellable)
33                 g_object_unref(task->cancellable);
34 }
35
36 gboolean dlr_async_task_complete(gpointer user_data)
37 {
38         dlr_async_task_t *cb_data = user_data;
39
40         DLEYNA_LOG_DEBUG("Enter. %s %s", cb_data->error ? "Error:" : "Success.",
41                          cb_data->error ? cb_data->error->message : "");
42         DLEYNA_LOG_DEBUG_NL();
43
44         if (cb_data->proxy != NULL)
45                 g_object_remove_weak_pointer((G_OBJECT(cb_data->proxy)),
46                                              (gpointer *)&cb_data->proxy);
47
48         cb_data->cb(&cb_data->task, cb_data->error);
49
50         return FALSE;
51 }
52
53 void dlr_async_task_cancelled(GCancellable *cancellable, gpointer user_data)
54 {
55         dlr_async_task_t *cb_data = user_data;
56
57         if (cb_data->proxy != NULL)
58                 gupnp_service_proxy_cancel_action(cb_data->proxy,
59                                                   cb_data->action);
60
61         if (!cb_data->error)
62                 cb_data->error = g_error_new(DLEYNA_SERVER_ERROR,
63                                              DLEYNA_ERROR_CANCELLED,
64                                              "Operation cancelled.");
65
66         (void) g_idle_add(dlr_async_task_complete, cb_data);
67 }
68
69 void dlr_async_task_cancel(dlr_async_task_t *task)
70 {
71         if (task->cancellable)
72                 g_cancellable_cancel(task->cancellable);
73 }