mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
fix coding style in Plugin class
This commit is contained in:
parent
1c1c88a417
commit
2a3b464a84
4 changed files with 38 additions and 78 deletions
|
@ -45,10 +45,16 @@
|
||||||
|
|
||||||
#define HTTP_USER_AGENT PROJECT_NAME " (" PROJECT_BUILD_ID ")"
|
#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 */
|
/* Paths */
|
||||||
#define PREFIX "@CMAKE_INSTALL_PREFIX@"
|
#define PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||||
#define PLUGIN_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/plugins"
|
#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 SYSFS_PATH "/sys"
|
||||||
#define PROCFS_PATH "/proc"
|
#define PROCFS_PATH "/proc"
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,11 @@ public:
|
||||||
list.push_back(t);
|
list.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Sort alphabetically */
|
||||||
|
list.sort([](const T *a, const T *b) {
|
||||||
|
return a->getName() < b->getName();
|
||||||
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,40 +110,48 @@ public:
|
||||||
dumpList();
|
dumpList();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Loader {
|
|
||||||
|
|
||||||
public:
|
|
||||||
int load(const std::string &path);
|
|
||||||
int unload();
|
|
||||||
|
|
||||||
virtual int parse(json_t *json);
|
|
||||||
};
|
|
||||||
|
|
||||||
class Plugin {
|
class Plugin {
|
||||||
|
|
||||||
friend plugin::Registry;
|
friend plugin::Registry;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Logger logger;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Plugin();
|
Plugin();
|
||||||
virtual ~Plugin();
|
|
||||||
|
virtual
|
||||||
|
~Plugin();
|
||||||
|
|
||||||
// copying a plugin doesn't make sense, so explicitly deny it
|
// copying a plugin doesn't make sense, so explicitly deny it
|
||||||
Plugin(Plugin const&) = delete;
|
Plugin(Plugin const&) = delete;
|
||||||
void operator=(Plugin const&) = delete;
|
void operator=(Plugin const&) = delete;
|
||||||
|
|
||||||
virtual void dump();
|
virtual
|
||||||
|
void dump();
|
||||||
|
|
||||||
/// Get plugin name
|
/// Get plugin name
|
||||||
virtual std::string
|
virtual
|
||||||
getName() const = 0;
|
std::string getName() const = 0;
|
||||||
|
|
||||||
/// Get plugin type
|
/// Get plugin type
|
||||||
virtual std::string
|
virtual
|
||||||
getType() const = 0;
|
std::string getType() const = 0;
|
||||||
|
|
||||||
// Get plugin description
|
// Get plugin description
|
||||||
virtual std::string
|
virtual
|
||||||
getDescription() const = 0;
|
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 */
|
/** Custom formatter for spdlog */
|
||||||
template<typename OStream>
|
template<typename OStream>
|
||||||
|
@ -146,17 +159,6 @@ public:
|
||||||
{
|
{
|
||||||
return os << p.getName();
|
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>
|
template<typename T = Plugin>
|
||||||
|
|
|
@ -42,55 +42,6 @@ Plugin::~Plugin()
|
||||||
Registry::remove(this);
|
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
|
void
|
||||||
Plugin::dump()
|
Plugin::dump()
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,6 +104,7 @@ void Table::header()
|
||||||
}
|
}
|
||||||
|
|
||||||
free(col);
|
free(col);
|
||||||
|
free(unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger->info("{}", line1);
|
logger->info("{}", line1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue