1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00
dindexer/include/backends/backend_loader.hpp
King_DuckZ f179d1fac5 Give more details when plugin discovery fails for a legit reason.
Skip files the whose mime type is not application/x-sharedlib,
which would be the ones allowed to fail loading. All errors on
failed dlopen() attempts now cause the code to throw.
2017-08-23 20:52:49 +01:00

68 lines
1.9 KiB
C++

/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id756A258A98B24B0DB2529BCEEC5137E2
#define id756A258A98B24B0DB2529BCEEC5137E2
#include <string>
#include <memory>
#include <boost/utility/string_ref.hpp>
#include <exception>
namespace YAML {
class Node;
} //namespace YAML
namespace dindb {
class Backend;
using BackendPtr = std::unique_ptr<dindb::Backend, void(*)(dindb::Backend*)>;
class SOLoadException : public std::runtime_error {
public:
explicit SOLoadException (std::string&& parMessage);
};
class BackendPlugin {
public:
BackendPlugin ( void );
BackendPlugin ( BackendPlugin&& ) = default;
BackendPlugin ( const std::string& parSOPath, const YAML::Node* parConfig );
~BackendPlugin ( void ) noexcept;
const boost::string_ref& name ( void ) const;
Backend& backend ( void );
const Backend& backend ( void ) const;
bool is_loaded ( void ) const;
int backend_interface_version ( void ) const;
int max_supported_interface_version ( void ) const;
BackendPlugin& operator= ( BackendPlugin&& ) = default;
private:
using SoHandle = std::unique_ptr<void, int(*)(void*)>;
SoHandle m_lib;
BackendPtr m_backend;
boost::string_ref m_name;
int m_iface_ver;
};
std::string backend_name ( const std::string& parSOPath );
} //namespace dindb
#endif