Add copyright notices to all relevant files. (based on svn log)
[profile/ivi/pulseaudio.git] / 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 <assert.h>
31 #include <stdlib.h>
32 #include <string.h>
33
34 #include <pulse/xmalloc.h>
35
36 #include <pulsecore/core-subscribe.h>
37 #include <pulsecore/log.h>
38
39 #include "client.h"
40
41 pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
42     pa_client *c;
43     int r;
44     assert(core);
45
46     c = pa_xmalloc(sizeof(pa_client));
47     c->name = pa_xstrdup(name);
48     c->driver = pa_xstrdup(driver);
49     c->owner = NULL;
50     c->core = core;
51
52     c->kill = NULL;
53     c->userdata = NULL;
54
55     r = pa_idxset_put(core->clients, c, &c->index);
56     assert(c->index != PA_IDXSET_INVALID && r >= 0);
57
58     pa_log_info("created %u \"%s\"", c->index, c->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     assert(c && c->core);
68
69     pa_idxset_remove_by_data(c->core->clients, c, NULL);
70
71     pa_core_check_quit(c->core);
72
73     pa_log_info("freed %u \"%s\"", c->index, c->name);
74     pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
75     pa_xfree(c->name);
76     pa_xfree(c->driver);
77     pa_xfree(c);
78 }
79
80 void pa_client_kill(pa_client *c) {
81     assert(c);
82     if (!c->kill) {
83         pa_log_warn("kill() operation not implemented for client %u", c->index);
84         return;
85     }
86
87     c->kill(c);
88 }
89
90 void pa_client_set_name(pa_client *c, const char *name) {
91     assert(c);
92
93     pa_log_info("client %u changed name from \"%s\" to \"%s\"", c->index, c->name, name);
94
95     pa_xfree(c->name);
96     c->name = pa_xstrdup(name);
97
98     pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
99 }