diff options
Diffstat (limited to '')
-rw-r--r-- | src/ClientList.cxx (renamed from src/client_list.c) | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/client_list.c b/src/ClientList.cxx index 2c7f37aff..a1248c8ec 100644 --- a/src/client_list.c +++ b/src/ClientList.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,11 +18,15 @@ */ #include "config.h" -#include "client_internal.h" +#include "ClientList.hxx" +#include "ClientInternal.hxx" + +#include <list> +#include <algorithm> #include <assert.h> -static GList *clients; +static std::list<Client *> clients; static unsigned num_clients; bool @@ -37,33 +41,36 @@ client_list_is_full(void) return num_clients >= client_max_connections; } -struct client * +Client * client_list_get_first(void) { - assert(clients != NULL); + assert(!clients.empty()); - return clients->data; + return clients.front(); } void -client_list_add(struct client *client) +client_list_add(Client *client) { - clients = g_list_prepend(clients, client); + clients.push_front(client); ++num_clients; } void -client_list_foreach(GFunc func, gpointer user_data) +client_list_foreach(void (*callback)(Client *client, void *ctx), void *ctx) { - g_list_foreach(clients, func, user_data); + for (auto client = clients.begin(); client != clients.end();) + callback(*(client++), ctx); } void -client_list_remove(struct client *client) +client_list_remove(Client *client) { assert(num_clients > 0); - assert(clients != NULL); + assert(!clients.empty()); - clients = g_list_remove(clients, client); + auto i = std::find(clients.begin(), clients.end(), client); + assert(i != clients.end()); + clients.erase(i); --num_clients; } |