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_xnew0(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);
72 pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
74 pa_log_info("Created %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
75 pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
77 pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
79 pa_core_check_idle(core);
84 void pa_client_free(pa_client *c) {
92 pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
94 pa_idxset_remove_by_data(c->core->clients, c, NULL);
96 pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
97 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
99 pa_assert(pa_idxset_isempty(c->sink_inputs));
100 pa_idxset_free(c->sink_inputs, NULL);
101 pa_assert(pa_idxset_isempty(c->source_outputs));
102 pa_idxset_free(c->source_outputs, NULL);
104 pa_proplist_free(c->proplist);
108 pa_core_check_idle(core);
111 void pa_client_kill(pa_client *c) {
115 pa_log_warn("kill() operation not implemented for client %u", c->index);
122 void pa_client_set_name(pa_client *c, const char *name) {
126 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);
127 pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
129 pa_client_update_proplist(c, 0, NULL);
132 void pa_client_update_proplist(pa_client *c, pa_update_mode_t mode, pa_proplist *p) {
136 pa_proplist_update(c->proplist, mode, p);
138 pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c);
139 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
143 void pa_client_dump_status(pa_client *c) {
146 pa_log_info(_("\t#%u, %s, %s(%s)"),
147 c->index, pa_strnull(c->driver),
148 pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_PROCESS_BINARY)),
149 pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_PROCESS_ID)));
151 /* ToDo : dump connection time */
155 void pa_client_send_event(pa_client *c, const char *event, pa_proplist *data) {
156 pa_proplist *pl = NULL;
157 pa_client_send_event_hook_data hook_data;
166 data = pl = pa_proplist_new();
168 hook_data.client = c;
169 hook_data.data = data;
170 hook_data.event = event;
172 if (pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_SEND_EVENT], &hook_data) < 0)
175 c->send_event(c, event, data);
180 pa_proplist_free(pl);