Merge HUGE set of changes temporarily into a branch, to allow me to move them from...
[profile/ivi/pulseaudio-panda.git] / src / pulsecore / asyncmsgq.h
1 #ifndef foopulseasyncmsgqhfoo
2 #define foopulseasyncmsgqhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of PulseAudio.
8
9   Copyright 2004-2006 Lennart Poettering
10
11   PulseAudio is free software; you can redistribute it and/or modify
12   it under the terms of the GNU Lesser General Public License as
13   published by the Free Software Foundation; either version 2.1 of the
14   License, or (at your option) any later version.
15
16   PulseAudio is distributed in the hope that it will be useful, but
17   WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   Lesser General Public License for more details.
20
21   You should have received a copy of the GNU Lesser General Public
22   License along with PulseAudio; if not, write to the Free Software
23   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24   USA.
25 ***/
26
27 #include <sys/types.h>
28
29 #include <pulsecore/asyncq.h>
30 #include <pulsecore/memchunk.h>
31 #include <pulsecore/msgobject.h>
32
33 /* A simple asynchronous message queue, based on pa_asyncq. In
34  * contrast to pa_asyncq this one is multiple-writer safe, though
35  * still not multiple-reader safe. This queue is intended to be used
36  * for controlling real-time threads from normal-priority
37  * threads. Multiple-writer-safety is accomplished by using a mutex on
38  * the writer side. This queue is thus not useful for communication
39  * between several real-time threads.
40  *
41  * The queue takes messages consisting of:
42  *    "Object" for which this messages is intended (may be NULL)
43  *    A numeric message code
44  *    Arbitrary userdata pointer (may be NULL)
45  *    A memchunk (may be NULL)
46  *
47  * There are two functions for submitting messages: _post and
48  * _send. The fromer just enqueues the message asynchronously, the
49  * latter waits for completion, synchronously. */
50
51 enum {
52     PA_MESSAGE_SHUTDOWN /* A generic message to inform the handler of this queue to quit */
53 };
54
55 typedef struct pa_asyncmsgq pa_asyncmsgq;
56
57 pa_asyncmsgq* pa_asyncmsgq_new(size_t size);
58 void pa_asyncmsgq_free(pa_asyncmsgq* q);
59
60 void pa_asyncmsgq_post(pa_asyncmsgq *q, pa_msgobject *object, int code, const void *userdata, const pa_memchunk *memchunk, pa_free_cb_t userdata_free_cb);
61 int pa_asyncmsgq_send(pa_asyncmsgq *q, pa_msgobject *object, int code, const void *userdata, const pa_memchunk *memchunk);
62
63 int pa_asyncmsgq_get(pa_asyncmsgq *q, pa_msgobject **object, int *code, void **userdata, pa_memchunk *memchunk, int wait);
64 int pa_asyncmsgq_dispatch(pa_msgobject *object, int code, void *userdata, pa_memchunk *memchunk);
65 void pa_asyncmsgq_done(pa_asyncmsgq *q, int ret);
66 int pa_asyncmsgq_wait_for(pa_asyncmsgq *a, int code);
67
68 /* Just for the reading side */
69 int pa_asyncmsgq_get_fd(pa_asyncmsgq *q);
70 int pa_asyncmsgq_before_poll(pa_asyncmsgq *a);
71 void pa_asyncmsgq_after_poll(pa_asyncmsgq *a);
72
73 #endif