From 028693c380109912810a21b04ac843a505f2fcd5 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 6 May 2024 16:56:58 +0200 Subject: [PATCH] lib/nfs/Manager: forward-declare class ManagedConnection --- src/lib/nfs/Manager.cxx | 30 ++++++++++++++++++++++++++++++ src/lib/nfs/Manager.hxx | 36 ++++++------------------------------ 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/lib/nfs/Manager.cxx b/src/lib/nfs/Manager.cxx index ad1509b52..7005d7a6d 100644 --- a/src/lib/nfs/Manager.cxx +++ b/src/lib/nfs/Manager.cxx @@ -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 { diff --git a/src/lib/nfs/Manager.hxx b/src/lib/nfs/Manager.hxx index d8e361048..32c531b4c 100644 --- a/src/lib/nfs/Manager.hxx +++ b/src/lib/nfs/Manager.hxx @@ -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; 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