• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
47 enum {
48     PA_MESSAGE_SHUTDOWN = -1/* A generic message to inform the handler of this queue to quit */
49 };
50 
51 typedef struct pa_asyncmsgq pa_asyncmsgq;
52 
53 pa_asyncmsgq* pa_asyncmsgq_new(unsigned size);
54 pa_asyncmsgq* pa_asyncmsgq_ref(pa_asyncmsgq *q);
55 
56 void pa_asyncmsgq_unref(pa_asyncmsgq* q);
57 
58 void 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);
59 int pa_asyncmsgq_send(pa_asyncmsgq *q, pa_msgobject *object, int code, const void *userdata, int64_t offset, const pa_memchunk *memchunk);
60 
61 int pa_asyncmsgq_get(pa_asyncmsgq *q, pa_msgobject **object, int *code, void **userdata, int64_t *offset, pa_memchunk *memchunk, bool wait);
62 int pa_asyncmsgq_dispatch(pa_msgobject *object, int code, void *userdata, int64_t offset, pa_memchunk *memchunk);
63 void pa_asyncmsgq_done(pa_asyncmsgq *q, int ret);
64 int pa_asyncmsgq_wait_for(pa_asyncmsgq *a, int code);
65 int pa_asyncmsgq_process_one(pa_asyncmsgq *a);
66 
67 void pa_asyncmsgq_flush(pa_asyncmsgq *a, bool run);
68 
69 /* For the reading side */
70 int pa_asyncmsgq_read_fd(pa_asyncmsgq *q);
71 int pa_asyncmsgq_read_before_poll(pa_asyncmsgq *a);
72 void pa_asyncmsgq_read_after_poll(pa_asyncmsgq *a);
73 
74 /* For the write side */
75 int pa_asyncmsgq_write_fd(pa_asyncmsgq *q);
76 void pa_asyncmsgq_write_before_poll(pa_asyncmsgq *a);
77 void pa_asyncmsgq_write_after_poll(pa_asyncmsgq *a);
78 
79 bool pa_asyncmsgq_dispatching(pa_asyncmsgq *a);
80 
81 #endif
82