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>
|
|
|
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
struct pa_client *pa_client_new(struct pa_core *core, const char *protocol_name, char *name) {
|
|
|
|
|
struct pa_client *c;
|
2004-06-08 23:54:24 +00:00
|
|
|
int r;
|
|
|
|
|
assert(core);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
c = malloc(sizeof(struct pa_client));
|
2004-06-08 23:54:24 +00:00
|
|
|
assert(c);
|
|
|
|
|
c->name = name ? strdup(name) : NULL;
|
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->protocol_name = protocol_name;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
fprintf(stderr, "client: created %u \"%s\"\n", c->index, c->name);
|
2004-06-08 23:54:24 +00:00
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void pa_client_free(struct 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-06-15 15:18:33 +00:00
|
|
|
fprintf(stderr, "client: freed %u \"%s\"\n", c->index, c->name);
|
2004-06-08 23:54:24 +00:00
|
|
|
free(c->name);
|
|
|
|
|
free(c);
|
|
|
|
|
}
|
2004-06-14 20:30:50 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void pa_client_kill(struct pa_client *c) {
|
2004-06-14 20:30:50 +00:00
|
|
|
assert(c);
|
2004-07-04 17:40:15 +00:00
|
|
|
if (!c->kill) {
|
|
|
|
|
fprintf(stderr, "kill() operation not implemented for client %u\n", c->index);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c->kill(c);
|
2004-06-14 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
void pa_client_rename(struct pa_client *c, const char *name) {
|
2004-06-29 16:48:37 +00:00
|
|
|
assert(c);
|
|
|
|
|
free(c->name);
|
|
|
|
|
c->name = name ? strdup(name) : NULL;
|
|
|
|
|
}
|