playlist/Plugin: convert _init() and _finish() to methods

This commit is contained in:
Max Kellermann 2024-07-12 15:59:04 +02:00
parent cf5970a6e1
commit de9f0dc910
2 changed files with 25 additions and 34 deletions

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#ifndef MPD_PLAYLIST_PLUGIN_HXX #pragma once
#define MPD_PLAYLIST_PLUGIN_HXX
#include "input/Ptr.hxx" #include "input/Ptr.hxx"
#include "thread/Mutex.hxx" #include "thread/Mutex.hxx"
@ -117,33 +116,26 @@ struct PlaylistPlugin {
*/ */
[[gnu::pure]] [[gnu::pure]]
bool SupportsMimeType(std::string_view mime_type) const noexcept; bool SupportsMimeType(std::string_view mime_type) const noexcept;
};
/** /**
* Initialize a plugin. * Initialize the plugin.
* *
* @param block a configuration block for this plugin, or nullptr if none * @param block a configuration block for this plugin, or nullptr if none
* is configured * is configured
* @return true if the plugin was initialized successfully, false if * @return true if the plugin was initialized successfully, false if
* the plugin is not available * the plugin is not available
*/ */
static inline bool bool Init(const ConfigBlock &block) const {
playlist_plugin_init(const PlaylistPlugin *plugin, return init != nullptr
const ConfigBlock &block) ? init(block)
{
return plugin->init != nullptr
? plugin->init(block)
: true; : true;
} }
/** /**
* Deinitialize a plugin which was initialized successfully. * Deinitialize the plugin which was initialized successfully.
*/ */
static inline void void Finish() const noexcept {
playlist_plugin_finish(const PlaylistPlugin *plugin) noexcept if (finish != nullptr)
{ finish();
if (plugin->finish != nullptr)
plugin->finish();
} }
};
#endif

View File

@ -84,8 +84,7 @@ playlist_list_global_init(const ConfigData &config)
if (param != nullptr) if (param != nullptr)
param->SetUsed(); param->SetUsed();
playlist_plugins_enabled[i] = playlist_plugins_enabled[i] = playlist_plugins[i]->Init(*param);
playlist_plugin_init(playlist_plugins[i], *param);
playlist_plugins_as_folder[i] = playlist_plugins_as_folder[i] =
param->GetBlockValue("as_directory", param->GetBlockValue("as_directory",
@ -97,7 +96,7 @@ void
playlist_list_global_finish() noexcept playlist_list_global_finish() noexcept
{ {
for (const auto &plugin : GetEnabledPlaylistPlugins()) { for (const auto &plugin : GetEnabledPlaylistPlugins()) {
playlist_plugin_finish(&plugin); plugin.Finish();
} }
} }