]>
code.delx.au - pulseaudio/blob - src/polyp/operation.c
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <polypcore/xmalloc.h>
32 #include "operation.h"
34 pa_operation
*pa_operation_new(pa_context
*c
, pa_stream
*s
, pa_operation_cb_t cb
, void *userdata
) {
38 o
= pa_xmalloc(sizeof(pa_operation
));
40 o
->context
= pa_context_ref(c
);
41 o
->stream
= s
? pa_stream_ref(s
) : NULL
;
43 o
->state
= PA_OPERATION_RUNNING
;
45 o
->userdata
= userdata
;
47 PA_LLIST_PREPEND(pa_operation
, o
->context
->operations
, o
);
48 return pa_operation_ref(o
);
51 pa_operation
*pa_operation_ref(pa_operation
*o
) {
52 assert(o
&& o
->ref
>= 1);
57 void pa_operation_unref(pa_operation
*o
) {
58 assert(o
&& o
->ref
>= 1);
60 if ((--(o
->ref
)) == 0) {
67 static void operation_set_state(pa_operation
*o
, pa_operation_state_t st
) {
68 assert(o
&& o
->ref
>= 1);
78 if ((o
->state
== PA_OPERATION_DONE
) || (o
->state
== PA_OPERATION_CANCELED
)) {
79 PA_LLIST_REMOVE(pa_operation
, o
->context
->operations
, o
);
80 pa_context_unref(o
->context
);
82 pa_stream_unref(o
->stream
);
88 pa_operation_unref(o
);
92 void pa_operation_cancel(pa_operation
*o
) {
93 assert(o
&& o
->ref
>= 1);
94 operation_set_state(o
, PA_OPERATION_CANCELED
);
97 void pa_operation_done(pa_operation
*o
) {
98 assert(o
&& o
->ref
>= 1);
99 operation_set_state(o
, PA_OPERATION_DONE
);
102 pa_operation_state_t
pa_operation_get_state(pa_operation
*o
) {
103 assert(o
&& o
->ref
>= 1);