]>
code.delx.au - pulseaudio/blob - polyp/polyplib-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
29 #include "polyplib-internal.h"
30 #include "polyplib-operation.h"
32 struct pa_operation
*pa_operation_new(struct pa_context
*c
, struct pa_stream
*s
) {
33 struct pa_operation
*o
;
36 o
= pa_xmalloc(sizeof(struct pa_operation
));
38 o
->context
= pa_context_ref(c
);
39 o
->stream
= s
? pa_stream_ref(s
) : NULL
;
41 o
->state
= PA_OPERATION_RUNNING
;
45 PA_LLIST_PREPEND(struct pa_operation
, o
->context
->operations
, o
);
46 return pa_operation_ref(o
);
49 struct pa_operation
*pa_operation_ref(struct pa_operation
*o
) {
50 assert(o
&& o
->ref
>= 1);
55 void pa_operation_unref(struct pa_operation
*o
) {
56 assert(o
&& o
->ref
>= 1);
58 if ((--(o
->ref
)) == 0) {
65 static void operation_set_state(struct pa_operation
*o
, enum pa_operation_state st
) {
66 assert(o
&& o
->ref
>= 1);
76 if ((o
->state
== PA_OPERATION_DONE
) || (o
->state
== PA_OPERATION_CANCELED
)) {
77 PA_LLIST_REMOVE(struct pa_operation
, o
->context
->operations
, o
);
78 pa_context_unref(o
->context
);
80 pa_stream_unref(o
->stream
);
86 pa_operation_unref(o
);
90 void pa_operation_cancel(struct pa_operation
*o
) {
91 assert(o
&& o
->ref
>= 1);
92 operation_set_state(o
, PA_OPERATION_CANCELED
);
95 void pa_operation_done(struct pa_operation
*o
) {
96 assert(o
&& o
->ref
>= 1);
97 operation_set_state(o
, PA_OPERATION_DONE
);
100 enum pa_operation_state
pa_operation_get_state(struct pa_operation
*o
) {
101 assert(o
&& o
->ref
>= 1);