Commit 05b8ddac authored by Max Kellermann's avatar Max Kellermann

Client: add method GetInstance()

parent 668724de
......@@ -25,6 +25,12 @@
const Domain client_domain("client");
Instance &
Client::GetInstance()
{
return partition.instance;
}
playlist &
Client::GetPlaylist()
{
......
......@@ -40,6 +40,7 @@
class SocketAddress;
class EventLoop;
class Path;
struct Instance;
struct Partition;
struct PlayerControl;
struct playlist;
......@@ -188,6 +189,9 @@ public:
void AllowFile(Path path_fs) const;
gcc_pure
Instance &GetInstance();
gcc_pure
playlist &GetPlaylist();
gcc_pure
......
......@@ -24,7 +24,6 @@
#include "client/ClientList.hxx"
#include "client/Response.hxx"
#include "Instance.hxx"
#include "Partition.hxx"
#include "util/ConstBuffer.hxx"
#include <set>
......@@ -80,7 +79,7 @@ handle_channels(Client &client, gcc_unused Request args, Response &r)
assert(args.IsEmpty());
std::set<std::string> channels;
for (const auto &c : *client.partition.instance.client_list)
for (const auto &c : *client.GetInstance().client_list)
channels.insert(c.subscriptions.begin(),
c.subscriptions.end());
......@@ -122,7 +121,7 @@ handle_send_message(Client &client, Request args, Response &r)
bool sent = false;
const ClientMessage msg(channel_name, message_text);
for (auto &c : *client.partition.instance.client_list)
for (auto &c : *client.GetInstance().client_list)
if (c.PushMessage(msg))
sent = true;
......
......@@ -23,7 +23,6 @@
#include "client/Client.hxx"
#include "client/Response.hxx"
#include "Instance.hxx"
#include "Partition.hxx"
#include "neighbor/Glue.hxx"
#include "neighbor/Info.hxx"
......@@ -39,7 +38,7 @@ CommandResult
handle_listneighbors(Client &client, gcc_unused Request args, Response &r)
{
const NeighborGlue *const neighbors =
client.partition.instance.neighbors;
client.GetInstance().neighbors;
if (neighbors == nullptr) {
r.Error(ACK_ERROR_UNKNOWN, "No neighbor plugin configured");
return CommandResult::ERROR;
......
......@@ -126,11 +126,11 @@ handle_listfiles(Client &client, Request args, Response &r)
case LocatedUri::Type::RELATIVE:
#ifdef ENABLE_DATABASE
if (client.partition.instance.storage != nullptr)
if (client.GetInstance().storage != nullptr)
/* if we have a storage instance, obtain a list of
files from it */
return handle_listfiles_storage(r,
*client.partition.instance.storage,
*client.GetInstance().storage,
uri);
/* fall back to entries from database if we have no storage */
......@@ -295,11 +295,11 @@ handle_update(Client &client, Request args, Response &r, bool discard)
}
}
UpdateService *update = client.partition.instance.update;
UpdateService *update = client.GetInstance().update;
if (update != nullptr)
return handle_update(r, *update, path, discard);
Database *db = client.partition.instance.database;
Database *db = client.GetInstance().database;
if (db != nullptr)
return handle_update(r, *db, path, discard);
#else
......
......@@ -31,7 +31,7 @@
CommandResult
handle_listpartitions(Client &client, Request, Response &r)
{
for (const auto &partition : client.partition.instance.partitions) {
for (const auto &partition : client.GetInstance().partitions) {
r.Format("partition: %s\n", partition.name.c_str());
}
......@@ -76,7 +76,7 @@ handle_newpartition(Client &client, Request request, Response &response)
return CommandResult::ERROR;
}
auto &instance = client.partition.instance;
auto &instance = client.GetInstance();
if (HasPartitionNamed(instance, name)) {
response.Error(ACK_ERROR_EXIST, "name already exists");
return CommandResult::ERROR;
......
......@@ -182,7 +182,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
}
#ifdef ENABLE_DATABASE
const UpdateService *update_service = client.partition.instance.update;
const UpdateService *update_service = client.GetInstance().update;
unsigned updateJobId = update_service != nullptr
? update_service->GetId()
: 0;
......
......@@ -109,7 +109,7 @@ handle_listfiles_storage(Response &r, Storage &storage, const char *uri)
CommandResult
handle_listfiles_storage(Client &client, Response &r, const char *uri)
{
auto &event_loop = client.partition.instance.io_thread.GetEventLoop();
auto &event_loop = client.GetInstance().io_thread.GetEventLoop();
std::unique_ptr<Storage> storage(CreateStorageURI(event_loop, uri));
if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
......@@ -148,7 +148,7 @@ print_storage_uri(Client &client, Response &r, const Storage &storage)
CommandResult
handle_listmounts(Client &client, gcc_unused Request args, Response &r)
{
Storage *_composite = client.partition.instance.storage;
Storage *_composite = client.GetInstance().storage;
if (_composite == nullptr) {
r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
......@@ -170,7 +170,9 @@ handle_listmounts(Client &client, gcc_unused Request args, Response &r)
CommandResult
handle_mount(Client &client, Request args, Response &r)
{
Storage *_composite = client.partition.instance.storage;
auto &instance = client.GetInstance();
Storage *_composite = instance.storage;
if (_composite == nullptr) {
r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
......@@ -196,7 +198,7 @@ handle_mount(Client &client, Request args, Response &r)
return CommandResult::ERROR;
}
auto &event_loop = client.partition.instance.io_thread.GetEventLoop();
auto &event_loop = instance.io_thread.GetEventLoop();
Storage *storage = CreateStorageURI(event_loop, remote_uri);
if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
......@@ -207,7 +209,7 @@ handle_mount(Client &client, Request args, Response &r)
client.partition.EmitIdle(IDLE_MOUNT);
#ifdef ENABLE_DATABASE
Database *_db = client.partition.instance.database;
Database *_db = instance.database;
if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) {
SimpleDatabase &db = *(SimpleDatabase *)_db;
......@@ -230,7 +232,9 @@ handle_mount(Client &client, Request args, Response &r)
CommandResult
handle_unmount(Client &client, Request args, Response &r)
{
Storage *_composite = client.partition.instance.storage;
auto &instance = client.GetInstance();
Storage *_composite = instance.storage;
if (_composite == nullptr) {
r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR;
......@@ -246,13 +250,13 @@ handle_unmount(Client &client, Request args, Response &r)
}
#ifdef ENABLE_DATABASE
if (client.partition.instance.update != nullptr)
if (instance.update != nullptr)
/* ensure that no database update will attempt to work
with the database/storage instances we're about to
destroy here */
client.partition.instance.update->CancelMount(local_uri);
instance.update->CancelMount(local_uri);
Database *_db = client.partition.instance.database;
Database *_db = instance.database;
if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) {
SimpleDatabase &db = *(SimpleDatabase *)_db;
......
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