]>
code.delx.au - pulseaudio/blob - polyp/polyplib-operation.c
4 #include "polyplib-internal.h"
5 #include "polyplib-operation.h"
7 struct pa_operation
*pa_operation_new(struct pa_context
*c
, struct pa_stream
*s
) {
8 struct pa_operation
*o
;
11 o
= pa_xmalloc(sizeof(struct pa_operation
));
13 o
->context
= pa_context_ref(c
);
14 o
->stream
= s
? pa_stream_ref(s
) : NULL
;
16 o
->state
= PA_OPERATION_RUNNING
;
20 PA_LLIST_PREPEND(struct pa_operation
, o
->context
->operations
, o
);
21 return pa_operation_ref(o
);
24 struct pa_operation
*pa_operation_ref(struct pa_operation
*o
) {
25 assert(o
&& o
->ref
>= 1);
30 void pa_operation_unref(struct pa_operation
*o
) {
31 assert(o
&& o
->ref
>= 1);
33 if ((--(o
->ref
)) == 0) {
40 static void operation_set_state(struct pa_operation
*o
, enum pa_operation_state st
) {
41 assert(o
&& o
->ref
>= 1);
51 if ((o
->state
== PA_OPERATION_DONE
) || (o
->state
== PA_OPERATION_CANCELED
)) {
52 PA_LLIST_REMOVE(struct pa_operation
, o
->context
->operations
, o
);
53 pa_context_unref(o
->context
);
55 pa_stream_unref(o
->stream
);
61 pa_operation_unref(o
);
65 void pa_operation_cancel(struct pa_operation
*o
) {
66 assert(o
&& o
->ref
>= 1);
67 operation_set_state(o
, PA_OPERATION_CANCELED
);
70 void pa_operation_done(struct pa_operation
*o
) {
71 assert(o
&& o
->ref
>= 1);
72 operation_set_state(o
, PA_OPERATION_DONE
);
75 enum pa_operation_state
pa_operation_get_state(struct pa_operation
*o
) {
76 assert(o
&& o
->ref
>= 1);