client/BackgroundCommand: infrastructure for commands running in background

This commit is contained in:
Max Kellermann
2019-04-03 14:31:57 +02:00
parent 28fc1d555f
commit 9f1c23e217
11 changed files with 272 additions and 0 deletions

View File

@@ -34,6 +34,7 @@
#include <set>
#include <string>
#include <list>
#include <memory>
#include <stddef.h>
@@ -47,6 +48,7 @@ class PlayerControl;
struct playlist;
class Database;
class Storage;
class BackgroundCommand;
class Client final
: FullyBufferedSocket,
@@ -102,6 +104,14 @@ private:
*/
std::list<ClientMessage> messages;
/**
* The command currently running in background. If this is
* set, then the client is occupied and will not process any
* new input. If the connection gets closed, the
* #BackgroundCommand will be cancelled.
*/
std::unique_ptr<BackgroundCommand> background_command;
public:
Client(EventLoop &loop, Partition &partition,
UniqueSocketDescriptor fd, int uid,
@@ -152,6 +162,19 @@ public:
void IdleAdd(unsigned flags) noexcept;
bool IdleWait(unsigned flags) noexcept;
/**
* Called by a command handler to defer execution to a
* #BackgroundCommand.
*/
void SetBackgroundCommand(std::unique_ptr<BackgroundCommand> _bc) noexcept;
/**
* Called by the current #BackgroundCommand when it has
* finished, after sending the response. This method then
* deletes the #BackgroundCommand.
*/
void OnBackgroundCommandFinished() noexcept;
enum class SubscribeResult {
/** success */
OK,