1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-23 00:00:01 +01:00
VILLASnode/common/lib/plugin.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
2.2 KiB
C++
Raw Normal View History

2018-08-21 00:25:44 +02:00
/** Loadable / plugin support.
*
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:15:25 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2018-08-21 00:25:44 +02:00
* @license GNU General Public License (version 3)
*
* VILLAScommon
2018-08-21 00:25:44 +02:00
*
* This program 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
* any later version.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#include <iostream>
#include <string>
#include <new>
#include <type_traits>
#include <dlfcn.h>
#include <villas/plugin.hpp>
2018-08-23 13:22:46 +02:00
using namespace villas::plugin;
2018-08-21 00:25:44 +02:00
2018-08-23 13:22:46 +02:00
List<> * Registry::plugins;
2018-08-21 00:25:44 +02:00
2018-08-23 13:22:46 +02:00
Plugin::Plugin(const std::string& name, const std::string& desc) :
2018-08-21 00:25:44 +02:00
name(name),
2018-08-23 13:22:46 +02:00
description(desc)
2018-08-21 00:25:44 +02:00
{
2018-08-23 13:22:46 +02:00
Registry::add(this);
2018-08-21 00:25:44 +02:00
}
Plugin::~Plugin()
{
2018-08-23 13:22:46 +02:00
Registry::remove(this);
2018-08-21 00:25:44 +02:00
}
2018-08-23 13:22:46 +02:00
#if 0
2018-08-21 00:25:44 +02:00
int
Plugin::parse(json_t *cfg)
{
const char *path;
path = json_string_value(cfg);
if (!path)
return -1;
this->path = std::string(path);
2019-06-23 16:12:53 +02:00
this->state = State::PARSED;
2018-08-21 00:25:44 +02:00
return 0;
}
int
Plugin::load()
{
2019-06-23 16:12:53 +02:00
assert(this->state == State::PARSED);
2018-08-21 00:25:44 +02:00
assert(not this->path.empty());
this->handle = dlopen(this->path.c_str(), RTLD_NOW);
if (this->handle == nullptr)
return -1;
2019-06-23 16:12:53 +02:00
this->state = State::LOADED;
2018-08-21 00:25:44 +02:00
return 0;
}
int
Plugin::unload()
{
int ret;
2019-06-23 16:12:53 +02:00
assert(this->state == State::LOADED);
2018-08-21 00:25:44 +02:00
ret = dlclose(this->handle);
if (ret != 0)
return -1;
2019-06-23 16:12:53 +02:00
this->state = State::UNLOADED;
2018-08-21 00:25:44 +02:00
return 0;
}
2018-08-23 13:22:46 +02:00
#endif
2018-08-21 00:25:44 +02:00
void
Plugin::dump()
{
2018-11-30 21:43:37 +01:00
Logger logger = Registry::getLogger();
2018-08-21 00:25:44 +02:00
logger->info("Name: '{}' Description: '{}'", name, description);
}
2019-10-27 20:23:47 +01:00
const std::string & Plugin::getName() const
2018-08-21 00:25:44 +02:00
{
2018-08-23 13:22:46 +02:00
return name;
2018-08-21 00:25:44 +02:00
}
2019-10-27 20:23:47 +01:00
const std::string & Plugin::getDescription() const
2018-08-21 00:25:44 +02:00
{
2018-08-23 13:22:46 +02:00
return description;
2018-08-21 00:25:44 +02:00
}