1#ifndef foopulseasyncmsgqhfoo
2#define foopulseasyncmsgqhfoo
3
4/***
5  This file is part of PulseAudio.
6
7  Copyright 2004-2006 Lennart Poettering
8
9  PulseAudio is free software; you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as
11  published by the Free Software Foundation; either version 2.1 of the
12  License, or (at your option) any later version.
13
14  PulseAudio is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18
19  You should have received a copy of the GNU Lesser General Public
20  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
21***/
22
23#include <sys/types.h>
24
25#include <pulsecore/asyncq.h>
26#include <pulsecore/memchunk.h>
27#include <pulsecore/msgobject.h>
28
29/* A simple asynchronous message queue, based on pa_asyncq. In
30 * contrast to pa_asyncq this one is multiple-writer safe, though
31 * still not multiple-reader safe. This queue is intended to be used
32 * for controlling real-time threads from normal-priority
33 * threads. Multiple-writer-safety is accomplished by using a mutex on
34 * the writer side. This queue is thus not useful for communication
35 * between several real-time threads.
36 *
37 * The queue takes messages consisting of:
38 *    "Object" for which this messages is intended (may be NULL)
39 *    A numeric message code
40 *    Arbitrary userdata pointer (may be NULL)
41 *    A memchunk (may be NULL)
42 *
43 * There are two functions for submitting messages: _post and
44 * _send. The former just enqueues the message asynchronously, the
45 * latter waits for completion, synchronously. */
46
47enum {
48    PA_MESSAGE_SHUTDOWN = -1/* A generic message to inform the handler of this queue to quit */
49};
50
51typedef struct pa_asyncmsgq pa_asyncmsgq;
52
53pa_asyncmsgq* pa_asyncmsgq_new(unsigned size);
54pa_asyncmsgq* pa_asyncmsgq_ref(pa_asyncmsgq *q);
55
56void pa_asyncmsgq_unref(pa_asyncmsgq* q);
57
58void pa_asyncmsgq_post(pa_asyncmsgq *q, pa_msgobject *object, int code, const void *userdata, int64_t offset, const pa_memchunk *memchunk, pa_free_cb_t userdata_free_cb);
59int pa_asyncmsgq_send(pa_asyncmsgq *q, pa_msgobject *object, int code, const void *userdata, int64_t offset, const pa_memchunk *memchunk);
60
61int pa_asyncmsgq_get(pa_asyncmsgq *q, pa_msgobject **object, int *code, void **userdata, int64_t *offset, pa_memchunk *memchunk, bool wait);
62int pa_asyncmsgq_dispatch(pa_msgobject *object, int code, void *userdata, int64_t offset, pa_memchunk *memchunk);
63void pa_asyncmsgq_done(pa_asyncmsgq *q, int ret);
64int pa_asyncmsgq_wait_for(pa_asyncmsgq *a, int code);
65int pa_asyncmsgq_process_one(pa_asyncmsgq *a);
66
67void pa_asyncmsgq_flush(pa_asyncmsgq *a, bool run);
68
69/* For the reading side */
70int pa_asyncmsgq_read_fd(pa_asyncmsgq *q);
71int pa_asyncmsgq_read_before_poll(pa_asyncmsgq *a);
72void pa_asyncmsgq_read_after_poll(pa_asyncmsgq *a);
73
74/* For the write side */
75int pa_asyncmsgq_write_fd(pa_asyncmsgq *q);
76void pa_asyncmsgq_write_before_poll(pa_asyncmsgq *a);
77void pa_asyncmsgq_write_after_poll(pa_asyncmsgq *a);
78
79bool pa_asyncmsgq_dispatching(pa_asyncmsgq *a);
80
81#endif
82