[seiscomp, scanloc] Install, add .gitignore
This commit is contained in:
1346
include/seiscomp/system/application.h
Normal file
1346
include/seiscomp/system/application.h
Normal file
File diff suppressed because it is too large
Load Diff
130
include/seiscomp/system/commandline.h
Normal file
130
include/seiscomp/system/commandline.h
Normal file
@ -0,0 +1,130 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_SYSTEM_COMMANDLINE_H
|
||||
#define SEISCOMP_SYSTEM_COMMANDLINE_H
|
||||
|
||||
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace System {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API CommandLine {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
CommandLine();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
void addGroup(const char*);
|
||||
|
||||
void addOption(const char* group, const char* option,
|
||||
const char* description);
|
||||
|
||||
template <typename T>
|
||||
void addOption(const char* group, const char* option,
|
||||
const char* description, T* storage,
|
||||
bool storageAsDefault = true);
|
||||
|
||||
template <typename T>
|
||||
void addOption(const char* group, const char* option,
|
||||
const char* description, std::vector<T>* storage);
|
||||
|
||||
template <typename T, typename DT>
|
||||
void addOption(const char* group, const char* option,
|
||||
const char* description, T* storage,
|
||||
const DT& defaultValue);
|
||||
|
||||
template <typename T>
|
||||
void addCustomOption(const char* group, const char* option,
|
||||
const char* description, T* customValidator);
|
||||
|
||||
bool parse(int argc, char** argv);
|
||||
bool parse(int argc, char** argv, std::function<bool(const std::string &)> unknownArgumentFilter);
|
||||
|
||||
void printOptions() const;
|
||||
|
||||
/**
|
||||
* Returns whether a command line option is set or not.
|
||||
* This does not apply to mapped parameters from the
|
||||
* configuration file.
|
||||
*/
|
||||
bool hasOption(const std::string& option) const;
|
||||
|
||||
template <typename T>
|
||||
T option(const std::string& option) const;
|
||||
|
||||
template <typename T, int LEN>
|
||||
T option(const char (&option)[LEN]) const;
|
||||
|
||||
std::vector<std::string> unrecognizedOptions() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected functions
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
typedef boost::program_options::options_description program_options;
|
||||
typedef boost::program_options::options_description_easy_init options_description_easy_init;
|
||||
typedef boost::program_options::options_description options_description;
|
||||
typedef boost::program_options::variables_map variables_map;
|
||||
|
||||
options_description* findGroup(const char* group,
|
||||
const char* option = nullptr) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
typedef boost::shared_ptr<options_description> program_options_ptr;
|
||||
typedef std::vector<program_options_ptr> program_options_list;
|
||||
typedef std::map<std::string, program_options_ptr> program_options_map;
|
||||
|
||||
program_options_ptr _options;
|
||||
program_options_list _groups;
|
||||
program_options_map _groupsMap;
|
||||
variables_map _variableMap;
|
||||
|
||||
std::vector<std::string> _unrecognizedOptions;
|
||||
};
|
||||
|
||||
|
||||
#include <seiscomp/system/commandline.ipp>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
110
include/seiscomp/system/commandline.ipp
Normal file
110
include/seiscomp/system/commandline.ipp
Normal file
@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
template <typename T>
|
||||
void CommandLine::addOption(const char* group, const char* option,
|
||||
const char* description, T* storage,
|
||||
bool storageAsDefault) {
|
||||
options_description* o = findGroup(group);
|
||||
if ( o ) {
|
||||
if ( storageAsDefault && storage )
|
||||
(options_description_easy_init(o))(option, boost::program_options::value<T>(storage)->default_value(*storage), description);
|
||||
else
|
||||
(options_description_easy_init(o))(option, boost::program_options::value<T>(storage), description);
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void CommandLine::addOption(const char* group, const char* option,
|
||||
const char* description,
|
||||
std::vector<T>* storage) {
|
||||
options_description* o = findGroup(group);
|
||||
if ( o )
|
||||
// NOTE: Because of a bug in boost 1.33.1 the option multitoken() eats up
|
||||
// all arguments until the end of the commandline. So multitoken works
|
||||
// only for switches at the end of the commandline. To make it work
|
||||
// multitoken is disabled. So one has to give the option multiple times.
|
||||
// e.g.: 'test -i foo -i bar -j' instead of 'test -i foo bar -j'
|
||||
//(options_description_easy_init(o))(option, boost::program_options::value<std::vector<T> >(&storage)->multitoken(), description);
|
||||
(options_description_easy_init(o))(option, boost::program_options::value<std::vector<T> >(storage), description);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T, typename DT>
|
||||
void CommandLine::addOption(const char* group, const char* option,
|
||||
const char* description, T* storage,
|
||||
const DT& defaultValue) {
|
||||
options_description* o = findGroup(group);
|
||||
if ( o )
|
||||
(options_description_easy_init(o))(option, boost::program_options::value<T>(storage)->default_value(defaultValue), description);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
void CommandLine::addCustomOption(const char* group,
|
||||
const char* option,
|
||||
const char* description,
|
||||
T* customValidator) {
|
||||
options_description* o = findGroup(group);
|
||||
if ( o )
|
||||
(options_description_easy_init(o))(option, customValidator, description);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T>
|
||||
inline T CommandLine::option(const std::string& option) const {
|
||||
try {
|
||||
return boost::any_cast<T>(_variableMap[option].value());
|
||||
}
|
||||
catch ( ... ) {
|
||||
throw Core::TypeException("Invalid type for cast");
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename T, int LEN>
|
||||
inline T CommandLine::option(const char (&option)[LEN]) const {
|
||||
return this->option<T>(std::string(option));
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
231
include/seiscomp/system/environment.h
Normal file
231
include/seiscomp/system/environment.h
Normal file
@ -0,0 +1,231 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_SEISCOMPINIT_H
|
||||
#define SEISCOMP_SEISCOMPINIT_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/config/config.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
class SC_SYSTEM_CORE_API Environment {
|
||||
public:
|
||||
enum ConfigStage {
|
||||
CS_UNDEFINED = -1,
|
||||
CS_FIRST = 0,
|
||||
CS_DEFAULT_GLOBAL = 0,
|
||||
CS_DEFAULT_APP = 1,
|
||||
CS_CONFIG_GLOBAL = 2,
|
||||
CS_CONFIG_APP = 3,
|
||||
CS_USER_GLOBAL = 4,
|
||||
CS_USER_APP = 5,
|
||||
CS_LAST = 5,
|
||||
CS_QUANTITY = 6
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
Environment();
|
||||
|
||||
public:
|
||||
~Environment();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns an instance of Environment
|
||||
static Environment* Instance();
|
||||
|
||||
//! Returns the home directory path
|
||||
const std::string& homeDir() const;
|
||||
|
||||
//! Returns the seiscomp user configuration path
|
||||
const std::string& configDir() const;
|
||||
|
||||
//! Returns the 2nd level seiscomp configuration path
|
||||
const std::string &appConfigDir() const;
|
||||
|
||||
//! Returns the global seiscomp configuration path
|
||||
const std::string &globalConfigDir() const;
|
||||
|
||||
//! Returns the directory where the application, libraries and
|
||||
//! data files have been installed
|
||||
const std::string& installDir() const;
|
||||
|
||||
//! Returns the default shared data directory
|
||||
const std::string& shareDir() const;
|
||||
|
||||
//! Returns the logging directory
|
||||
const std::string& logDir() const;
|
||||
|
||||
//! Returns the path to the users configuration for the given name
|
||||
std::string configFileName(const std::string& programname) const;
|
||||
|
||||
//! Returns the path to the 2nd level configuration for the given name
|
||||
std::string appConfigFileName(const std::string& programname) const;
|
||||
|
||||
//! Returns the path to the 2nd level configuration for the given name
|
||||
std::string globalConfigFileName(const std::string& programname) const;
|
||||
|
||||
//! Returns a name for a logfile in the logging directory
|
||||
//! logDir + "/" + name + ".log"
|
||||
std::string logFile(const std::string& name) const;
|
||||
|
||||
std::string absolutePath(const std::string& name) const;
|
||||
std::string resolvePath(const std::string& name) const;
|
||||
|
||||
std::string configFileLocation(const std::string& name, int stage) const;
|
||||
|
||||
/** Confenience method to fill the symboltable.
|
||||
* Following files will be read:
|
||||
* SEISCOMP_ROOT/etc/global.cfg
|
||||
* SEISCOMP_ROOT/etc/<programname>.cfg
|
||||
* SEISCOMP_ROOT/config/global.cfg
|
||||
* SEISCOMP_ROOT/config/<programname>.cfg
|
||||
* ~/.seiscomp/global.cfg
|
||||
* ~/.seiscomp/<programname>.cfg
|
||||
*/
|
||||
bool initConfig(Config::Config *config, const std::string& name,
|
||||
int fromStage = CS_FIRST,
|
||||
int toStage = CS_LAST,
|
||||
bool standalone = false) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool init();
|
||||
|
||||
//! Creates a directory if it is not still existing
|
||||
bool createDir( const std::string& dir ) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
//! Home directory path
|
||||
std::string _homeDir;
|
||||
|
||||
//! Path of of the seiscomp home directory
|
||||
std::string _localConfigDir;
|
||||
|
||||
//! Seiscomp log directory
|
||||
std::string _logDir;
|
||||
|
||||
//! Seiscomp install directory
|
||||
std::string _installDir;
|
||||
|
||||
//! Seiscomp plugin directory
|
||||
std::string _shareDir;
|
||||
|
||||
//! Suffix of the clients archive file
|
||||
std::string _archiveFileName;
|
||||
|
||||
std::string _appConfigDir;
|
||||
std::string _globalConfigDir;
|
||||
|
||||
static std::unique_ptr<Environment> _instance;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Inline methods
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string& Environment::configDir() const {
|
||||
return _localConfigDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string &Environment::appConfigDir() const {
|
||||
return _appConfigDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string &Environment::globalConfigDir() const {
|
||||
return _globalConfigDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string& Environment::homeDir() const {
|
||||
return _homeDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string& Environment::installDir() const {
|
||||
return _installDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string& Environment::shareDir() const {
|
||||
return _shareDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
inline const std::string& Environment::logDir() const {
|
||||
return _logDir;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
95
include/seiscomp/system/hostinfo.h
Normal file
95
include/seiscomp/system/hostinfo.h
Normal file
@ -0,0 +1,95 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_SYSTEM_HOSTINFO_H
|
||||
#define SEISCOMP_SYSTEM_HOSTINFO_H
|
||||
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace System {
|
||||
|
||||
|
||||
/**
|
||||
* @brief The HostInfo class returns information about the host system of
|
||||
* the current process.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API HostInfo {
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
HostInfo();
|
||||
~HostInfo();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public query interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
int pid() const;
|
||||
std::string name() const;
|
||||
std::string login() const;
|
||||
std::string programName() const;
|
||||
|
||||
/**
|
||||
* @brief Returns the amount of available memory on this host.
|
||||
* @return Total memory in kb
|
||||
*/
|
||||
int64_t totalMemory() const;
|
||||
|
||||
/**
|
||||
* @brief Returns the currently used memory of this process.
|
||||
* @return Used memory in kb
|
||||
*/
|
||||
int getCurrentMemoryUsage() const;
|
||||
|
||||
/**
|
||||
* @brief Computes the current CPU usage with respect to the
|
||||
* last call. The very first call to this method will not
|
||||
* succeed and return an invalid value (-1).
|
||||
* @param forceReset Forces resetting of the internal state. If set
|
||||
* to true then an invalid value will be returned
|
||||
* and the current time is set as the next reference
|
||||
* time.
|
||||
* @return The relative CPU usage. 1 means 100% of one core. If
|
||||
* the returned value is negative then it is invalid.
|
||||
*/
|
||||
double getCurrentCpuUsage(bool forceReset = false);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private members
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
class Impl;
|
||||
Impl *_impl;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
759
include/seiscomp/system/model.h
Normal file
759
include/seiscomp/system/model.h
Normal file
@ -0,0 +1,759 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CONFIGURATION_MODEL_H
|
||||
#define SEISCOMP_CONFIGURATION_MODEL_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/config/log.h>
|
||||
#include <seiscomp/config/symboltable.h>
|
||||
#include <seiscomp/system/environment.h>
|
||||
#include <seiscomp/system/schema.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace System {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Module);
|
||||
DEFINE_SMARTPOINTER(Parameter);
|
||||
|
||||
struct SC_SYSTEM_CORE_API ConfigDelegate : Config::Logger {
|
||||
struct CSConflict {
|
||||
Module *module;
|
||||
Parameter *parameter;
|
||||
int stage;
|
||||
Config::Symbol *symbol;
|
||||
};
|
||||
|
||||
enum Operation {
|
||||
Added,
|
||||
Removed,
|
||||
Updated
|
||||
};
|
||||
|
||||
struct Change {
|
||||
Change() {}
|
||||
Change(Operation op, const std::string &var,
|
||||
const std::string &old_content, const std::string &new_content)
|
||||
: operation(op), variable(var)
|
||||
, oldContent(old_content), newContent(new_content) {}
|
||||
|
||||
Operation operation;
|
||||
std::string variable;
|
||||
std::string oldContent;
|
||||
std::string newContent;
|
||||
};
|
||||
|
||||
typedef std::vector<Change> ChangeList;
|
||||
|
||||
virtual void aboutToRead(const char *filename) {}
|
||||
virtual void finishedReading(const char *filename) {}
|
||||
|
||||
//! Return true to cause the model to re-read the file
|
||||
//! or false to go on.
|
||||
virtual bool handleReadError(const char *filename) { return false; }
|
||||
|
||||
virtual void aboutToWrite(const char *filename) {}
|
||||
virtual void finishedWriting(const char *filename, const ChangeList &changes) {}
|
||||
|
||||
//! Notification about a write error of a file
|
||||
virtual void hasWriteError(const char *filename) {}
|
||||
|
||||
//! Return true to cause the model to skip writing to the file
|
||||
//! or false to go on.
|
||||
virtual bool handleWriteTimeMismatch(const char *filename, const ChangeList &changes) { return false; }
|
||||
virtual void caseSensitivityConflict(const CSConflict &) {}
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SymbolMapItem);
|
||||
struct SC_SYSTEM_CORE_API SymbolMapItem : public Core::BaseObject {
|
||||
SymbolMapItem() : known(false) {}
|
||||
SymbolMapItem(const Config::Symbol &s) : symbol(s), known(false) {}
|
||||
|
||||
Config::Symbol symbol;
|
||||
bool known;
|
||||
};
|
||||
|
||||
class ModelVisitor;
|
||||
|
||||
DEFINE_SMARTPOINTER(Group);
|
||||
DEFINE_SMARTPOINTER(Structure);
|
||||
DEFINE_SMARTPOINTER(Parameter);
|
||||
class SC_SYSTEM_CORE_API Container : public Core::BaseObject {
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
Container(const char *path_, const Container *super_ = nullptr)
|
||||
: super(super_), parent(nullptr), path(path_) {}
|
||||
|
||||
Container(const std::string &path_, const Container *super_ = nullptr)
|
||||
: super(super_), parent(nullptr), path(path_) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void add(Parameter *);
|
||||
Parameter *parameter(size_t i) const { return parameters[i].get(); }
|
||||
size_t parameterCount() const { return parameters.size(); }
|
||||
|
||||
void add(Group *);
|
||||
Group *group(size_t i) const { return groups[i].get(); }
|
||||
size_t groupCount() const { return groups.size(); }
|
||||
|
||||
void add(Structure *);
|
||||
Structure *structure(size_t i) const { return structures[i].get(); }
|
||||
size_t structureCount() const { return structures.size(); }
|
||||
|
||||
void addType(Structure *);
|
||||
|
||||
bool hasStructure(const char *name) const;
|
||||
bool hasStructure(const std::string &name) const;
|
||||
|
||||
//! Creates a new structure with name of a certain type wich must
|
||||
//! exist. If a valid pointer is returned the structure has been
|
||||
//! added to this->structures.
|
||||
Structure *instantiate(const Structure *s, const char *name);
|
||||
|
||||
//! Removes an existing structure
|
||||
bool remove(Structure *s);
|
||||
|
||||
Structure *findStructureType(const std::string &type) const;
|
||||
|
||||
//! Returns a parameter in the tree where the fully expanded name
|
||||
//! matches @fullName@.
|
||||
Parameter *findParameter(const std::string &fullName) const;
|
||||
|
||||
//! Returns a container at path @path@.
|
||||
Container *findContainer(const std::string &path) const;
|
||||
|
||||
//! Accepts a model visitor and starts to traversing its nodes
|
||||
void accept(ModelVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
const Container *super;
|
||||
Core::BaseObject *parent;
|
||||
std::string path;
|
||||
std::vector<GroupPtr> groups;
|
||||
std::vector<ParameterPtr> parameters;
|
||||
std::vector<StructurePtr> structures;
|
||||
std::vector<StructurePtr> structureTypes;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Parameter : public Core::BaseObject {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Parameter(SchemaParameter *def, const char *n);
|
||||
Parameter(SchemaParameter *def, const std::string &n);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Parameter *copy(bool backImport = false);
|
||||
Parameter *clone() const;
|
||||
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
bool inherits(const Parameter *param) const;
|
||||
|
||||
void updateFinalValue(int maxStage = Environment::CS_LAST);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Core::BaseObject *parent;
|
||||
const Parameter *super;
|
||||
SchemaParameter *definition;
|
||||
SymbolMapItemPtr symbols[Environment::CS_QUANTITY];
|
||||
Config::Symbol symbol;
|
||||
std::string variableName;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Structure : public Container {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Structure(SchemaStructure *def, const char *xpth, const char *n)
|
||||
: Container(xpth), definition(def), name(n) {}
|
||||
Structure(SchemaStructure *def, const std::string &xpth, const std::string &n)
|
||||
: Container(xpth), definition(def), name(n) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Structure *copy(bool backImport = false);
|
||||
Structure *clone() const;
|
||||
Structure *instantiate(const char *name) const;
|
||||
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaStructure *definition;
|
||||
std::vector<SchemaStructExtentPtr> extensions;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Group : public Container {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Group(SchemaGroup *def, const char *path_)
|
||||
: Container(path_), definition(def) {}
|
||||
Group(SchemaGroup *def, const std::string &path_)
|
||||
: Container(path_), definition(def) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Group *copy(bool backImport = false);
|
||||
Group *clone() const;
|
||||
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaGroup *definition;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Section);
|
||||
class SC_SYSTEM_CORE_API Section : public Container {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Section(const char *n) : Container(""), name(n) {}
|
||||
Section(const std::string &n) : Container(""), name(n) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Section *copy(bool backImport = false);
|
||||
Section *clone() const;
|
||||
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Module);
|
||||
DEFINE_SMARTPOINTER(Model);
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Binding);
|
||||
class SC_SYSTEM_CORE_API Binding : public Core::BaseObject {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Binding(const std::string &n) : parent(nullptr), definition(nullptr), name(n) {}
|
||||
Binding *clone() const;
|
||||
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
Section *section(size_t i) const { return sections[i].get(); }
|
||||
size_t sectionCount() const { return sections.size(); }
|
||||
|
||||
//! Returns a container at path @path@.
|
||||
virtual Container *findContainer(const std::string &path) const;
|
||||
|
||||
//! Returns a parameters in the tree where the fully expanded name
|
||||
//! matches fullName.
|
||||
virtual Parameter *findParameter(const std::string &fullName) const;
|
||||
|
||||
virtual void accept(ModelVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Core::BaseObject *parent;
|
||||
SchemaBinding *definition;
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::vector<SectionPtr> sections;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(BindingCategory);
|
||||
class SC_SYSTEM_CORE_API BindingCategory : public Core::BaseObject {
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
BindingCategory(const char *n) : name(n) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
// Returns a binding (template) with given name
|
||||
Binding *binding(const std::string &name) const;
|
||||
BindingCategory *clone() const;
|
||||
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
//! Returns if a binding is instantiated with a given alias.
|
||||
bool hasBinding(const char *alias) const;
|
||||
|
||||
//! Creates a new binding as alias of a certain binding wich must
|
||||
//! exist. If a valid pointer is returned the binding has been
|
||||
//! added to this->bindings.
|
||||
Binding *instantiate(const Binding *b, const char *alias);
|
||||
|
||||
//! Returns the alias for an instantiated binding.
|
||||
//! Returns nullptr if the binding is not instantiated in this
|
||||
//! category.
|
||||
const char *alias(const Binding *b) const;
|
||||
|
||||
bool removeInstance(const Binding *b);
|
||||
bool removeInstance(const char *alias);
|
||||
|
||||
//! Returns a container at path @path@.
|
||||
Container *findContainer(const std::string &path) const;
|
||||
|
||||
//! Returns a parameters in the tree where the fully expanded name
|
||||
//! matches fullName.
|
||||
Parameter *findParameter(const std::string &fullName) const;
|
||||
|
||||
void accept(ModelVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
struct BindingInstance {
|
||||
BindingInstance(Binding *b, const std::string &a)
|
||||
: binding(b), alias(a) {}
|
||||
BindingPtr binding;
|
||||
std::string alias;
|
||||
};
|
||||
|
||||
typedef std::vector<BindingPtr> Bindings;
|
||||
typedef std::vector<BindingInstance> BindingInstances;
|
||||
|
||||
Binding *parent;
|
||||
std::string name;
|
||||
BindingInstances bindings;
|
||||
Bindings bindingTypes;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ModuleBinding);
|
||||
class SC_SYSTEM_CORE_API ModuleBinding : public Binding {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
ModuleBinding(const std::string &n) : Binding(n) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
ModuleBinding *clone() const;
|
||||
|
||||
void add(BindingCategory *);
|
||||
BindingCategory *category(const std::string &name) const;
|
||||
|
||||
bool writeConfig(const std::string &filename,
|
||||
ConfigDelegate *delegate = nullptr) const;
|
||||
void dump(std::ostream &os) const;
|
||||
|
||||
//! Returns a container at path @path@.
|
||||
Container *findContainer(const std::string &path) const;
|
||||
|
||||
//! Returns a parameters in the tree where the fully expanded name
|
||||
//! matches fullName.
|
||||
Parameter *findParameter(const std::string &fullName) const;
|
||||
|
||||
void accept(ModelVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef std::vector<BindingCategoryPtr> Categories;
|
||||
std::string configFile;
|
||||
Categories categories;
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API StationID {
|
||||
StationID() {}
|
||||
StationID(const std::string &net, const std::string &sta)
|
||||
: networkCode(net), stationCode(sta) {}
|
||||
|
||||
bool operator==(const StationID &other) const {
|
||||
return networkCode == other.networkCode &&
|
||||
stationCode == other.stationCode;
|
||||
}
|
||||
|
||||
bool operator<(const StationID &other) const {
|
||||
if ( networkCode == other.networkCode )
|
||||
return stationCode < other.stationCode;
|
||||
return networkCode < other.networkCode;
|
||||
}
|
||||
|
||||
std::string networkCode;
|
||||
std::string stationCode;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Module : public Core::BaseObject {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Module(SchemaModule *def)
|
||||
: definition(def) {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns if the module has any parameter to configure.
|
||||
bool hasConfiguration() const;
|
||||
|
||||
void add(Section *);
|
||||
Section *section(size_t i) const { return sections[i].get(); }
|
||||
size_t sectionCount() const { return sections.size(); }
|
||||
|
||||
//! Returns a parameters in the tree where the fully expanded name
|
||||
//! matches fullName.
|
||||
Parameter *findParameter(const std::string &fullName) const;
|
||||
|
||||
//! Returns a container at path @path@.
|
||||
Container *findContainer(const std::string &path) const;
|
||||
|
||||
bool supportsBindings() const { return bindingTemplate.get() != nullptr; }
|
||||
|
||||
int loadProfiles(const std::string &dir, ConfigDelegate *delegate = nullptr);
|
||||
|
||||
//! Adds a profile. Returns false if a profile with the same
|
||||
//! name exists already or the binding belongs to another
|
||||
//! module.
|
||||
bool addProfile(ModuleBinding *);
|
||||
|
||||
//! Removes a profile. Returns false if the profile does not exist.
|
||||
//! All station bindings that refer to that profile are removed.
|
||||
bool removeProfile(const std::string &profile);
|
||||
|
||||
//! Removes a profile. Returns false if the profile does not exist.
|
||||
//! All station bindings that refer to that profile are removed.
|
||||
bool removeProfile(ModuleBinding *);
|
||||
|
||||
//! Binds a station to a profile. If the profile does not
|
||||
//! exist or if the binding belongs to another module,
|
||||
//! false is returned.
|
||||
ModuleBinding *bind(const StationID &, const std::string &profile);
|
||||
|
||||
//! Binds the station to station binding. If the binding belongs
|
||||
//! to another module, false is returned.
|
||||
bool bind(const StationID &, ModuleBinding *binding);
|
||||
|
||||
//! Removes a binding for a station
|
||||
bool removeStation(const StationID &);
|
||||
|
||||
//! Creates an empty binding based on the templateBinding.
|
||||
//! Returns nullptr if no template binding is available.
|
||||
ModuleBinding *createBinding() const;
|
||||
|
||||
//! Creates an empty profile with name.
|
||||
ModuleBinding *createProfile(const std::string &name);
|
||||
|
||||
ModuleBinding *getProfile(const std::string &profile) const;
|
||||
|
||||
//! Returns a station binding if available
|
||||
ModuleBinding *getBinding(const StationID &) const;
|
||||
|
||||
ModuleBinding *readBinding(const StationID &,
|
||||
const std::string &profile = "",
|
||||
bool allowConfigFileErrors = false,
|
||||
ConfigDelegate *delegate = nullptr);
|
||||
|
||||
//! Accepts a model visitor and starts to traversing its nodes
|
||||
void accept(ModelVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
void syncProfileRemoval(Binding *);
|
||||
bool loadBinding(ModuleBinding &, const std::string &filename,
|
||||
bool allowConfigFileErrors = false,
|
||||
ConfigDelegate *delegate = nullptr) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
using BindingMap = std::map<StationID, ModuleBindingPtr> ;
|
||||
using BindingCategories = std::set<std::string>;
|
||||
using Profiles = std::vector<ModuleBindingPtr>;
|
||||
|
||||
Model *model;
|
||||
std::string keyDirectory;
|
||||
std::string configFile;
|
||||
SchemaModule *definition;
|
||||
ModuleBindingPtr bindingTemplate;
|
||||
std::vector<SectionPtr> sections;
|
||||
std::vector<ParameterPtr> unknowns;
|
||||
BindingMap bindings;
|
||||
Profiles profiles;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Station);
|
||||
class SC_SYSTEM_CORE_API Station : public Core::BaseObject {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Station() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool readConfig(const char *filename);
|
||||
bool writeConfig(const char *filename,
|
||||
ConfigDelegate *delegate = nullptr) const;
|
||||
|
||||
void setConfig(const std::string &module, const std::string &profile);
|
||||
|
||||
//! Returns whether a tag with name has a certain value
|
||||
bool compareTag(const std::string &name, const std::string &value) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
struct ModuleConfig {
|
||||
ModuleConfig() {}
|
||||
ModuleConfig(const std::string &name, const std::string &prof = "")
|
||||
: moduleName(name), profile(prof) {}
|
||||
|
||||
std::string moduleName;
|
||||
std::string profile;
|
||||
};
|
||||
|
||||
typedef std::vector<ModuleConfig> ModuleConfigs;
|
||||
typedef std::map<std::string, std::string> Tags;
|
||||
ModuleConfigs config;
|
||||
Tags tags;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Model : public Core::BaseObject {
|
||||
DECLARE_RTTI;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Model();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Generators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Creates the tree from schema definitions
|
||||
bool create(SchemaDefinitions *def);
|
||||
bool recreate();
|
||||
|
||||
bool readConfig(int updateMaxStage = Environment::CS_LAST,
|
||||
ConfigDelegate *delegate = nullptr);
|
||||
bool writeConfig(bool multilineLists,
|
||||
int stage = Environment::CS_CONFIG_APP,
|
||||
ConfigDelegate *delegate = nullptr);
|
||||
bool writeConfig(Module *, const std::string &filename, int stage,
|
||||
bool multilineLists,
|
||||
ConfigDelegate *delegate = nullptr);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Module *module(const std::string &name) const;
|
||||
|
||||
/* By default the SeisComP environment paths are used. But for testing
|
||||
* or alternative locations this methods can be reimplemented to
|
||||
* use different directories.
|
||||
*/
|
||||
virtual std::string systemConfigFilename(bool read, const std::string &name) const;
|
||||
virtual std::string configFileLocation(bool read, const std::string &name, int stage) const;
|
||||
virtual std::string stationConfigDir(bool read, const std::string &name = "") const;
|
||||
|
||||
//! Updates parameter values of a container
|
||||
void update(const Module *mod, Container *container) const;
|
||||
|
||||
//! Updates parameter values of a binding
|
||||
void updateBinding(const ModuleBinding *mod, Binding *binding) const;
|
||||
|
||||
//! Adds a global empty station configuration.
|
||||
bool addStation(const StationID &);
|
||||
|
||||
//! Removes a global station configuration. The station is also
|
||||
//! removed from all available modules.
|
||||
bool removeStation(const StationID &);
|
||||
|
||||
//! Removes all global station configurations that are part of
|
||||
//! the given network.
|
||||
bool removeNetwork(const std::string &);
|
||||
|
||||
//! Removes a station binding from a module.
|
||||
bool removeStationModule(const StationID &, Module *);
|
||||
|
||||
//! Accepts a model visitor and starts to traversing its nodes
|
||||
void accept(ModelVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
Module *create(SchemaDefinitions *schema, SchemaModule *def);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
struct SymbolFileMap : std::map<std::string, SymbolMapItemPtr> {
|
||||
time_t lastModified;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, SymbolFileMap> SymbolMap;
|
||||
typedef std::map<std::string, Module*> ModMap;
|
||||
typedef std::set<std::string> Categories;
|
||||
typedef std::map<StationID, StationPtr> Stations;
|
||||
|
||||
SchemaDefinitions *schema;
|
||||
std::vector<ModulePtr> modules;
|
||||
Categories categories;
|
||||
Stations stations;
|
||||
mutable SymbolMap symbols;
|
||||
ModMap modMap;
|
||||
std::string keyDirOverride;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ModelVisitor {
|
||||
protected:
|
||||
ModelVisitor() {}
|
||||
virtual ~ModelVisitor() {}
|
||||
|
||||
protected:
|
||||
virtual bool visit(Module*) = 0;
|
||||
virtual bool visit(Section*) = 0;
|
||||
virtual bool visit(Group*) = 0;
|
||||
virtual bool visit(Structure*) = 0;
|
||||
virtual void visit(Parameter*, bool unknown = false) = 0;
|
||||
|
||||
friend class Container;
|
||||
friend class Module;
|
||||
friend class Model;
|
||||
friend class Binding;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
155
include/seiscomp/system/pluginregistry.h
Normal file
155
include/seiscomp/system/pluginregistry.h
Normal file
@ -0,0 +1,155 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_SYSTEM_PLUGINREGISTRY_H
|
||||
#define SEISCOMP_SYSTEM_PLUGINREGISTRY_H
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
#include <seiscomp/core/plugin.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
namespace Config {
|
||||
class Config;
|
||||
}
|
||||
|
||||
namespace System {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API PluginRegistry {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
struct PluginEntry {
|
||||
PluginEntry(void *h, Core::PluginPtr p, const std::string &fn = "")
|
||||
: handle(h), plugin(p), filename(fn) {}
|
||||
void *handle;
|
||||
Core::PluginPtr plugin;
|
||||
std::string filename;
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API iterator : public std::list<PluginEntry>::const_iterator {
|
||||
private:
|
||||
typedef std::list<PluginEntry>::const_iterator base;
|
||||
|
||||
public:
|
||||
iterator();
|
||||
iterator(const base&);
|
||||
|
||||
public:
|
||||
const Core::Plugin* operator*() const;
|
||||
Core::Plugin* value_type(const iterator&);
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
PluginRegistry();
|
||||
|
||||
public:
|
||||
~PluginRegistry();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns the global instance
|
||||
static PluginRegistry *Instance();
|
||||
static void Reset();
|
||||
|
||||
//! Adds a plugin to be loaded
|
||||
void addPluginName(const std::string &name);
|
||||
|
||||
//! Adds a plugin search path
|
||||
void addPluginPath(const std::string &path);
|
||||
|
||||
//! Adds a plugin package search path pointing to
|
||||
//! shareDir + "/plugins/" + package
|
||||
void addPackagePath(const std::string &package);
|
||||
|
||||
/**
|
||||
* Loads all plugins in the defined search paths
|
||||
* added with addPluginName
|
||||
* @return The number of loaded plugins or -1 in case of an error
|
||||
*/
|
||||
int loadPlugins();
|
||||
|
||||
/**
|
||||
* Loads all plugins in the defined search paths
|
||||
* configured by the config object. All names added
|
||||
* with addPluginName will be replaced by the configured
|
||||
* plugin names in "core.plugins" if there are any.
|
||||
* Otherwise the default plugin list will be extended by
|
||||
* "plugins".
|
||||
* @return The number of loaded plugins or -1 in case of an error
|
||||
*/
|
||||
int loadConfiguredPlugins(const Config::Config *config);
|
||||
|
||||
|
||||
//! Unloads all plugins
|
||||
void freePlugins();
|
||||
|
||||
//! Returns the number of registered plugins
|
||||
int pluginCount() const;
|
||||
|
||||
//! Returns the start iterator over all registered plugins
|
||||
iterator begin() const;
|
||||
//! Returns the end iterator over all registered plugins
|
||||
iterator end() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
std::string find(const std::string &name) const;
|
||||
PluginEntry open(const std::string &file) const;
|
||||
bool findLibrary(void *handle) const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
using PluginList = std::list<PluginEntry>;
|
||||
using PathList = std::vector<std::string>;
|
||||
using NameList = std::vector<std::string>;
|
||||
|
||||
static PluginRegistry *_instance;
|
||||
|
||||
PluginList _plugins;
|
||||
PathList _paths;
|
||||
NameList _pluginNames;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
510
include/seiscomp/system/schema.h
Normal file
510
include/seiscomp/system/schema.h
Normal file
@ -0,0 +1,510 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_CONFIGURATION_SCHEMA_H
|
||||
#define SEISCOMP_CONFIGURATION_SCHEMA_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/strings.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace System {
|
||||
|
||||
|
||||
class SchemaVisitor;
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaParameter);
|
||||
class SC_SYSTEM_CORE_API SchemaParameter : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaParameter);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaParameter() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::string type;
|
||||
std::string unit;
|
||||
std::string defaultValue;
|
||||
std::string description;
|
||||
OPT(bool) readOnly;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaGroup);
|
||||
DEFINE_SMARTPOINTER(SchemaStructure);
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaParameters);
|
||||
class SC_SYSTEM_CORE_API SchemaParameters : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaParameter);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaParameters() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
size_t parameterCount() const;
|
||||
SchemaParameter *parameter(size_t i);
|
||||
bool add(SchemaParameter *param);
|
||||
|
||||
size_t groupCount() const;
|
||||
SchemaGroup *group(size_t i);
|
||||
bool add(SchemaGroup *group);
|
||||
|
||||
size_t structureCount() const;
|
||||
SchemaStructure *structure(size_t i);
|
||||
bool add(SchemaStructure *structure);
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
void accept(SchemaVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
std::vector<SchemaParameterPtr> _parameters;
|
||||
std::vector<SchemaGroupPtr> _groups;
|
||||
std::vector<SchemaStructurePtr> _structs;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SchemaGroup : public SchemaParameters {
|
||||
DECLARE_SC_CLASS(SchemaGroup);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaGroup() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SchemaStructure : public SchemaParameters {
|
||||
DECLARE_SC_CLASS(SchemaStructure);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaStructure() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string type;
|
||||
std::string title;
|
||||
std::string link;
|
||||
std::string description;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaSetupInput);
|
||||
DEFINE_SMARTPOINTER(SchemaSetupInputOption);
|
||||
class SC_SYSTEM_CORE_API SchemaSetupInputOption : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaSetupInputOption);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaSetupInputOption() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string value;
|
||||
std::string description;
|
||||
std::vector<SchemaSetupInputPtr> inputs;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SchemaSetupInput : public SchemaParameter {
|
||||
DECLARE_SC_CLASS(SchemaSetupInput);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaSetupInput() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string text;
|
||||
std::string echo;
|
||||
std::vector<SchemaSetupInputOptionPtr> options;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaSetupGroup);
|
||||
class SC_SYSTEM_CORE_API SchemaSetupGroup : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaSetupGroup);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaSetupGroup() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::vector<SchemaSetupInputPtr> inputs;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaSetup);
|
||||
class SC_SYSTEM_CORE_API SchemaSetup : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaSetup);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaSetup() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::vector<SchemaSetupGroupPtr> groups;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaModule);
|
||||
class SC_SYSTEM_CORE_API SchemaModule : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaModule);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaModule() : aliasedModule(nullptr) {}
|
||||
|
||||
bool isStandalone() const {
|
||||
return standalone && *standalone;
|
||||
}
|
||||
|
||||
void accept(SchemaVisitor *) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaModule *aliasedModule;
|
||||
std::string name;
|
||||
std::string category;
|
||||
std::string import;
|
||||
std::string description;
|
||||
OPT(bool) standalone;
|
||||
OPT(bool) inheritGlobalBinding;
|
||||
SchemaParametersPtr parameters;
|
||||
SchemaSetupPtr setup;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaStructExtent);
|
||||
DEFINE_SMARTPOINTER(SchemaPluginParameters);
|
||||
struct SchemaPluginParameters : SchemaParameters {
|
||||
DECLARE_SC_CLASS(SchemaPluginParameters);
|
||||
|
||||
void serialize(Archive& ar);
|
||||
std::vector<SchemaStructExtentPtr> structExtents;
|
||||
};
|
||||
|
||||
|
||||
struct SchemaStructExtent : SchemaPluginParameters {
|
||||
DECLARE_SC_CLASS(SchemaStructExtent);
|
||||
|
||||
void serialize(Archive& ar);
|
||||
std::string type;
|
||||
std::string matchName;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaPlugin);
|
||||
class SC_SYSTEM_CORE_API SchemaPlugin : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaPlugin);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaPlugin() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::vector<std::string> extends;
|
||||
std::string description;
|
||||
SchemaPluginParametersPtr parameters;
|
||||
SchemaSetupPtr setup;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaBinding);
|
||||
class SC_SYSTEM_CORE_API SchemaBinding : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(SchemaBinding);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaBinding() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
std::string name;
|
||||
std::string module;
|
||||
std::string category;
|
||||
std::string description;
|
||||
SchemaParametersPtr parameters;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SchemaDefinitions);
|
||||
class SC_SYSTEM_CORE_API SchemaDefinitions : public Core::BaseObject {
|
||||
// ------------------------------------------------------------------
|
||||
// Public types
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef std::vector<SchemaPlugin*> PluginList;
|
||||
typedef std::vector<SchemaBinding*> BindingList;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaDefinitions() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Setters/Getters
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
SchemaModule *createAlias(const char *existingModule, const char *newModule);
|
||||
bool removeAlias(const char *existingModule);
|
||||
|
||||
size_t moduleCount() const;
|
||||
SchemaModule *module(size_t i);
|
||||
SchemaModule *module(const char *name);
|
||||
SchemaModule *module(const std::string &name);
|
||||
bool add(SchemaModule *module);
|
||||
|
||||
size_t pluginCount() const;
|
||||
SchemaPlugin *plugin(size_t i);
|
||||
SchemaPlugin *plugin(const char *name);
|
||||
SchemaPlugin *plugin(const std::string &name);
|
||||
bool add(SchemaPlugin *plugin);
|
||||
|
||||
size_t bindingCount() const;
|
||||
SchemaBinding *binding(size_t i);
|
||||
SchemaBinding *binding(const char *name);
|
||||
SchemaBinding *binding(const std::string &name);
|
||||
bool add(SchemaBinding *binding);
|
||||
|
||||
//! Returns all plugins for a certain module
|
||||
//! The plugin pointers are managed by the Definition instance
|
||||
//! and must not be deleted.
|
||||
PluginList pluginsForModule(const char *name) const;
|
||||
PluginList pluginsForModule(const std::string &name) const;
|
||||
|
||||
//! Returns all bindings for a certain module
|
||||
//! The binding pointers are managed by the Definition instance
|
||||
//! and must not be deleted.
|
||||
BindingList bindingsForModule(const char *name) const;
|
||||
BindingList bindingsForModule(const std::string &name) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Serialization
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
void serialize(Archive& ar);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Read methods
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
bool load(const char *path);
|
||||
bool reload();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Attributes
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
std::vector<SchemaModulePtr> _modules;
|
||||
std::vector<SchemaPluginPtr> _plugins;
|
||||
std::vector<SchemaBindingPtr> _bindings;
|
||||
std::string _path;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SchemaVisitor {
|
||||
protected:
|
||||
SchemaVisitor() {}
|
||||
virtual ~SchemaVisitor() {}
|
||||
|
||||
protected:
|
||||
virtual bool visit(const SchemaModule*) = 0;
|
||||
virtual bool visit(const SchemaGroup*) = 0;
|
||||
virtual bool visit(const SchemaStructure*) = 0;
|
||||
virtual void visit(const SchemaParameter*) = 0;
|
||||
virtual void finished() = 0;
|
||||
|
||||
friend class SchemaModule;
|
||||
friend class SchemaParameters;
|
||||
friend class SchemaGroup;
|
||||
friend class SchemaStructure;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
604
include/seiscomp/system/settings.h
Normal file
604
include/seiscomp/system/settings.h
Normal file
@ -0,0 +1,604 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef SEISCOMP_SYSTEM_SETTINGS_H
|
||||
#define SEISCOMP_SYSTEM_SETTINGS_H
|
||||
|
||||
|
||||
#include <seiscomp/core/strings.h>
|
||||
#include <seiscomp/config/config.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace System {
|
||||
|
||||
namespace Generic {
|
||||
|
||||
namespace Detail {
|
||||
|
||||
|
||||
class No { };
|
||||
class Yes { No no[2]; };
|
||||
|
||||
template <typename Type, Type Ptr>
|
||||
struct MemberHelperClass;
|
||||
|
||||
template <typename T, typename Type>
|
||||
Yes MemberHelper_accept(MemberHelperClass<Type, &T::accept> *);
|
||||
template<typename T,typename Type>
|
||||
No MemberHelper_accept(...);
|
||||
|
||||
template<typename T, typename PARAM>
|
||||
struct HasMemberAccept {
|
||||
enum {
|
||||
value = sizeof(MemberHelper_accept<T, void (T::*)(PARAM &)>(0)) == sizeof(Yes)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsClassType {
|
||||
enum {
|
||||
value = boost::is_same<int, T>::value ?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<unsigned int, T>::value ?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<size_t, T>::value ?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<double, T>::value ?
|
||||
0
|
||||
:
|
||||
(
|
||||
boost::is_same<bool, T>::value ?
|
||||
0
|
||||
:
|
||||
1
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename C, typename T>
|
||||
struct MustMatch {
|
||||
static T get(const C &value) {
|
||||
throw std::runtime_error("key attribute must be a string");
|
||||
}
|
||||
};
|
||||
|
||||
template <typename C>
|
||||
struct MustMatch<C,C> {
|
||||
static C get(const C &value) {
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
T getConfig(const Config::Config *cfg, const std::string &symbol, bool asPath);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
class SettingsVisitor {
|
||||
public:
|
||||
typedef SettingsVisitor<VisitedItem, Proc> SelfType;
|
||||
|
||||
SettingsVisitor() : _success(true) {}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface for visited classes
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Bind a value
|
||||
template <typename T>
|
||||
SettingsVisitor &operator&(VisitedItem<T> visitedItem);
|
||||
|
||||
//! Bind a value
|
||||
template <typename T>
|
||||
SettingsVisitor &operator&(VisitedItem< std::vector<T> > visitedItem);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public state management
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool success() const;
|
||||
const std::string lastError() const;
|
||||
|
||||
//! Resets the success flag and the error message
|
||||
void reset();
|
||||
|
||||
//! Returns the processor
|
||||
Proc &proc();
|
||||
|
||||
|
||||
public:
|
||||
operator bool() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Interface to be used in processor
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
template <typename T>
|
||||
void push(const VisitedItem<T> &visitedItem);
|
||||
void pop();
|
||||
void setError(const std::string &msg);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private methods and helpers
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
template <typename T, int IS_CLASS>
|
||||
struct VisitHelper {};
|
||||
|
||||
// Non-class types never have member functions. This includes vectors
|
||||
// of non-class types
|
||||
template <typename T>
|
||||
struct VisitHelper<T, 0> {
|
||||
static SettingsVisitor &process(SettingsVisitor &visitor, VisitedItem<T> &visitedItem) {
|
||||
visitor.handleSingle(visitedItem);
|
||||
return visitor;
|
||||
}
|
||||
};
|
||||
|
||||
// Class type
|
||||
template <typename T>
|
||||
struct VisitHelper<T, 1> {
|
||||
static SettingsVisitor &process(SettingsVisitor &visitor, VisitedItem<T> &visitedItem) {
|
||||
return VisitCompositeHelper<T, Detail::HasMemberAccept<T, SelfType>::value>::dispatch(visitor, visitedItem);
|
||||
}
|
||||
};
|
||||
|
||||
// Vector with class type
|
||||
template <typename T>
|
||||
struct VisitHelper<std::vector<T>, 1> {
|
||||
static SettingsVisitor &process(SettingsVisitor &visitor, VisitedItem< std::vector<T> > &visitedItem) {
|
||||
return VisitCompositeHelper<std::vector<T>, Detail::HasMemberAccept<T, SelfType>::value>::dispatch(visitor, visitedItem);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, int HAS_VISIT>
|
||||
struct VisitCompositeHelper {};
|
||||
|
||||
// No bind method
|
||||
template <typename T>
|
||||
struct VisitCompositeHelper<T,0> {
|
||||
static SettingsVisitor &dispatch(SettingsVisitor &visitor, VisitedItem<T> &visitedItem) {
|
||||
visitor.handleSingle(visitedItem);
|
||||
return visitor;
|
||||
}
|
||||
};
|
||||
|
||||
// Bind method => descent
|
||||
template <typename T>
|
||||
struct VisitCompositeHelper<T,1> {
|
||||
static SettingsVisitor &dispatch(SettingsVisitor &visitor, VisitedItem<T> &visitedItem) {
|
||||
visitor.push(visitedItem);
|
||||
visitedItem.value.accept(visitor);
|
||||
visitor.pop();
|
||||
return visitor;
|
||||
}
|
||||
};
|
||||
|
||||
// Vector of elements without bind method
|
||||
template <typename T>
|
||||
struct VisitCompositeHelper< std::vector<T> ,0> {
|
||||
static SettingsVisitor &dispatch(SettingsVisitor &visitor, VisitedItem< std::vector<T> > &visitedItem) {
|
||||
visitor.handleSingle(visitedItem);
|
||||
return visitor;
|
||||
}
|
||||
};
|
||||
|
||||
// Vector with elements with bind method
|
||||
template <typename T>
|
||||
struct VisitCompositeHelper< std::vector<T> ,1> {
|
||||
static SettingsVisitor &dispatch(SettingsVisitor &visitor, VisitedItem< std::vector<T> > &visitedItem) {
|
||||
visitor.handleMultiple(visitedItem);
|
||||
return visitor;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Callbacks which delegate calls to the processor
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
template <typename T>
|
||||
void handleSingle(VisitedItem<T> &visitedItem);
|
||||
|
||||
template <typename T>
|
||||
void handleMultiple(VisitedItem< std::vector<T> > &visitedItem);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Members
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
std::string indent; //!< Indentation for each tree level in two-space steps
|
||||
std::string configPrefix;
|
||||
|
||||
protected:
|
||||
std::deque<std::string> _prefixStack;
|
||||
bool _success;
|
||||
std::string _errorMessage;
|
||||
|
||||
private:
|
||||
Proc _proc;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct ConfigOptionBinding {
|
||||
enum Flags {
|
||||
NoFlags = 0x00,
|
||||
IsKey = 0x01,
|
||||
InterpretAsPath = 0x02
|
||||
};
|
||||
|
||||
ConfigOptionBinding(T &value, int flags, const char *configFileRelativeSymbol)
|
||||
: value(value)
|
||||
, flags(flags)
|
||||
, configFileRelativeSymbol(configFileRelativeSymbol) {}
|
||||
|
||||
bool isKey() { return flags & IsKey; }
|
||||
|
||||
T &value;
|
||||
int flags;
|
||||
const char *configFileRelativeSymbol;
|
||||
};
|
||||
|
||||
|
||||
class ConfigOptionLinker {
|
||||
public:
|
||||
ConfigOptionLinker()
|
||||
: _stage(None) {}
|
||||
|
||||
|
||||
public:
|
||||
void get(const Config::Config *cfg) {
|
||||
setStage(GetCfg);
|
||||
_external.cfg = cfg;
|
||||
}
|
||||
|
||||
void get(const Config::Config &cfg) {
|
||||
get(&cfg);
|
||||
}
|
||||
|
||||
void dump(std::ostream &os) {
|
||||
setStage(Print);
|
||||
_external.os = &os;
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
// A single non-array option
|
||||
template <typename T, typename V>
|
||||
void visitSingle(V &visitor, ConfigOptionBinding<T> &visitedItem) {
|
||||
switch ( _stage ) {
|
||||
case GetCfg:
|
||||
if ( !visitedItem.isKey() && !visitedItem.configFileRelativeSymbol )
|
||||
return;
|
||||
if ( !CfgLinkHelper<T, IsNativelySupported<T>::value>::process(*this, visitedItem, visitor.configPrefix) )
|
||||
visitor.setError("Invalid configuration value for " + visitor.configPrefix + visitedItem.configFileRelativeSymbol);
|
||||
break;
|
||||
break;
|
||||
case Print:
|
||||
if ( visitedItem.configFileRelativeSymbol )
|
||||
*_external.os << visitor.configPrefix << visitedItem.configFileRelativeSymbol;
|
||||
else if ( visitedItem.isKey() )
|
||||
*_external.os << "*KEY*";
|
||||
else
|
||||
return;
|
||||
*_external.os << ": ";
|
||||
PrintHelper<T, IsNativelySupported<T>::value>::process(*_external.os, visitedItem.value);
|
||||
*_external.os << std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// A single array option
|
||||
template <typename T, typename V>
|
||||
void visitSingle(V &visitor, ConfigOptionBinding< std::vector<T> > &visitedItem) {
|
||||
switch ( _stage ) {
|
||||
case GetCfg:
|
||||
if ( !visitedItem.configFileRelativeSymbol )
|
||||
return;
|
||||
if ( !CfgLinkHelper<std::vector<T>, IsNativelySupported<T>::value>::process(*this, visitedItem, visitor.configPrefix) )
|
||||
visitor.setError("Invalid configuration value for " + visitor.configPrefix + visitedItem.configFileRelativeSymbol);
|
||||
break;
|
||||
case Print:
|
||||
if ( visitedItem.configFileRelativeSymbol )
|
||||
*_external.os << visitor.configPrefix << visitedItem.configFileRelativeSymbol;
|
||||
else if ( visitedItem.isKey() )
|
||||
*_external.os << "*KEY*";
|
||||
else
|
||||
return;
|
||||
*_external.os << ": ";
|
||||
PrintHelper<std::vector<T>, IsNativelySupported<T>::value>::process(*_external.os, visitedItem.value);
|
||||
*_external.os << std::endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// An array option consisting of composites
|
||||
template <typename T, typename V>
|
||||
void visitMultiple(V &visitor, ConfigOptionBinding< std::vector<T> > &visitedItem) {
|
||||
switch ( _stage ) {
|
||||
case GetCfg:
|
||||
try {
|
||||
std::vector<std::string> items;
|
||||
items = Generic::Detail::getConfig< std::vector<std::string> >(_external.cfg, visitor.configPrefix + visitedItem.configFileRelativeSymbol, false);
|
||||
std::string oldKey = _key;
|
||||
visitor.push(visitedItem);
|
||||
for ( size_t i = 0; i < items.size(); ++i ) {
|
||||
T value;
|
||||
ConfigOptionBinding<T> item(value, false, items[i].c_str());
|
||||
std::string oldKey = _key;
|
||||
visitor.push(item);
|
||||
_key = items[i];
|
||||
item.value.accept(visitor);
|
||||
if ( visitor.success() )
|
||||
visitedItem.value.push_back(value);
|
||||
visitor.pop();
|
||||
_key = oldKey;
|
||||
}
|
||||
visitor.pop();
|
||||
_key = oldKey;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
break;
|
||||
case Print:
|
||||
if ( visitedItem.configFileRelativeSymbol ) {
|
||||
*_external.os << visitor.configPrefix << visitedItem.configFileRelativeSymbol;
|
||||
*_external.os << ": ";
|
||||
if ( visitedItem.value.empty() )
|
||||
*_external.os << "[]" << std::endl;
|
||||
else {
|
||||
*_external.os << "[" << visitedItem.value.size() << "]" << std::endl;
|
||||
std::string oldKey = _key;
|
||||
visitor.push(visitedItem);
|
||||
for ( size_t i = 0; i < visitedItem.value.size(); ++i ) {
|
||||
*_external.os << "{" << std::endl;
|
||||
visitedItem.value[i].accept(visitor);
|
||||
*_external.os << "}" << std::endl;
|
||||
}
|
||||
visitor.pop();
|
||||
_key = oldKey;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Helpers
|
||||
private:
|
||||
template <typename T>
|
||||
T key() const {
|
||||
return Generic::Detail::MustMatch<std::string,T>::get(_key);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct IsNativelySupported {
|
||||
enum {
|
||||
value = Generic::Detail::IsClassType<T>::value ?
|
||||
(
|
||||
boost::is_same<std::string,T>::value ?
|
||||
1
|
||||
:
|
||||
0
|
||||
)
|
||||
:
|
||||
1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
template <typename T, int IS_SUPPORTED>
|
||||
struct CfgLinkHelper {};
|
||||
|
||||
template <typename T>
|
||||
struct CfgLinkHelper<T,0> {
|
||||
template <typename P>
|
||||
static bool process(P &proc,
|
||||
ConfigOptionBinding<T> &visitedItem,
|
||||
const std::string &prefix) {
|
||||
try {
|
||||
std::string tmp;
|
||||
if ( visitedItem.isKey() )
|
||||
tmp = proc.template key<std::string>();
|
||||
else
|
||||
tmp = Generic::Detail::getConfig<std::string>(proc._external.cfg, prefix + visitedItem.configFileRelativeSymbol, visitedItem.flags & ConfigOptionBinding< std::vector<T> >::InterpretAsPath);
|
||||
return fromString(visitedItem.value, tmp);
|
||||
}
|
||||
catch ( ... ) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CfgLinkHelper<std::vector<T>,0> {
|
||||
template <typename P>
|
||||
static bool process(P &proc,
|
||||
ConfigOptionBinding< std::vector<T> > &visitedItem,
|
||||
const std::string &prefix) {
|
||||
try {
|
||||
std::vector<std::string> tmp;
|
||||
if ( visitedItem.isKey() )
|
||||
tmp = proc.template key<std::vector<std::string> >();
|
||||
else
|
||||
tmp = Generic::Detail::getConfig<std::vector<std::string> >(proc._external.cfg, prefix + visitedItem.configFileRelativeSymbol, visitedItem.flags & ConfigOptionBinding< std::vector<T> >::InterpretAsPath);
|
||||
visitedItem.value.resize(tmp.size());
|
||||
for ( size_t i = 0; i < tmp.size(); ++i ) {
|
||||
if ( !fromString(visitedItem.value[i], tmp[i]) )
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch ( ... ) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct CfgLinkHelper<T,1> {
|
||||
template <typename P>
|
||||
static bool process(P &proc,
|
||||
ConfigOptionBinding<T> &visitedItem,
|
||||
const std::string &prefix) {
|
||||
if ( visitedItem.isKey() )
|
||||
visitedItem.value = proc.template key<T>();
|
||||
else {
|
||||
try {
|
||||
visitedItem.value = Generic::Detail::getConfig<T>(proc._external.cfg, prefix + visitedItem.configFileRelativeSymbol, visitedItem.flags & ConfigOptionBinding< std::vector<T> >::InterpretAsPath);
|
||||
}
|
||||
catch ( ... ) {}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, int IS_SUPPORTED>
|
||||
struct PrintHelper {};
|
||||
|
||||
template <typename T>
|
||||
struct PrintHelper<T,0> {
|
||||
static void process(std::ostream &os, const T &value) {
|
||||
os << toString(value);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PrintHelper<std::vector<T>,0> {
|
||||
static void process(std::ostream &os, const std::vector<T> &value) {
|
||||
if ( value.empty() ) {
|
||||
os << "[]";
|
||||
return;
|
||||
}
|
||||
|
||||
for ( size_t i = 0; i < value.size(); ++i ) {
|
||||
if ( i ) os << ", ";
|
||||
PrintHelper<T,0>::process(os, value[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PrintHelper<T,1> {
|
||||
static void process(std::ostream &os, const T &value) {
|
||||
os << value;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PrintHelper<std::vector<T>,1> {
|
||||
static void process(std::ostream &os, const std::vector<T> &value) {
|
||||
if ( value.empty() )
|
||||
os << "[]";
|
||||
else
|
||||
os << Core::toString(value);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
enum Stage {
|
||||
None,
|
||||
GetCfg,
|
||||
Print
|
||||
};
|
||||
|
||||
void setStage(Stage s) {
|
||||
_stage = s;
|
||||
}
|
||||
|
||||
Stage _stage;
|
||||
std::string _key; //!< The current array item key value
|
||||
|
||||
// Output structures depending on the stage
|
||||
union {
|
||||
std::ostream *os;
|
||||
const Config::Config *cfg;
|
||||
} _external;
|
||||
};
|
||||
|
||||
|
||||
struct ConfigSettingsLinker : Generic::SettingsVisitor<ConfigOptionBinding, ConfigOptionLinker> {
|
||||
template <typename T>
|
||||
static ConfigOptionBinding<T> key(T &boundValue) {
|
||||
return ConfigOptionBinding<T>(boundValue, ConfigOptionBinding<T>::IsKey, nullptr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static ConfigOptionBinding<T> cfg(T &boundValue, const char *name) {
|
||||
return ConfigOptionBinding<T>(boundValue, 0, name);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static ConfigOptionBinding<T> cfgAsPath(T &boundValue, const char *name) {
|
||||
return ConfigOptionBinding<T>(boundValue, ConfigOptionBinding<T>::InterpretAsPath, name);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#include <seiscomp/system/settings.ipp>
|
||||
|
||||
|
||||
#endif
|
117
include/seiscomp/system/settings.ipp
Normal file
117
include/seiscomp/system/settings.ipp
Normal file
@ -0,0 +1,117 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) gempa GmbH *
|
||||
* All rights reserved. *
|
||||
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||||
* *
|
||||
* GNU Affero General Public License Usage *
|
||||
* This file may be used under the terms of the GNU Affero *
|
||||
* Public License version 3.0 as published by the Free Software Foundation *
|
||||
* and appearing in the file LICENSE included in the packaging of this *
|
||||
* file. Please review the following information to ensure the GNU Affero *
|
||||
* Public License version 3.0 requirements will be met: *
|
||||
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||||
* *
|
||||
* Other Usage *
|
||||
* Alternatively, this file may be used in accordance with the terms and *
|
||||
* conditions contained in a signed written agreement between you and *
|
||||
* gempa GmbH. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace System {
|
||||
|
||||
namespace Generic {
|
||||
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
template <typename T>
|
||||
inline SettingsVisitor<VisitedItem, Proc> &SettingsVisitor<VisitedItem, Proc>
|
||||
::operator&(VisitedItem<T> visitedItem) {
|
||||
return VisitHelper<T, Detail::IsClassType<T>::value>::process(*this, visitedItem);
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
template <typename T>
|
||||
inline SettingsVisitor<VisitedItem, Proc> &SettingsVisitor<VisitedItem, Proc>
|
||||
::operator&(VisitedItem< std::vector<T> > visitedItem) {
|
||||
return VisitHelper<std::vector<T>, Detail::IsClassType<T>::value>::process(*this, visitedItem);
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline bool SettingsVisitor<VisitedItem, Proc>
|
||||
::success() const {
|
||||
return _success;
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline const std::string SettingsVisitor<VisitedItem, Proc>
|
||||
::lastError() const {
|
||||
return _errorMessage;
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline void SettingsVisitor<VisitedItem, Proc>::reset() {
|
||||
_success = true;
|
||||
_errorMessage = std::string();
|
||||
configPrefix = "";
|
||||
indent = "";
|
||||
}
|
||||
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline Proc &SettingsVisitor<VisitedItem, Proc>
|
||||
::proc() {
|
||||
return _proc;
|
||||
}
|
||||
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline SettingsVisitor<VisitedItem, Proc>
|
||||
::operator bool() const {
|
||||
return success();
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
template <typename T>
|
||||
inline void SettingsVisitor<VisitedItem, Proc>::push(const VisitedItem<T> &visitedItem) {
|
||||
_prefixStack.push_back(configPrefix);
|
||||
indent += " ";
|
||||
if ( visitedItem.configFileRelativeSymbol && *visitedItem.configFileRelativeSymbol ) {
|
||||
if ( !configPrefix.empty() ) {
|
||||
configPrefix += '.';
|
||||
}
|
||||
configPrefix += visitedItem.configFileRelativeSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline void SettingsVisitor<VisitedItem, Proc>::pop() {
|
||||
configPrefix = _prefixStack.back();
|
||||
_prefixStack.pop_back();
|
||||
indent.erase(indent.size()-2);
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
inline void SettingsVisitor<VisitedItem, Proc>::setError(const std::string &msg) {
|
||||
_success = false;
|
||||
_errorMessage = msg;
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
template <typename T>
|
||||
inline void SettingsVisitor<VisitedItem, Proc>::handleSingle(VisitedItem<T> &visitedItem) {
|
||||
_proc.visitSingle(*this, visitedItem);
|
||||
}
|
||||
|
||||
template <template <typename> class VisitedItem, class Proc>
|
||||
template <typename T>
|
||||
inline void SettingsVisitor<VisitedItem, Proc>::handleMultiple(VisitedItem< std::vector<T> > &visitedItem) {
|
||||
_proc.visitMultiple(*this, visitedItem);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user