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 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, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <pulse/xmalloc.h>
32 #include <pulse/util.h>
34 #include <pulsecore/core-subscribe.h>
35 #include <pulsecore/log.h>
36 #include <pulsecore/macro.h>
37 #include <pulsecore/core-util.h>
41 pa_client_new_data
* pa_client_new_data_init(pa_client_new_data
*data
) {
44 memset(data
, 0, sizeof(*data
));
45 data
->proplist
= pa_proplist_new();
50 void pa_client_new_data_done(pa_client_new_data
*data
) {
53 pa_proplist_free(data
->proplist
);
56 pa_client
*pa_client_new(pa_core
*core
, pa_client_new_data
*data
) {
59 pa_core_assert_ref(core
);
62 if (pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_CLIENT_NEW
], data
) < 0)
65 c
= pa_xnew(pa_client
, 1);
67 c
->proplist
= pa_proplist_copy(data
->proplist
);
68 c
->driver
= pa_xstrdup(pa_path_get_filename(data
->driver
));
69 c
->module
= data
->module
;
71 c
->sink_inputs
= pa_idxset_new(NULL
, NULL
);
72 c
->source_outputs
= pa_idxset_new(NULL
, NULL
);
77 pa_assert_se(pa_idxset_put(core
->clients
, c
, &c
->index
) >= 0);
79 pa_log_info("Created %u \"%s\"", c
->index
, pa_strnull(pa_proplist_gets(c
->proplist
, PA_PROP_APPLICATION_NAME
)));
80 pa_subscription_post(core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_NEW
, c
->index
);
82 pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_CLIENT_PUT
], c
);
84 pa_core_check_idle(core
);
89 void pa_client_free(pa_client
*c
) {
97 pa_hook_fire(&core
->hooks
[PA_CORE_HOOK_CLIENT_UNLINK
], c
);
99 pa_idxset_remove_by_data(c
->core
->clients
, c
, NULL
);
101 pa_log_info("Freed %u \"%s\"", c
->index
, pa_strnull(pa_proplist_gets(c
->proplist
, PA_PROP_APPLICATION_NAME
)));
102 pa_subscription_post(c
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_REMOVE
, c
->index
);
104 pa_assert(pa_idxset_isempty(c
->sink_inputs
));
105 pa_idxset_free(c
->sink_inputs
, NULL
, NULL
);
106 pa_assert(pa_idxset_isempty(c
->source_outputs
));
107 pa_idxset_free(c
->source_outputs
, NULL
, NULL
);
109 pa_proplist_free(c
->proplist
);
113 pa_core_check_idle(core
);
116 void pa_client_kill(pa_client
*c
) {
120 pa_log_warn("kill() operation not implemented for client %u", c
->index
);
127 void pa_client_set_name(pa_client
*c
, const char *name
) {
131 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
);
132 pa_proplist_sets(c
->proplist
, PA_PROP_APPLICATION_NAME
, name
);
134 pa_hook_fire(&c
->core
->hooks
[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED
], c
);
135 pa_subscription_post(c
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->index
);
138 void pa_client_update_proplist(pa_client
*c
, pa_update_mode_t mode
, pa_proplist
*p
) {
142 pa_proplist_update(c
->proplist
, mode
, p
);
144 pa_hook_fire(&c
->core
->hooks
[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED
], c
);
145 pa_subscription_post(c
->core
, PA_SUBSCRIPTION_EVENT_CLIENT
|PA_SUBSCRIPTION_EVENT_CHANGE
, c
->index
);