]> code.delx.au - pulseaudio/blob - src/pulsecore/client.c
s/pulsecore\/gccmacro.h/pulse\/gccmacro.h/
[pulseaudio] / src / pulsecore / client.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2 of the License,
12 or (at your option) any later version.
13
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include <pulse/xmalloc.h>
34
35 #include <pulsecore/core-subscribe.h>
36 #include <pulsecore/log.h>
37 #include <pulsecore/macro.h>
38 #include <pulsecore/core-util.h>
39
40 #include "client.h"
41
42 pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
43 pa_client *c;
44
45 pa_core_assert_ref(core);
46
47 c = pa_xnew(pa_client, 1);
48 c->core = core;
49 c->proplist = pa_proplist_new();
50 if (name)
51 pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
52 c->driver = pa_xstrdup(driver);
53 c->module = NULL;
54
55 c->kill = NULL;
56 c->userdata = NULL;
57
58 pa_assert_se(pa_idxset_put(core->clients, c, &c->index) >= 0);
59
60 pa_log_info("Created %u \"%s\"", c->index, pa_strnull(name));
61 pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
62
63 pa_core_check_quit(core);
64
65 return c;
66 }
67
68 void pa_client_free(pa_client *c) {
69 pa_assert(c);
70 pa_assert(c->core);
71
72 pa_idxset_remove_by_data(c->core->clients, c, NULL);
73
74 pa_core_check_quit(c->core);
75
76 pa_log_info("Freed %u \"%s\"", c->index, pa_strnull(pa_proplist_gets(c->proplist, PA_PROP_APPLICATION_NAME)));
77 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
78 pa_proplist_free(c->proplist);
79 pa_xfree(c->driver);
80 pa_xfree(c);
81 }
82
83 void pa_client_kill(pa_client *c) {
84 pa_assert(c);
85
86 if (!c->kill) {
87 pa_log_warn("kill() operation not implemented for client %u", c->index);
88 return;
89 }
90
91 c->kill(c);
92 }
93
94 void pa_client_set_name(pa_client *c, const char *name) {
95 pa_assert(c);
96
97 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);
98 pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
99 pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
100 }