2004-08-17 19:47:42 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
|
|
|
|
This file is part of polypaudio.
|
|
|
|
|
|
|
|
|
|
polypaudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2004-08-17 19:47:42 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
polypaudio is distributed in the hope that it will be useful, but
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2004-08-17 19:47:42 +00:00
|
|
|
along with polypaudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-08-14 20:25:32 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
2006-02-16 19:19:58 +00:00
|
|
|
#include <polypcore/xmalloc.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2006-02-16 22:43:59 +00:00
|
|
|
#include "internal.h"
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2006-02-16 22:43:59 +00:00
|
|
|
#include "operation.h"
|
2004-08-14 20:25:32 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_operation *pa_operation_new(pa_context *c, pa_stream *s) {
|
|
|
|
|
pa_operation *o;
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(c);
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
o = pa_xmalloc(sizeof(pa_operation));
|
2004-08-14 20:25:32 +00:00
|
|
|
o->ref = 1;
|
|
|
|
|
o->context = pa_context_ref(c);
|
|
|
|
|
o->stream = s ? pa_stream_ref(s) : NULL;
|
|
|
|
|
|
|
|
|
|
o->state = PA_OPERATION_RUNNING;
|
|
|
|
|
o->userdata = NULL;
|
|
|
|
|
o->callback = NULL;
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
PA_LLIST_PREPEND(pa_operation, o->context->operations, o);
|
2004-08-14 20:25:32 +00:00
|
|
|
return pa_operation_ref(o);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_operation *pa_operation_ref(pa_operation *o) {
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(o && o->ref >= 1);
|
|
|
|
|
o->ref++;
|
|
|
|
|
return o;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_operation_unref(pa_operation *o) {
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(o && o->ref >= 1);
|
|
|
|
|
|
|
|
|
|
if ((--(o->ref)) == 0) {
|
|
|
|
|
assert(!o->context);
|
|
|
|
|
assert(!o->stream);
|
|
|
|
|
free(o);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-27 16:25:31 +00:00
|
|
|
static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(o && o->ref >= 1);
|
|
|
|
|
|
|
|
|
|
if (st == o->state)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!o->context)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
o->state = st;
|
|
|
|
|
|
|
|
|
|
if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED)) {
|
2006-01-11 01:17:39 +00:00
|
|
|
PA_LLIST_REMOVE(pa_operation, o->context->operations, o);
|
2004-08-14 20:25:32 +00:00
|
|
|
pa_context_unref(o->context);
|
|
|
|
|
if (o->stream)
|
|
|
|
|
pa_stream_unref(o->stream);
|
|
|
|
|
o->context = NULL;
|
|
|
|
|
o->stream = NULL;
|
|
|
|
|
o->callback = NULL;
|
|
|
|
|
o->userdata = NULL;
|
|
|
|
|
|
|
|
|
|
pa_operation_unref(o);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_operation_cancel(pa_operation *o) {
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(o && o->ref >= 1);
|
|
|
|
|
operation_set_state(o, PA_OPERATION_CANCELED);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_operation_done(pa_operation *o) {
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(o && o->ref >= 1);
|
|
|
|
|
operation_set_state(o, PA_OPERATION_DONE);
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-27 16:25:31 +00:00
|
|
|
pa_operation_state_t pa_operation_get_state(pa_operation *o) {
|
2004-08-14 20:25:32 +00:00
|
|
|
assert(o && o->ref >= 1);
|
|
|
|
|
return o->state;
|
|
|
|
|
}
|