Client: move "idle" functions into the class
This commit is contained in:
@@ -25,43 +25,36 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
/**
|
void
|
||||||
* Send "idle" response to this client.
|
Client::IdleNotify()
|
||||||
*/
|
|
||||||
static void
|
|
||||||
client_idle_notify(Client *client)
|
|
||||||
{
|
{
|
||||||
unsigned flags, i;
|
assert(idle_waiting);
|
||||||
const char *const* idle_names;
|
assert(idle_flags != 0);
|
||||||
|
|
||||||
assert(client->idle_waiting);
|
unsigned flags = idle_flags;
|
||||||
assert(client->idle_flags != 0);
|
idle_flags = 0;
|
||||||
|
idle_waiting = false;
|
||||||
|
|
||||||
flags = client->idle_flags;
|
const char *const*idle_names = idle_get_names();
|
||||||
client->idle_flags = 0;
|
for (unsigned i = 0; idle_names[i]; ++i) {
|
||||||
client->idle_waiting = false;
|
if (flags & (1 << i) & idle_subscriptions)
|
||||||
|
client_printf(this, "changed: %s\n",
|
||||||
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",
|
|
||||||
idle_names[i]);
|
idle_names[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
client_puts(client, "OK\n");
|
client_puts(this, "OK\n");
|
||||||
g_timer_start(client->last_activity);
|
g_timer_start(last_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
client_idle_add(Client *client, unsigned flags)
|
Client::IdleAdd(unsigned flags)
|
||||||
{
|
{
|
||||||
if (client->IsExpired())
|
if (IsExpired())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
client->idle_flags |= flags;
|
idle_flags |= flags;
|
||||||
if (client->idle_waiting
|
if (idle_waiting && (idle_flags & idle_subscriptions))
|
||||||
&& (client->idle_flags & client->idle_subscriptions))
|
IdleNotify();
|
||||||
client_idle_notify(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -69,7 +62,7 @@ client_idle_callback(Client *client, gpointer user_data)
|
|||||||
{
|
{
|
||||||
unsigned flags = GPOINTER_TO_UINT(user_data);
|
unsigned flags = GPOINTER_TO_UINT(user_data);
|
||||||
|
|
||||||
client_idle_add(client, flags);
|
client->IdleAdd(flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
void client_manager_idle_add(unsigned 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));
|
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;
|
idle_waiting = true;
|
||||||
client->idle_subscriptions = flags;
|
idle_subscriptions = flags;
|
||||||
|
|
||||||
if (client->idle_flags & client->idle_subscriptions) {
|
if (idle_flags & idle_subscriptions) {
|
||||||
client_idle_notify(client);
|
IdleNotify();
|
||||||
return true;
|
return true;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
|
@@ -20,11 +20,6 @@
|
|||||||
#ifndef MPD_CLIENT_IDLE_HXX
|
#ifndef MPD_CLIENT_IDLE_HXX
|
||||||
#define 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
|
* Adds the specified idle flags to all clients and immediately sends
|
||||||
* notifications to all waiting clients.
|
* notifications to all waiting clients.
|
||||||
@@ -32,12 +27,4 @@ client_idle_add(Client *client, unsigned flags);
|
|||||||
void
|
void
|
||||||
client_manager_idle_add(unsigned flags);
|
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
|
#endif
|
||||||
|
@@ -112,6 +112,13 @@ public:
|
|||||||
|
|
||||||
using BufferedSocket::Write;
|
using BufferedSocket::Write;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send "idle" response to this client.
|
||||||
|
*/
|
||||||
|
void IdleNotify();
|
||||||
|
void IdleAdd(unsigned flags);
|
||||||
|
bool IdleWait(unsigned flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* virtual methods from class BufferedSocket */
|
/* virtual methods from class BufferedSocket */
|
||||||
virtual InputResult OnSocketInput(const void *data,
|
virtual InputResult OnSocketInput(const void *data,
|
||||||
|
@@ -86,7 +86,7 @@ client_push_message(Client *client, const ClientMessage &msg)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (client->messages.empty())
|
if (client->messages.empty())
|
||||||
client_idle_add(client, IDLE_MESSAGE);
|
client->IdleAdd(IDLE_MESSAGE);
|
||||||
|
|
||||||
client->messages.push_back(msg);
|
client->messages.push_back(msg);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -41,9 +41,8 @@ extern "C" {
|
|||||||
|
|
||||||
#include "Permission.hxx"
|
#include "Permission.hxx"
|
||||||
#include "PlaylistFile.hxx"
|
#include "PlaylistFile.hxx"
|
||||||
#include "ClientIdle.hxx"
|
|
||||||
#include "ClientFile.hxx"
|
#include "ClientFile.hxx"
|
||||||
#include "Client.hxx"
|
#include "ClientInternal.hxx"
|
||||||
#include "Idle.hxx"
|
#include "Idle.hxx"
|
||||||
|
|
||||||
#ifdef ENABLE_SQLITE
|
#ifdef ENABLE_SQLITE
|
||||||
@@ -302,7 +301,7 @@ handle_idle(Client *client,
|
|||||||
flags = ~0;
|
flags = ~0;
|
||||||
|
|
||||||
/* enable "idle" mode on this client */
|
/* enable "idle" mode on this client */
|
||||||
client_idle_wait(client, flags);
|
client->IdleWait(flags);
|
||||||
|
|
||||||
return COMMAND_RETURN_IDLE;
|
return COMMAND_RETURN_IDLE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user