diff options
author | Max Kellermann <max@duempel.org> | 2013-01-09 08:12:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-09 08:12:44 +0100 |
commit | 2564f763d7c206f36d6c10c16b78590e4a47714d (patch) | |
tree | 39786632609607cce887b4fa5d55ce73dfd9e32d /src | |
parent | 377a2b9e077d19501b89f4347afa78baa6c32f5f (diff) | |
download | mpd-2564f763d7c206f36d6c10c16b78590e4a47714d.tar.gz mpd-2564f763d7c206f36d6c10c16b78590e4a47714d.tar.xz mpd-2564f763d7c206f36d6c10c16b78590e4a47714d.zip |
ClientList: don't use GLib
Use std::list instead of GList.
Diffstat (limited to '')
-rw-r--r-- | src/ClientExpire.cxx | 4 | ||||
-rw-r--r-- | src/ClientIdle.cxx | 3 | ||||
-rw-r--r-- | src/ClientList.cxx | 22 | ||||
-rw-r--r-- | src/ClientList.hxx | 4 | ||||
-rw-r--r-- | src/MessageCommands.cxx | 6 |
5 files changed, 19 insertions, 20 deletions
diff --git a/src/ClientExpire.cxx b/src/ClientExpire.cxx index 36d54cda3..1e271c052 100644 --- a/src/ClientExpire.cxx +++ b/src/ClientExpire.cxx @@ -41,10 +41,8 @@ client_set_expired(Client *client) } static void -client_check_expired_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) +client_check_expired_callback(Client *client, G_GNUC_UNUSED gpointer user_data) { - Client *client = (Client *)data; - if (client_is_expired(client)) { g_debug("[%u] expired", client->num); client_close(client); diff --git a/src/ClientIdle.cxx b/src/ClientIdle.cxx index a787cc401..c125a8dfa 100644 --- a/src/ClientIdle.cxx +++ b/src/ClientIdle.cxx @@ -70,9 +70,8 @@ client_idle_add(Client *client, unsigned flags) } static void -client_idle_callback(gpointer data, gpointer user_data) +client_idle_callback(Client *client, gpointer user_data) { - Client *client = (Client *)data; unsigned flags = GPOINTER_TO_UINT(user_data); client_idle_add(client, flags); diff --git a/src/ClientList.cxx b/src/ClientList.cxx index ffefc7c05..b45be34c3 100644 --- a/src/ClientList.cxx +++ b/src/ClientList.cxx @@ -21,9 +21,12 @@ #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 @@ -41,30 +44,33 @@ client_list_is_full(void) Client * client_list_get_first(void) { - assert(clients != NULL); + assert(!clients.empty()); - return (Client *)clients->data; + return clients.front(); } void 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 (Client *client : clients) + callback(client, ctx); } void 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; } diff --git a/src/ClientList.hxx b/src/ClientList.hxx index 93e0f5408..fccc01d81 100644 --- a/src/ClientList.hxx +++ b/src/ClientList.hxx @@ -20,8 +20,6 @@ #ifndef MPD_CLIENT_LIST_HXX #define MPD_CLIENT_LIST_HXX -#include <glib.h> - class Client; bool @@ -37,7 +35,7 @@ void client_list_add(Client *client); void -client_list_foreach(GFunc func, gpointer user_data); +client_list_foreach(void (*callback)(Client *client, void *ctx), void *ctx); void client_list_remove(Client *client); diff --git a/src/MessageCommands.cxx b/src/MessageCommands.cxx index 3a7c38755..6a967f95b 100644 --- a/src/MessageCommands.cxx +++ b/src/MessageCommands.cxx @@ -78,11 +78,10 @@ struct channels_context { }; static void -collect_channels(gpointer data, gpointer user_data) +collect_channels(Client *client, gpointer user_data) { struct channels_context *context = (struct channels_context *)user_data; - const Client *client = (const Client *)data; context->channels.insert(client->subscriptions.begin(), client->subscriptions.end()); @@ -133,11 +132,10 @@ struct send_message_context { }; static void -send_message(gpointer data, gpointer user_data) +send_message(Client *client, gpointer user_data) { struct send_message_context *context = (struct send_message_context *)user_data; - Client *client = (Client *)data; if (client_push_message(client, context->msg)) context->sent = true; |