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.1 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>
* @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC
* @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);
this->state = STATE_PARSED;
return 0;
}
int
Plugin::load()
{
assert(this->state == STATE_PARSED);
assert(not this->path.empty());
this->handle = dlopen(this->path.c_str(), RTLD_NOW);
if (this->handle == nullptr)
return -1;
this->state = STATE_LOADED;
return 0;
}
int
Plugin::unload()
{
int ret;
assert(this->state == STATE_LOADED);
ret = dlclose(this->handle);
if (ret != 0)
return -1;
this->state = STATE_UNLOADED;
return 0;
}
2018-08-23 13:22:46 +02:00
#endif
2018-08-21 00:25:44 +02:00
void
Plugin::dump()
{
2018-08-23 13:22:46 +02:00
auto logger = Registry::getLogger();
2018-08-21 00:25:44 +02:00
logger->info("Name: '{}' Description: '{}'", name, description);
}
2018-08-23 13:22:46 +02:00
std::string Plugin::getName()
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
}
2018-08-23 13:22:46 +02:00
std::string Plugin::getDescription()
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
}