Client: add method GetInstance()

This commit is contained in:
Max Kellermann
2017-02-25 10:00:05 +01:00
parent 668724de4e
commit 05b8ddac4c
8 changed files with 33 additions and 21 deletions

View File

@@ -25,6 +25,12 @@
const Domain client_domain("client"); const Domain client_domain("client");
Instance &
Client::GetInstance()
{
return partition.instance;
}
playlist & playlist &
Client::GetPlaylist() Client::GetPlaylist()
{ {

View File

@@ -40,6 +40,7 @@
class SocketAddress; class SocketAddress;
class EventLoop; class EventLoop;
class Path; class Path;
struct Instance;
struct Partition; struct Partition;
struct PlayerControl; struct PlayerControl;
struct playlist; struct playlist;
@@ -187,6 +188,9 @@ public:
*/ */
void AllowFile(Path path_fs) const; void AllowFile(Path path_fs) const;
gcc_pure
Instance &GetInstance();
gcc_pure gcc_pure
playlist &GetPlaylist(); playlist &GetPlaylist();

View File

@@ -24,7 +24,6 @@
#include "client/ClientList.hxx" #include "client/ClientList.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"
#include "Instance.hxx" #include "Instance.hxx"
#include "Partition.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include <set> #include <set>
@@ -80,7 +79,7 @@ handle_channels(Client &client, gcc_unused Request args, Response &r)
assert(args.IsEmpty()); assert(args.IsEmpty());
std::set<std::string> channels; 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(), channels.insert(c.subscriptions.begin(),
c.subscriptions.end()); c.subscriptions.end());
@@ -122,7 +121,7 @@ handle_send_message(Client &client, Request args, Response &r)
bool sent = false; bool sent = false;
const ClientMessage msg(channel_name, message_text); 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)) if (c.PushMessage(msg))
sent = true; sent = true;

View File

@@ -23,7 +23,6 @@
#include "client/Client.hxx" #include "client/Client.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"
#include "Instance.hxx" #include "Instance.hxx"
#include "Partition.hxx"
#include "neighbor/Glue.hxx" #include "neighbor/Glue.hxx"
#include "neighbor/Info.hxx" #include "neighbor/Info.hxx"
@@ -39,7 +38,7 @@ CommandResult
handle_listneighbors(Client &client, gcc_unused Request args, Response &r) handle_listneighbors(Client &client, gcc_unused Request args, Response &r)
{ {
const NeighborGlue *const neighbors = const NeighborGlue *const neighbors =
client.partition.instance.neighbors; client.GetInstance().neighbors;
if (neighbors == nullptr) { if (neighbors == nullptr) {
r.Error(ACK_ERROR_UNKNOWN, "No neighbor plugin configured"); r.Error(ACK_ERROR_UNKNOWN, "No neighbor plugin configured");
return CommandResult::ERROR; return CommandResult::ERROR;

View File

@@ -126,11 +126,11 @@ handle_listfiles(Client &client, Request args, Response &r)
case LocatedUri::Type::RELATIVE: case LocatedUri::Type::RELATIVE:
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (client.partition.instance.storage != nullptr) if (client.GetInstance().storage != nullptr)
/* if we have a storage instance, obtain a list of /* if we have a storage instance, obtain a list of
files from it */ files from it */
return handle_listfiles_storage(r, return handle_listfiles_storage(r,
*client.partition.instance.storage, *client.GetInstance().storage,
uri); uri);
/* fall back to entries from database if we have no storage */ /* 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) if (update != nullptr)
return handle_update(r, *update, path, discard); return handle_update(r, *update, path, discard);
Database *db = client.partition.instance.database; Database *db = client.GetInstance().database;
if (db != nullptr) if (db != nullptr)
return handle_update(r, *db, path, discard); return handle_update(r, *db, path, discard);
#else #else

View File

@@ -31,7 +31,7 @@
CommandResult CommandResult
handle_listpartitions(Client &client, Request, Response &r) 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()); r.Format("partition: %s\n", partition.name.c_str());
} }
@@ -76,7 +76,7 @@ handle_newpartition(Client &client, Request request, Response &response)
return CommandResult::ERROR; return CommandResult::ERROR;
} }
auto &instance = client.partition.instance; auto &instance = client.GetInstance();
if (HasPartitionNamed(instance, name)) { if (HasPartitionNamed(instance, name)) {
response.Error(ACK_ERROR_EXIST, "name already exists"); response.Error(ACK_ERROR_EXIST, "name already exists");
return CommandResult::ERROR; return CommandResult::ERROR;

View File

@@ -182,7 +182,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
} }
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const UpdateService *update_service = client.partition.instance.update; const UpdateService *update_service = client.GetInstance().update;
unsigned updateJobId = update_service != nullptr unsigned updateJobId = update_service != nullptr
? update_service->GetId() ? update_service->GetId()
: 0; : 0;

View File

@@ -109,7 +109,7 @@ handle_listfiles_storage(Response &r, Storage &storage, const char *uri)
CommandResult CommandResult
handle_listfiles_storage(Client &client, Response &r, const char *uri) 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)); std::unique_ptr<Storage> storage(CreateStorageURI(event_loop, uri));
if (storage == nullptr) { if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI"); r.Error(ACK_ERROR_ARG, "Unrecognized storage URI");
@@ -148,7 +148,7 @@ print_storage_uri(Client &client, Response &r, const Storage &storage)
CommandResult CommandResult
handle_listmounts(Client &client, gcc_unused Request args, Response &r) handle_listmounts(Client &client, gcc_unused Request args, Response &r)
{ {
Storage *_composite = client.partition.instance.storage; Storage *_composite = client.GetInstance().storage;
if (_composite == nullptr) { if (_composite == nullptr) {
r.Error(ACK_ERROR_NO_EXIST, "No database"); r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR; return CommandResult::ERROR;
@@ -170,7 +170,9 @@ handle_listmounts(Client &client, gcc_unused Request args, Response &r)
CommandResult CommandResult
handle_mount(Client &client, Request args, Response &r) 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) { if (_composite == nullptr) {
r.Error(ACK_ERROR_NO_EXIST, "No database"); r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR; return CommandResult::ERROR;
@@ -196,7 +198,7 @@ handle_mount(Client &client, Request args, Response &r)
return CommandResult::ERROR; 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); Storage *storage = CreateStorageURI(event_loop, remote_uri);
if (storage == nullptr) { if (storage == nullptr) {
r.Error(ACK_ERROR_ARG, "Unrecognized storage URI"); 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); client.partition.EmitIdle(IDLE_MOUNT);
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
Database *_db = client.partition.instance.database; Database *_db = instance.database;
if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) { if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) {
SimpleDatabase &db = *(SimpleDatabase *)_db; SimpleDatabase &db = *(SimpleDatabase *)_db;
@@ -230,7 +232,9 @@ handle_mount(Client &client, Request args, Response &r)
CommandResult CommandResult
handle_unmount(Client &client, Request args, Response &r) 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) { if (_composite == nullptr) {
r.Error(ACK_ERROR_NO_EXIST, "No database"); r.Error(ACK_ERROR_NO_EXIST, "No database");
return CommandResult::ERROR; return CommandResult::ERROR;
@@ -246,13 +250,13 @@ handle_unmount(Client &client, Request args, Response &r)
} }
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
if (client.partition.instance.update != nullptr) if (instance.update != nullptr)
/* ensure that no database update will attempt to work /* ensure that no database update will attempt to work
with the database/storage instances we're about to with the database/storage instances we're about to
destroy here */ 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)) { if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) {
SimpleDatabase &db = *(SimpleDatabase *)_db; SimpleDatabase &db = *(SimpleDatabase *)_db;