2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2019-04-03 21:26:16 +02:00
|
|
|
#include "Client.hxx"
|
2019-04-03 14:31:57 +02:00
|
|
|
#include "Config.hxx"
|
2014-02-01 00:26:34 +01:00
|
|
|
#include "Partition.hxx"
|
|
|
|
#include "Instance.hxx"
|
2019-04-03 14:31:57 +02:00
|
|
|
#include "BackgroundCommand.hxx"
|
2020-01-18 22:14:50 +01:00
|
|
|
#include "IdleFlags.hxx"
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2013-09-27 22:31:24 +02:00
|
|
|
|
2019-04-03 14:44:01 +02:00
|
|
|
Client::~Client() noexcept
|
|
|
|
{
|
|
|
|
if (FullyBufferedSocket::IsDefined())
|
|
|
|
FullyBufferedSocket::Close();
|
2019-04-03 14:31:57 +02:00
|
|
|
|
|
|
|
if (background_command) {
|
|
|
|
background_command->Cancel();
|
|
|
|
background_command.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Client::SetBackgroundCommand(std::unique_ptr<BackgroundCommand> _bc) noexcept
|
|
|
|
{
|
|
|
|
assert(!background_command);
|
|
|
|
assert(_bc);
|
|
|
|
|
|
|
|
background_command = std::move(_bc);
|
|
|
|
|
|
|
|
/* disable timeouts while in "idle" */
|
|
|
|
timeout_event.Cancel();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Client::OnBackgroundCommandFinished() noexcept
|
|
|
|
{
|
|
|
|
assert(background_command);
|
|
|
|
|
|
|
|
background_command.reset();
|
|
|
|
|
|
|
|
/* just in case OnSocketInput() has returned
|
|
|
|
InputResult::PAUSE meanwhile */
|
|
|
|
ResumeInput();
|
|
|
|
|
|
|
|
timeout_event.Schedule(client_timeout);
|
2019-04-03 14:44:01 +02:00
|
|
|
}
|
|
|
|
|
2020-01-18 22:14:50 +01:00
|
|
|
void
|
|
|
|
Client::SetPartition(Partition &new_partition) noexcept
|
|
|
|
{
|
|
|
|
if (partition == &new_partition)
|
|
|
|
return;
|
|
|
|
|
2020-01-20 13:16:13 +01:00
|
|
|
partition->clients.erase(partition->clients.iterator_to(*this));
|
2020-01-18 22:14:50 +01:00
|
|
|
partition = &new_partition;
|
2020-01-20 13:16:13 +01:00
|
|
|
partition->clients.push_back(*this);
|
2020-01-18 22:14:50 +01:00
|
|
|
|
|
|
|
/* set idle flags for those subsystems which are specific to
|
|
|
|
the current partition to force the client to reload its
|
|
|
|
state */
|
|
|
|
idle_flags |= IDLE_PLAYLIST|IDLE_PLAYER|IDLE_MIXER|IDLE_OUTPUT|IDLE_OPTIONS;
|
|
|
|
/* note: we're not using IdleAdd() here because we don't need
|
|
|
|
to notify the client; the method is only used while this
|
|
|
|
client's "partition" command is handled, which means the
|
|
|
|
client is currently active and doesn't need to be woken
|
|
|
|
up */
|
|
|
|
}
|
|
|
|
|
2017-02-25 10:00:05 +01:00
|
|
|
Instance &
|
2020-01-20 12:47:53 +01:00
|
|
|
Client::GetInstance() const noexcept
|
2017-02-25 10:00:05 +01:00
|
|
|
{
|
2017-02-25 10:23:23 +01:00
|
|
|
return partition->instance;
|
2017-02-25 10:00:05 +01:00
|
|
|
}
|
|
|
|
|
2017-02-20 12:44:09 +01:00
|
|
|
playlist &
|
2020-01-20 12:47:53 +01:00
|
|
|
Client::GetPlaylist() const noexcept
|
2017-02-20 12:44:09 +01:00
|
|
|
{
|
2017-02-25 10:23:23 +01:00
|
|
|
return partition->playlist;
|
2017-02-20 12:44:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
PlayerControl &
|
2020-01-20 12:47:53 +01:00
|
|
|
Client::GetPlayerControl() const noexcept
|
2017-02-20 12:44:09 +01:00
|
|
|
{
|
2017-02-25 10:23:23 +01:00
|
|
|
return partition->pc;
|
2017-02-20 12:44:09 +01:00
|
|
|
}
|
|
|
|
|
2014-02-01 00:26:34 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
|
|
|
|
|
|
|
const Database *
|
2017-05-08 14:44:49 +02:00
|
|
|
Client::GetDatabase() const noexcept
|
2014-02-01 00:26:34 +01:00
|
|
|
{
|
2017-02-25 10:23:23 +01:00
|
|
|
return partition->instance.GetDatabase();
|
2014-02-01 00:26:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-26 18:47:19 +02:00
|
|
|
const Database &
|
|
|
|
Client::GetDatabaseOrThrow() const
|
|
|
|
{
|
2017-02-25 10:23:23 +01:00
|
|
|
return partition->instance.GetDatabaseOrThrow();
|
2016-10-26 18:47:19 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 00:29:07 +01:00
|
|
|
const Storage *
|
2017-05-08 14:44:49 +02:00
|
|
|
Client::GetStorage() const noexcept
|
2014-02-07 00:29:07 +01:00
|
|
|
{
|
2017-02-25 10:23:23 +01:00
|
|
|
return partition->instance.storage;
|
2014-02-07 00:29:07 +01:00
|
|
|
}
|
|
|
|
|
2014-02-01 00:26:34 +01:00
|
|
|
#endif
|