153a5a1b3Sopenharmony_ci#ifndef foopulseasyncmsgqhfoo
253a5a1b3Sopenharmony_ci#define foopulseasyncmsgqhfoo
353a5a1b3Sopenharmony_ci
453a5a1b3Sopenharmony_ci/***
553a5a1b3Sopenharmony_ci  This file is part of PulseAudio.
653a5a1b3Sopenharmony_ci
753a5a1b3Sopenharmony_ci  Copyright 2004-2006 Lennart Poettering
853a5a1b3Sopenharmony_ci
953a5a1b3Sopenharmony_ci  PulseAudio is free software; you can redistribute it and/or modify
1053a5a1b3Sopenharmony_ci  it under the terms of the GNU Lesser General Public License as
1153a5a1b3Sopenharmony_ci  published by the Free Software Foundation; either version 2.1 of the
1253a5a1b3Sopenharmony_ci  License, or (at your option) any later version.
1353a5a1b3Sopenharmony_ci
1453a5a1b3Sopenharmony_ci  PulseAudio is distributed in the hope that it will be useful, but
1553a5a1b3Sopenharmony_ci  WITHOUT ANY WARRANTY; without even the implied warranty of
1653a5a1b3Sopenharmony_ci  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1753a5a1b3Sopenharmony_ci  Lesser General Public License for more details.
1853a5a1b3Sopenharmony_ci
1953a5a1b3Sopenharmony_ci  You should have received a copy of the GNU Lesser General Public
2053a5a1b3Sopenharmony_ci  License along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
2153a5a1b3Sopenharmony_ci***/
2253a5a1b3Sopenharmony_ci
2353a5a1b3Sopenharmony_ci#include <sys/types.h>
2453a5a1b3Sopenharmony_ci
2553a5a1b3Sopenharmony_ci#include <pulsecore/asyncq.h>
2653a5a1b3Sopenharmony_ci#include <pulsecore/memchunk.h>
2753a5a1b3Sopenharmony_ci#include <pulsecore/msgobject.h>
2853a5a1b3Sopenharmony_ci
2953a5a1b3Sopenharmony_ci/* A simple asynchronous message queue, based on pa_asyncq. In
3053a5a1b3Sopenharmony_ci * contrast to pa_asyncq this one is multiple-writer safe, though
3153a5a1b3Sopenharmony_ci * still not multiple-reader safe. This queue is intended to be used
3253a5a1b3Sopenharmony_ci * for controlling real-time threads from normal-priority
3353a5a1b3Sopenharmony_ci * threads. Multiple-writer-safety is accomplished by using a mutex on
3453a5a1b3Sopenharmony_ci * the writer side. This queue is thus not useful for communication
3553a5a1b3Sopenharmony_ci * between several real-time threads.
3653a5a1b3Sopenharmony_ci *
3753a5a1b3Sopenharmony_ci * The queue takes messages consisting of:
3853a5a1b3Sopenharmony_ci *    "Object" for which this messages is intended (may be NULL)
3953a5a1b3Sopenharmony_ci *    A numeric message code
4053a5a1b3Sopenharmony_ci *    Arbitrary userdata pointer (may be NULL)
4153a5a1b3Sopenharmony_ci *    A memchunk (may be NULL)
4253a5a1b3Sopenharmony_ci *
4353a5a1b3Sopenharmony_ci * There are two functions for submitting messages: _post and
4453a5a1b3Sopenharmony_ci * _send. The former just enqueues the message asynchronously, the
4553a5a1b3Sopenharmony_ci * latter waits for completion, synchronously. */
4653a5a1b3Sopenharmony_ci
4753a5a1b3Sopenharmony_cienum {
4853a5a1b3Sopenharmony_ci    PA_MESSAGE_SHUTDOWN = -1/* A generic message to inform the handler of this queue to quit */
4953a5a1b3Sopenharmony_ci};
5053a5a1b3Sopenharmony_ci
5153a5a1b3Sopenharmony_citypedef struct pa_asyncmsgq pa_asyncmsgq;
5253a5a1b3Sopenharmony_ci
5353a5a1b3Sopenharmony_cipa_asyncmsgq* pa_asyncmsgq_new(unsigned size);
5453a5a1b3Sopenharmony_cipa_asyncmsgq* pa_asyncmsgq_ref(pa_asyncmsgq *q);
5553a5a1b3Sopenharmony_ci
5653a5a1b3Sopenharmony_civoid pa_asyncmsgq_unref(pa_asyncmsgq* q);
5753a5a1b3Sopenharmony_ci
5853a5a1b3Sopenharmony_civoid 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);
5953a5a1b3Sopenharmony_ciint pa_asyncmsgq_send(pa_asyncmsgq *q, pa_msgobject *object, int code, const void *userdata, int64_t offset, const pa_memchunk *memchunk);
6053a5a1b3Sopenharmony_ci
6153a5a1b3Sopenharmony_ciint pa_asyncmsgq_get(pa_asyncmsgq *q, pa_msgobject **object, int *code, void **userdata, int64_t *offset, pa_memchunk *memchunk, bool wait);
6253a5a1b3Sopenharmony_ciint pa_asyncmsgq_dispatch(pa_msgobject *object, int code, void *userdata, int64_t offset, pa_memchunk *memchunk);
6353a5a1b3Sopenharmony_civoid pa_asyncmsgq_done(pa_asyncmsgq *q, int ret);
6453a5a1b3Sopenharmony_ciint pa_asyncmsgq_wait_for(pa_asyncmsgq *a, int code);
6553a5a1b3Sopenharmony_ciint pa_asyncmsgq_process_one(pa_asyncmsgq *a);
6653a5a1b3Sopenharmony_ci
6753a5a1b3Sopenharmony_civoid pa_asyncmsgq_flush(pa_asyncmsgq *a, bool run);
6853a5a1b3Sopenharmony_ci
6953a5a1b3Sopenharmony_ci/* For the reading side */
7053a5a1b3Sopenharmony_ciint pa_asyncmsgq_read_fd(pa_asyncmsgq *q);
7153a5a1b3Sopenharmony_ciint pa_asyncmsgq_read_before_poll(pa_asyncmsgq *a);
7253a5a1b3Sopenharmony_civoid pa_asyncmsgq_read_after_poll(pa_asyncmsgq *a);
7353a5a1b3Sopenharmony_ci
7453a5a1b3Sopenharmony_ci/* For the write side */
7553a5a1b3Sopenharmony_ciint pa_asyncmsgq_write_fd(pa_asyncmsgq *q);
7653a5a1b3Sopenharmony_civoid pa_asyncmsgq_write_before_poll(pa_asyncmsgq *a);
7753a5a1b3Sopenharmony_civoid pa_asyncmsgq_write_after_poll(pa_asyncmsgq *a);
7853a5a1b3Sopenharmony_ci
7953a5a1b3Sopenharmony_cibool pa_asyncmsgq_dispatching(pa_asyncmsgq *a);
8053a5a1b3Sopenharmony_ci
8153a5a1b3Sopenharmony_ci#endif
82