2
This file is part of PulseAudio.
4
Copyright 2004-2006 Lennart Poettering
5
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
7
PulseAudio is free software; you can redistribute it and/or modify
8
it under the terms of the GNU Lesser General Public License as published
9
by the Free Software Foundation; either version 2.1 of the License,
10
or (at your option) any later version.
12
PulseAudio is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public License
18
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
29
#include <pulse/xmalloc.h>
30
#include <pulse/util.h>
32
#include <pulsecore/core-subscribe.h>
33
#include <pulsecore/log.h>
34
#include <pulsecore/macro.h>
35
#include <pulsecore/core-util.h>
39
pa_client_new_data* pa_client_new_data_init(pa_client_new_data *data) {
42
memset(data, 0, sizeof(*data));
43
data->proplist = pa_proplist_new();
48
void pa_client_new_data_done(pa_client_new_data *data) {
51
pa_proplist_free(data->proplist);
54
pa_client *pa_client_new(pa_core *core, pa_client_new_data *data) {
57
pa_core_assert_ref(core);
60
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_NEW], data) < 0)
63
c = pa_xnew(pa_client, 1);
65
c->proplist = pa_proplist_copy(data->proplist);
66
c->driver = pa_xstrdup(pa_path_get_filename(data->driver));
67
c->module = data->module;
69
c->sink_inputs = pa_idxset_new(NULL, NULL);
70
c->source_outputs = pa_idxset_new(NULL, NULL);
76
pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
78
pa_log_info("Created %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
79
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
81
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
83
pa_core_check_idle(core);
88
void pa_client_free(pa_client *c) {
96
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
98
pa_idxset_remove_by_data(c->core->clients, c, NULL);
100
pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
101
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
103
pa_assert(pa_idxset_isempty(c->sink_inputs));
104
pa_idxset_free(c->sink_inputs, NULL);
105
pa_assert(pa_idxset_isempty(c->source_outputs));
106
pa_idxset_free(c->source_outputs, NULL);
108
pa_proplist_free(c->proplist);
112
pa_core_check_idle(core);
115
void pa_client_kill(pa_client *c) {
119
pa_log_warn("kill() operation not implemented for client %u", c->index);
126
void pa_client_set_name(pa_client *c, const char *name) {
130
pa_log_info("Client %u changed name from \"%s\" to \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)), name);
131
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
133
pa_client_update_proplist(c, 0, NULL);
136
void pa_client_update_proplist(pa_client *c, pa_update_mode_t mode, pa_proplist *p) {
140
pa_proplist_update(c->proplist, mode, p);
142
pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c);
143
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
146
void pa_client_send_event(pa_client *c, const char *event, pa_proplist *data) {
147
pa_proplist *pl = NULL;
148
pa_client_send_event_hook_data hook_data;
157
data = pl = pa_proplist_new();
159
hook_data.client = c;
160
hook_data.data = data;
161
hook_data.event = event;
163
if (pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_SEND_EVENT], &hook_data) < 0)
166
c->send_event(c, event, data);
171
pa_proplist_free(pl);