]> code.delx.au - pulseaudio/blob - src/pulsecore/client.c
Merge commit 'e0f8ffe41f99789fafac575e944acf02e940bbf7'
[pulseaudio] / src / pulsecore / client.c
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 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
33 #include <pulsecore/core-subscribe.h>
34 #include <pulsecore/log.h>
35 #include <pulsecore/macro.h>
36 #include <pulsecore/core-util.h>
37
38 #include "client.h"
39
40 pa_client_new_data* pa_client_new_data_init(pa_client_new_data *data) {
41 pa_assert(data);
42
43 memset(data, 0, sizeof(*data));
44 data->proplist = pa_proplist_new();
45
46 return data;
47 }
48
49 void pa_client_new_data_done(pa_client_new_data *data) {
50 pa_assert(data);
51
52 pa_proplist_free(data->proplist);
53 }
54
55 pa_client *pa_client_new(pa_core *core, pa_client_new_data *data) {
56 pa_client *c;
57
58 pa_core_assert_ref(core);
59 pa_assert(data);
60
61 if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_NEW], data) < 0)
62 return NULL;
63
64 c = pa_xnew(pa_client, 1);
65 c->core = core;
66 c->proplist = pa_proplist_copy(data->proplist);
67 c->driver = pa_xstrdup(data->driver);
68 c->module = data->module;
69
70 c->sink_inputs = pa_idxset_new(NULL, NULL);
71 c->source_outputs = pa_idxset_new(NULL, NULL);
72
73 c->userdata = NULL;
74 c->kill = NULL;
75
76 pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
77
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);
80
81 pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_PUT], c);
82
83 pa_core_check_idle(core);
84
85 return c;
86 }
87
88 void pa_client_free(pa_client *c) {
89 pa_core *core;
90
91 pa_assert(c);
92 pa_assert(c->core);
93
94 core = c->core;
95
96 pa_hook_fire(&core->hooks[PA_CORE_HOOK_CLIENT_UNLINK], c);
97
98 pa_idxset_remove_by_data(c->core->clients, c, NULL);
99
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);
102
103 pa_assert(pa_idxset_isempty(c->sink_inputs));
104 pa_idxset_free(c->sink_inputs, NULL, NULL);
105 pa_assert(pa_idxset_isempty(c->source_outputs));
106 pa_idxset_free(c->source_outputs, NULL, NULL);
107
108 pa_proplist_free(c->proplist);
109 pa_xfree(c->driver);
110 pa_xfree(c);
111
112 pa_core_check_idle(core);
113 }
114
115 void pa_client_kill(pa_client *c) {
116 pa_assert(c);
117
118 if (!c->kill) {
119 pa_log_warn("kill() operation not implemented for client %u", c->index);
120 return;
121 }
122
123 c->kill(c);
124 }
125
126 void pa_client_set_name(pa_client *c, const char *name) {
127 pa_assert(c);
128
129 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);
130 pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
131 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
132 }