]> code.delx.au - pulseaudio/blob - src/pulsecore/client.c
Merge dead branch 'prepare-0.9.10'
[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 *pa_client_new(pa_core *core, const char *driver, const char *name) {
41 pa_client *c;
42
43 pa_core_assert_ref(core);
44
45 c = pa_xnew(pa_client, 1);
46 c->core = core;
47 c->proplist = pa_proplist_new();
48 if (name)
49 pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
50 c->driver = pa_xstrdup(driver);
51 c->module = NULL;
52
53 c->kill = NULL;
54 c->userdata = NULL;
55
56 pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
57
58 pa_log_info("Created %u \"%s\"", c->index, pa_strnull(name));
59 pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
60
61 pa_core_check_quit(core);
62
63 return c;
64 }
65
66 void pa_client_free(pa_client *c) {
67 pa_core *core;
68
69 pa_assert(c);
70 pa_assert(c->core);
71
72 core = c->core;
73 pa_idxset_remove_by_data(c->core->clients, c, NULL);
74
75 pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
76 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
77 pa_proplist_free(c->proplist);
78 pa_xfree(c->driver);
79 pa_xfree(c);
80
81 pa_core_check_quit(core);
82 }
83
84 void pa_client_kill(pa_client *c) {
85 pa_assert(c);
86
87 if (!c->kill) {
88 pa_log_warn("kill() operation not implemented for client %u", c->index);
89 return;
90 }
91
92 c->kill(c);
93 }
94
95 void pa_client_set_name(pa_client *c, const char *name) {
96 pa_assert(c);
97
98 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 pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
100 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
101 }