lib/nfs/Manager: forward-declare class ManagedConnection
This commit is contained in:
parent
63920be17e
commit
028693c380
@ -2,6 +2,7 @@
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#include "Manager.hxx"
|
||||
#include "Connection.hxx"
|
||||
#include "lib/fmt/ExceptionFormatter.hxx"
|
||||
#include "event/Loop.hxx"
|
||||
#include "util/DeleteDisposer.hxx"
|
||||
@ -11,6 +12,24 @@
|
||||
|
||||
static constexpr Domain nfs_domain("nfs");
|
||||
|
||||
class NfsManager::ManagedConnection final
|
||||
: public NfsConnection,
|
||||
public IntrusiveListHook<>
|
||||
{
|
||||
NfsManager &manager;
|
||||
|
||||
public:
|
||||
ManagedConnection(NfsManager &_manager, EventLoop &_loop,
|
||||
const char *_server,
|
||||
const char *_export_name) noexcept
|
||||
:NfsConnection(_loop, _server, _export_name),
|
||||
manager(_manager) {}
|
||||
|
||||
protected:
|
||||
/* virtual methods from NfsConnection */
|
||||
void OnNfsConnectionError(std::exception_ptr &&e) noexcept override;
|
||||
};
|
||||
|
||||
void
|
||||
NfsManager::ManagedConnection::OnNfsConnectionError(std::exception_ptr &&e) noexcept
|
||||
{
|
||||
@ -23,6 +42,9 @@ NfsManager::ManagedConnection::OnNfsConnectionError(std::exception_ptr &&e) noex
|
||||
manager.ScheduleDelete(*this);
|
||||
}
|
||||
|
||||
NfsManager::NfsManager(EventLoop &_loop) noexcept
|
||||
:idle_event(_loop, BIND_THIS_METHOD(OnIdle)) {}
|
||||
|
||||
NfsManager::~NfsManager() noexcept
|
||||
{
|
||||
assert(!GetEventLoop().IsAlive() || GetEventLoop().IsInside());
|
||||
@ -50,6 +72,14 @@ NfsManager::GetConnection(const char *server, const char *export_name) noexcept
|
||||
return *c;
|
||||
}
|
||||
|
||||
inline void
|
||||
NfsManager::ScheduleDelete(ManagedConnection &c) noexcept
|
||||
{
|
||||
connections.erase(connections.iterator_to(c));
|
||||
garbage.push_front(c);
|
||||
idle_event.Schedule();
|
||||
}
|
||||
|
||||
void
|
||||
NfsManager::CollectGarbage() noexcept
|
||||
{
|
||||
|
@ -1,36 +1,19 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_NFS_MANAGER_HXX
|
||||
#define MPD_NFS_MANAGER_HXX
|
||||
#pragma once
|
||||
|
||||
#include "Connection.hxx"
|
||||
#include "event/IdleEvent.hxx"
|
||||
#include "util/IntrusiveList.hxx"
|
||||
|
||||
class NfsConnection;
|
||||
|
||||
/**
|
||||
* A manager for NFS connections. Handles multiple connections to
|
||||
* multiple NFS servers.
|
||||
*/
|
||||
class NfsManager final {
|
||||
class ManagedConnection final
|
||||
: public NfsConnection,
|
||||
public IntrusiveListHook<>
|
||||
{
|
||||
NfsManager &manager;
|
||||
|
||||
public:
|
||||
ManagedConnection(NfsManager &_manager, EventLoop &_loop,
|
||||
const char *_server,
|
||||
const char *_export_name) noexcept
|
||||
:NfsConnection(_loop, _server, _export_name),
|
||||
manager(_manager) {}
|
||||
|
||||
protected:
|
||||
/* virtual methods from NfsConnection */
|
||||
void OnNfsConnectionError(std::exception_ptr &&e) noexcept override;
|
||||
};
|
||||
|
||||
class ManagedConnection;
|
||||
using List = IntrusiveList<ManagedConnection>;
|
||||
|
||||
List connections;
|
||||
@ -45,8 +28,7 @@ class NfsManager final {
|
||||
IdleEvent idle_event;
|
||||
|
||||
public:
|
||||
explicit NfsManager(EventLoop &_loop) noexcept
|
||||
:idle_event(_loop, BIND_THIS_METHOD(OnIdle)) {}
|
||||
explicit NfsManager(EventLoop &_loop) noexcept;
|
||||
|
||||
/**
|
||||
* Must be run from EventLoop's thread.
|
||||
@ -62,11 +44,7 @@ public:
|
||||
const char *export_name) noexcept;
|
||||
|
||||
private:
|
||||
void ScheduleDelete(ManagedConnection &c) noexcept {
|
||||
connections.erase(connections.iterator_to(c));
|
||||
garbage.push_front(c);
|
||||
idle_event.Schedule();
|
||||
}
|
||||
void ScheduleDelete(ManagedConnection &c) noexcept;
|
||||
|
||||
/**
|
||||
* Delete all connections on the #garbage list.
|
||||
@ -76,5 +54,3 @@ private:
|
||||
/* virtual methods from IdleMonitor */
|
||||
void OnIdle() noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user