]> code.delx.au - pulseaudio/blobdiff - src/client.c
esound protocol
[pulseaudio] / src / client.c
index 578d51c32539cabf536beff44f593760a9885c4f..3769128320cefb2e64aa291d4058316300be6fb3 100644 (file)
@@ -4,6 +4,7 @@
 #include <string.h>
 
 #include "client.h"
+#include "strbuf.h"
 
 struct client *client_new(struct core *core, const char *protocol_name, char *name) {
     struct client *c;
@@ -12,11 +13,12 @@ struct client *client_new(struct core *core, const char *protocol_name, char *na
 
     c = malloc(sizeof(struct client));
     assert(c);
-    c->protocol_name = protocol_name;
     c->name = name ? strdup(name) : NULL;
-    c->kill = NULL;
-    c->kill_userdata = NULL;
     c->core = core;
+    c->protocol_name = protocol_name;
+
+    c->kill = NULL;
+    c->userdata = NULL;
 
     r = idxset_put(core->clients, c, &c->index);
     assert(c->index != IDXSET_INVALID && r >= 0);
@@ -35,14 +37,32 @@ void client_free(struct client *c) {
     free(c);
 }
 
-void client_set_kill_callback(struct client *c, void (*kill)(struct client *c, void *userdata), void *userdata) {
-    assert(c && kill);
-    c->kill = kill;
-    c->kill_userdata = userdata;
+void client_kill(struct client *c) {
+    assert(c);
+    if (c->kill)
+        c->kill(c);
 }
 
-void client_kill(struct client *c) {
+char *client_list_to_string(struct core *c) {
+    struct strbuf *s;
+    struct client *client;
+    uint32_t index = IDXSET_INVALID;
     assert(c);
-    c->kill(c, c->kill_userdata);
+
+    s = strbuf_new();
+    assert(s);
+
+    strbuf_printf(s, "%u client(s).\n", idxset_ncontents(c->clients));
+    
+    for (client = idxset_first(c->clients, &index); client; client = idxset_next(c->clients, &index))
+        strbuf_printf(s, "    index: %u, name: <%s>, protocol_name: <%s>\n", client->index, client->name, client->protocol_name);
+    
+    return strbuf_tostring_free(s);
 }
 
+
+void client_rename(struct client *c, const char *name) {
+    assert(c);
+    free(c->name);
+    c->name = name ? strdup(name) : NULL;
+}