1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

fix coding style in Plugin class

This commit is contained in:
Steffen Vogel 2021-11-03 17:12:11 -04:00
parent b5977ed96f
commit da90facaa4
4 changed files with 38 additions and 78 deletions

View file

@ -45,10 +45,16 @@
#define HTTP_USER_AGENT PROJECT_NAME " (" PROJECT_BUILD_ID ")"
/* Hard-coded cache line size */
#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
#define CACHELINE_SIZE 64
#else
#error "Unsupported architecture"
#endif
/* Paths */
#define PREFIX "@CMAKE_INSTALL_PREFIX@"
#define PLUGIN_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/plugins"
#define WEB_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/web"
#define SYSFS_PATH "/sys"
#define PROCFS_PATH "/proc"

View file

@ -97,6 +97,11 @@ public:
list.push_back(t);
}
/* Sort alphabetically */
list.sort([](const T *a, const T *b) {
return a->getName() < b->getName();
});
return list;
}
@ -105,40 +110,48 @@ public:
dumpList();
};
class Loader {
public:
int load(const std::string &path);
int unload();
virtual int parse(json_t *json);
};
class Plugin {
friend plugin::Registry;
protected:
Logger logger;
public:
Plugin();
virtual ~Plugin();
virtual
~Plugin();
// copying a plugin doesn't make sense, so explicitly deny it
Plugin(Plugin const&) = delete;
void operator=(Plugin const&) = delete;
virtual void dump();
virtual
void dump();
/// Get plugin name
virtual std::string
getName() const = 0;
virtual
std::string getName() const = 0;
/// Get plugin type
virtual std::string
getType() const = 0;
virtual
std::string getType() const = 0;
// Get plugin description
virtual std::string
getDescription() const = 0;
virtual
std::string getDescription() const = 0;
virtual
Logger getLogger()
{
if (!logger) {
auto name = fmt::format("{}:{}", getType(), getName());
logger = logging.get(name);
}
return logger;
}
/** Custom formatter for spdlog */
template<typename OStream>
@ -146,17 +159,6 @@ public:
{
return os << p.getName();
}
protected:
std::string path;
virtual
Logger
getLogger()
{
auto name = fmt::format("{}:{}", getType(), getName());
return logging.get(name);
}
};
template<typename T = Plugin>

View file

@ -42,55 +42,6 @@ Plugin::~Plugin()
Registry::remove(this);
}
#if 0
int
Plugin::parse(json_t *json)
{
const char *path;
path = json_string_value(json);
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;
}
#endif
void
Plugin::dump()
{

View file

@ -104,6 +104,7 @@ void Table::header()
}
free(col);
free(unit);
}
logger->info("{}", line1);