1 | //operation.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011 |
---|
5 | * The code (may) include prototypes and comments (and maybe |
---|
6 | * other code fragements) from libpulse*. They are mostly copyrighted by: |
---|
7 | * Lennart Poettering <poettering@users.sourceforge.net> and |
---|
8 | * Pierre Ossman <drzeus@drzeus.cx> |
---|
9 | * |
---|
10 | * This file is part of libroarpulse a part of RoarAudio, |
---|
11 | * a cross-platform sound system for both, home and professional use. |
---|
12 | * See README for details. |
---|
13 | * |
---|
14 | * This file is free software; you can redistribute it and/or modify |
---|
15 | * it under the terms of the GNU General Public License version 3 |
---|
16 | * as published by the Free Software Foundation. |
---|
17 | * |
---|
18 | * RoarAudio is distributed in the hope that it will be useful, |
---|
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | * GNU General Public License for more details. |
---|
22 | * |
---|
23 | * You should have received a copy of the GNU General Public License |
---|
24 | * along with this software; see the file COPYING. If not, write to |
---|
25 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
26 | * Boston, MA 02110-1301, USA. |
---|
27 | * |
---|
28 | * NOTE for everyone want's to change something and send patches: |
---|
29 | * read README and HACKING! There a addition information on |
---|
30 | * the license of this document you need to read before you send |
---|
31 | * any patches. |
---|
32 | * |
---|
33 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
34 | * or libpulse*: |
---|
35 | * The libs libroaresd, libroararts and libroarpulse link this libroar |
---|
36 | * and are therefore GPL. Because of this it may be illigal to use |
---|
37 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
38 | */ |
---|
39 | |
---|
40 | #include <libroarpulse/libroarpulse.h> |
---|
41 | |
---|
42 | /** An asynchronous operation object */ |
---|
43 | struct pa_operation { |
---|
44 | size_t refc; |
---|
45 | pa_operation_state_t state; |
---|
46 | }; |
---|
47 | |
---|
48 | pa_operation *roar_pa_operation_new(pa_operation_state_t initstate) { |
---|
49 | pa_operation * o = roar_mm_malloc(sizeof(pa_operation)); |
---|
50 | |
---|
51 | if ( o == NULL ) |
---|
52 | return NULL; |
---|
53 | |
---|
54 | memset(o, 0, sizeof(pa_operation)); |
---|
55 | |
---|
56 | o->refc = 1; |
---|
57 | |
---|
58 | o->state = initstate; |
---|
59 | |
---|
60 | return o; |
---|
61 | } |
---|
62 | |
---|
63 | static void _operation_free(pa_operation *o) { |
---|
64 | roar_mm_free(o); |
---|
65 | } |
---|
66 | |
---|
67 | /** Increase the reference count by one */ |
---|
68 | pa_operation *pa_operation_ref(pa_operation *o) { |
---|
69 | if ( o == NULL ) |
---|
70 | return NULL; |
---|
71 | |
---|
72 | o->refc++; |
---|
73 | |
---|
74 | return o; |
---|
75 | } |
---|
76 | |
---|
77 | /** Decrease the reference count by one */ |
---|
78 | void pa_operation_unref(pa_operation *o) { |
---|
79 | if ( o == NULL ) |
---|
80 | return; |
---|
81 | |
---|
82 | o->refc--; |
---|
83 | |
---|
84 | if ( o->refc < 1 ) |
---|
85 | _operation_free(o); |
---|
86 | } |
---|
87 | |
---|
88 | /** Cancel the operation. Beware! This will not necessarily cancel the execution of the operation on the server side. */ |
---|
89 | void pa_operation_cancel(pa_operation *o) { |
---|
90 | // we ignore this |
---|
91 | } |
---|
92 | |
---|
93 | /** Return the current status of the operation */ |
---|
94 | pa_operation_state_t pa_operation_get_state(pa_operation *o) { |
---|
95 | if ( o == NULL ) |
---|
96 | return -1; |
---|
97 | |
---|
98 | return o->state; |
---|
99 | } |
---|
100 | |
---|
101 | //ll |
---|