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-06-18 00:22:37 +00:00
|
|
|
#include "strbuf.h"
|
2004-06-08 23:54:24 +00:00
|
|
|
|
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;
|
|
|
|
|
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-06-15 17:05:03 +00:00
|
|
|
if (c->kill)
|
|
|
|
|
c->kill(c);
|
2004-06-14 20:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
char *pa_client_list_to_string(struct pa_core *c) {
|
|
|
|
|
struct pa_strbuf *s;
|
|
|
|
|
struct pa_client *client;
|
|
|
|
|
uint32_t index = PA_IDXSET_INVALID;
|
2004-06-18 00:22:37 +00:00
|
|
|
assert(c);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
s = pa_strbuf_new();
|
2004-06-18 00:22:37 +00:00
|
|
|
assert(s);
|
|
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
pa_strbuf_printf(s, "%u client(s).\n", pa_idxset_ncontents(c->clients));
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
for (client = pa_idxset_first(c->clients, &index); client; client = pa_idxset_next(c->clients, &index))
|
|
|
|
|
pa_strbuf_printf(s, " index: %u, name: <%s>, protocol_name: <%s>\n", client->index, client->name, client->protocol_name);
|
2004-06-18 00:22:37 +00:00
|
|
|
|
2004-07-03 23:35:12 +00:00
|
|
|
return pa_strbuf_tostring_free(s);
|
2004-06-18 00:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
2004-06-29 16:48:37 +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;
|
|
|
|
|
}
|