Commit cab84af7 authored by Max Kellermann's avatar Max Kellermann

Client: move "idle" functions into the class

parent 74500eac
sisyphus 0.23.15-alt1 0.23.14-alt1 0.23.13-alt1 0.23.12-alt1 0.23.11-alt1 0.23.8-alt3 0.23.8-alt2 0.23.8-alt1 0.21.24-alt1.1 0.21.24-alt1 0.20.23-alt3 0.20.23-alt2 0.20.23-alt1 0.20.21-alt1 0.20.15-alt1 0.18.14-alt1 0.18.11-alt1.1 0.18.11-alt1 0.18.10-alt1 v0.18.14 v0.18.13 v0.18.12 v0.18.11 v0.18.10 v0.18.9 v0.18.8 v0.18.7 v0.18.6 v0.18.5 v0.18.4 v0.18.3 v0.18.2 mpd/0.20.6-alt1 mpd/0.19.9-alt1 mpd/0.18.14-alt2 gb-sisyphus-task339776.6100 gb-sisyphus-task337393.100 gb-sisyphus-task337176.300 gb-sisyphus-task334590.100 gb-sisyphus-task333607.100 gb-sisyphus-task331543.2500 gb-sisyphus-task328663.4700 gb-sisyphus-task325064.100 gb-sisyphus-task319111.4000 gb-sisyphus-task313704.100 gb-sisyphus-task312885.100 gb-sisyphus-task308905.3200 gb-sisyphus-task305294.500 gb-sisyphus-task304007.100 gb-sisyphus-task303674.1700 gb-sisyphus-task298681.300 gb-sisyphus-task296051.1000 gb-sisyphus-task274827.100 gb-sisyphus-task269249.2000 gb-sisyphus-task266579.400 gb-sisyphus-task258132.600 gb-sisyphus-task254601.200 gb-sisyphus-task253310.100 gb-sisyphus-task252214.300 gb-sisyphus-task251539.6100 gb-sisyphus-task247988.7000 gb-sisyphus-task238768.6000 gb-sisyphus-task229151.100 gb-sisyphus-task227574.200 gb-sisyphus-task226762.6000 gb-sisyphus-task219546.1700 gb-sisyphus-task213491.100 gb-sisyphus-task198806.100 gb-sisyphus-task181400.100 gb-sisyphus-task141957.100 gb-sisyphus-task135039.100 gb-sisyphus-task130102.100 gb-sisyphus-task129023.100 gb-sisyphus-task127959.100 gb-sisyphus-task118591.100 gb-p9-task277538.2600 gb-c9f2-task327704.1100
No related merge requests found
......@@ -25,43 +25,36 @@
#include <assert.h>
/**
* Send "idle" response to this client.
*/
static void
client_idle_notify(Client *client)
void
Client::IdleNotify()
{
unsigned flags, i;
const char *const* idle_names;
assert(client->idle_waiting);
assert(client->idle_flags != 0);
assert(idle_waiting);
assert(idle_flags != 0);
flags = client->idle_flags;
client->idle_flags = 0;
client->idle_waiting = false;
unsigned flags = idle_flags;
idle_flags = 0;
idle_waiting = false;
idle_names = idle_get_names();
for (i = 0; idle_names[i]; ++i) {
if (flags & (1 << i) & client->idle_subscriptions)
client_printf(client, "changed: %s\n",
const char *const*idle_names = idle_get_names();
for (unsigned i = 0; idle_names[i]; ++i) {
if (flags & (1 << i) & idle_subscriptions)
client_printf(this, "changed: %s\n",
idle_names[i]);
}
client_puts(client, "OK\n");
g_timer_start(client->last_activity);
client_puts(this, "OK\n");
g_timer_start(last_activity);
}
void
client_idle_add(Client *client, unsigned flags)
Client::IdleAdd(unsigned flags)
{
if (client->IsExpired())
if (IsExpired())
return;
client->idle_flags |= flags;
if (client->idle_waiting
&& (client->idle_flags & client->idle_subscriptions))
client_idle_notify(client);
idle_flags |= flags;
if (idle_waiting && (idle_flags & idle_subscriptions))
IdleNotify();
}
static void
......@@ -69,7 +62,7 @@ client_idle_callback(Client *client, gpointer user_data)
{
unsigned flags = GPOINTER_TO_UINT(user_data);
client_idle_add(client, flags);
client->IdleAdd(flags);
}
void client_manager_idle_add(unsigned flags)
......@@ -79,15 +72,16 @@ void client_manager_idle_add(unsigned flags)
client_list_foreach(client_idle_callback, GUINT_TO_POINTER(flags));
}
bool client_idle_wait(Client *client, unsigned flags)
bool
Client::IdleWait(unsigned flags)
{
assert(!client->idle_waiting);
assert(!idle_waiting);
client->idle_waiting = true;
client->idle_subscriptions = flags;
idle_waiting = true;
idle_subscriptions = flags;
if (client->idle_flags & client->idle_subscriptions) {
client_idle_notify(client);
if (idle_flags & idle_subscriptions) {
IdleNotify();
return true;
} else
return false;
......
......@@ -20,11 +20,6 @@
#ifndef MPD_CLIENT_IDLE_HXX
#define MPD_CLIENT_IDLE_HXX
class Client;
void
client_idle_add(Client *client, unsigned flags);
/**
* Adds the specified idle flags to all clients and immediately sends
* notifications to all waiting clients.
......@@ -32,12 +27,4 @@ client_idle_add(Client *client, unsigned flags);
void
client_manager_idle_add(unsigned flags);
/**
* Checks whether the client has pending idle flags. If yes, they are
* sent immediately and "true" is returned". If no, it puts the
* client into waiting mode and returns false.
*/
bool
client_idle_wait(Client *client, unsigned flags);
#endif
......@@ -112,6 +112,13 @@ public:
using BufferedSocket::Write;
/**
* Send "idle" response to this client.
*/
void IdleNotify();
void IdleAdd(unsigned flags);
bool IdleWait(unsigned flags);
private:
/* virtual methods from class BufferedSocket */
virtual InputResult OnSocketInput(const void *data,
......
......@@ -86,7 +86,7 @@ client_push_message(Client *client, const ClientMessage &msg)
return false;
if (client->messages.empty())
client_idle_add(client, IDLE_MESSAGE);
client->IdleAdd(IDLE_MESSAGE);
client->messages.push_back(msg);
return true;
......
......@@ -41,9 +41,8 @@ extern "C" {
#include "Permission.hxx"
#include "PlaylistFile.hxx"
#include "ClientIdle.hxx"
#include "ClientFile.hxx"
#include "Client.hxx"
#include "ClientInternal.hxx"
#include "Idle.hxx"
#ifdef ENABLE_SQLITE
......@@ -302,7 +301,7 @@ handle_idle(Client *client,
flags = ~0;
/* enable "idle" mode on this client */
client_idle_wait(client, flags);
client->IdleWait(flags);
return COMMAND_RETURN_IDLE;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment