Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2004-2006 Lennart Poettering
5 : : Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
6 : :
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.
11 : :
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.
16 : :
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
20 : : USA.
21 : : ***/
22 : :
23 : : #ifdef HAVE_CONFIG_H
24 : : #include <config.h>
25 : : #endif
26 : :
27 : : #include <stdio.h>
28 : : #include <stdlib.h>
29 : : #include <string.h>
30 : :
31 : : #include <pulse/xmalloc.h>
32 : : #include <pulse/util.h>
33 : :
34 : : #include <pulsecore/core-subscribe.h>
35 : : #include <pulsecore/log.h>
36 : : #include <pulsecore/macro.h>
37 : : #include <pulsecore/core-util.h>
38 : :
39 : : #include "client.h"
40 : :
41 : 0 : pa_client_new_data* pa_client_new_data_init(pa_client_new_data *data) {
42 [ # # ]: 0 : pa_assert(data);
43 : :
44 : : memset(data, 0, sizeof(*data));
45 : 0 : data->proplist = pa_proplist_new();
46 : :
47 : 0 : return data;
48 : : }
49 : :
50 : 0 : void pa_client_new_data_done(pa_client_new_data *data) {
51 [ # # ]: 0 : pa_assert(data);
52 : :
53 : 0 : pa_proplist_free(data->proplist);
54 : 0 : }
55 : :
56 : 0 : pa_client *pa_client_new(pa_core *core, pa_client_new_data *data) {
57 : : pa_client *c;
58 : :
59 : : pa_core_assert_ref(core);
60 [ # # ]: 0 : pa_assert(data);
61 : :
62 [ # # ]: 0 : if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_NEW], data) < 0)
63 : : return NULL;
64 : :
65 : 0 : c = pa_xnew(pa_client, 1);
66 : 0 : c->core = core;
67 : 0 : c->proplist = pa_proplist_copy(data->proplist);
68 : 0 : c->driver = pa_xstrdup(pa_path_get_filename(data->driver));
69 : 0 : c->module = data->module;
70 : :
71 : 0 : c->sink_inputs = pa_idxset_new(NULL, NULL);
72 : 0 : c->source_outputs = pa_idxset_new(NULL, NULL);
73 : :
74 : 0 : c->userdata = NULL;
75 : 0 : c->kill = NULL;
76 : 0 : c->send_event = NULL;
77 : :
78 [ # # ]: 0 : pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
79 : :
80 : 0 : pa_log_info("Created %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
81 : 0 : pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
82 : :
83 : 0 : pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
84 : :
85 : 0 : pa_core_check_idle(core);
86 : :
87 : 0 : return c;
88 : : }
89 : :
90 : 0 : void pa_client_free(pa_client *c) {
91 : : pa_core *core;
92 : :
93 [ # # ]: 0 : pa_assert(c);
94 [ # # ]: 0 : pa_assert(c->core);
95 : :
96 : 0 : core = c->core;
97 : :
98 : 0 : pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
99 : :
100 : 0 : pa_idxset_remove_by_data(c->core->clients, c, NULL);
101 : :
102 : 0 : pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
103 : 0 : pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
104 : :
105 [ # # ]: 0 : pa_assert(pa_idxset_isempty(c->sink_inputs));
106 : 0 : pa_idxset_free(c->sink_inputs, NULL, NULL);
107 [ # # ]: 0 : pa_assert(pa_idxset_isempty(c->source_outputs));
108 : 0 : pa_idxset_free(c->source_outputs, NULL, NULL);
109 : :
110 : 0 : pa_proplist_free(c->proplist);
111 : 0 : pa_xfree(c->driver);
112 : 0 : pa_xfree(c);
113 : :
114 : 0 : pa_core_check_idle(core);
115 : 0 : }
116 : :
117 : 0 : void pa_client_kill(pa_client *c) {
118 [ # # ]: 0 : pa_assert(c);
119 : :
120 [ # # ]: 0 : if (!c->kill) {
121 : 0 : pa_log_warn("kill() operation not implemented for client %u", c->index);
122 : 0 : return;
123 : : }
124 : :
125 : 0 : c->kill(c);
126 : : }
127 : :
128 : 0 : void pa_client_set_name(pa_client *c, const char *name) {
129 [ # # ]: 0 : pa_assert(c);
130 [ # # ]: 0 : pa_assert(name);
131 : :
132 : 0 : 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);
133 : 0 : pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
134 : :
135 : 0 : pa_client_update_proplist(c, 0, NULL);
136 : 0 : }
137 : :
138 : 0 : void pa_client_update_proplist(pa_client *c, pa_update_mode_t mode, pa_proplist *p) {
139 [ # # ]: 0 : pa_assert(c);
140 : :
141 [ # # ]: 0 : if (p)
142 : 0 : pa_proplist_update(c->proplist, mode, p);
143 : :
144 : 0 : pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_PROPLIST_CHANGED], c);
145 : 0 : pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
146 : 0 : }
147 : :
148 : 0 : void pa_client_send_event(pa_client *c, const char *event, pa_proplist *data) {
149 : 0 : pa_proplist *pl = NULL;
150 : : pa_client_send_event_hook_data hook_data;
151 : :
152 [ # # ]: 0 : pa_assert(c);
153 [ # # ]: 0 : pa_assert(event);
154 : :
155 [ # # ]: 0 : if (!c->send_event)
156 : 0 : return;
157 : :
158 [ # # ]: 0 : if (!data)
159 : 0 : data = pl = pa_proplist_new();
160 : :
161 : 0 : hook_data.client = c;
162 : 0 : hook_data.data = data;
163 : 0 : hook_data.event = event;
164 : :
165 [ # # ]: 0 : if (pa_hook_fire(&c->core->hooks[PA_CORE_HOOK_CLIENT_SEND_EVENT], &hook_data) < 0)
166 : : goto finish;
167 : :
168 : 0 : c->send_event(c, event, data);
169 : :
170 : : finish:
171 : :
172 [ # # ]: 0 : if (pl)
173 : 0 : pa_proplist_free(pl);
174 : : }
|