7
7
PulseAudio is free software; you can redistribute it and/or modify
8
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,
9
by the Free Software Foundation; either version 2.1 of the License,
10
10
or (at your option) any later version.
12
12
PulseAudio is distributed in the hope that it will be useful, but
38
39
#include "client.h"
40
pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
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) {
43
59
pa_core_assert_ref(core);
62
if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_NEW], data) < 0)
45
65
c = pa_xnew(pa_client, 1);
47
c->proplist = pa_proplist_new();
49
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
50
c->driver = pa_xstrdup(driver);
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);
56
78
pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
58
pa_log_info("Created %u \"%s\"", c->index, pa_strnull(name));
80
pa_log_info("Created %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
59
81
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
83
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
61
85
pa_core_check_idle(core);
70
94
pa_assert(c->core);
98
pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
73
100
pa_idxset_remove_by_data(c->core->clients, c, NULL);
75
102
pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
76
103
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
105
pa_assert(pa_idxset_isempty(c->sink_inputs));
106
pa_idxset_free(c->sink_inputs, NULL, NULL);
107
pa_assert(pa_idxset_isempty(c->source_outputs));
108
pa_idxset_free(c->source_outputs, NULL, NULL);
77
110
pa_proplist_free(c->proplist);
78
111
pa_xfree(c->driver);
95
128
void pa_client_set_name(pa_client *c, const char *name) {
98
132
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);
99
133
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
135
pa_client_update_proplist(c, 0, NULL);
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);
100
145
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
148
void pa_client_send_event(pa_client *c, const char *event, pa_proplist *data) {
149
pa_proplist *pl = NULL;
150
pa_client_send_event_hook_data hook_data;
159
data = pl = pa_proplist_new();
161
hook_data.client = c;
162
hook_data.data = data;
163
hook_data.event = event;
165
if (pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_SEND_EVENT], &hook_data) < 0)
168
c->send_event(c, event, data);
173
pa_proplist_free(pl);