Skip to content

Commit

Permalink
playlist/Plugin: convert _init() and _finish() to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jul 12, 2024
1 parent cf5970a commit de9f0dc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
54 changes: 23 additions & 31 deletions src/playlist/PlaylistPlugin.hxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project

#ifndef MPD_PLAYLIST_PLUGIN_HXX
#define MPD_PLAYLIST_PLUGIN_HXX
#pragma once

#include "input/Ptr.hxx"
#include "thread/Mutex.hxx"
Expand Down Expand Up @@ -117,33 +116,26 @@ struct PlaylistPlugin {
*/
[[gnu::pure]]
bool SupportsMimeType(std::string_view mime_type) const noexcept;
};

/**
* Initialize a plugin.
*
* @param block a configuration block for this plugin, or nullptr if none
* is configured
* @return true if the plugin was initialized successfully, false if
* the plugin is not available
*/
static inline bool
playlist_plugin_init(const PlaylistPlugin *plugin,
const ConfigBlock &block)
{
return plugin->init != nullptr
? plugin->init(block)
: true;
}

/**
* Deinitialize a plugin which was initialized successfully.
*/
static inline void
playlist_plugin_finish(const PlaylistPlugin *plugin) noexcept
{
if (plugin->finish != nullptr)
plugin->finish();
}

#endif
/**
* Initialize the plugin.
*
* @param block a configuration block for this plugin, or nullptr if none
* is configured
* @return true if the plugin was initialized successfully, false if
* the plugin is not available
*/
bool Init(const ConfigBlock &block) const {
return init != nullptr
? init(block)
: true;
}

/**
* Deinitialize the plugin which was initialized successfully.
*/
void Finish() const noexcept {
if (finish != nullptr)
finish();
}
};
5 changes: 2 additions & 3 deletions src/playlist/PlaylistRegistry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ playlist_list_global_init(const ConfigData &config)
if (param != nullptr)
param->SetUsed();

playlist_plugins_enabled[i] =
playlist_plugin_init(playlist_plugins[i], *param);
playlist_plugins_enabled[i] = playlist_plugins[i]->Init(*param);

playlist_plugins_as_folder[i] =
param->GetBlockValue("as_directory",
Expand All @@ -97,7 +96,7 @@ void
playlist_list_global_finish() noexcept
{
for (const auto &plugin : GetEnabledPlaylistPlugins()) {
playlist_plugin_finish(&plugin);
plugin.Finish();
}
}

Expand Down

0 comments on commit de9f0dc

Please sign in to comment.