]> code.delx.au - pulseaudio/blob - src/client.c
more work
[pulseaudio] / src / client.c
1 #include <stdio.h>
2 #include <assert.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "client.h"
7
8 struct client *client_new(struct core *core, const char *protocol_name, char *name) {
9 struct client *c;
10 int r;
11 assert(core);
12
13 c = malloc(sizeof(struct client));
14 assert(c);
15 c->protocol_name = protocol_name;
16 c->name = name ? strdup(name) : NULL;
17 c->kill = NULL;
18 c->kill_userdata = NULL;
19 c->core = core;
20
21 r = idxset_put(core->clients, c, &c->index);
22 assert(c->index != IDXSET_INVALID && r >= 0);
23
24 fprintf(stderr, "client: created %u \"%s\"\n", c->index, c->name);
25
26 return c;
27 }
28
29 void client_free(struct client *c) {
30 assert(c && c->core);
31
32 idxset_remove_by_data(c->core->clients, c, NULL);
33 fprintf(stderr, "client: freed %u \"%s\"\n", c->index, c->name);
34 free(c->name);
35 free(c);
36 }
37
38 void client_set_kill_callback(struct client *c, void (*kill)(struct client *c, void *userdata), void *userdata) {
39 assert(c && kill);
40 c->kill = kill;
41 c->kill_userdata = userdata;
42 }
43
44 void client_kill(struct client *c) {
45 assert(c);
46 c->kill(c, c->kill_userdata);
47 }
48