153a5a1b3Sopenharmony_ci/*** 253a5a1b3Sopenharmony_ci This file is part of PulseAudio. 353a5a1b3Sopenharmony_ci 453a5a1b3Sopenharmony_ci Copyright 2004-2006 Lennart Poettering 553a5a1b3Sopenharmony_ci 653a5a1b3Sopenharmony_ci PulseAudio is free software; you can redistribute it and/or modify 753a5a1b3Sopenharmony_ci it under the terms of the GNU Lesser General Public License as published 853a5a1b3Sopenharmony_ci by the Free Software Foundation; either version 2.1 of the License, 953a5a1b3Sopenharmony_ci or (at your option) any later version. 1053a5a1b3Sopenharmony_ci 1153a5a1b3Sopenharmony_ci PulseAudio is distributed in the hope that it will be useful, but 1253a5a1b3Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 1353a5a1b3Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1453a5a1b3Sopenharmony_ci General Public License for more details. 1553a5a1b3Sopenharmony_ci 1653a5a1b3Sopenharmony_ci You should have received a copy of the GNU Lesser General Public License 1753a5a1b3Sopenharmony_ci along with PulseAudio; if not, see <http://www.gnu.org/licenses/>. 1853a5a1b3Sopenharmony_ci***/ 1953a5a1b3Sopenharmony_ci 2053a5a1b3Sopenharmony_ci#ifdef HAVE_CONFIG_H 2153a5a1b3Sopenharmony_ci#include <config.h> 2253a5a1b3Sopenharmony_ci#endif 2353a5a1b3Sopenharmony_ci 2453a5a1b3Sopenharmony_ci#include <stdio.h> 2553a5a1b3Sopenharmony_ci 2653a5a1b3Sopenharmony_ci#include <pulsecore/macro.h> 2753a5a1b3Sopenharmony_ci#include <pulsecore/pstream-util.h> 2853a5a1b3Sopenharmony_ci 2953a5a1b3Sopenharmony_ci#include "internal.h" 3053a5a1b3Sopenharmony_ci#include "subscribe.h" 3153a5a1b3Sopenharmony_ci 3253a5a1b3Sopenharmony_civoid pa_command_subscribe_event(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { 3353a5a1b3Sopenharmony_ci pa_context *c = userdata; 3453a5a1b3Sopenharmony_ci pa_subscription_event_type_t e; 3553a5a1b3Sopenharmony_ci uint32_t idx; 3653a5a1b3Sopenharmony_ci 3753a5a1b3Sopenharmony_ci pa_assert(pd); 3853a5a1b3Sopenharmony_ci pa_assert(command == PA_COMMAND_SUBSCRIBE_EVENT); 3953a5a1b3Sopenharmony_ci pa_assert(t); 4053a5a1b3Sopenharmony_ci pa_assert(c); 4153a5a1b3Sopenharmony_ci pa_assert(PA_REFCNT_VALUE(c) >= 1); 4253a5a1b3Sopenharmony_ci 4353a5a1b3Sopenharmony_ci pa_context_ref(c); 4453a5a1b3Sopenharmony_ci 4553a5a1b3Sopenharmony_ci if (pa_tagstruct_getu32(t, &e) < 0 || 4653a5a1b3Sopenharmony_ci pa_tagstruct_getu32(t, &idx) < 0 || 4753a5a1b3Sopenharmony_ci !pa_tagstruct_eof(t)) { 4853a5a1b3Sopenharmony_ci pa_context_fail(c, PA_ERR_PROTOCOL); 4953a5a1b3Sopenharmony_ci goto finish; 5053a5a1b3Sopenharmony_ci } 5153a5a1b3Sopenharmony_ci 5253a5a1b3Sopenharmony_ci if (c->subscribe_callback) 5353a5a1b3Sopenharmony_ci c->subscribe_callback(c, e, idx, c->subscribe_userdata); 5453a5a1b3Sopenharmony_ci 5553a5a1b3Sopenharmony_cifinish: 5653a5a1b3Sopenharmony_ci pa_context_unref(c); 5753a5a1b3Sopenharmony_ci} 5853a5a1b3Sopenharmony_ci 5953a5a1b3Sopenharmony_cipa_operation* pa_context_subscribe(pa_context *c, pa_subscription_mask_t m, pa_context_success_cb_t cb, void *userdata) { 6053a5a1b3Sopenharmony_ci pa_operation *o; 6153a5a1b3Sopenharmony_ci pa_tagstruct *t; 6253a5a1b3Sopenharmony_ci uint32_t tag; 6353a5a1b3Sopenharmony_ci 6453a5a1b3Sopenharmony_ci pa_assert(c); 6553a5a1b3Sopenharmony_ci pa_assert(PA_REFCNT_VALUE(c) >= 1); 6653a5a1b3Sopenharmony_ci 6753a5a1b3Sopenharmony_ci PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE); 6853a5a1b3Sopenharmony_ci 6953a5a1b3Sopenharmony_ci o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata); 7053a5a1b3Sopenharmony_ci 7153a5a1b3Sopenharmony_ci t = pa_tagstruct_command(c, PA_COMMAND_SUBSCRIBE, &tag); 7253a5a1b3Sopenharmony_ci pa_tagstruct_putu32(t, m); 7353a5a1b3Sopenharmony_ci pa_pstream_send_tagstruct(c->pstream, t); 7453a5a1b3Sopenharmony_ci pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref); 7553a5a1b3Sopenharmony_ci 7653a5a1b3Sopenharmony_ci return o; 7753a5a1b3Sopenharmony_ci} 7853a5a1b3Sopenharmony_ci 7953a5a1b3Sopenharmony_civoid pa_context_set_subscribe_callback(pa_context *c, pa_context_subscribe_cb_t cb, void *userdata) { 8053a5a1b3Sopenharmony_ci pa_assert(c); 8153a5a1b3Sopenharmony_ci pa_assert(PA_REFCNT_VALUE(c) >= 1); 8253a5a1b3Sopenharmony_ci 8353a5a1b3Sopenharmony_ci if (c->state == PA_CONTEXT_TERMINATED || c->state == PA_CONTEXT_FAILED) 8453a5a1b3Sopenharmony_ci return; 8553a5a1b3Sopenharmony_ci 8653a5a1b3Sopenharmony_ci c->subscribe_callback = cb; 8753a5a1b3Sopenharmony_ci c->subscribe_userdata = userdata; 8853a5a1b3Sopenharmony_ci} 89