4 This file is part of PulseAudio.
6 Copyright 2004-2006 Lennart Poettering
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <pulse/xmalloc.h>
33 #include "operation.h"
35 pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t cb, void *userdata) {
39 o = pa_xnew(pa_operation, 1);
44 o->state = PA_OPERATION_RUNNING;
46 o->userdata = userdata;
48 /* Refcounting is strictly one-way: from the "bigger" to the "smaller" object. */
49 PA_LLIST_PREPEND(pa_operation, c->operations, o);
55 pa_operation *pa_operation_ref(pa_operation *o) {
63 void pa_operation_unref(pa_operation *o) {
67 if ((--(o->ref)) == 0) {
74 static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
85 if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED)) {
90 PA_LLIST_REMOVE(pa_operation, o->context->operations, o);
91 pa_operation_unref(o);
100 pa_operation_unref(o);
103 void pa_operation_cancel(pa_operation *o) {
107 operation_set_state(o, PA_OPERATION_CANCELED);
110 void pa_operation_done(pa_operation *o) {
114 operation_set_state(o, PA_OPERATION_DONE);
117 pa_operation_state_t pa_operation_get_state(pa_operation *o) {