2004-07-16 19:56:36 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
|
|
/***
|
2006-06-19 21:53:48 +00:00
|
|
|
This file is part of PulseAudio.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2007-02-13 15:35:19 +00:00
|
|
|
Copyright 2004-2006 Lennart Poettering
|
|
|
|
|
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
2004-11-14 14:58:54 +00:00
|
|
|
it under the terms of the GNU Lesser General Public License as published
|
2004-07-16 19:56:36 +00:00
|
|
|
by the Free Software Foundation; either version 2 of the License,
|
|
|
|
|
or (at your option) any later version.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
PulseAudio is distributed in the hope that it will be useful, but
|
2004-07-16 19:56:36 +00:00
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
General Public License for more details.
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-11-14 14:58:54 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2006-06-19 21:53:48 +00:00
|
|
|
along with PulseAudio; if not, write to the Free Software
|
2004-07-16 19:56:36 +00:00
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
|
|
|
|
***/
|
|
|
|
|
|
2004-07-16 19:16:42 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-06-15 15:18:33 +00:00
|
|
|
#include <stdio.h>
|
2004-06-08 23:54:24 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulse/xmalloc.h>
|
2006-05-17 16:34:18 +00:00
|
|
|
|
2006-06-19 21:53:48 +00:00
|
|
|
#include <pulsecore/core-subscribe.h>
|
|
|
|
|
#include <pulsecore/log.h>
|
2006-02-17 12:10:58 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
#include "client.h"
|
|
|
|
|
|
2006-05-14 00:36:06 +00:00
|
|
|
pa_client *pa_client_new(pa_core *core, const char *driver, const char *name) {
|
2006-01-11 01:17:39 +00:00
|
|
|
pa_client *c;
|
2004-06-08 23:54:24 +00:00
|
|
|
int r;
|
|
|
|
|
assert(core);
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
c = pa_xmalloc(sizeof(pa_client));
|
2004-08-04 16:39:30 +00:00
|
|
|
c->name = pa_xstrdup(name);
|
2006-01-27 16:25:31 +00:00
|
|
|
c->driver = pa_xstrdup(driver);
|
2004-07-10 20:56:38 +00:00
|
|
|
c->owner = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
c->core = core;
|
2004-06-15 17:05:03 +00:00
|
|
|
|
|
|
|
|
c->kill = NULL;
|
|
|
|
|
c->userdata = NULL;
|
2004-06-08 23:54:24 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
r = pa_idxset_put(core->clients, c, &c->index);
|
|
|
|
|
assert(c->index != PA_IDXSET_INVALID && r >= 0);
|
2004-06-15 15:18:33 +00:00
|
|
|
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_info("created %u \"%s\"", c->index, c->name);
|
2004-08-11 00:11:12 +00:00
|
|
|
pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_NEW, c->index);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
|
|
|
|
pa_core_check_quit(core);
|
2007-01-04 13:43:45 +00:00
|
|
|
|
2004-06-08 23:54:24 +00:00
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_free(pa_client *c) {
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(c && c->core);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_idxset_remove_by_data(c->core->clients, c, NULL);
|
2004-09-04 00:27:36 +00:00
|
|
|
|
|
|
|
|
pa_core_check_quit(c->core);
|
|
|
|
|
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_info("freed %u \"%s\"", c->index, c->name);
|
2004-08-11 00:11:12 +00:00
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_REMOVE, c->index);
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(c->name);
|
2006-01-27 16:25:31 +00:00
|
|
|
pa_xfree(c->driver);
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(c);
|
2004-06-08 23:54:24 +00:00
|
|
|
}
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_kill(pa_client *c) {
|
2004-06-14 20:30:50 +00:00
|
|
|
assert(c);
|
2004-07-04 17:40:15 +00:00
|
|
|
if (!c->kill) {
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_warn("kill() operation not implemented for client %u", c->index);
|
2004-07-04 17:40:15 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->kill(c);
|
2004-06-14 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2006-01-11 01:17:39 +00:00
|
|
|
void pa_client_set_name(pa_client *c, const char *name) {
|
2004-06-29 16:48:37 +00:00
|
|
|
assert(c);
|
2006-06-13 09:33:55 +00:00
|
|
|
|
2006-08-18 21:38:40 +00:00
|
|
|
pa_log_info("client %u changed name from \"%s\" to \"%s\"", c->index, c->name, name);
|
2006-06-13 09:33:55 +00:00
|
|
|
|
2004-08-04 16:39:30 +00:00
|
|
|
pa_xfree(c->name);
|
|
|
|
|
c->name = pa_xstrdup(name);
|
2004-08-15 00:02:26 +00:00
|
|
|
|
|
|
|
|
pa_subscription_post(c->core, PA_SUBSCRIPTION_EVENT_CLIENT|PA_SUBSCRIPTION_EVENT_CHANGE, c->index);
|
2004-06-29 16:48:37 +00:00
|
|
|
}
|