[seiscomp, scanloc] Install, add .gitignore
This commit is contained in:
256
include/seiscomp/io/archive/binarchive.h
Normal file
256
include/seiscomp/io/archive/binarchive.h
Normal file
@ -0,0 +1,256 @@
|
||||
/***************************************************************************
|
||||
* 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 SCARCHIVE_BIN_H
|
||||
#define SCARCHIVE_BIN_H
|
||||
|
||||
#include <seiscomp/core/io.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <streambuf>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An archive using binary streams
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API BinaryArchive : public Seiscomp::Core::Archive {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
BinaryArchive();
|
||||
|
||||
//! Constructor with predefined buffer and mode
|
||||
BinaryArchive(std::streambuf* buf, bool isReading = true);
|
||||
|
||||
//! Destructor
|
||||
~BinaryArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool open(const char* file);
|
||||
bool open(std::streambuf*);
|
||||
|
||||
bool create(const char* file);
|
||||
bool create(std::streambuf*);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void close();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Read methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Reads an integer
|
||||
virtual void read(std::int8_t& value);
|
||||
virtual void read(std::int16_t& value);
|
||||
virtual void read(std::int32_t& value);
|
||||
virtual void read(std::int64_t& value);
|
||||
//! Reads a float
|
||||
virtual void read(float& value);
|
||||
//! Reads a double
|
||||
virtual void read(double& value);
|
||||
|
||||
virtual void read(std::vector<char>& value);
|
||||
virtual void read(std::vector<int8_t>& value);
|
||||
virtual void read(std::vector<int16_t>& value);
|
||||
virtual void read(std::vector<int32_t>& value);
|
||||
virtual void read(std::vector<int64_t>& value);
|
||||
virtual void read(std::vector<float>& value);
|
||||
virtual void read(std::vector<double>& value);
|
||||
virtual void read(std::vector<std::string>& value);
|
||||
virtual void read(std::vector<Core::Time>& value);
|
||||
|
||||
//! Reads a complex float
|
||||
virtual void read(std::complex<float>& value);
|
||||
//! Reads a complex double
|
||||
virtual void read(std::complex<double>& value);
|
||||
//! Reads a boolean
|
||||
virtual void read(bool& value);
|
||||
|
||||
//! Reads a vector of complex doubles
|
||||
virtual void read(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Reads a string
|
||||
virtual void read(std::string& value);
|
||||
|
||||
//! Reads a time
|
||||
virtual void read(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Write methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Writes an integer
|
||||
virtual void write(std::int8_t value);
|
||||
virtual void write(std::int16_t value);
|
||||
virtual void write(std::int32_t value);
|
||||
virtual void write(std::int64_t value);
|
||||
//! Writes a float
|
||||
virtual void write(float value);
|
||||
//! Writes a double
|
||||
virtual void write(double value);
|
||||
|
||||
virtual void write(std::vector<char>& value);
|
||||
virtual void write(std::vector<int8_t>& value);
|
||||
virtual void write(std::vector<int16_t>& value);
|
||||
virtual void write(std::vector<int32_t>& value);
|
||||
virtual void write(std::vector<int64_t>& value);
|
||||
virtual void write(std::vector<float>& value);
|
||||
virtual void write(std::vector<double>& value);
|
||||
virtual void write(std::vector<std::string>& value);
|
||||
virtual void write(std::vector<Core::Time>& value);
|
||||
|
||||
//! Writes a complex float
|
||||
virtual void write(std::complex<float>& value);
|
||||
//! Writes a complex double
|
||||
virtual void write(std::complex<double>& value);
|
||||
//! Writes a boolean
|
||||
virtual void write(bool value);
|
||||
|
||||
//! Writes a vector of complex doubles
|
||||
virtual void write(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Writes a string
|
||||
virtual void write(std::string& value);
|
||||
|
||||
//! Writes a time
|
||||
virtual void write(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
//! Implements derived virtual method
|
||||
bool locateObjectByName(const char* name, const char* targetClass, bool nullable);
|
||||
bool locateNextObjectByName(const char* name, const char* targetClass);
|
||||
void locateNullObjectByName(const char* name, const char* targetClass, bool first);
|
||||
|
||||
void readSequence();
|
||||
void writeSequence(int size);
|
||||
|
||||
//! Implements derived virtual method
|
||||
std::string determineClassName();
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void setClassName(const char* className);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(RootType* object);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(SerializeDispatcher&);
|
||||
|
||||
int writeBytes(const void*, int);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
int classId(const std::string& classname);
|
||||
|
||||
template <typename T>
|
||||
void readInt(T &value);
|
||||
|
||||
template <typename T>
|
||||
void readIntVector(std::vector<T> &value);
|
||||
|
||||
template <typename T>
|
||||
void writeVector(std::vector<T> &value);
|
||||
|
||||
|
||||
protected:
|
||||
std::streambuf* _buf;
|
||||
|
||||
private:
|
||||
bool _deleteOnClose;
|
||||
bool _nullable;
|
||||
bool _usedObject;
|
||||
std::string _classname;
|
||||
|
||||
int _sequenceSize;
|
||||
|
||||
typedef std::vector<std::string> ClassList;
|
||||
ClassList _classes;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
class SC_SYSTEM_CORE_API VBinaryArchive : public BinaryArchive {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
VBinaryArchive(int forceWriteVersion = -1);
|
||||
|
||||
//! Constructor with predefined buffer and mode
|
||||
VBinaryArchive(std::streambuf* buf, bool isReading = true,
|
||||
int forceWriteVersion = -1);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
void setWriteVersion(int version);
|
||||
|
||||
bool open(const char* file);
|
||||
bool open(std::streambuf*);
|
||||
|
||||
bool create(const char* file);
|
||||
bool create(std::streambuf*);
|
||||
|
||||
void close();
|
||||
|
||||
const char *errorMsg() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
void writeHeader();
|
||||
bool readHeader();
|
||||
|
||||
|
||||
private:
|
||||
int _forceWriteVersion;
|
||||
std::string _error;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
253
include/seiscomp/io/archive/bsonarchive.h
Normal file
253
include/seiscomp/io/archive/bsonarchive.h
Normal file
@ -0,0 +1,253 @@
|
||||
/***************************************************************************
|
||||
* 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 SCARCHIVE_BSON_H
|
||||
#define SCARCHIVE_BSON_H
|
||||
|
||||
#include <seiscomp/core/io.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An archive using BSON streams
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API BSONArchive : public Seiscomp::Core::Archive {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
BSONArchive();
|
||||
|
||||
//! Constructor with predefined buffer and mode
|
||||
BSONArchive(std::streambuf* buf, bool isReading = true,
|
||||
int forceWriteVersion = -1);
|
||||
|
||||
//! Destructor
|
||||
~BSONArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Opens an archive reading from a streambuf
|
||||
bool open(std::streambuf*);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual bool open(const char* filename);
|
||||
|
||||
//! Creates an archive writing to a streambuf
|
||||
bool create(std::streambuf* buf, bool writeVersion = true);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual bool create(const char* filename, bool writeVersion = true);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void close();
|
||||
|
||||
/**
|
||||
* Enables/Disables zip compression
|
||||
* @param enable The state of this flag
|
||||
*/
|
||||
void setCompression(bool enable);
|
||||
|
||||
/**
|
||||
* Enables/Disables JSON format
|
||||
* @param enable The state of this flag
|
||||
*/
|
||||
void setJSON(bool enable);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Read methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Reads an int8
|
||||
virtual void read(std::int8_t& value);
|
||||
//! Reads an int16
|
||||
virtual void read(std::int16_t& value);
|
||||
//! Reads an int32
|
||||
virtual void read(std::int32_t& value);
|
||||
//! Reads an int64
|
||||
virtual void read(std::int64_t& value);
|
||||
//! Reads a float
|
||||
virtual void read(float& value);
|
||||
//! Reads a double
|
||||
virtual void read(double& value);
|
||||
|
||||
virtual void read(char& value);
|
||||
|
||||
//! Reads a vector of native types
|
||||
virtual void read(std::vector<char>& value);
|
||||
virtual void read(std::vector<int8_t>& value);
|
||||
virtual void read(std::vector<int16_t>& value);
|
||||
virtual void read(std::vector<int32_t>& value);
|
||||
virtual void read(std::vector<int64_t>& value);
|
||||
virtual void read(std::vector<float>& value);
|
||||
virtual void read(std::vector<double>& value);
|
||||
virtual void read(std::vector<std::string>& value);
|
||||
virtual void read(std::vector<Core::Time>& value);
|
||||
|
||||
//! Reads a complex float
|
||||
virtual void read(std::complex<float>& value);
|
||||
//! Reads a complex double
|
||||
virtual void read(std::complex<double>& value);
|
||||
//! Reads a boolean
|
||||
virtual void read(bool& value);
|
||||
|
||||
//! Reads a vector of complex doubles
|
||||
virtual void read(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Reads a string
|
||||
virtual void read(std::string& value);
|
||||
|
||||
//! Reads a time
|
||||
virtual void read(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Write methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Writes an int8
|
||||
virtual void write(std::int8_t value);
|
||||
//! Writes an int16
|
||||
virtual void write(std::int16_t value);
|
||||
//! Writes an int32
|
||||
virtual void write(std::int32_t value);
|
||||
//! Writes an int64
|
||||
virtual void write(std::int64_t value);
|
||||
//! Writes a float
|
||||
virtual void write(float value);
|
||||
//! Writes a double
|
||||
virtual void write(double value);
|
||||
|
||||
virtual void write(char& value);
|
||||
|
||||
//! Writes a vector of native types
|
||||
virtual void write(std::vector<char>& value);
|
||||
virtual void write(std::vector<int8_t>& value);
|
||||
virtual void write(std::vector<int16_t>& value);
|
||||
virtual void write(std::vector<int32_t>& value);
|
||||
virtual void write(std::vector<int64_t>& value);
|
||||
virtual void write(std::vector<float>& value);
|
||||
virtual void write(std::vector<double>& value);
|
||||
virtual void write(std::vector<std::string>& value);
|
||||
virtual void write(std::vector<Core::Time>& value);
|
||||
|
||||
//! Writes a complex float
|
||||
virtual void write(std::complex<float>& value);
|
||||
//! Writes a complex double
|
||||
virtual void write(std::complex<double>& value);
|
||||
//! Writes a boolean
|
||||
virtual void write(bool value);
|
||||
|
||||
//! Writes a vector of complex doubles
|
||||
virtual void write(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Writes a string
|
||||
virtual void write(std::string& value);
|
||||
|
||||
//! Writes a time
|
||||
virtual void write(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
void setValidity(bool v);
|
||||
|
||||
//! Implements derived virtual method
|
||||
bool locateObjectByName(const char* name, const char* targetClass, bool nullable);
|
||||
bool locateNextObjectByName(const char* name, const char* targetClass);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void readSequence();
|
||||
void writeSequence(int size);
|
||||
|
||||
//! Implements derived virtual method
|
||||
std::string determineClassName();
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void setClassName(const char* className);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(RootType* object);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(SerializeDispatcher&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool open();
|
||||
bool create(bool writeVersion);
|
||||
|
||||
template<typename T>
|
||||
void readInt(T& value);
|
||||
|
||||
template<typename T>
|
||||
void readVector(std::vector<T>& value);
|
||||
|
||||
template<typename T>
|
||||
void readComplex(std::complex<T>& value);
|
||||
|
||||
template<typename T>
|
||||
void writeVector(std::vector<T>& value);
|
||||
|
||||
template<typename T>
|
||||
void writeComplex(std::complex<T>& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
DEFINE_SMARTPOINTER(BSONImpl);
|
||||
|
||||
BSONImplPtr _impl;
|
||||
|
||||
std::string _className;
|
||||
std::string _attribName;
|
||||
int _siblingCount;
|
||||
bool _startSequence;
|
||||
bool _validObject;
|
||||
|
||||
std::streambuf *_buf;
|
||||
bool _deleteOnClose;
|
||||
|
||||
bool _compression;
|
||||
bool _json;
|
||||
int _forceWriteVersion;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
266
include/seiscomp/io/archive/jsonarchive.h
Normal file
266
include/seiscomp/io/archive/jsonarchive.h
Normal file
@ -0,0 +1,266 @@
|
||||
/***************************************************************************
|
||||
* 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 SCARCHIVE_JSON_H
|
||||
#define SCARCHIVE_JSON_H
|
||||
|
||||
|
||||
#include <seiscomp/core/io.h>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An archive using JSON streams
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API JSONArchive : public Core::Archive {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public data types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
typedef rapidjson::Document Document;
|
||||
typedef Document::ValueType Value;
|
||||
typedef Value::ConstMemberIterator ConstItr;
|
||||
typedef rapidjson::SizeType Size;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
JSONArchive();
|
||||
|
||||
//! Constructor with predefined buffer and mode
|
||||
JSONArchive(std::streambuf* buf, bool isReading = true,
|
||||
int forceWriteVersion = -1);
|
||||
|
||||
//! Destructor
|
||||
~JSONArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool open(const char *file);
|
||||
bool open(std::streambuf*);
|
||||
//! Reads an archive from a rapidjson document value
|
||||
bool from(const Value*);
|
||||
//! Reads the archive from a string
|
||||
bool from(const char *str);
|
||||
//! Reads the archive from a string and allows optional insitu parsing
|
||||
//! which replaces the contents of the string (destructive).
|
||||
bool from(char *str, bool insitu = true);
|
||||
|
||||
bool create(const char *file, bool writeVersion = true);
|
||||
bool create(std::streambuf*, bool writeVersion = true);
|
||||
bool create(std::ostream*, bool writeVersion = true);
|
||||
|
||||
void setFormattedOutput(bool);
|
||||
|
||||
//! Sets if a root object is wrapped around the serialized objects.
|
||||
//! Default is true.
|
||||
void setRootObject(bool);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void close();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Read methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Reads an int8
|
||||
virtual void read(std::int8_t& value);
|
||||
//! Reads an int16
|
||||
virtual void read(std::int16_t& value);
|
||||
//! Reads an int32
|
||||
virtual void read(std::int32_t& value);
|
||||
//! Reads an int64
|
||||
virtual void read(std::int64_t& value);
|
||||
//! Reads a float
|
||||
virtual void read(float& value);
|
||||
//! Reads a double
|
||||
virtual void read(double& value);
|
||||
|
||||
virtual void read(std::vector<char>& value);
|
||||
virtual void read(std::vector<int8_t>& value);
|
||||
virtual void read(std::vector<int16_t>& value);
|
||||
virtual void read(std::vector<int32_t>& value);
|
||||
virtual void read(std::vector<int64_t>& value);
|
||||
virtual void read(std::vector<float>& value);
|
||||
virtual void read(std::vector<double>& value);
|
||||
virtual void read(std::vector<std::string>& value);
|
||||
virtual void read(std::vector<Core::Time>& value);
|
||||
|
||||
//! Reads a complex float
|
||||
virtual void read(std::complex<float>& value);
|
||||
//! Reads a complex double
|
||||
virtual void read(std::complex<double>& value);
|
||||
//! Reads a boolean
|
||||
virtual void read(bool& value);
|
||||
|
||||
//! Reads a vector of complex doubles
|
||||
virtual void read(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Reads a string
|
||||
virtual void read(std::string& value);
|
||||
|
||||
//! Reads a time
|
||||
virtual void read(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Write methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Writes an int8
|
||||
virtual void write(std::int8_t value);
|
||||
//! Writes an int16
|
||||
virtual void write(std::int16_t value);
|
||||
//! Writes an int32
|
||||
virtual void write(std::int32_t value);
|
||||
//! Writes an int64
|
||||
virtual void write(std::int64_t value);
|
||||
//! Writes a float
|
||||
virtual void write(float value);
|
||||
//! Writes a double
|
||||
virtual void write(double value);
|
||||
|
||||
virtual void write(std::vector<char>& value);
|
||||
virtual void write(std::vector<int8_t>& value);
|
||||
virtual void write(std::vector<int16_t>& value);
|
||||
virtual void write(std::vector<int32_t>& value);
|
||||
virtual void write(std::vector<int64_t>& value);
|
||||
virtual void write(std::vector<float>& value);
|
||||
virtual void write(std::vector<double>& value);
|
||||
virtual void write(std::vector<std::string>& value);
|
||||
virtual void write(std::vector<Core::Time>& value);
|
||||
|
||||
//! Writes a complex float
|
||||
virtual void write(std::complex<float>& value);
|
||||
//! Writes a complex double
|
||||
virtual void write(std::complex<double>& value);
|
||||
//! Writes a boolean
|
||||
virtual void write(bool value);
|
||||
|
||||
//! Writes a vector of complex doubles
|
||||
virtual void write(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Writes a string
|
||||
virtual void write(std::string& value);
|
||||
|
||||
//! Writes a time
|
||||
virtual void write(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
//! Implements derived virtual method
|
||||
bool locateObjectByName(const char* name, const char* targetClass, bool nullable);
|
||||
bool locateNextObjectByName(const char* name, const char* targetClass);
|
||||
void locateNullObjectByName(const char* name, const char* targetClass, bool first);
|
||||
|
||||
void readSequence();
|
||||
void writeSequence(int size);
|
||||
|
||||
//! Implements derived virtual method
|
||||
std::string determineClassName();
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void setClassName(const char* className);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(RootType* object);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(SerializeDispatcher&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
void parseVersion();
|
||||
void createDocument(bool writeVersion);
|
||||
|
||||
template <typename T>
|
||||
void _serialize(T &target);
|
||||
|
||||
void preAttrib();
|
||||
void postAttrib();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
const Value *findAttrib(const Value *node, const char* name);
|
||||
const Value *findTag(const Value *node, Size &index,
|
||||
const char* name, const char* targetClass);
|
||||
const Value *findNextTag(const Value *node, Size &index,
|
||||
const char* name, const char* targetClass);
|
||||
|
||||
template <typename T>
|
||||
void readIntVector(std::vector<T> &value);
|
||||
|
||||
template <typename T>
|
||||
void writeVector(std::vector<T> &value);
|
||||
|
||||
|
||||
private:
|
||||
int _forceWriteVersion;
|
||||
bool _deleteBufOnClose;
|
||||
bool _deleteStreamOnClose;
|
||||
bool _rootObject;
|
||||
bool _nullable;
|
||||
std::string _tagname;
|
||||
int _indent;
|
||||
int _sequenceSize;
|
||||
bool _isSequence;
|
||||
int _attribIndex;
|
||||
bool _isClass;
|
||||
bool _formattedOutput;
|
||||
std::streambuf *_buf;
|
||||
std::ostream *_os;
|
||||
Document *_document;
|
||||
const Value *_objectLocation;
|
||||
const Value *_current;
|
||||
const Value *_currentArray;
|
||||
Size _currentIndex;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
261
include/seiscomp/io/archive/xmlarchive.h
Normal file
261
include/seiscomp/io/archive/xmlarchive.h
Normal file
@ -0,0 +1,261 @@
|
||||
/***************************************************************************
|
||||
* 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 SCARCHIVE_XML_H
|
||||
#define SCARCHIVE_XML_H
|
||||
|
||||
#include <seiscomp/core/io.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An archive using XML streams
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API XMLArchive : public Seiscomp::Core::Archive {
|
||||
public:
|
||||
enum CompressionMethod {
|
||||
ZIP,
|
||||
GZIP
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructor
|
||||
XMLArchive();
|
||||
|
||||
//! Constructor with predefined buffer and mode
|
||||
XMLArchive(std::streambuf* buf, bool isReading = true,
|
||||
int forceWriteVersion = -1);
|
||||
|
||||
//! Destructor
|
||||
~XMLArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Opens an archive reading from a streambuf
|
||||
bool open(std::streambuf*);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual bool open(const char* filename);
|
||||
|
||||
//! Creates an archive writing to a streambuf
|
||||
bool create(std::streambuf* buf, bool writeVersion = true, bool headerNode = true);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual bool create(const char* filename, bool writeVersion = true, bool headerNode = true);
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void close();
|
||||
|
||||
//! Sets the root tagname to define the document entry.
|
||||
//! The default tagname is "seiscomp"
|
||||
void setRootName(const std::string &name);
|
||||
|
||||
/**
|
||||
* Enables/Disabled formatted XML output meaning inserting
|
||||
* formatting spaces.
|
||||
* @param enable The state of this flag
|
||||
*/
|
||||
void setFormattedOutput(bool enable);
|
||||
|
||||
/**
|
||||
* Enables/Disabled zip compression of XML output
|
||||
* @param enable The state of this flag
|
||||
*/
|
||||
void setCompression(bool enable);
|
||||
|
||||
/**
|
||||
* Sets the compression method if compression is enabled
|
||||
* @param method The method to be used
|
||||
*/
|
||||
void setCompressionMethod(CompressionMethod method);
|
||||
|
||||
//! Returns the used namesspace. If no namespace has been used,
|
||||
//! an empty string will be returned
|
||||
const std::string& rootNamespace() const;
|
||||
|
||||
//! Returns the used namesspace uri. If no namespace uri has been used,
|
||||
//! an empty string will be returned
|
||||
const std::string& rootNamespaceUri() const;
|
||||
|
||||
//! Sets the root namespace used when creating new documents
|
||||
void setRootNamespace(const std::string& name, const std::string& uri);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Read methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Reads an int8
|
||||
virtual void read(std::int8_t& value);
|
||||
//! Reads an int16
|
||||
virtual void read(std::int16_t& value);
|
||||
//! Reads an int32
|
||||
virtual void read(std::int32_t& value);
|
||||
//! Reads an int64
|
||||
virtual void read(std::int64_t& value);
|
||||
//! Reads a float
|
||||
virtual void read(float& value);
|
||||
//! Reads a double
|
||||
virtual void read(double& value);
|
||||
|
||||
//! Reads a vector of native types
|
||||
virtual void read(std::vector<char>& value);
|
||||
virtual void read(std::vector<int8_t>& value);
|
||||
virtual void read(std::vector<int16_t>& value);
|
||||
virtual void read(std::vector<int32_t>& value);
|
||||
virtual void read(std::vector<int64_t>& value);
|
||||
virtual void read(std::vector<float>& value);
|
||||
virtual void read(std::vector<double>& value);
|
||||
virtual void read(std::vector<std::string>& value);
|
||||
virtual void read(std::vector<Core::Time>& value);
|
||||
|
||||
//! Reads a complex float
|
||||
virtual void read(std::complex<float>& value);
|
||||
//! Reads a complex double
|
||||
virtual void read(std::complex<double>& value);
|
||||
//! Reads a boolean
|
||||
virtual void read(bool& value);
|
||||
|
||||
//! Reads a vector of complex doubles
|
||||
virtual void read(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Reads a string
|
||||
virtual void read(std::string& value);
|
||||
|
||||
//! Reads a time
|
||||
virtual void read(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Write methods
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Writes an int8
|
||||
virtual void write(std::int8_t value);
|
||||
//! Writes an int16
|
||||
virtual void write(std::int16_t value);
|
||||
//! Writes an int32
|
||||
virtual void write(std::int32_t value);
|
||||
//! Writes an int64
|
||||
virtual void write(std::int64_t value);
|
||||
//! Writes a float
|
||||
virtual void write(float value);
|
||||
//! Writes a double
|
||||
virtual void write(double value);
|
||||
|
||||
//! Writes a vector of native types
|
||||
virtual void write(std::vector<char>& value);
|
||||
virtual void write(std::vector<int8_t>& value);
|
||||
virtual void write(std::vector<int16_t>& value);
|
||||
virtual void write(std::vector<int32_t>& value);
|
||||
virtual void write(std::vector<int64_t>& value);
|
||||
virtual void write(std::vector<float>& value);
|
||||
virtual void write(std::vector<double>& value);
|
||||
virtual void write(std::vector<std::string>& value);
|
||||
virtual void write(std::vector<Core::Time>& value);
|
||||
|
||||
//! Writes a complex float
|
||||
virtual void write(std::complex<float>& value);
|
||||
//! Writes a complex double
|
||||
virtual void write(std::complex<double>& value);
|
||||
//! Writes a boolean
|
||||
virtual void write(bool value);
|
||||
|
||||
//! Writes a vector of complex doubles
|
||||
virtual void write(std::vector<std::complex<double> >& value);
|
||||
|
||||
//! Writes a string
|
||||
virtual void write(std::string& value);
|
||||
|
||||
//! Writes a time
|
||||
virtual void write(Seiscomp::Core::Time& value);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
void setValidity(bool v);
|
||||
|
||||
//! Implements derived virtual method
|
||||
bool locateObjectByName(const char* name, const char* targetClass, bool nullable);
|
||||
bool locateNextObjectByName(const char* name, const char* targetClass);
|
||||
|
||||
//! Implements derived virtual method
|
||||
std::string determineClassName();
|
||||
|
||||
//! Implements derived virtual method
|
||||
virtual void setClassName(const char* className);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(RootType* object);
|
||||
|
||||
//! Implements derived virtual method
|
||||
void serialize(SerializeDispatcher&);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool open();
|
||||
bool create(bool writeVersion, bool headerNode);
|
||||
|
||||
void addChild(const char* name, const char* type) const;
|
||||
void* addRootNode(const char* name) const;
|
||||
void writeAttrib(const std::string& value);
|
||||
|
||||
|
||||
protected:
|
||||
mutable void* _document;
|
||||
mutable void* _current;
|
||||
mutable void* _objectLocation;
|
||||
mutable std::string _property;
|
||||
mutable std::string _attribName;
|
||||
|
||||
int _forceWriteVersion;
|
||||
std::string _rootTag;
|
||||
|
||||
std::streambuf* _buf;
|
||||
bool _deleteOnClose;
|
||||
|
||||
bool _formattedOutput;
|
||||
bool _compression;
|
||||
CompressionMethod _compressionMethod;
|
||||
|
||||
std::pair<std::string, std::string> _namespace;
|
||||
};
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
334
include/seiscomp/io/database.h
Normal file
334
include/seiscomp/io/database.h
Normal file
@ -0,0 +1,334 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_DATABASE_H
|
||||
#define SEISCOMP_IO_DATABASE_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/interfacefactory.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(DatabaseInterface);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An abstract database interface and factory
|
||||
|
||||
This class provides an interface to databases such as MySQL, Oracle
|
||||
and so on.
|
||||
Database interface classes will be registered in its constructor in
|
||||
the global interface pool. They can only be created through the
|
||||
interface factory.
|
||||
|
||||
Example to request a database interface
|
||||
\code
|
||||
DatabaseInterfacePtr db = DatabaseInterface::Create("mysql");
|
||||
\endcode
|
||||
|
||||
To implement new interface, just derive from DatabaseInterface
|
||||
and register the instance with REGISTER_DB_INTERFACE
|
||||
\code
|
||||
class MyDatabaseInterface : Seiscomp::IO::DatabaseInterface {
|
||||
DECLARE_SC_CLASS(MyDatabaseInterface)
|
||||
|
||||
public:
|
||||
MyDatabaseInterface(const char* serviceName)
|
||||
: DatabaseInterface(serviceName) {}
|
||||
|
||||
// Implement all virtual methods
|
||||
};
|
||||
|
||||
IMPLEMENT_SC_CLASS_DERIVED(MyDatabaseInterface,
|
||||
Seiscomp::IO::DatabaseInterface,
|
||||
"MyDatabaseInterface")
|
||||
REGISTER_DB_INTERFACE(MyDatabaseInterface, "MyServiceName");
|
||||
\endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API DatabaseInterface : public Seiscomp::Core::BaseObject {
|
||||
DECLARE_SC_CLASS(DatabaseInterface);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public types
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef uint64_t OID;
|
||||
static const OID INVALID_OID;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Protected constructor
|
||||
DatabaseInterface();
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~DatabaseInterface();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Returns a database driver for the given database service
|
||||
//! @return A pointer to the database driver
|
||||
//! NOTE: The returned pointer has to be deleted by the
|
||||
//! caller!
|
||||
static DatabaseInterface *Create(const char* service);
|
||||
|
||||
//! Opens a database source.
|
||||
//! @param url A source URL of format [service://]user:pwd@host/database,
|
||||
//! e.g. mysql://user:pwd@localhost/mydb.
|
||||
//! @return A pointer to the database interface.
|
||||
//! NOTE: The returned pointer has to be deleted by the
|
||||
//! caller!
|
||||
static DatabaseInterface *Open(const char* uri);
|
||||
|
||||
/** Opens a connection to the database server
|
||||
@param connection The string containing the connection
|
||||
data. Its format is
|
||||
username:password@host:port/database?column_prefix=[prefix]
|
||||
Default values:
|
||||
username = ""
|
||||
password = ""
|
||||
host = "localhost"
|
||||
port = "0" = undefined
|
||||
database = ""
|
||||
column_prefix = ""
|
||||
@return The result of the connection
|
||||
*/
|
||||
virtual bool connect(const char* connection);
|
||||
|
||||
//! Closes the connection to the database
|
||||
virtual void disconnect() = 0;
|
||||
|
||||
//! Returns the current connection state.
|
||||
virtual bool isConnected() const = 0;
|
||||
|
||||
//! Starts a transaction
|
||||
virtual void start() = 0;
|
||||
|
||||
//! Ends a transaction.
|
||||
//! Everthing between begin and end transaction will
|
||||
//! be committed atomically
|
||||
virtual void commit() = 0;
|
||||
|
||||
//! Aborts a transaction and does a rollback of
|
||||
//! statements between begin and rollback
|
||||
virtual void rollback() = 0;
|
||||
|
||||
//! Executes a SQL command without a expecting a result
|
||||
virtual bool execute(const char* command) = 0;
|
||||
|
||||
/** Starts a SQL query. If a query has not been closed
|
||||
with endQuery it will be done in the first place.
|
||||
@return False, if the query has not been executed because
|
||||
of errors.
|
||||
True, the query has been executed and results can
|
||||
be fetched.
|
||||
*/
|
||||
virtual bool beginQuery(const char* query) = 0;
|
||||
|
||||
//! Ends a query after its results are not needed anymore
|
||||
virtual void endQuery() = 0;
|
||||
|
||||
/** Returns the default value name for the 'insert into' statement.
|
||||
This is needed because sqlite3 does not support
|
||||
\code
|
||||
insert into MyTable values(default);
|
||||
\endcode
|
||||
if there is just one attribute in MyTable (e.g. an
|
||||
autoincrement ID). sqlite3 supports only nullptr as default
|
||||
value string. The default implementation returns "default".
|
||||
@return The default value name
|
||||
*/
|
||||
virtual const char *defaultValue() const;
|
||||
|
||||
/** Returns the last inserted id when using auto increment id's
|
||||
@param table The table name for which the last generated id
|
||||
will be returned. In MySQL last_insert_id() is
|
||||
independant of the table name. PostgreSQL
|
||||
does not support autoincrement attributes but
|
||||
uses named sequences. To retrieve the last
|
||||
generated ID one has to use something like
|
||||
\code
|
||||
select currval('MyTable_seq');
|
||||
\endcode
|
||||
assuming the sequence names are created as
|
||||
[tablename]_seq.
|
||||
@return The last generated ID or INVALID_OID if there
|
||||
hasn't been created an ID yet.
|
||||
*/
|
||||
virtual OID lastInsertId(const char* table) = 0;
|
||||
|
||||
/** Returns the number of rows affected by a SQL statement.
|
||||
This function should only be used after a UPDATE or DELETE
|
||||
statement.
|
||||
@return An integer greater than zero indicates the number
|
||||
of rows affected or retrieved. Zero indicates that
|
||||
no records were updated for an UPDATE statement,
|
||||
no rows matched the WHERE clause in the query or
|
||||
that no query has yet been executed. 0xFFFFFFFF (-1)
|
||||
indicates an error.
|
||||
*/
|
||||
virtual uint64_t numberOfAffectedRows() = 0;
|
||||
|
||||
/** Fetches a row from the results of a query.
|
||||
@return True, a row has been fetched
|
||||
False, there is no row left to fetch
|
||||
*/
|
||||
virtual bool fetchRow() = 0;
|
||||
|
||||
/** Returns the index of the column with name <name>
|
||||
This method is valid for the most recent query.
|
||||
@param name The name of the column
|
||||
@return The index of the column, -1 if no column
|
||||
with that name exists
|
||||
*/
|
||||
virtual int findColumn(const char* name) = 0;
|
||||
|
||||
/** Returns the number of columns returned by a query.
|
||||
@return The column count. This number can be less or equal
|
||||
to zero in case of an error.
|
||||
*/
|
||||
virtual int getRowFieldCount() const = 0;
|
||||
|
||||
/** Returns the name of an indexed field of a
|
||||
fetched row.
|
||||
@param index The field index (column)
|
||||
@return The name of the field.
|
||||
*/
|
||||
virtual const char *getRowFieldName(int index) = 0;
|
||||
|
||||
/** Returns the content of an indexed field of a
|
||||
fetched row.
|
||||
@param index The field index (column)
|
||||
@return The content of the field. If the field
|
||||
is nullptr, nullptr will be returned.
|
||||
*/
|
||||
virtual const void *getRowField(int index) = 0;
|
||||
|
||||
/**
|
||||
* Convenience method to return the string of a certain column
|
||||
* @param index The field index (column)
|
||||
* @return The content of the field as string. If the field
|
||||
is nullptr, an empty string will be returned
|
||||
*/
|
||||
std::string getRowFieldString(int index);
|
||||
|
||||
/** Returns the size of an indexed field of a
|
||||
fetched row.
|
||||
@param index The field index
|
||||
@return The size of the field data.
|
||||
*/
|
||||
virtual size_t getRowFieldSize(int index) = 0;
|
||||
|
||||
//! Converts a time to a string representation used by
|
||||
//! the database.
|
||||
virtual std::string timeToString(const Seiscomp::Core::Time&);
|
||||
|
||||
//! Parses a string containing time information and returns
|
||||
//! the corresponding time object.
|
||||
//! The format of the string is database dependant.
|
||||
virtual Seiscomp::Core::Time stringToTime(const char*);
|
||||
|
||||
/**
|
||||
* @brief Escapes an input string to a database specific escaped
|
||||
* string to be used in an SQL statement.
|
||||
*
|
||||
* The default implementation does C escaping and duplicates a
|
||||
* single quote.
|
||||
*
|
||||
* Note that the output string will have the correct size but the
|
||||
* capacity (string::reserve, string::capacity) is most likely much
|
||||
* larger to fit the maximum number of escaped characters. If the
|
||||
* output string should be used permanently and not just as temporary
|
||||
* value then call out.reserve(0) afterwards to allow it to shrink to
|
||||
* its size.
|
||||
*
|
||||
* @param to The output string
|
||||
* @param from The input string.
|
||||
* @return Success flag
|
||||
*/
|
||||
virtual bool escape(std::string &out, const std::string &in);
|
||||
|
||||
//! Returns the used column prefix
|
||||
const std::string &columnPrefix() const;
|
||||
|
||||
//! Prepends the column prefix to the name and returns it
|
||||
std::string convertColumnName(const std::string& name) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! This method can be implemented in an interface to handle
|
||||
//! additional URI parameters:
|
||||
//! mysql://sysop:sysop@localhost/test?param1=value1¶m2=value2
|
||||
//! This method would be called for param1 and param2.
|
||||
//! If this method is reimplemented the base implementation should
|
||||
//! be called otherwise column_prefix and timeout are not handled
|
||||
//! by default.
|
||||
virtual bool handleURIParameter(const std::string &name,
|
||||
const std::string &value);
|
||||
|
||||
//! This method has to be implemented in derived classes to
|
||||
//! connect to the database using the members _user, _password,
|
||||
//! _host, _port and _database
|
||||
virtual bool open() = 0;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected members
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
std::string _user;
|
||||
std::string _password;
|
||||
std::string _host;
|
||||
int _port;
|
||||
unsigned int _timeout;
|
||||
std::string _database;
|
||||
std::string _columnPrefix;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(DatabaseInterface);
|
||||
|
||||
#define REGISTER_DB_INTERFACE(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::IO::DatabaseInterface, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
124
include/seiscomp/io/exporter.h
Normal file
124
include/seiscomp/io/exporter.h
Normal file
@ -0,0 +1,124 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_EXPORTER_H
|
||||
#define SEISCOMP_IO_EXPORTER_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/interfacefactory.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <streambuf>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API ExportSink {
|
||||
virtual ~ExportSink() {}
|
||||
virtual int write(const char *data, int size) { return 0; }
|
||||
};
|
||||
|
||||
|
||||
typedef std::vector<Core::BaseObject*> ExportObjectList;
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Exporter);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An abstract exporter interface and factory
|
||||
|
||||
This class provides an interface to export sc3 (meta) data
|
||||
formats into any other format such as QuakeML.
|
||||
\endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Exporter : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Exporter);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Exporter();
|
||||
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~Exporter();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static Exporter *Create(const char *type);
|
||||
|
||||
void setFormattedOutput(bool enable);
|
||||
void setIndent(int);
|
||||
|
||||
bool write(std::streambuf* buf, Core::BaseObject *);
|
||||
bool write(std::string filename, Core::BaseObject *);
|
||||
|
||||
//! Converts the object using the Sink interface to write
|
||||
//! the data.
|
||||
bool write(ExportSink *sink, Core::BaseObject *);
|
||||
|
||||
bool write(std::streambuf* buf, const ExportObjectList &objects);
|
||||
bool write(std::string filename, const ExportObjectList &objects);
|
||||
|
||||
//! Converts the objects using the Sink interface to write
|
||||
//! the data.
|
||||
bool write(ExportSink *sink, const ExportObjectList &objects);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Interface method that must be implemented by real exporters.
|
||||
virtual bool put(std::streambuf* buf, Core::BaseObject *) = 0;
|
||||
|
||||
//! Interface method that should be implemented by real exporters. The
|
||||
//! default implementation does nothing and returns false. Since that
|
||||
//! method has been introduced with API 12 it is not abstract to
|
||||
//! maintain compilation of existing exporters.
|
||||
virtual bool put(std::streambuf* buf, const ExportObjectList &objects);
|
||||
|
||||
|
||||
protected:
|
||||
bool _prettyPrint;
|
||||
int _indentation;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(Exporter);
|
||||
|
||||
#define REGISTER_EXPORTER_INTERFACE(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::IO::Exporter, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
144
include/seiscomp/io/gfarchive.h
Normal file
144
include/seiscomp/io/gfarchive.h
Normal file
@ -0,0 +1,144 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_GFARCHIVE_H
|
||||
#define __SEISCOMP_IO_GFARCHIVE_H
|
||||
|
||||
|
||||
#include <seiscomp/core/interfacefactory.h>
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/math/coord.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
namespace Core {
|
||||
|
||||
class GreensFunction;
|
||||
|
||||
}
|
||||
|
||||
namespace IO {
|
||||
|
||||
|
||||
struct GFSource : Math::Geo::CoordD {
|
||||
explicit GFSource(double lat = 0.0, double lon = 0.0, double d = 0.0)
|
||||
: Math::Geo::CoordD(lat, lon), depth(d) {}
|
||||
|
||||
double depth; //!< Depth in kilometer
|
||||
};
|
||||
|
||||
|
||||
struct GFReceiver : Math::Geo::CoordD {
|
||||
explicit GFReceiver(double lat = 0.0, double lon = 0.0, double e = 0.0)
|
||||
: Math::Geo::CoordD(lat, lon), elevation(e) {}
|
||||
|
||||
double elevation; //!< Elevation in meter
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(GFArchive);
|
||||
|
||||
class SC_SYSTEM_CORE_API GFArchive : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(GFArchive);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! C'tor
|
||||
GFArchive();
|
||||
|
||||
public:
|
||||
//! Virtual d'tor
|
||||
virtual ~GFArchive();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool setSource(std::string) = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual std::list<std::string> availableModels() const;
|
||||
virtual std::list<double> availableDepths(const std::string &model) const;
|
||||
|
||||
//! Sets the default timespan used for requests without
|
||||
//! a timespan.
|
||||
virtual bool setTimeSpan(const Core::TimeSpan &span) = 0;
|
||||
|
||||
//! Adds a request for a greensfunction.
|
||||
virtual bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver) = 0;
|
||||
|
||||
virtual bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver,
|
||||
const Core::TimeSpan &span) = 0;
|
||||
|
||||
//! Retrieves a greensfunction from the archive. The end of
|
||||
//! sequence is marked with a nullptr pointer.
|
||||
virtual Core::GreensFunction* get() = 0;
|
||||
|
||||
/**
|
||||
* @brief Returns the travel time of a given phase from the source
|
||||
* to the receiver.
|
||||
* @param phase The phase code
|
||||
* @param model The requested model.
|
||||
* @param source The source location.
|
||||
* @param receiver The receiver location.
|
||||
* @return The relative travel time in seconds. If not supported then
|
||||
* None must be returned.
|
||||
*/
|
||||
virtual OPT(double) getTravelTime(const std::string &phase,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver) = 0;
|
||||
|
||||
|
||||
bool hasLocalTravelTimes() const { return _hasLocalTravelTimes; }
|
||||
|
||||
|
||||
public:
|
||||
static GFArchive* Create(const char* service);
|
||||
static GFArchive* Open(const char* url);
|
||||
|
||||
protected:
|
||||
bool _hasLocalTravelTimes{false};
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(GFArchive);
|
||||
|
||||
|
||||
#define REGISTER_GFARCHIVE(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::IO::GFArchive, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
124
include/seiscomp/io/gfarchive/helmberger.h
Normal file
124
include/seiscomp/io/gfarchive/helmberger.h
Normal file
@ -0,0 +1,124 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_GFARCHIVE_HELMBERGER_H
|
||||
#define SEISCOMP_IO_GFARCHIVE_HELMBERGER_H
|
||||
|
||||
|
||||
#include <seiscomp/io/gfarchive.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API HelmbergerArchive : public GFArchive {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
HelmbergerArchive();
|
||||
HelmbergerArchive(const std::string &baseDirectory);
|
||||
|
||||
//! D'tor
|
||||
~HelmbergerArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setSource(std::string);
|
||||
void close();
|
||||
|
||||
std::list<std::string> availableModels() const;
|
||||
std::list<double> availableDepths(const std::string &model) const;
|
||||
|
||||
bool setTimeSpan(const Core::TimeSpan &span);
|
||||
|
||||
//! Adds a request for a greensfunction.
|
||||
bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver);
|
||||
|
||||
bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver,
|
||||
const Core::TimeSpan &span);
|
||||
|
||||
Core::GreensFunction* get();
|
||||
|
||||
OPT(double) getTravelTime(const std::string &phase,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private member
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool hasModel(const std::string &) const;
|
||||
Core::GreensFunction* read(const std::string &file,
|
||||
const Core::TimeSpan &ts, double timeOfs);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private member
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct Request {
|
||||
Core::TimeSpan timeSpan;
|
||||
std::string id;
|
||||
std::string model;
|
||||
double distance;
|
||||
double depth;
|
||||
};
|
||||
|
||||
typedef std::list<Request> RequestList;
|
||||
typedef std::set<double> DoubleList;
|
||||
|
||||
struct ModelConfig {
|
||||
double velocity;
|
||||
DoubleList distances;
|
||||
DoubleList depths;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, ModelConfig> ModelMap;
|
||||
|
||||
ModelMap _models;
|
||||
std::string _baseDirectory;
|
||||
Core::TimeSpan _defaultTimespan;
|
||||
RequestList _requests;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
130
include/seiscomp/io/gfarchive/instaseis.h
Normal file
130
include/seiscomp/io/gfarchive/instaseis.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_IO_GFARCHIVE_INSTASEIS_H
|
||||
#define SEISCOMP_IO_GFARCHIVE_INSTASEIS_H
|
||||
|
||||
|
||||
#include <seiscomp/io/gfarchive.h>
|
||||
#include <seiscomp/io/socket.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Instaseis : public GFArchive {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Instaseis();
|
||||
Instaseis(const std::string &url);
|
||||
|
||||
//! D'tor
|
||||
~Instaseis();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setSource(std::string);
|
||||
void close();
|
||||
|
||||
std::list<std::string> availableModels() const;
|
||||
std::list<double> availableDepths(const std::string &model) const;
|
||||
|
||||
bool setTimeSpan(const Core::TimeSpan &span);
|
||||
|
||||
//! Adds a request for a greensfunction.
|
||||
bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver);
|
||||
|
||||
bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver,
|
||||
const Core::TimeSpan &span);
|
||||
|
||||
Core::GreensFunction* get();
|
||||
|
||||
OPT(double) getTravelTime(const std::string &phase,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool getInfo() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private member
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct Request {
|
||||
Core::TimeSpan timeSpan;
|
||||
std::string id;
|
||||
double distance;
|
||||
double depth;
|
||||
};
|
||||
|
||||
typedef std::list<Request> RequestList;
|
||||
|
||||
std::string _host;
|
||||
std::string _path;
|
||||
int _timeout;
|
||||
Core::TimeSpan _defaultTimespan;
|
||||
RequestList _requests;
|
||||
|
||||
mutable Socket _socket;
|
||||
mutable std::string _model;
|
||||
|
||||
mutable double _dt;
|
||||
|
||||
mutable int _maxLength;
|
||||
mutable double _srcShift;
|
||||
|
||||
mutable double _minDepth;
|
||||
mutable double _maxDepth;
|
||||
|
||||
mutable double _minDist;
|
||||
mutable double _maxDist;
|
||||
|
||||
mutable bool _hasInfo;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
133
include/seiscomp/io/gfarchive/sc3gf1d.h
Normal file
133
include/seiscomp/io/gfarchive/sc3gf1d.h
Normal file
@ -0,0 +1,133 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_GFARCHIVE_SAUL_H
|
||||
#define SEISCOMP_IO_GFARCHIVE_SAUL_H
|
||||
|
||||
|
||||
#include <seiscomp/io/gfarchive.h>
|
||||
#include <seiscomp/seismology/ttt.h>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SC3GF1DArchive : public GFArchive {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
SC3GF1DArchive();
|
||||
SC3GF1DArchive(const std::string &baseDirectory);
|
||||
|
||||
//! D'tor
|
||||
~SC3GF1DArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setSource(std::string);
|
||||
void close();
|
||||
|
||||
std::list<std::string> availableModels() const;
|
||||
std::list<double> availableDepths(const std::string &model) const;
|
||||
|
||||
bool setTimeSpan(const Core::TimeSpan &span);
|
||||
|
||||
//! Adds a request for a greensfunction.
|
||||
bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver);
|
||||
|
||||
bool addRequest(const std::string &id,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver,
|
||||
const Core::TimeSpan &span);
|
||||
|
||||
Core::GreensFunction* get();
|
||||
|
||||
OPT(double) getTravelTime(const std::string &phase,
|
||||
const std::string &model,
|
||||
const GFSource &source,
|
||||
const GFReceiver &receiver);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private member
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
bool hasModel(const std::string &) const;
|
||||
Core::GreensFunction* read(const std::string &file,
|
||||
const Core::TimeSpan &ts, double timeOfs);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private member
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct Request {
|
||||
Core::TimeSpan timeSpan;
|
||||
std::string id;
|
||||
std::string model;
|
||||
double distance;
|
||||
double depth;
|
||||
};
|
||||
|
||||
typedef std::list<Request> RequestList;
|
||||
typedef std::set<double> DoubleList;
|
||||
typedef std::map<double, double> TTDepth;
|
||||
typedef std::map<double, TTDepth> TTDistance;
|
||||
typedef std::map<std::string, TTDistance> TTPhases;
|
||||
|
||||
struct ModelConfig {
|
||||
ModelConfig() : travelTimesInitialized(false) {}
|
||||
|
||||
DoubleList distances;
|
||||
DoubleList depths;
|
||||
TTPhases travelTimes;
|
||||
bool travelTimesInitialized;
|
||||
std::string travelTimeInterfaceName{"LOCSAT"};
|
||||
std::string travelTimeInterfaceProfile{"iasp91"};
|
||||
TravelTimeTableInterfacePtr travelTimeTable;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, ModelConfig> ModelMap;
|
||||
|
||||
ModelMap _models;
|
||||
std::string _baseDirectory;
|
||||
Core::TimeSpan _defaultTimespan;
|
||||
RequestList _requests;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
63
include/seiscomp/io/httpsocket.h
Normal file
63
include/seiscomp/io/httpsocket.h
Normal file
@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_HTTPSOCKET_H
|
||||
#define SEISCOMP_IO_HTTPSOCKET_H
|
||||
|
||||
|
||||
#include <boost/iostreams/filter/zlib.hpp>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
template <typename SocketType>
|
||||
class SC_SYSTEM_CORE_API HttpSocket : public SocketType {
|
||||
public:
|
||||
HttpSocket();
|
||||
virtual ~HttpSocket();
|
||||
virtual void open(const std::string& serverHost,
|
||||
const std::string& user = "", const std::string& password = "");
|
||||
void httpGet(const std::string &path);
|
||||
void httpPost(const std::string &path, const std::string &msg);
|
||||
std::string httpReadRaw(int size);
|
||||
std::string httpReadSome(int size);
|
||||
std::string httpRead(int size);
|
||||
|
||||
private:
|
||||
std::string _serverHost;
|
||||
std::string _user;
|
||||
std::string _password;
|
||||
std::string _error;
|
||||
bool _chunkMode;
|
||||
int _remainingBytes;
|
||||
boost::iostreams::zlib_decompressor *_decomp;
|
||||
|
||||
void httpReadResponse();
|
||||
void sendAuthorization();
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
332
include/seiscomp/io/httpsocket.ipp
Normal file
332
include/seiscomp/io/httpsocket.ipp
Normal file
@ -0,0 +1,332 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_HTTPSOCKET_IPP__
|
||||
#define SEISCOMP_IO_HTTPSOCKET_IPP__
|
||||
|
||||
|
||||
#include <boost/iostreams/concepts.hpp>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
template <typename SocketType>
|
||||
class SC_SYSTEM_CORE_API HttpSource : public boost::iostreams::source {
|
||||
public:
|
||||
HttpSource(HttpSocket<SocketType> *sock);
|
||||
std::streamsize read(char* buf, std::streamsize size);
|
||||
|
||||
private:
|
||||
HttpSocket<SocketType> *_sock;
|
||||
};
|
||||
|
||||
template <typename SocketType>
|
||||
HttpSource<SocketType>::HttpSource(HttpSocket<SocketType> *sock): _sock(sock)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename SocketType>
|
||||
std::streamsize HttpSource<SocketType>::read(char* buf, std::streamsize size) {
|
||||
std::string data = _sock->httpReadRaw(size);
|
||||
|
||||
if ( (int)data.size() > size ) {
|
||||
SEISCOMP_ERROR("impossible thing happened");
|
||||
memcpy(buf, data.data(), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
memcpy(buf, data.data(), data.size());
|
||||
return data.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
HttpSocket<SocketType>::HttpSocket(): _chunkMode(false), _remainingBytes(0),
|
||||
_decomp(nullptr)
|
||||
{
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
HttpSocket<SocketType>::~HttpSocket()
|
||||
{
|
||||
if ( _decomp )
|
||||
delete _decomp;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
void HttpSocket<SocketType>::open(const std::string& serverHost,
|
||||
const std::string& user, const std::string& password)
|
||||
{
|
||||
_serverHost = serverHost;
|
||||
_user = user;
|
||||
_password = password;
|
||||
_chunkMode = false;
|
||||
_remainingBytes = 0;
|
||||
SocketType::open(serverHost);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
void HttpSocket<SocketType>::httpReadResponse()
|
||||
{
|
||||
if ( _decomp != nullptr ) {
|
||||
delete _decomp;
|
||||
_decomp = nullptr;
|
||||
}
|
||||
|
||||
std::string line = this->readline();
|
||||
if ( line.compare(0, 7, "HTTP/1.") != 0 )
|
||||
throw Core::GeneralException(("server sent invalid response: " + line).c_str());
|
||||
|
||||
size_t pos;
|
||||
pos = line.find(' ');
|
||||
if ( pos == std::string::npos )
|
||||
throw Core::GeneralException(("server sent invalid response: " + line).c_str());
|
||||
|
||||
line.erase(0, pos+1);
|
||||
|
||||
pos = line.find(' ');
|
||||
if ( pos == std::string::npos )
|
||||
throw Core::GeneralException(("server sent invalid response: " + line).c_str());
|
||||
|
||||
int code;
|
||||
if ( !Core::fromString(code, line.substr(0, pos)) )
|
||||
throw Core::GeneralException(("server sent invalid status code: " + line.substr(0, pos)).c_str());
|
||||
|
||||
if ( code != 200 && code != 204 )
|
||||
_error = "server request error: " + line;
|
||||
|
||||
_remainingBytes = -1;
|
||||
|
||||
int lc = 0;
|
||||
|
||||
while ( !this->isInterrupted() ) {
|
||||
++lc;
|
||||
line = this->readline();
|
||||
if ( line.empty() ) break;
|
||||
|
||||
SEISCOMP_DEBUG("[%02d] %s", lc, line.c_str());
|
||||
if ( line == "Transfer-Encoding: chunked" ) {
|
||||
_chunkMode = true;
|
||||
SEISCOMP_DEBUG(" -> enabled 'chunked' transfer");
|
||||
}
|
||||
else if ( line == "Content-Encoding: gzip" ) {
|
||||
_decomp = new boost::iostreams::zlib_decompressor(boost::iostreams::zlib::default_window_bits | 16);
|
||||
SEISCOMP_DEBUG(" -> enabled 'gzip' compression");
|
||||
}
|
||||
else if ( line == "Content-Encoding: deflate" ) {
|
||||
_decomp = new boost::iostreams::zlib_decompressor(boost::iostreams::zlib::default_window_bits);
|
||||
SEISCOMP_DEBUG(" -> enabled 'deflate' compression");
|
||||
}
|
||||
else if ( line.compare(0, 15, "Content-Length:") == 0 ) {
|
||||
if ( !Core::fromString(_remainingBytes, line.substr(15)) )
|
||||
throw Core::GeneralException("invalid Content-Length response");
|
||||
if ( _remainingBytes < 0 )
|
||||
throw Core::GeneralException("Content-Length must be positive");
|
||||
}
|
||||
}
|
||||
|
||||
if ( _chunkMode ) {
|
||||
if ( _remainingBytes >= 0 )
|
||||
throw Core::GeneralException("protocol error: transfer encoding is chunked and content length given");
|
||||
_remainingBytes = 0;
|
||||
}
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
void HttpSocket<SocketType>::sendAuthorization()
|
||||
{
|
||||
std::string auth = _user + ':' + _password;
|
||||
BIO* b64 = BIO_new(BIO_f_base64());
|
||||
BIO* bio = BIO_new(BIO_s_mem());
|
||||
BIO_push(b64, bio);
|
||||
BIO_write(b64, auth.c_str(), auth.length());
|
||||
BIO_flush(b64);
|
||||
BUF_MEM *mem;
|
||||
BIO_get_mem_ptr(b64, &mem);
|
||||
this->sendRequest("Authorization: Basic " + std::string(mem->data, mem->length - 1), false);
|
||||
BIO_free_all(b64);
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
void HttpSocket<SocketType>::httpGet(const std::string &path)
|
||||
{
|
||||
this->sendRequest(std::string("GET ") + path + " HTTP/1.1", false);
|
||||
this->sendRequest(std::string("Host: ") + _serverHost, false);
|
||||
this->sendRequest("User-Agent: Mosaic/1.0", false);
|
||||
this->sendRequest("Accept-Encoding: gzip, deflate", false);
|
||||
|
||||
if ( _user.length() > 0 )
|
||||
sendAuthorization();
|
||||
|
||||
this->sendRequest("", false);
|
||||
httpReadResponse();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
void HttpSocket<SocketType>::httpPost(const std::string &path, const std::string &msg)
|
||||
{
|
||||
this->sendRequest(std::string("POST ") + path + " HTTP/1.1", false);
|
||||
this->sendRequest(std::string("Host: ") + _serverHost, false);
|
||||
this->sendRequest("User-Agent: Mosaic/1.0", false);
|
||||
this->sendRequest("Accept-Encoding: gzip, deflate", false);
|
||||
this->sendRequest("Content-Type: application/bson", false);
|
||||
this->sendRequest(std::string("Content-Length: ") + Core::toString(msg.size()), false);
|
||||
|
||||
if ( _user.length() > 0 )
|
||||
sendAuthorization();
|
||||
|
||||
this->sendRequest("", false);
|
||||
this->write(msg);
|
||||
httpReadResponse();
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
std::string HttpSocket<SocketType>::httpReadRaw(int size)
|
||||
{
|
||||
if ( _chunkMode && _remainingBytes <= 0 ) {
|
||||
std::string r = this->readline();
|
||||
size_t pos = r.find(' ');
|
||||
unsigned int remainingBytes;
|
||||
|
||||
if ( sscanf(r.substr(0, pos).c_str(), "%X", &remainingBytes) != 1 )
|
||||
throw Core::GeneralException((std::string("invalid chunk header: ") + r).c_str());
|
||||
|
||||
_remainingBytes = remainingBytes;
|
||||
|
||||
if ( _remainingBytes <= 0 ) {
|
||||
this->close();
|
||||
|
||||
if ( _error.size() )
|
||||
throw Core::GeneralException(_error.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if ( _remainingBytes <= 0 )
|
||||
return "";
|
||||
|
||||
int toBeRead = _remainingBytes;
|
||||
if ( toBeRead > size ) toBeRead = size;
|
||||
|
||||
// seiscomp/io/socket.h defines BUFSIZE as the max read size
|
||||
std::string data = this->read(std::min(toBeRead, BUFSIZE));
|
||||
_remainingBytes -= data.size();
|
||||
|
||||
if ( _chunkMode && _remainingBytes <= 0 )
|
||||
// Read trailing new line
|
||||
this->readline();
|
||||
|
||||
if ( _error.size() ) {
|
||||
this->close();
|
||||
throw Core::GeneralException(_error.c_str());
|
||||
}
|
||||
|
||||
if ( !_chunkMode && _remainingBytes <= 0 )
|
||||
this->close();
|
||||
|
||||
return data;
|
||||
}
|
||||
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
std::string HttpSocket<SocketType>::httpReadSome(int size)
|
||||
{
|
||||
if ( _decomp != nullptr ) {
|
||||
HttpSource<SocketType> src(this);
|
||||
std::vector<char> tmp(size);
|
||||
std::streamsize bytesRead = _decomp->read(src, &tmp[0], size);
|
||||
return std::string(&tmp[0], bytesRead);
|
||||
}
|
||||
else {
|
||||
return httpReadRaw(size);
|
||||
}
|
||||
}
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
|
||||
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
template <typename SocketType>
|
||||
std::string HttpSocket<SocketType>::httpRead(int size)
|
||||
{
|
||||
std::string data;
|
||||
|
||||
while ( (int)data.size() < size ) {
|
||||
std::string::size_type bytesRead = data.size();
|
||||
data += httpReadSome(size - bytesRead);
|
||||
|
||||
if ( data.size() == bytesRead )
|
||||
break;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
95
include/seiscomp/io/importer.h
Normal file
95
include/seiscomp/io/importer.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_IO_IMPORTER_H
|
||||
#define SEISCOMP_IO_IMPORTER_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/core/interfacefactory.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <streambuf>
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Importer);
|
||||
|
||||
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||||
/** \brief An abstract importer interface and factory
|
||||
|
||||
This class provides an interface to import foreign (meta) data
|
||||
formats such as QuakeML.
|
||||
\endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API Importer : public Core::BaseObject {
|
||||
DECLARE_SC_CLASS(Importer);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Importer();
|
||||
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~Importer();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
static Importer *Create(const char *type);
|
||||
|
||||
Core::BaseObject *read(std::streambuf* buf);
|
||||
Core::BaseObject *read(std::string filename);
|
||||
|
||||
bool withoutErrors() const;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Interface method that must be implemented by real importers.
|
||||
virtual Core::BaseObject *get(std::streambuf* buf) = 0;
|
||||
|
||||
|
||||
protected:
|
||||
bool _hasErrors;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(Importer);
|
||||
|
||||
#define REGISTER_IMPORTER_INTERFACE(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::IO::Importer, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
413
include/seiscomp/io/quakelink/connection.h
Normal file
413
include/seiscomp/io/quakelink/connection.h
Normal file
@ -0,0 +1,413 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_QUAKELINK_CONNECTION_H
|
||||
#define SEISCOMP_IO_QUAKELINK_CONNECTION_H
|
||||
|
||||
|
||||
#include <seiscomp/core/baseobject.h>
|
||||
#include <seiscomp/io/socket.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
namespace QuakeLink {
|
||||
|
||||
extern const char *SummaryTimeFormat;
|
||||
extern const char *RequestTimeFormat;
|
||||
|
||||
enum RequestFormat {
|
||||
rfSummary = 0,
|
||||
rfXML = 1,
|
||||
rfGZXML = 2,
|
||||
rfNative = 3,
|
||||
rfGZNative = 4
|
||||
};
|
||||
|
||||
enum ContentType {
|
||||
ctUndefined = -1,
|
||||
ctXML = 0,
|
||||
ctEvSum = 1,
|
||||
ctEvLog = 2,
|
||||
ctText = 3
|
||||
};
|
||||
|
||||
enum Options {
|
||||
opIgnore = 0x0000,
|
||||
opDefaults = 0x0001,
|
||||
opXMLIndent = 0x0002,
|
||||
opDataPicks = 0x0004,
|
||||
opDataAmplitudes = 0x0008,
|
||||
opDataStaMags = 0x0010,
|
||||
opDataArrivals = 0x0020,
|
||||
opDataStaMts = 0x0040,
|
||||
opDataPreferred = 0x0080,
|
||||
opKeepAlive = 0x8000, // since API 1.6.0
|
||||
opAll = 0xFFFF
|
||||
};
|
||||
|
||||
enum OrderBy {
|
||||
obUndefined = -1,
|
||||
obOTimeAsc = 0,
|
||||
obOTimeDesc = 1
|
||||
};
|
||||
|
||||
enum Domain {
|
||||
doEvents = 0,
|
||||
doDYFI = 1
|
||||
};
|
||||
|
||||
// API and format version type
|
||||
typedef unsigned int Version;
|
||||
|
||||
// Maps a version of a specific RequestFormat to a minimum required API version
|
||||
typedef std::vector<Version> APIList;
|
||||
|
||||
// Maps a RequestFormat to the list of required API versions
|
||||
typedef std::map<RequestFormat, APIList> FormatAPIMap;
|
||||
|
||||
class RequestFormatVersion {
|
||||
public:
|
||||
RequestFormatVersion(RequestFormat format, Version version=1)
|
||||
: _format(format), _version(version < 1 ? 1 : version) {}
|
||||
operator RequestFormat() const { return _format; }
|
||||
RequestFormat format() const { return _format; }
|
||||
Version version() const { return _version; }
|
||||
|
||||
private:
|
||||
RequestFormat _format;
|
||||
Version _version;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Response class
|
||||
*/
|
||||
DEFINE_SMARTPOINTER(Response);
|
||||
class Response : public Core::BaseObject {
|
||||
DECLARE_CASTS(Response);
|
||||
public:
|
||||
// Header
|
||||
ContentType type;
|
||||
uint length;
|
||||
Core::Time timestamp;
|
||||
std::string format;
|
||||
bool gzip;
|
||||
OPT(int) revision; // since API 1.6.0
|
||||
bool disposed; // since API 4.0.0
|
||||
|
||||
// Payload
|
||||
std::string data;
|
||||
|
||||
Response() { reset(); }
|
||||
Response(const Response &other) { *this = other; }
|
||||
|
||||
const Response& operator=(const Response &other) {
|
||||
type = other.type;
|
||||
length = other.length;
|
||||
timestamp = other.timestamp;
|
||||
format = other.format;
|
||||
gzip = other.gzip;
|
||||
data = other.data;
|
||||
revision = other.revision;
|
||||
disposed = other.disposed;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
type = ctUndefined;
|
||||
length = 0;
|
||||
timestamp = Core::Time::Null;
|
||||
gzip = false;
|
||||
revision = Core::None;
|
||||
disposed = false;
|
||||
format.clear();
|
||||
data.clear();
|
||||
}
|
||||
};
|
||||
typedef std::vector<Response> Responses;
|
||||
typedef std::vector<Response*> ResponsesPtr;
|
||||
|
||||
DEFINE_SMARTPOINTER(Connection);
|
||||
class Connection : public Core::BaseObject {
|
||||
|
||||
public:
|
||||
/** Default constructor */
|
||||
Connection();
|
||||
|
||||
/** Destructor */
|
||||
virtual ~Connection();
|
||||
|
||||
/**
|
||||
* @brief Initializes client instance with connection URL and options
|
||||
* @param url URL of the QuakeLink including user name and password if
|
||||
* required
|
||||
* @param options Bit mask of all options to enable
|
||||
* @return
|
||||
*/
|
||||
bool init(const std::string &url, int options = opIgnore);
|
||||
|
||||
/**
|
||||
* @brief Returns connection state
|
||||
* @return True if a connection to the QuakeLink server is established
|
||||
*/
|
||||
bool connected() const;
|
||||
|
||||
/** Disconnects from QL server */
|
||||
void disconnect();
|
||||
|
||||
/**
|
||||
* @brief Executes the hello command which retrieves the server ID and
|
||||
* API version.
|
||||
* @param id Variable to store the server identifier including build
|
||||
* version, e.g. QuakeLink (gempa GmbH) v2020.083#da048827b
|
||||
* @param api Variable to store the server API version
|
||||
* @return True on success. Note: The first QuakeLink server versions
|
||||
* did not report a API version. If such a server is encountered the
|
||||
* version is set to 0.
|
||||
* @since SeisComP ABI version 13.0.0
|
||||
*/
|
||||
bool hello(std::string &id, Version &api);
|
||||
|
||||
/**
|
||||
* @brief Sets connection options
|
||||
* @param options Bit mask of all options to enable
|
||||
* @return True if the options could be set
|
||||
*/
|
||||
bool setOptions(int options);
|
||||
|
||||
/**
|
||||
* @brief Gets all updates of a particular event. The response format is
|
||||
* restricted to 'summary'.
|
||||
* @param resp Response object to store the result
|
||||
* @param eventID Event ID to retrieve all updates from
|
||||
* @param formatVersion Response format and version. Note currently only
|
||||
* the rfSummary format is supported but in different versions.
|
||||
* since API 13.0.0
|
||||
* @return True if the updates of an event could be fetched
|
||||
*/
|
||||
bool getUpdates(Response &resp, const std::string &eventID,
|
||||
const RequestFormatVersion &formatVersion = rfSummary);
|
||||
|
||||
/**
|
||||
* @brief Gets one particular event revision
|
||||
* @param response Response object to store the result
|
||||
* @param eventID Event ID to retrive the particular revision from
|
||||
* @param revision Event revision, use a negative number to query the
|
||||
* latest revision
|
||||
* @param formatVersion Response format and version
|
||||
* @return True if the event revision could be fetched
|
||||
*/
|
||||
bool get(Response &response, const std::string &eventID,
|
||||
int revision = -1,
|
||||
const RequestFormatVersion &formatVersion = rfSummary);
|
||||
|
||||
/**
|
||||
* @brief Selects archived events. Returns when all matching events have
|
||||
* been processed.
|
||||
* @param responses List of Response objects to store the results
|
||||
* @param from Begin of time window
|
||||
* @param to End of time window
|
||||
* @param formatVersion Response format
|
||||
* will request the default version.
|
||||
* @param where SQL like filter clause, of form
|
||||
* clause := condition[ AND|OR [(]clause[)]]
|
||||
* condition := MAG|DEPTH|LAT|LON|PHASES op {float} |
|
||||
* UPDATED|OTIME op time |
|
||||
* MAG|DEPTH|LAT|LON|PHASES|OTIME|UPDATED IS [NOT] nullptr
|
||||
* op := =|>|>=|<|<=|eq|gt|ge|lt|ge
|
||||
* @param orderBy sort order of the results,
|
||||
* Note: Requires server API >= 1,
|
||||
* Since: SeisComP ABI version 13.0.0
|
||||
* @param limit maximum number of results to return, a value of 0 will
|
||||
* disable any limit,
|
||||
* Note: Requires server API >= 1,
|
||||
* Since: SeisComP ABI version 13.0.0
|
||||
* @param offset of the requested result set, a value of 0 will return
|
||||
* the first item
|
||||
* Note: Requires server API >= 1,
|
||||
* Since: SeisComP ABI version 13.0.0
|
||||
* @return True if the query could be executed
|
||||
*/
|
||||
bool selectArchived(Responses &responses,
|
||||
const Core::Time &from = Core::Time(),
|
||||
const Core::Time &to = Core::Time(),
|
||||
const RequestFormatVersion &formatVersion = rfSummary,
|
||||
const std::string &where = "",
|
||||
Domain domain = doEvents,
|
||||
OrderBy orderBy = obUndefined,
|
||||
unsigned long limit = 0,
|
||||
unsigned long offset = 0);
|
||||
|
||||
/**
|
||||
* @brief Selects updated and (optional) archived events. This call
|
||||
* blocks until 'disconnect()', or 'abort()' is called from a different
|
||||
* thread or a connection failure occurs and automatic reconnection is
|
||||
* disabled. The results are send as notifier objects.
|
||||
* @param archived If enabled also archived events are returned
|
||||
* @param from Begin of time window
|
||||
* @param to End of time window
|
||||
* @param formatVersion Response format
|
||||
* @param where SQL like filter clause, of form
|
||||
* clause := condition[ AND|OR [(]clause[)]]
|
||||
* condition := MAG|DEPTH|LAT|LON|PHASES op {float} |
|
||||
* UPDATED|OTIME op time |
|
||||
* MAG|DEPTH|LAT|LON|PHASES|OTIME|UPDATED IS [NOT] nullptr
|
||||
* op := =|>|>=|<|<=|eq|gt|ge|lt|ge
|
||||
* @param updatedBufferSize Size of the buffer to store updated events
|
||||
* until all archived events have been processed. If set to a negative
|
||||
* value the buffer will be disabled. In this case archived and updated
|
||||
* events may be mixed. If set to an insufficient positive value updated
|
||||
* events may be lost if a buffer overflow occurs while archived events
|
||||
* are still processed.
|
||||
* @param orderBy sort order of the results,
|
||||
* Note: Requires server API >= 1,
|
||||
* Since: SeisComP ABI version 13.0.0
|
||||
* @param limit maximum number of results to return, a value of 0 will
|
||||
* disable any limit,
|
||||
* Note: Requires server API >= 1,
|
||||
* Since: SeisComP ABI version 13.0.0
|
||||
* @param offset of the requested result set, a value of 0 will return
|
||||
* the first item
|
||||
* Note: Requires server API >= 1,
|
||||
* Since: SeisComP ABI version 13.0.0
|
||||
* @return True if the query could be executed and then was gracefully
|
||||
* aborted.
|
||||
*/
|
||||
bool select(bool archived = false,
|
||||
const Core::Time &from = Core::Time(),
|
||||
const Core::Time &to = Core::Time(),
|
||||
const RequestFormatVersion &formatVersion = rfSummary,
|
||||
const std::string &where = "",
|
||||
Domain domain = doEvents,
|
||||
int updatedBufferSize = 1000,
|
||||
OrderBy orderBy = obUndefined,
|
||||
unsigned long limit = 0,
|
||||
unsigned long offset = 0);
|
||||
|
||||
/**
|
||||
* @brief Gracefully aborts data transmission by sending an abort
|
||||
* command to the server.
|
||||
* @return True if the abort command could be sent
|
||||
*/
|
||||
bool abort();
|
||||
|
||||
/**
|
||||
* @brief serverID
|
||||
* @return The server ID or an empty string if no connection could be
|
||||
* established.
|
||||
* @since SeisComP ABI version 13.0.0
|
||||
*/
|
||||
const std::string& serverID();
|
||||
|
||||
/**
|
||||
* @brief serverAPI
|
||||
* @return The server API version or 0 if the version could not be
|
||||
* obtained
|
||||
* @since SeisComP ABI version 13.0.0
|
||||
*/
|
||||
Version serverAPI();
|
||||
|
||||
/**
|
||||
* @brief initialized
|
||||
* @return True if this instance was sucessfully initialized via the
|
||||
* init() call
|
||||
*/
|
||||
inline bool initialized() { return _sock; }
|
||||
|
||||
/**
|
||||
* @brief interrupted
|
||||
* @return True if underlying socket of this instance was interrupted
|
||||
*/
|
||||
inline bool interrupted() { return _sock && _sock->isInterrupted(); }
|
||||
|
||||
/**
|
||||
* @brief isSupported
|
||||
* @param formatVersion The format version to check
|
||||
* @param log If enabled negative answers will be logged
|
||||
* @return True if the format version combination is supported by the
|
||||
* current server connection
|
||||
* @since SeisComP ABI version 13.0.0
|
||||
*/
|
||||
bool isSupported(const RequestFormatVersion &formatVersion,
|
||||
bool log=false);
|
||||
|
||||
/**
|
||||
* @brief maximumSupportedVersion
|
||||
* @param format The request format
|
||||
* @return Maximum format version supported by the current server
|
||||
* connection. Returns 0 if no connection could be established.
|
||||
* @since SeisComP ABI version 13.0.0
|
||||
*/
|
||||
Version maximumSupportedVersion(RequestFormat format);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Processes a response recevied by a select request.
|
||||
* @param response Response object received,
|
||||
* the ownership is transfered to the method
|
||||
*/
|
||||
virtual void processResponse(Response* response) { delete response; }
|
||||
|
||||
inline void setLogPrefix(const std::string &prefix) {
|
||||
_logPrefix = prefix;
|
||||
}
|
||||
|
||||
bool connect();
|
||||
bool sendRequest(const std::string &req, bool log = true);
|
||||
bool sendOptions(int changedOptions);
|
||||
bool updateOption(Options option, const char *cmd,
|
||||
int changedOptions = opAll);
|
||||
bool readResponse(Response &response);
|
||||
|
||||
size_t readLine(std::string &line);
|
||||
void logAndDisconnect(const char *msg, const char *detail = 0);
|
||||
void logInvalidResp(const char *expected, const char *got);
|
||||
bool readResponseCode(std::string &code);
|
||||
bool assertResponseCode(const std::string &expected);
|
||||
bool assertLineBreak();
|
||||
bool readPayload(std::string &data, uint count);
|
||||
bool checkFormatVersion(std::string &error,
|
||||
const RequestFormatVersion &formatVerion);
|
||||
|
||||
protected:
|
||||
std::string _logPrefix;
|
||||
|
||||
std::string _service;
|
||||
std::string _user;
|
||||
std::string _pass;
|
||||
Socket *_sock;
|
||||
|
||||
int _options;
|
||||
std::string _serverID;
|
||||
Version _serverAPI;
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // ns QuakeLink
|
||||
} // ns IO
|
||||
} // ns Seiscomp
|
||||
|
||||
|
||||
#endif // SEISCOMP_IO_QUAKELINK_CONNECTION_H__
|
108
include/seiscomp/io/recordfilter.h
Normal file
108
include/seiscomp/io/recordfilter.h
Normal file
@ -0,0 +1,108 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDFILTER_H
|
||||
#define SEISCOMP_IO_RECORDFILTER_H
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(RecordFilterInterface);
|
||||
|
||||
/**
|
||||
* @brief The RecordFilterInterface class defines an interface to process
|
||||
* records.
|
||||
*
|
||||
* There are actually two methods involved: push and flush. A filter might
|
||||
* produce:
|
||||
* 1. the same amount of output records as input records
|
||||
* 2. less output records than input records
|
||||
* 3. more output records than input records
|
||||
*
|
||||
* Case 1 and 2 is trivial. Whenever a record is pushed, the method returns
|
||||
* either a new record or nothing (nullptr). Case 3 requires that after a
|
||||
* record was fed, nullptr must be fed as long as a valid records is being
|
||||
* returned.
|
||||
*
|
||||
* A generic way to implement the consumer part is the following code
|
||||
* snippet:
|
||||
*
|
||||
* @code
|
||||
* auto out = filter.feed(rec)
|
||||
* while ( out ) {
|
||||
* // Do something with out
|
||||
* out = filter.feed(nullptr)
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* Once feeding has finished, call flush to retrieve possible pending records:
|
||||
*
|
||||
* @code
|
||||
* while ( (out = filter.flush()) ) {
|
||||
* // Do something with out
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API RecordFilterInterface : public Seiscomp::Core::BaseObject {
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
virtual ~RecordFilterInterface();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Can return a copy of the filtered record. Some filters might
|
||||
//! collect more data until a record is output so a return of
|
||||
//! nullptr is *not* an error. Other filters might produce more
|
||||
//! output records than input records. Calling feed(nullptr) will
|
||||
//! return pending records as long as nullptr is returned.
|
||||
//! Call flush() if no more records are
|
||||
//! expected to be fed.
|
||||
//! @return A copy of a filtered record
|
||||
virtual Record *feed(const Record *rec) = 0;
|
||||
|
||||
//! Requests to flush pending data. Flush should be called until
|
||||
//! nullptr is returned to flush all pending records.
|
||||
//! @return A copy of the flushed record
|
||||
virtual Record *flush() = 0;
|
||||
|
||||
//! Resets the record filter.
|
||||
virtual void reset() = 0;
|
||||
|
||||
//! Clones a filter and must preserve currently configured parameters
|
||||
//! but not the states (e.g. last record time). Basically clone must
|
||||
//! result in the same as copying the instance and calling reset.
|
||||
virtual RecordFilterInterface *clone() const = 0;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
130
include/seiscomp/io/recordfilter/crop.h
Normal file
130
include/seiscomp/io/recordfilter/crop.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_IO_RECORDFILTER_CROP
|
||||
#define SEISCOMP_IO_RECORDFILTER_CROP
|
||||
|
||||
|
||||
#include <seiscomp/io/recordfilter.h>
|
||||
#include <seiscomp/core/typedarray.h>
|
||||
#include <seiscomp/core/record.h>
|
||||
|
||||
#include <deque>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Cropper);
|
||||
class SC_SYSTEM_CORE_API Cropper : public RecordFilterInterface {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
~Cropper() override;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setWindowLength(double length);
|
||||
//! Must be less than 1
|
||||
bool setWindowOverlap(double overlap);
|
||||
bool setNoAlign(bool noalign);
|
||||
|
||||
//! Push an record and compute spectra. Returns true if a records
|
||||
//! can be popped. The record id (net,sta,loc,cha) is not checked
|
||||
//! against the last record pushed. This filtering is left to
|
||||
//! the caller.
|
||||
Record *feed(const Record *rec) override;
|
||||
|
||||
//! Requests to flush pending data. Flush should be called until
|
||||
//! nullptr is returned to flush all pending records.
|
||||
//! @return A copy of the flushed record
|
||||
Record *flush() override;
|
||||
|
||||
//! Resets the record filter.
|
||||
void reset() override;
|
||||
|
||||
RecordFilterInterface *clone() const override;
|
||||
|
||||
|
||||
protected:
|
||||
//! Clean up all associated resources
|
||||
void cleanup();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct CropBuffer {
|
||||
// Fixed source sample rate derived from the first record
|
||||
// received.
|
||||
double sampleRate;
|
||||
double dt;
|
||||
|
||||
// The ring buffer that holds the last samples.
|
||||
std::vector<double> buffer;
|
||||
DoubleArray tmp;
|
||||
int tmpOffset;
|
||||
|
||||
size_t samplesToSkip;
|
||||
|
||||
// The number of samples still missing in the buffer before
|
||||
// fft can be done
|
||||
size_t missingSamples;
|
||||
|
||||
// The front index of the ring buffer
|
||||
size_t front;
|
||||
|
||||
// Time of front of ring buffer
|
||||
Core::Time startTime;
|
||||
|
||||
// End time of last record
|
||||
Core::Time lastEndTime;
|
||||
|
||||
void reset() {
|
||||
missingSamples = buffer.size();
|
||||
front = 0;
|
||||
samplesToSkip = 0;
|
||||
startTime = Core::Time();
|
||||
lastEndTime = Core::Time();
|
||||
}
|
||||
};
|
||||
|
||||
void init(const Record *rec);
|
||||
void crop(const Record *rec);
|
||||
|
||||
double _windowLength{20.0};
|
||||
double _timeStep{10.0};
|
||||
bool _noalign{false};
|
||||
CropBuffer *_buffer{nullptr};
|
||||
std::deque<Record*> _nextRecords;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
79
include/seiscomp/io/recordfilter/demux.h
Normal file
79
include/seiscomp/io/recordfilter/demux.h
Normal file
@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDFILTER_DEMUX_H
|
||||
#define SEISCOMP_IO_RECORDFILTER_DEMUX_H
|
||||
|
||||
#include <seiscomp/io/recordfilter.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
/**
|
||||
* \brief Record demuxer that demultiplexes different channels and applies
|
||||
* \brief a given record filter to each of them.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API RecordDemuxFilter : public RecordFilterInterface {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructs a record demuxer with an optional record filter
|
||||
//! applied to each channel.
|
||||
//! Note: the ownership goes to the record demuxer
|
||||
RecordDemuxFilter(RecordFilterInterface *recordFilter = nullptr);
|
||||
virtual ~RecordDemuxFilter();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Note: the ownership goes to the record demuxer
|
||||
void setFilter(RecordFilterInterface *recordFilter);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// RecordFilter interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
virtual Record *feed(const Record *rec);
|
||||
virtual Record *flush();
|
||||
virtual void reset();
|
||||
virtual RecordFilterInterface *clone() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private members
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
typedef std::map<std::string, RecordFilterInterfacePtr> FilterMap;
|
||||
RecordFilterInterfacePtr _template;
|
||||
FilterMap _streams;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
122
include/seiscomp/io/recordfilter/iirfilter.h
Normal file
122
include/seiscomp/io/recordfilter/iirfilter.h
Normal file
@ -0,0 +1,122 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDFILTER_IIRFILTER_H
|
||||
#define SEISCOMP_IO_RECORDFILTER_IIRFILTER_H
|
||||
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
#include <seiscomp/io/recordfilter.h>
|
||||
#include <seiscomp/math/filter.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
/**
|
||||
* \brief RecordInplaceFilter is a record filter that applies a
|
||||
* \brief Math::InplaceFilter to each passed record. Type conversion
|
||||
* \brief and gap/overlap handling (causing a filter reset) are part of it.
|
||||
*
|
||||
* RecordIIRFilter does not distinguish between different channels. All
|
||||
* records fed into this class are assumed to be of the same stream/channel.
|
||||
*/
|
||||
template <typename T>
|
||||
class SC_SYSTEM_CORE_API RecordIIRFilter : public RecordFilterInterface {
|
||||
// ------------------------------------------------------------------
|
||||
// Public types
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
typedef Math::Filtering::InPlaceFilter<T> InplaceFilterType;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Constructs a record filter with an optional inplace filter.
|
||||
//! The passed instance is managed by the record filter.
|
||||
RecordIIRFilter(Seiscomp::Math::Filtering::InPlaceFilter<T> *filter = nullptr);
|
||||
~RecordIIRFilter();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Note: the ownership goes to the record filter
|
||||
RecordIIRFilter<T> &operator=(Seiscomp::Math::Filtering::InPlaceFilter<T> *f);
|
||||
|
||||
//! Note: the ownership goes to the record filter
|
||||
void setIIR(Seiscomp::Math::Filtering::InPlaceFilter<T> *f);
|
||||
|
||||
Seiscomp::Math::Filtering::InPlaceFilter<T> *filter() { return _filter; }
|
||||
const Seiscomp::Math::Filtering::InPlaceFilter<T> *filter() const { return _filter; }
|
||||
|
||||
//! Applies the IIR filter on the input data. The data type of the
|
||||
//! input record must match the requested data type (template
|
||||
//! parameter)!
|
||||
//! @returns True, if apply was successfull, false otherwise
|
||||
bool apply(GenericRecord *rec);
|
||||
|
||||
//! The bool operator returns if an IIR filter is set or not
|
||||
operator bool() const { return _filter != nullptr; }
|
||||
|
||||
//! Returns the last error in case feed or apply returned nullptr or false.
|
||||
const std::string &lastError() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// RecordFilter interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Applies the filter and returns a copy with a record of the
|
||||
//! requested datatype. The returned record instance is a GenericRecord.
|
||||
//! If no IIR filter is set a type converted copy is returned.
|
||||
virtual Record *feed(const Record *rec);
|
||||
|
||||
virtual Record *flush();
|
||||
|
||||
virtual void reset();
|
||||
|
||||
RecordFilterInterface *clone() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private members
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
InplaceFilterType *_filter;
|
||||
Core::Time _lastEndTime;
|
||||
double _samplingFrequency;
|
||||
std::string _lastError;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline const std::string &RecordIIRFilter<T>::lastError() const {
|
||||
return _lastError;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
69
include/seiscomp/io/recordfilter/pipe.h
Normal file
69
include/seiscomp/io/recordfilter/pipe.h
Normal file
@ -0,0 +1,69 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDFILTER_PIPE_H
|
||||
#define SEISCOMP_IO_RECORDFILTER_PIPE_H
|
||||
|
||||
|
||||
#include <seiscomp/io/recordfilter.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
/**
|
||||
* \brief Filter chain that routes records through a chain of filters.
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API PipeFilter : public RecordFilterInterface {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! Connects two filters
|
||||
PipeFilter(RecordFilterInterface *filter1 = nullptr,
|
||||
RecordFilterInterface *filter2 = nullptr);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// RecordFilter interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
Record *feed(const Record *rec) override;
|
||||
Record *flush() override;
|
||||
void reset() override;
|
||||
RecordFilterInterface *clone() const override;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private members
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
RecordFilterInterfacePtr _first;
|
||||
RecordFilterInterfacePtr _second;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
189
include/seiscomp/io/recordfilter/resample.h
Normal file
189
include/seiscomp/io/recordfilter/resample.h
Normal file
@ -0,0 +1,189 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDFILTER_RESAMPLE_H
|
||||
#define SEISCOMP_IO_RECORDFILTER_RESAMPLE_H
|
||||
|
||||
|
||||
#include <seiscomp/io/recordfilter.h>
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
//! @brief Base class for template class Resampler which defines
|
||||
//! @brief common data structures.
|
||||
class SC_SYSTEM_CORE_API RecordResamplerBase : public RecordFilterInterface {
|
||||
protected:
|
||||
RecordResamplerBase();
|
||||
virtual ~RecordResamplerBase();
|
||||
|
||||
public:
|
||||
virtual Record *flush();
|
||||
virtual void reset();
|
||||
|
||||
protected:
|
||||
typedef std::vector<double> Coefficients;
|
||||
typedef std::map<int, Coefficients*> CoefficientMap;
|
||||
|
||||
static int _instanceCount;
|
||||
static CoefficientMap _coefficients;
|
||||
static std::mutex _coefficientMutex;
|
||||
|
||||
double _currentRate;
|
||||
double _targetRate;
|
||||
double _fp;
|
||||
double _fs;
|
||||
int _maxN;
|
||||
int _lanczosKernelWidth;
|
||||
int _coeffScale;
|
||||
};
|
||||
|
||||
|
||||
//! @brief Resamples records to a given target rate.
|
||||
//! @brief The output datatype is float.
|
||||
//! This class does not demultiplexing and therefore handles only one stream
|
||||
//! per instance or to put it into other words: subsequent fed records are not
|
||||
//! checked for their stream ID and just taken as one contiuous stream.
|
||||
//! Note: this class is only implemented for float and double outputs.
|
||||
template <typename T>
|
||||
class SC_SYSTEM_CORE_API RecordResampler : public RecordResamplerBase {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
RecordResampler(double targetFrequency, double fp = 0.7, double fs = 0.9,
|
||||
double coeffScale = 10, int lanczosWidth = 3);
|
||||
|
||||
//! D'tor
|
||||
virtual ~RecordResampler();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! Feeds a record.
|
||||
//! @return A resampled record. May return nullptr if not enough data are
|
||||
//! available to flush the record.
|
||||
virtual Record *feed(const Record *record);
|
||||
|
||||
virtual void reset();
|
||||
|
||||
RecordFilterInterface *clone() const;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct Stage {
|
||||
double targetRate;
|
||||
|
||||
// Fixed source sample rate derived from the first record
|
||||
// received.
|
||||
double sampleRate;
|
||||
double dt;
|
||||
|
||||
int N;
|
||||
int N2;
|
||||
|
||||
// The ring buffer that holds the last samples for downsampling.
|
||||
std::vector<T> buffer;
|
||||
|
||||
// The number of samples still missing in the buffer before
|
||||
// filtering can be done
|
||||
size_t missingSamples;
|
||||
|
||||
// The front index of the ring buffer
|
||||
size_t front;
|
||||
|
||||
// Time of front of ring buffer
|
||||
Seiscomp::Core::Time startTime;
|
||||
|
||||
// End time of last record
|
||||
Seiscomp::Core::Time lastEndTime;
|
||||
|
||||
void reset() {
|
||||
missingSamples = buffer.size();
|
||||
front = 0;
|
||||
startTime = Seiscomp::Core::Time();
|
||||
lastEndTime = Seiscomp::Core::Time();
|
||||
}
|
||||
};
|
||||
|
||||
struct DownsampleStage : Stage {
|
||||
DownsampleStage() : nextStage(nullptr) {}
|
||||
~DownsampleStage() { if ( nextStage ) delete nextStage; }
|
||||
|
||||
// Flag that indicates that a streams is passed through
|
||||
// without resampling.
|
||||
bool passThrough;
|
||||
|
||||
bool valid;
|
||||
|
||||
size_t samplesToSkip;
|
||||
|
||||
Coefficients *coefficients;
|
||||
|
||||
DownsampleStage *nextStage;
|
||||
|
||||
void reset() {
|
||||
Stage::reset();
|
||||
samplesToSkip = 0;
|
||||
if ( nextStage != nullptr ) nextStage->reset();
|
||||
}
|
||||
};
|
||||
|
||||
struct UpsampleStage : Stage {
|
||||
double downRatio;
|
||||
int width;
|
||||
};
|
||||
|
||||
void initCoefficients(DownsampleStage *stage);
|
||||
|
||||
void init(DownsampleStage *stage, const Seiscomp::Record *rec, int upscale, int N);
|
||||
void init(UpsampleStage *stage, const Seiscomp::Record *rec, int N);
|
||||
|
||||
Seiscomp::GenericRecord *resample(DownsampleStage *stage, const Seiscomp::Record *rec);
|
||||
Seiscomp::GenericRecord *resample(UpsampleStage *stage, const Seiscomp::Record *rec);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
DownsampleStage *_downsampler;
|
||||
UpsampleStage *_upsampler;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
214
include/seiscomp/io/recordfilter/spectralizer.h
Normal file
214
include/seiscomp/io/recordfilter/spectralizer.h
Normal file
@ -0,0 +1,214 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDFILTER_SPECTRALIZER
|
||||
#define SEISCOMP_IO_RECORDFILTER_SPECTRALIZER
|
||||
|
||||
|
||||
#include <map>
|
||||
#include <deque>
|
||||
|
||||
#include <seiscomp/math/filter.h>
|
||||
#include <seiscomp/core/typedarray.h>
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Spectrum);
|
||||
class SC_SYSTEM_CORE_API Spectrum : public Core::BaseObject {
|
||||
public:
|
||||
Spectrum(const Core::Time &stime,
|
||||
const Core::Time &etime,
|
||||
const Core::TimeSpan &dt,
|
||||
double freq, int sampleCount)
|
||||
: _startTime(stime), _endTime(etime), _dt(dt), _sampleCount(sampleCount)
|
||||
, _frequency(freq) {}
|
||||
|
||||
void setData(ComplexDoubleArray *data) {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
bool isValid() const { return _data && _data->size() > 0; }
|
||||
|
||||
const ComplexDoubleArray *data() const { return _data.get(); }
|
||||
ComplexDoubleArray *data() { return _data.get(); }
|
||||
|
||||
const Core::Time &startTime() const { return _startTime; }
|
||||
const Core::Time &endTime() const { return _endTime; }
|
||||
const Core::TimeSpan &dt() const { return _dt; }
|
||||
|
||||
Core::TimeSpan length() const { return _endTime - _startTime; }
|
||||
Core::Time center() const { return _startTime + Core::TimeSpan(double(length())*0.5); }
|
||||
|
||||
double minimumFrequency() const { return 0; }
|
||||
double maximumFrequency() const { return _frequency; }
|
||||
|
||||
|
||||
private:
|
||||
Core::Time _startTime;
|
||||
Core::Time _endTime;
|
||||
Core::TimeSpan _dt;
|
||||
int _sampleCount;
|
||||
double _frequency;
|
||||
ComplexDoubleArrayPtr _data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Spectralizer);
|
||||
class SC_SYSTEM_CORE_API Spectralizer : public Core::BaseObject {
|
||||
// ----------------------------------------------------------------------
|
||||
// Public types
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief The Options struct holds the parameters used to
|
||||
* compute the spectrum.
|
||||
*/
|
||||
struct Options {
|
||||
Options();
|
||||
|
||||
//! The window length in seconds used to compute the spectrum.
|
||||
double windowLength;
|
||||
//! The window overlap for subsequent spectra. This value is
|
||||
//! defined as a fraction of windowLength and must be in [0,1).
|
||||
//! The effective time step is windowLength*windowOverlap.
|
||||
double windowOverlap;
|
||||
//! The output spectrum samples. A value of -1 returns the full
|
||||
//! spectrum whereas values > 0 reduce the spectrum to the given
|
||||
//! number of samples using the maximum value of each bin with
|
||||
//! respect to magnitude of each spectrum sample.
|
||||
int specSamples;
|
||||
//! An optional filter applied in advance to compute a spectrum.
|
||||
std::string filter;
|
||||
//! Disables aligning the processed time window with the given
|
||||
//! time step.
|
||||
bool noalign;
|
||||
//! The taper width applied to either side of the processed time
|
||||
//! window given as fraction of windowLength, e.g. 0.05 for 5%.
|
||||
double taperWidth;
|
||||
};
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Spectralizer();
|
||||
virtual ~Spectralizer();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setOptions(const Options &opts);
|
||||
|
||||
//! Push an record and compute spectra. Returns true if a records
|
||||
//! can be popped. The record id (net,sta,loc,cha) is not checked
|
||||
//! against the last record pushed. This filtering is left to
|
||||
//! the caller.
|
||||
bool push(const Record *rec);
|
||||
|
||||
//! Pops an spectrum if available. Returns nullptr if more data are
|
||||
//! required.
|
||||
Spectrum *pop();
|
||||
|
||||
//! Returns whether records are available
|
||||
bool canPop() const { return !_nextSpectra.empty(); }
|
||||
|
||||
//! Clean up all associated resources
|
||||
void cleanup();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
typedef Core::SmartPointer< Math::Filtering::InPlaceFilter<double> >::Impl FilterPtr;
|
||||
struct SpecBuffer {
|
||||
SpecBuffer() {}
|
||||
~SpecBuffer() {}
|
||||
|
||||
FilterPtr filter;
|
||||
|
||||
// Fixed source sample rate derived from the first record
|
||||
// received.
|
||||
double sampleRate;
|
||||
double dt;
|
||||
|
||||
// The ring buffer that holds the last samples for fft.
|
||||
std::vector<double> buffer;
|
||||
DoubleArray tmp;
|
||||
int tmpOffset;
|
||||
|
||||
size_t samplesToSkip;
|
||||
|
||||
// The number of samples still missing in the buffer before
|
||||
// fft can be done
|
||||
size_t missingSamples;
|
||||
|
||||
// The front index of the ring buffer
|
||||
size_t front;
|
||||
|
||||
// Time of front of ring buffer
|
||||
Core::Time startTime;
|
||||
|
||||
// End time of last record
|
||||
Core::Time lastEndTime;
|
||||
|
||||
void reset(FilterPtr refFilter) {
|
||||
missingSamples = buffer.size();
|
||||
front = 0;
|
||||
samplesToSkip = 0;
|
||||
startTime = Core::Time();
|
||||
lastEndTime = Core::Time();
|
||||
|
||||
if ( refFilter ) {
|
||||
filter = refFilter->clone();
|
||||
filter->setSamplingFrequency(sampleRate);
|
||||
}
|
||||
else
|
||||
filter = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
void init(const Record *rec);
|
||||
Record *fft(const Record *rec);
|
||||
|
||||
double _windowLength;
|
||||
double _timeStep;
|
||||
bool _noalign;
|
||||
int _specSamples;
|
||||
double _taperWidth;
|
||||
FilterPtr _filter;
|
||||
SpecBuffer *_buffer;
|
||||
std::deque<Spectrum*> _nextSpectra;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
124
include/seiscomp/io/recordinput.h
Normal file
124
include/seiscomp/io/recordinput.h
Normal file
@ -0,0 +1,124 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDINPUT_H
|
||||
#define SEISCOMP_IO_RECORDINPUT_H
|
||||
|
||||
#include <iterator>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
class RecordInput;
|
||||
|
||||
class SC_SYSTEM_CORE_API RecordIterator : public std::iterator<std::input_iterator_tag, Record *> {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
RecordIterator();
|
||||
//! Copy c'tor
|
||||
RecordIterator(const RecordIterator &iter);
|
||||
//! D'tor
|
||||
~RecordIterator();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Operators
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
RecordIterator &operator=(const RecordIterator &iter);
|
||||
Record *operator*();
|
||||
RecordIterator &operator++();
|
||||
RecordIterator operator++(int);
|
||||
bool operator!=(const RecordIterator &iter) const;
|
||||
bool operator==(const RecordIterator &iter) const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* Returns the source used by the iterator
|
||||
* @return A RecordInput pointer which must not be deleted
|
||||
* by the caller!
|
||||
*/
|
||||
RecordInput *source() const;
|
||||
|
||||
/**
|
||||
* Returns the current record read from the input stream.
|
||||
* The record pointer is a raw pointer and has to be managed
|
||||
* by the caller.
|
||||
* @return The raw record pointer.
|
||||
*/
|
||||
Record *current() const;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
RecordIterator(RecordInput *from, Record *cur);
|
||||
RecordInput *_source;
|
||||
Record *_current;
|
||||
|
||||
friend class RecordInput;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(RecordInput);
|
||||
|
||||
class SC_SYSTEM_CORE_API RecordInput : public Seiscomp::Core::BaseObject {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
RecordInput(RecordStream *in,
|
||||
Array::DataType dt = Array::DOUBLE,
|
||||
Record::Hint h = Record::SAVE_RAW);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Iteration
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
RecordIterator begin();
|
||||
RecordIterator end();
|
||||
Record *next();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
RecordStream *_in;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
87
include/seiscomp/io/recordoutputstream.h
Normal file
87
include/seiscomp/io/recordoutputstream.h
Normal file
@ -0,0 +1,87 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDOUTPUTSTREAM_H
|
||||
#define SEISCOMP_IO_RECORDOUTPUTSTREAM_H
|
||||
|
||||
#include <iostream>
|
||||
#include <seiscomp/core/interruptible.h>
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/io/recordstreamexceptions.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(RecordOutputStream);
|
||||
|
||||
class SC_SYSTEM_CORE_API RecordOutputStream : public Seiscomp::Core::InterruptibleObject {
|
||||
DECLARE_SC_CLASS(RecordOutputStream);
|
||||
|
||||
protected:
|
||||
RecordOutputStream();
|
||||
|
||||
public:
|
||||
virtual ~RecordOutputStream() {}
|
||||
|
||||
public:
|
||||
virtual bool setTarget(std::string) = 0;
|
||||
virtual void close() = 0;
|
||||
|
||||
virtual std::ostream& stream() = 0;
|
||||
|
||||
//! Returns a record stream for the given service
|
||||
//! @return A pointer to the recordstream object
|
||||
//! NOTE: The returned pointer has to be deleted by the
|
||||
//! caller!
|
||||
static RecordOutputStream* Create(const char* service);
|
||||
|
||||
//! Returns a record stream for the given service that creates
|
||||
//! records of type recordType
|
||||
//! @return A pointer to the recordstream object. If the recordstream
|
||||
//! does not support the requested type, nullptr will be returned
|
||||
//! NOTE: The returned pointer has to be deleted by the
|
||||
//! caller!
|
||||
static RecordOutputStream* Create(const char* service, const char* recordType);
|
||||
|
||||
//! Opens a recordstream at source.
|
||||
//! @param url A source URL of format [service://]address[#type],
|
||||
//! e.g. file:///data/record.mseed#mseed. service defaults to
|
||||
//! 'file' and the default type is 'mseed'
|
||||
//! @return A pointer to the recordstream object. If the recordstream
|
||||
//! does not support the requested type, nullptr will be returned
|
||||
//! NOTE: The returned pointer has to be deleted by the
|
||||
//! caller!
|
||||
static RecordOutputStream* Open(const char* url);
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(RecordOutputStream);
|
||||
|
||||
|
||||
#define REGISTER_RECORDOUTPUTSTREAM(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::IO::RecordOutputStreamFactory, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
47
include/seiscomp/io/records/binaryrecord.h
Normal file
47
include/seiscomp/io/records/binaryrecord.h
Normal file
@ -0,0 +1,47 @@
|
||||
/***************************************************************************
|
||||
* 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 SC_IO_BINARYRECORD_H
|
||||
#define SC_IO_BINARYRECORD_H
|
||||
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(BinaryRecord);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API BinaryRecord : public GenericRecord {
|
||||
public:
|
||||
//! Default Constructor
|
||||
BinaryRecord();
|
||||
|
||||
public:
|
||||
void read(std::istream &in);
|
||||
void write(std::ostream &out);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
188
include/seiscomp/io/records/mseedrecord.h
Normal file
188
include/seiscomp/io/records/mseedrecord.h
Normal file
@ -0,0 +1,188 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDS_MSEEDRECORD_H
|
||||
#define SEISCOMP_IO_RECORDS_MSEEDRECORD_H
|
||||
|
||||
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/core/typedarray.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
typedef struct MSRecord_s MSRecord;
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(MSeedRecord);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API LibmseedException : public Core::StreamException {
|
||||
public:
|
||||
LibmseedException() : Core::StreamException("libmseed error") {}
|
||||
LibmseedException(std::string what) : Core::StreamException(what) {}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Uses seiscomp error logging as component MSEEDRECORD.
|
||||
**/
|
||||
class SC_SYSTEM_CORE_API MSeedRecord: public Record {
|
||||
DECLARE_SC_CLASS(MSeedRecord)
|
||||
|
||||
public:
|
||||
//! Initializing Constructor
|
||||
MSeedRecord(Array::DataType dt = Array::DOUBLE, Hint h = SAVE_RAW);
|
||||
|
||||
//! Initializing Constructor
|
||||
MSeedRecord(MSRecord *msrec, Array::DataType dt = Array::DOUBLE, Hint h = SAVE_RAW);
|
||||
|
||||
//! Copy Constructor
|
||||
MSeedRecord(const MSeedRecord &ms);
|
||||
|
||||
//! Copy-from-Record Constructor
|
||||
MSeedRecord(const Record &rec, int reclen=512);
|
||||
|
||||
//! Destructor
|
||||
~MSeedRecord() override;
|
||||
|
||||
|
||||
public:
|
||||
//! Assignment Operator
|
||||
MSeedRecord& operator=(const MSeedRecord &ms);
|
||||
|
||||
void setNetworkCode(std::string net) override;
|
||||
|
||||
//! Sets the station code
|
||||
void setStationCode(std::string sta) override;
|
||||
|
||||
//! Sets the location code
|
||||
void setLocationCode(std::string loc) override;
|
||||
|
||||
//! Sets the channel code
|
||||
void setChannelCode(std::string cha) override;
|
||||
|
||||
//! Sets the start time
|
||||
void setStartTime(const Core::Time& time) override;
|
||||
|
||||
//! Returns the sequence number
|
||||
int sequenceNumber() const;
|
||||
|
||||
//! Sets the sequence number
|
||||
void setSequenceNumber(int seqno);
|
||||
|
||||
//! Returns the data quality
|
||||
char dataQuality() const;
|
||||
|
||||
//! Sets the data quality
|
||||
void setDataQuality(char qual);
|
||||
|
||||
//! Returns the sample rate factor
|
||||
int sampleRateFactor() const;
|
||||
|
||||
//! Sets the sample rate factor
|
||||
void setSampleRateFactor(int srfact);
|
||||
|
||||
//! Returns the sample rate multiplier
|
||||
int sampleRateMultiplier() const;
|
||||
|
||||
//! Sets the sample rate multiplier
|
||||
void setSampleRateMultiplier(int srmult);
|
||||
|
||||
//! Returns the byteorder
|
||||
int8_t byteOrder() const;
|
||||
|
||||
//! Returns the encoding code
|
||||
int8_t encoding() const;
|
||||
|
||||
//! Returns the sample rate numerator
|
||||
int sampleRateNumerator() const;
|
||||
|
||||
//! Returns the sample rate denominator
|
||||
int sampleRateDenominator() const;
|
||||
|
||||
//! Returns the number of data frames
|
||||
int frameNumber() const;
|
||||
|
||||
//! Returns the end time of data samples
|
||||
const Seiscomp::Core::Time& endTime() const;
|
||||
|
||||
//! Returns the length of a Mini SEED record
|
||||
int recordLength() const;
|
||||
|
||||
//! Returns the leap seconds
|
||||
int leapSeconds() const;
|
||||
|
||||
//! Returns a nonmutable pointer to the data samples if the data is available; otherwise 0
|
||||
//! (the data type is independent from the original one and was given by the DataType flag in the constructor)
|
||||
const Array* data() const override;
|
||||
|
||||
const Array* raw() const override;
|
||||
|
||||
//! Frees the memory occupied by the decoded data samples.
|
||||
//! ! Use it with the hint SAVE_RAW only otherwise the data samples cannot be redecoded!
|
||||
void saveSpace() const override;
|
||||
|
||||
//! Returns a deep copy of the calling object.
|
||||
Record* copy() const;
|
||||
|
||||
//! Sets flag specifying the encoding type of the write routine.
|
||||
//! true(default) -> use the encoding of the original record; false -> use the type of the data
|
||||
void useEncoding(bool flag);
|
||||
|
||||
//! Sets the record length used for the output
|
||||
void setOutputRecordLength(int reclen);
|
||||
|
||||
//! Extract the packed MSeedRecord attributes from the given stream
|
||||
void read(std::istream &in);
|
||||
|
||||
//! Encode the record into the given stream
|
||||
void write(std::ostream& out);
|
||||
|
||||
private:
|
||||
void _setDataAttributes(int reclen, char *data) const;
|
||||
|
||||
private:
|
||||
CharArray _raw;
|
||||
mutable ArrayPtr _data;
|
||||
int _seqno;
|
||||
char _rectype;
|
||||
int _srfact;
|
||||
int _srmult;
|
||||
int8_t _byteorder;
|
||||
int8_t _encoding;
|
||||
int _srnum;
|
||||
int _srdenom;
|
||||
int _reclen;
|
||||
int _nframes;
|
||||
int _leap;
|
||||
Seiscomp::Core::Time _etime;
|
||||
bool _encodingFlag;
|
||||
};
|
||||
|
||||
} // namespace IO
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
89
include/seiscomp/io/records/sacrecord.h
Normal file
89
include/seiscomp/io/records/sacrecord.h
Normal file
@ -0,0 +1,89 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDS_SACRECORD_H
|
||||
#define SEISCOMP_IO_RECORDS_SACRECORD_H
|
||||
|
||||
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/core/array.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SACRecord);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SACRecord : public Record {
|
||||
public:
|
||||
//! Initializing Constructor
|
||||
SACRecord(const std::string &net = "AB", const std::string &sta = "12345",
|
||||
const std::string &loc = "", const std::string &cha = "XYZ",
|
||||
Core::Time stime = Core::Time(), double fsamp=0., int tqual=-1,
|
||||
Array::DataType dt = Array::DOUBLE, Hint h = DATA_ONLY);
|
||||
|
||||
//! Copy Constructor
|
||||
SACRecord(const SACRecord &rec);
|
||||
SACRecord(const Record &rec);
|
||||
|
||||
//! Destructor
|
||||
virtual ~SACRecord();
|
||||
|
||||
|
||||
public:
|
||||
//! Assignment operator
|
||||
SACRecord &operator=(const SACRecord &other);
|
||||
|
||||
//! Returns the data samples if the data is available; otherwise 0
|
||||
Array* data();
|
||||
|
||||
//! Returns the data samples if the data is available; otherwise 0
|
||||
const Array* data() const;
|
||||
|
||||
const Array* raw() const;
|
||||
|
||||
//! Sets the data sample array. The ownership goes over to the record.
|
||||
void setData(Array* data);
|
||||
|
||||
//! Sets the data sample array.
|
||||
void setData(int size, const void *data, Array::DataType datatype);
|
||||
|
||||
//! Returns a deep copy of the calling object.
|
||||
SACRecord *copy() const;
|
||||
|
||||
void saveSpace() const;
|
||||
|
||||
void read(std::istream &in);
|
||||
void write(std::ostream &out);
|
||||
|
||||
|
||||
private:
|
||||
mutable ArrayPtr _data;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
117
include/seiscomp/io/records/shrecord.h
Normal file
117
include/seiscomp/io/records/shrecord.h
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. *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
|
||||
//! HACK
|
||||
//! INCOMPLETE IMPLEMENTATION OF SEISMIC HANDLER FORMAT ( SH )
|
||||
//! HACK
|
||||
|
||||
|
||||
#ifndef SEISCOMP_IO_RECORDS_SHRECORD_H
|
||||
#define SEISCOMP_IO_RECORDS_SHRECORD_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <ostream>
|
||||
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/core/array.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SHRecord);
|
||||
|
||||
class SC_SYSTEM_CORE_API SHRecord : public Record {
|
||||
DECLARE_SC_CLASS(SHRecord);
|
||||
|
||||
public:
|
||||
//! Default Constructor
|
||||
// SHRecord();
|
||||
|
||||
//! Initializing Constructor
|
||||
SHRecord(std::string net="AB", std::string sta="ABC",
|
||||
std::string loc="", std::string cha="XYZ",
|
||||
Core::Time stime=Core::Time(), double fsamp=0., int tqual=-1,
|
||||
Array::DataType dt = Array::DOUBLE, Hint h = DATA_ONLY);
|
||||
|
||||
//! Copy Constructor
|
||||
SHRecord(const SHRecord& rec);
|
||||
SHRecord(const Record& rec);
|
||||
|
||||
//! Destructor
|
||||
virtual ~SHRecord();
|
||||
|
||||
//! Assignment operator
|
||||
SHRecord& operator=(const SHRecord& rec);
|
||||
|
||||
//! Returns the data samples if the data is available; otherwise 0
|
||||
Array* data();
|
||||
|
||||
//! Returns the data samples if the data is available; otherwise 0
|
||||
const Array* data() const;
|
||||
|
||||
const Array* raw() const;
|
||||
|
||||
//! Sets the data sample array. The ownership goes over to the record.
|
||||
void setData(Array* data);
|
||||
|
||||
//! Sets the data sample array.
|
||||
void setData(int size, const void *data, Array::DataType datatype);
|
||||
|
||||
//! Frees the memory allocated for the data samples.
|
||||
void saveSpace() const {}
|
||||
|
||||
//! Returns a deep copy of the calling object.
|
||||
SHRecord* copy() const;
|
||||
|
||||
void read(std::istream &in);
|
||||
void write(std::ostream &out);
|
||||
|
||||
|
||||
private:
|
||||
ArrayPtr _data;
|
||||
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API SHOutput {
|
||||
public:
|
||||
SHOutput() : _ofstream(0) {}
|
||||
SHOutput(const std::string& filename);
|
||||
SHOutput(const Record *rec);
|
||||
|
||||
~SHOutput();
|
||||
|
||||
bool put(const SHRecord *rec);
|
||||
|
||||
private:
|
||||
std::string _filename;
|
||||
std::ofstream *_ofstream;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
288
include/seiscomp/io/recordstream.h
Normal file
288
include/seiscomp/io/recordstream.h
Normal file
@ -0,0 +1,288 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_H
|
||||
|
||||
|
||||
#include <seiscomp/core/interruptible.h>
|
||||
#include <seiscomp/core/record.h>
|
||||
#include <seiscomp/io/recordstreamexceptions.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(RecordStream);
|
||||
|
||||
|
||||
/**
|
||||
* @brief The RecordStream class defines an abstract interface to read data
|
||||
* records from arbitrary sources.
|
||||
*
|
||||
* \code{.cpp}
|
||||
* RecordStreamPtr rs = RecordStream::Open(URL);
|
||||
* if ( rs != nullptr ) {
|
||||
* rs->addStream("XY", "ABCD", "", "BHZ");
|
||||
* RecordPtr rec;
|
||||
* while ( (rec = rs->next()) ) {
|
||||
* // Do something with rec
|
||||
* }
|
||||
* rs->close();
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
class SC_SYSTEM_CORE_API RecordStream : public Core::InterruptibleObject {
|
||||
DECLARE_SC_CLASS(RecordStream)
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
/**
|
||||
* @brief The constructor is protected because this is an
|
||||
* abstract base class.
|
||||
*/
|
||||
RecordStream();
|
||||
|
||||
|
||||
public:
|
||||
//! D'tor
|
||||
virtual ~RecordStream() {}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// RecordStream interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Sets the source location of the data. This is implementation
|
||||
* specific. It can be a path to a file on disk or a hostname
|
||||
* with port or something else.
|
||||
* @param source The source definition.
|
||||
* @return Status flag
|
||||
*/
|
||||
virtual bool setSource(const std::string &source) = 0;
|
||||
|
||||
/**
|
||||
* @brief Closes the recordstream. This method will usually be called
|
||||
* from within another thread while reading data. So it must be
|
||||
* implemented with thread safety in mind.
|
||||
*/
|
||||
virtual void close() = 0;
|
||||
|
||||
/**
|
||||
* @brief Adds a data channel to the request. This will not yet start
|
||||
* the request. Some implementations may support wildcard
|
||||
* characters (* and ?) at any level.
|
||||
*
|
||||
* The time window request for this channel will be using the globally
|
||||
* configured time window, see setStartTime(const Seiscomp::Core::Time &),
|
||||
* setEndTime(const Seiscomp::Core::Time &) and setTimeWindow(const Seiscomp::Core::TimeWindow &timeWindow).
|
||||
*
|
||||
* If addStream() is called another time with the same channel
|
||||
* identifiers then most implementations will overwrite the previous
|
||||
* request. In short: multiple requests (different time windows) for
|
||||
* the same channel are not supported.
|
||||
*
|
||||
* @param networkCode The network code
|
||||
* @param stationCode The station code
|
||||
* @param locationCode The location code
|
||||
* @param channelCode The channel code
|
||||
* @return Status flag
|
||||
*/
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode) = 0;
|
||||
|
||||
/**
|
||||
* @brief Same as addStream(const std::string &, const std::string &, const std::string &, const std::string &)
|
||||
* but with an additional time window for this particular channel.
|
||||
*
|
||||
* If addStream() is called another time with the same channel
|
||||
* identifiers then most implementations will overwrite the previous
|
||||
* request. In short: multiple requests (different time windows) for
|
||||
* the same channel are not supported.
|
||||
*
|
||||
* @param networkCode The network code
|
||||
* @param stationCode The station code
|
||||
* @param locationCode The location code
|
||||
* @param channelCode The channel code
|
||||
* @param startTime The start time for this particular stream
|
||||
* @param endTime The end time for this particular stream
|
||||
* @return
|
||||
*/
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime) = 0;
|
||||
|
||||
/**
|
||||
* @brief Sets the start time for all streams that haven't been
|
||||
* requested with a specific time window.
|
||||
* @param startTime The start time.
|
||||
* @return Status flag
|
||||
*/
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &startTime) = 0;
|
||||
|
||||
/**
|
||||
* @brief Sets the end time for all streams that haven't been
|
||||
* requested with a specific time window.
|
||||
* @param endTime The end time. And invalid time is treated as open
|
||||
* end time and will return as much data as is available.
|
||||
* @return Status flag
|
||||
*/
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &endTime) = 0;
|
||||
|
||||
/**
|
||||
* @brief Convenience function to set start time and end time.
|
||||
* @param timeWindow The time window
|
||||
* @return Status flag
|
||||
*/
|
||||
virtual bool setTimeWindow(const Seiscomp::Core::TimeWindow &timeWindow);
|
||||
|
||||
/**
|
||||
* @brief Sets an optional timeout for data retrieval. If within \p seconds
|
||||
* seconds no data is returned then the recordstream will abort.
|
||||
* The default implementation return false.
|
||||
* @param seconds The maximum number of seconds to wait for data.
|
||||
* @return Status flag.
|
||||
*/
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
/**
|
||||
* @brief Sets the type of the record to be generated. Not all
|
||||
* implementations support this call or will just ignore it as
|
||||
* the type of data is defined in the data protocol. This is
|
||||
* most useful for files.
|
||||
* @param type The type name. Currently the following record types are
|
||||
* supported:
|
||||
* - 'mseed' MiniSeed
|
||||
* - 'ah' AH format
|
||||
* - 'sac' SAC
|
||||
* @return Status flag. The default implementation will return false.
|
||||
*/
|
||||
virtual bool setRecordType(const char *type);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Data retrieval interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Sets the desired data type of the records returned. The
|
||||
* default is DOUBLE. This method must be called before
|
||||
* calling next().
|
||||
* @param dataType The data type
|
||||
*/
|
||||
void setDataType(Array::DataType dataType);
|
||||
|
||||
/**
|
||||
* @brief Sets the hint how records should be created. The default
|
||||
* is SAVE_RAW. This method must be called before calling
|
||||
* next().
|
||||
* @param hint The record creation hint
|
||||
*/
|
||||
void setDataHint(Record::Hint hint);
|
||||
|
||||
/**
|
||||
* @brief Returns the next record from the source.
|
||||
* @return The ownership of the returned instance goes to the
|
||||
* caller. Iteration stops of nullptr is returned.
|
||||
*/
|
||||
virtual Record *next() = 0;
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// RecordStream static interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
/**
|
||||
* @brief Creates a recordstream for the given service.
|
||||
* @param service The service name
|
||||
* @return A pointer to the recordstream object
|
||||
*
|
||||
* \note
|
||||
* The returned pointer has to be deleted by the caller!
|
||||
*/
|
||||
static RecordStream *Create(const char *service);
|
||||
|
||||
/**
|
||||
* @brief Opens a recordstream at source. This will call @Create
|
||||
* @param url A source URL of format [service://]address[#type],
|
||||
//! e.g. file:///data/record.mseed#mseed. Service defaults
|
||||
//! 'file' and the default type is 'mseed'.
|
||||
* @return A pointer to the recordstream object. If the recordstream
|
||||
* does not support the requested type, nullptr will be returned.
|
||||
*
|
||||
* \note
|
||||
* The returned pointer has to be deleted by the caller!
|
||||
*/
|
||||
static RecordStream *Open(const char *url);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
// Does nothing
|
||||
virtual void handleInterrupt(int);
|
||||
|
||||
/**
|
||||
* @brief Helper function to set up a created record. Basically
|
||||
* this will set the desired data type and hint.
|
||||
* @param rec
|
||||
*/
|
||||
void setupRecord(Record *rec);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected members
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
Array::DataType _dataType;
|
||||
Record::Hint _hint;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_INTERFACE_FACTORY(RecordStream);
|
||||
|
||||
|
||||
#define REGISTER_RECORDSTREAM_VAR(Class, Service) \
|
||||
Seiscomp::Core::Generic::InterfaceFactory<Seiscomp::IO::RecordStream, Class> __##Class##InterfaceFactory__(Service)
|
||||
|
||||
#define REGISTER_RECORDSTREAM(Class, Service) \
|
||||
static REGISTER_RECORDSTREAM_VAR(Class, Service)
|
||||
|
||||
|
||||
inline void RecordStream::setupRecord(Record *rec) {
|
||||
rec->setDataType(_dataType);
|
||||
rec->setHint(_hint);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
41
include/seiscomp/io/recordstream/archive.h
Normal file
41
include/seiscomp/io/recordstream/archive.h
Normal file
@ -0,0 +1,41 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_ARCHIVE_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_ARCHIVE_H
|
||||
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API ArchiveException: public Seiscomp::IO::RecordStreamException {
|
||||
public:
|
||||
ArchiveException(): RecordStreamException("Archive exception") {}
|
||||
ArchiveException(const std::string& what): RecordStreamException(what) {}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
147
include/seiscomp/io/recordstream/arclink.h
Normal file
147
include/seiscomp/io/recordstream/arclink.h
Normal file
@ -0,0 +1,147 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_ARCLINK_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_ARCLINK_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <seiscomp/core/interruptible.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/utils/timer.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/io/socket.h>
|
||||
#include <seiscomp/io/recordstream/streamidx.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
namespace Arclink {
|
||||
namespace _private {
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkException: public Seiscomp::IO::RecordStreamException {
|
||||
public:
|
||||
ArclinkException(): RecordStreamException("ArcLink exception") {}
|
||||
ArclinkException(const std::string& what): RecordStreamException(what) {}
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkCommandException: public ArclinkException {
|
||||
public:
|
||||
ArclinkCommandException(): ArclinkException("command not accepted") {}
|
||||
ArclinkCommandException(const std::string& what): ArclinkException(what) {}
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(ArclinkConnection);
|
||||
|
||||
class SC_SYSTEM_CORE_API ArclinkConnection : public Seiscomp::IO::RecordStream {
|
||||
DECLARE_SC_CLASS(ArclinkConnection);
|
||||
|
||||
public:
|
||||
//! C'tor
|
||||
ArclinkConnection();
|
||||
|
||||
//! Initializing Constructor
|
||||
ArclinkConnection(std::string serverloc);
|
||||
|
||||
//! Destructor
|
||||
virtual ~ArclinkConnection();
|
||||
|
||||
public:
|
||||
//! The recordtype cannot be selected when using an arclink
|
||||
//! connection. It will always create MiniSeed records
|
||||
virtual bool setRecordType(const char*);
|
||||
|
||||
//! Initialize the arclink connection.
|
||||
virtual bool setSource(const std::string &serverloc);
|
||||
|
||||
//! Supply user credentials
|
||||
bool setUser(std::string name, std::string password);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &stime,
|
||||
const Seiscomp::Core::Time &etime);
|
||||
|
||||
//! Adds the given start time to the server connection description
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||
|
||||
//! Adds the given end time to the server connection description
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||
|
||||
//! Sets timeout
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
//! Terminates the arclink connection.
|
||||
virtual void close();
|
||||
|
||||
virtual Record *next();
|
||||
|
||||
//! Removes all stream list, time window, etc. -entries from the connection description object.
|
||||
bool clear();
|
||||
|
||||
//! Reconnects a terminated arclink connection.
|
||||
bool reconnect();
|
||||
|
||||
|
||||
private:
|
||||
Seiscomp::IO::Socket _sock;
|
||||
std::string _serverloc;
|
||||
std::string _user;
|
||||
std::string _passwd;
|
||||
std::list<StreamIdx> _ordered;
|
||||
std::set<StreamIdx> _streams;
|
||||
Seiscomp::Core::Time _stime;
|
||||
Seiscomp::Core::Time _etime;
|
||||
std::string _reqID;
|
||||
bool _readingData;
|
||||
bool _chunkMode;
|
||||
int _remainingBytes;
|
||||
std::ofstream _dump;
|
||||
|
||||
void handshake();
|
||||
void cleanup();
|
||||
};
|
||||
|
||||
} // namespace _private
|
||||
|
||||
//using _private::ArclinkException;
|
||||
//using _private::ArclinkCommandException;
|
||||
using _private::ArclinkConnection;
|
||||
using _private::ArclinkConnectionPtr;
|
||||
|
||||
} // namespace Arclink
|
||||
} // namespace RecordStream
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
||||
|
107
include/seiscomp/io/recordstream/combined.h
Normal file
107
include/seiscomp/io/recordstream/combined.h
Normal file
@ -0,0 +1,107 @@
|
||||
/***************************************************************************
|
||||
* 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_SERVICES_RECORDSTREAM_COMBINED_H
|
||||
#define SEISCOMP_SERVICES_RECORDSTREAM_COMBINED_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core/timewindow.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
DEFINE_SMARTPOINTER(CombinedConnection);
|
||||
|
||||
class SC_SYSTEM_CORE_API CombinedConnection : public IO::RecordStream {
|
||||
public:
|
||||
//! C'tor
|
||||
CombinedConnection();
|
||||
|
||||
//! Initializing Constructor
|
||||
CombinedConnection(std::string serverloc);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CombinedConnection();
|
||||
|
||||
virtual bool setRecordType(const char*);
|
||||
|
||||
//! Initialize the combined connection.
|
||||
virtual bool setSource(const std::string &serverloc);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime);
|
||||
|
||||
//! Adds the given start time to the server connection description
|
||||
virtual bool setStartTime(const Core::Time &stime);
|
||||
|
||||
//! Adds the given end time to the server connection description
|
||||
virtual bool setEndTime(const Core::Time &etime);
|
||||
|
||||
//! Sets timeout
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
//! Terminates the combined connection.
|
||||
virtual void close();
|
||||
|
||||
//! Returns the data stream
|
||||
virtual Record *next();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
private:
|
||||
bool _started;
|
||||
|
||||
size_t _nStream;
|
||||
size_t _nArchive;
|
||||
size_t _nRealtime;
|
||||
|
||||
Core::Time _startTime;
|
||||
Core::Time _endTime;
|
||||
Core::Time _archiveEndTime;
|
||||
Core::TimeSpan _realtimeAvailability;
|
||||
|
||||
std::set<StreamIdx> _tmpStreams;
|
||||
IO::RecordStreamPtr _realtime;
|
||||
IO::RecordStreamPtr _archive;
|
||||
};
|
||||
|
||||
|
||||
} // namespace RecordStream
|
||||
} // namespace Seiscomp
|
||||
|
||||
|
||||
#endif
|
||||
|
122
include/seiscomp/io/recordstream/concurrent.h
Normal file
122
include/seiscomp/io/recordstream/concurrent.h
Normal file
@ -0,0 +1,122 @@
|
||||
/***************************************************************************
|
||||
* 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_SERVICES_RECORDSTREAM_CONCURRENT_H
|
||||
#define SEISCOMP_SERVICES_RECORDSTREAM_CONCURRENT_H
|
||||
|
||||
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/core/timewindow.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/client/queue.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Concurrent : public IO::RecordStream {
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Concurrent();
|
||||
|
||||
//! Destructor
|
||||
~Concurrent() override;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// RecordStream Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setRecordType(const char*) override;
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode) override;
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime) override;
|
||||
|
||||
//! Adds the given start time to the server connection description
|
||||
bool setStartTime(const Core::Time &stime) override;
|
||||
|
||||
//! Adds the given end time to the server connection description
|
||||
bool setEndTime(const Core::Time &etime) override;
|
||||
|
||||
//! Adds the given end time window to the server connection description
|
||||
bool setTimeWindow(const Core::TimeWindow &w) override;
|
||||
|
||||
//! Sets timeout
|
||||
bool setTimeout(int seconds) override;
|
||||
|
||||
//! Terminates the combined connection.
|
||||
void close() override;
|
||||
|
||||
Record *next() override;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Concurrent interface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
virtual int getRS(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode) = 0;
|
||||
|
||||
void reset();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private methods and members
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
void acquiThread(IO::RecordStream *rs);
|
||||
|
||||
protected:
|
||||
using RecordStreamItem = std::pair<IO::RecordStreamPtr, bool>;
|
||||
|
||||
bool _started{false};
|
||||
std::vector<RecordStreamItem> _rsarray;
|
||||
|
||||
private:
|
||||
int _nthreads{0};
|
||||
std::list<std::thread> _threads;
|
||||
Client::ThreadedQueue<Record*> _queue;
|
||||
std::mutex _mtx;
|
||||
};
|
||||
|
||||
|
||||
} // namespace RecordStream
|
||||
} // namespace Seiscomp
|
||||
|
||||
|
||||
#endif
|
166
include/seiscomp/io/recordstream/decimation.h
Normal file
166
include/seiscomp/io/recordstream/decimation.h
Normal file
@ -0,0 +1,166 @@
|
||||
/***************************************************************************
|
||||
* 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_RECORDSTREAM_DECIMATION_H
|
||||
#define SEISCOMP_RECORDSTREAM_DECIMATION_H
|
||||
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
#include <seiscomp/core/genericrecord.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
DEFINE_SMARTPOINTER(Decimation);
|
||||
|
||||
class SC_SYSTEM_CORE_API Decimation : public Seiscomp::IO::RecordStream {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Decimation();
|
||||
virtual ~Decimation();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool setSource(const std::string &source);
|
||||
virtual bool setRecordType(const char *type);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &stime,
|
||||
const Seiscomp::Core::Time &etime);
|
||||
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||
virtual bool setTimeWindow(const Seiscomp::Core::TimeWindow &w);
|
||||
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
virtual void close();
|
||||
|
||||
virtual Record *next();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private Interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
void cleanup();
|
||||
|
||||
int checkSR(Record *rec) const;
|
||||
|
||||
bool push(Record *rec);
|
||||
GenericRecord *convert(Record *rec);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
typedef std::vector<double> Coefficients;
|
||||
|
||||
struct ResampleStage {
|
||||
ResampleStage() : nextStage(nullptr) {}
|
||||
~ResampleStage() { if ( nextStage ) delete nextStage; }
|
||||
|
||||
double targetRate;
|
||||
|
||||
// Fixed source sample rate derived from the first record
|
||||
// received.
|
||||
double sampleRate;
|
||||
double dt;
|
||||
|
||||
// Flag that indicates that a streams is passed through
|
||||
// without resampling.
|
||||
bool passThrough;
|
||||
|
||||
bool valid;
|
||||
|
||||
int N;
|
||||
int N2;
|
||||
size_t samplesToSkip;
|
||||
|
||||
Coefficients *coefficients;
|
||||
|
||||
// The ring buffer that holds the last samples for downsampling.
|
||||
std::vector<double> buffer;
|
||||
|
||||
// The number of samples still missing in the buffer before
|
||||
// filtering can be done
|
||||
size_t missingSamples;
|
||||
|
||||
// The front index of the ring buffer
|
||||
size_t front;
|
||||
|
||||
// Time of front of ring buffer
|
||||
Core::Time startTime;
|
||||
|
||||
// End time of last record
|
||||
Core::Time lastEndTime;
|
||||
|
||||
ResampleStage *nextStage;
|
||||
|
||||
void reset() {
|
||||
missingSamples = buffer.size();
|
||||
front = 0;
|
||||
samplesToSkip = 0;
|
||||
startTime = Core::Time();
|
||||
lastEndTime = Core::Time();
|
||||
|
||||
if ( nextStage ) nextStage->reset();
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<int, Coefficients*> CoefficientMap;
|
||||
typedef std::map<std::string, ResampleStage*> StreamMap;
|
||||
|
||||
void init(ResampleStage *stage, Record *rec);
|
||||
bool initCoefficients(ResampleStage *stage);
|
||||
GenericRecord *resample(ResampleStage *stage, Record *rec);
|
||||
|
||||
IO::RecordStreamPtr _source;
|
||||
double _targetRate;
|
||||
double _fp;
|
||||
double _fs;
|
||||
int _maxN;
|
||||
int _coeffScale;
|
||||
StreamMap _streams;
|
||||
CoefficientMap _coefficients;
|
||||
GenericRecord *_nextRecord;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
133
include/seiscomp/io/recordstream/fdsnws.h
Normal file
133
include/seiscomp/io/recordstream/fdsnws.h
Normal file
@ -0,0 +1,133 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_WS_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_WS_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/interruptible.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/utils/timer.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/io/socket.h>
|
||||
#include <seiscomp/io/recordstream/streamidx.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API FDSNWSConnectionBase : public IO::RecordStream {
|
||||
protected:
|
||||
//! C'tor
|
||||
FDSNWSConnectionBase(const char *protocol, IO::Socket *socket, int defaultPort);
|
||||
|
||||
|
||||
public:
|
||||
//! The recordtype cannot be selected when using an arclink
|
||||
//! connection. It will always create MiniSeed records
|
||||
virtual bool setRecordType(const char *type);
|
||||
|
||||
//! Initialize the arclink connection.
|
||||
virtual bool setSource(const std::string &source);
|
||||
|
||||
//! Supply user credentials
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Core::Time &startTime,
|
||||
const Core::Time &endTime);
|
||||
|
||||
//! Adds the given start time to the server connection description
|
||||
virtual bool setStartTime(const Core::Time &startTime);
|
||||
|
||||
//! Adds the given end time to the server connection description
|
||||
virtual bool setEndTime(const Core::Time &endTime);
|
||||
|
||||
//! Sets timeout
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
//! Terminates the arclink connection.
|
||||
virtual void close();
|
||||
|
||||
virtual Record *next();
|
||||
|
||||
//! Reconnects a terminated arclink connection.
|
||||
bool reconnect();
|
||||
|
||||
//! Removes all stream list, time window, etc. -entries from the connection description object.
|
||||
bool clear();
|
||||
|
||||
|
||||
private:
|
||||
const char *getProxy() const;
|
||||
void openConnection(const std::string &);
|
||||
|
||||
//! Blocking read from socket
|
||||
std::string readBinary(int size);
|
||||
void handshake();
|
||||
|
||||
|
||||
private:
|
||||
const char *_protocol;
|
||||
IO::SocketPtr _socket;
|
||||
std::string _host;
|
||||
std::string _url;
|
||||
int _defaultPort;
|
||||
std::set<StreamIdx> _streams;
|
||||
Core::Time _stime;
|
||||
Core::Time _etime;
|
||||
std::string _reqID;
|
||||
bool _readingData;
|
||||
bool _chunkMode;
|
||||
int _remainingBytes;
|
||||
std::string _error;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API FDSNWSConnection : public FDSNWSConnectionBase {
|
||||
public:
|
||||
FDSNWSConnection();
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API FDSNWSSSLConnection : public FDSNWSConnectionBase {
|
||||
public:
|
||||
FDSNWSSSLConnection();
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
137
include/seiscomp/io/recordstream/file.h
Normal file
137
include/seiscomp/io/recordstream/file.h
Normal file
@ -0,0 +1,137 @@
|
||||
/***************************************************************************
|
||||
* 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_SERVICES_RECORDSTREAM_RECORDFILE_H
|
||||
#define SEISCOMP_SERVICES_RECORDSTREAM_RECORDFILE_H
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(File);
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API File : public Seiscomp::IO::RecordStream {
|
||||
public:
|
||||
enum SeekDir {
|
||||
Begin = std::ios_base::beg,
|
||||
Current = std::ios_base::cur,
|
||||
End = std::ios_base::end
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
File() = default;
|
||||
File(std::string name);
|
||||
File(const File &f);
|
||||
~File() override;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Operators
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
File &operator=(const File &f);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public RecordStream interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
bool setSource(const std::string &filename) override;
|
||||
|
||||
bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode) override;
|
||||
|
||||
bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime) override;
|
||||
|
||||
bool setStartTime(const Seiscomp::Core::Time &startTime) override;
|
||||
bool setEndTime(const Seiscomp::Core::Time &endTime) override;
|
||||
|
||||
void close() override;
|
||||
|
||||
bool setRecordType(const char *type) override;
|
||||
|
||||
Record *next() override;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public file specific interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
std::string name() const;
|
||||
size_t tell();
|
||||
|
||||
File &seek(size_t pos);
|
||||
File &seek(int off, SeekDir dir);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct TimeWindowFilter {
|
||||
TimeWindowFilter() {}
|
||||
TimeWindowFilter(const Core::Time &stime, const Core::Time &etime)
|
||||
: start(stime), end(etime) {}
|
||||
|
||||
Core::Time start;
|
||||
Core::Time end;
|
||||
};
|
||||
|
||||
using FilterMap = std::map<std::string, TimeWindowFilter>;
|
||||
using ReFilterList = std::vector<std::pair<std::string,TimeWindowFilter> >;
|
||||
|
||||
const TimeWindowFilter* findTimeWindowFilter(Record *rec);
|
||||
|
||||
RecordFactory *_factory{nullptr};
|
||||
std::string _name;
|
||||
bool _closeRequested;
|
||||
std::fstream _fstream;
|
||||
std::istream *_current{&_fstream};
|
||||
FilterMap _filter;
|
||||
ReFilterList _reFilter;
|
||||
Core::Time _startTime;
|
||||
Core::Time _endTime;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
154
include/seiscomp/io/recordstream/httpmsgbus.h
Normal file
154
include/seiscomp/io/recordstream/httpmsgbus.h
Normal file
@ -0,0 +1,154 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_WS_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_WS_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/io/socket.h>
|
||||
#include <seiscomp/io/httpsocket.h>
|
||||
#include <seiscomp/io/recordstream/streamidx.h>
|
||||
|
||||
extern "C" {
|
||||
#include "bson/bson.h"
|
||||
}
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API HMBQueue {
|
||||
public:
|
||||
//! C'tor
|
||||
HMBQueue();
|
||||
|
||||
//! Destructor
|
||||
virtual ~HMBQueue();
|
||||
|
||||
//! Adds the given stream
|
||||
void addStream(std::string loc, std::string cha,
|
||||
const Seiscomp::Core::Time &stime, const Seiscomp::Core::Time &etime);
|
||||
|
||||
//! Sets the sequence number
|
||||
void setSequenceNumber(int64_t seq);
|
||||
|
||||
//! Removes all entries
|
||||
void clear();
|
||||
|
||||
//! Returns a BSON document
|
||||
bson_t* toBSON() const;
|
||||
|
||||
private:
|
||||
Core::Time _stime;
|
||||
Core::Time _etime;
|
||||
int64_t _seq;
|
||||
std::set<std::string> _topics;
|
||||
};
|
||||
|
||||
|
||||
template<typename SocketType>
|
||||
class SC_SYSTEM_CORE_API HMBConnection : public Seiscomp::IO::RecordStream {
|
||||
//DECLARE_SC_CLASS(HMBConnection<SocketType>);
|
||||
|
||||
public:
|
||||
//! C'tor
|
||||
HMBConnection();
|
||||
|
||||
//! Initializing Constructor
|
||||
HMBConnection(std::string serverloc);
|
||||
|
||||
//! Destructor
|
||||
virtual ~HMBConnection();
|
||||
|
||||
//! The recordtype cannot be selected when using an HMB
|
||||
//! connection. It will always create MiniSeed records
|
||||
virtual bool setRecordType(const char *type);
|
||||
|
||||
//! Initialize the HMB connection.
|
||||
virtual bool setSource(const std::string &source);
|
||||
|
||||
//! Supply user credentials
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime);
|
||||
|
||||
//! Adds the given start time to the server connection description
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||
|
||||
//! Adds the given end time to the server connection description
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||
|
||||
//! Sets timeout
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
//! Terminates the HMB connection.
|
||||
virtual void close();
|
||||
|
||||
virtual Record *next();
|
||||
|
||||
//! Removes all stream list, time window, etc. -entries from the connection description object.
|
||||
bool clear();
|
||||
|
||||
//! Reconnects a terminated HMB connection.
|
||||
bool reconnect();
|
||||
|
||||
|
||||
private:
|
||||
IO::HttpSocket<SocketType> _sock;
|
||||
std::string _serverHost;
|
||||
std::string _serverPath;
|
||||
std::string _user;
|
||||
std::string _password;
|
||||
std::set<Seiscomp::RecordStream::StreamIdx> _streams;
|
||||
Seiscomp::Core::Time _stime;
|
||||
Seiscomp::Core::Time _etime;
|
||||
std::map<std::string, HMBQueue> _queues;
|
||||
std::string _sid;
|
||||
std::string _cid;
|
||||
bool _readingData;
|
||||
|
||||
std::string bsonGetString(const bson_t *bson, const char *key);
|
||||
int64_t bsonGetInt(const bson_t *bson, const char *key);
|
||||
void bsonGetBlob(const bson_t *bson, const char *key, const void **data, int *data_len);
|
||||
void initSession();
|
||||
std::string receive();
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
86
include/seiscomp/io/recordstream/memory.h
Normal file
86
include/seiscomp/io/recordstream/memory.h
Normal file
@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* 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_SERVICES_RECORDSTREAM_MEMORY_H
|
||||
#define SEISCOMP_SERVICES_RECORDSTREAM_MEMORY_H
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Memory);
|
||||
|
||||
class SC_SYSTEM_CORE_API Memory: public Seiscomp::IO::RecordStream {
|
||||
DECLARE_SC_CLASS(Memory);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Memory();
|
||||
Memory(const char *data, int size);
|
||||
Memory(const Memory &mem);
|
||||
virtual ~Memory();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// X'truction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Memory &operator=(const Memory &mem);
|
||||
|
||||
virtual bool setSource(const std::string &);
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime);
|
||||
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||
|
||||
virtual void close();
|
||||
|
||||
virtual bool setRecordType(const char *type);
|
||||
|
||||
Record *next();
|
||||
|
||||
|
||||
private:
|
||||
RecordFactory *_factory;
|
||||
std::istringstream _stream;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
106
include/seiscomp/io/recordstream/resample.h
Normal file
106
include/seiscomp/io/recordstream/resample.h
Normal file
@ -0,0 +1,106 @@
|
||||
/***************************************************************************
|
||||
* 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_RECORDSTREAM_RESAMPLE_H
|
||||
#define SEISCOMP_RECORDSTREAM_RESAMPLE_H
|
||||
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/io/recordfilter/demux.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Resample);
|
||||
|
||||
class SC_SYSTEM_CORE_API Resample : public Seiscomp::IO::RecordStream {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
Resample();
|
||||
virtual ~Resample();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool setSource(const std::string &source);
|
||||
virtual bool setRecordType(const char *type);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime);
|
||||
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||
virtual bool setTimeWindow(const Seiscomp::Core::TimeWindow &w);
|
||||
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
virtual void close();
|
||||
|
||||
virtual Record *next();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Private Interface
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
void push(Record *rec);
|
||||
void cleanup();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
typedef std::deque<GenericRecord*> OutputQueue;
|
||||
|
||||
IO::RecordStreamPtr _source;
|
||||
bool _debug;
|
||||
IO::RecordDemuxFilter _demuxer;
|
||||
OutputQueue _queue;
|
||||
|
||||
double _targetRate;
|
||||
double _fp;
|
||||
double _fs;
|
||||
int _lanczosKernelWidth;
|
||||
int _coeffScale;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
164
include/seiscomp/io/recordstream/sdsarchive.h
Normal file
164
include/seiscomp/io/recordstream/sdsarchive.h
Normal file
@ -0,0 +1,164 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_SDSARCHIVE_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_SDSARCHIVE_H
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <queue>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
|
||||
#include <seiscomp/core/version.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SDS);
|
||||
|
||||
|
||||
class SDSArchive : public Seiscomp::IO::RecordStream {
|
||||
// ----------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
SDSArchive();
|
||||
SDSArchive(const std::string arcroot);
|
||||
virtual ~SDSArchive();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
virtual bool setSource(const std::string &source);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime);
|
||||
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &stime);
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &etime);
|
||||
virtual bool setTimeWindow(const Seiscomp::Core::TimeWindow &tw);
|
||||
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
virtual void close();
|
||||
|
||||
virtual Seiscomp::Record *next();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ----------------------------------------------------------------------
|
||||
private:
|
||||
struct Index {
|
||||
Index();
|
||||
Index(const std::string& net, const std::string& sta,
|
||||
const std::string& loc, const std::string& cha);
|
||||
Index(const std::string& net, const std::string& sta,
|
||||
const std::string& loc, const std::string& cha,
|
||||
const Seiscomp::Core::Time& stime,
|
||||
const Seiscomp::Core::Time& etime);
|
||||
|
||||
Index &operator=(const Index &other);
|
||||
bool operator<(const Index &other) const;
|
||||
bool operator!=(const Index &other) const;
|
||||
bool operator==(const Index &other) const;
|
||||
|
||||
std::string net;
|
||||
std::string sta;
|
||||
std::string loc;
|
||||
std::string cha;
|
||||
mutable Seiscomp::Core::Time stime;
|
||||
mutable Seiscomp::Core::Time etime;
|
||||
};
|
||||
|
||||
|
||||
typedef std::set<Index> IndexSet;
|
||||
typedef std::list<Index> IndexList;
|
||||
typedef std::pair<std::string,bool> File;
|
||||
typedef std::queue<File> FileQueue;
|
||||
|
||||
std::vector<std::string> _arcroots;
|
||||
Seiscomp::Core::Time _stime;
|
||||
Seiscomp::Core::Time _etime;
|
||||
IndexList _orderedRequests;
|
||||
IndexSet _streamSet;
|
||||
IndexList::iterator _curiter;
|
||||
const Index *_curidx;
|
||||
FileQueue _fnames;
|
||||
std::set<std::string> _readFiles;
|
||||
std::mutex _mutex;
|
||||
bool _closeRequested;
|
||||
std::ifstream _file;
|
||||
|
||||
int getDoy(const Seiscomp::Core::Time &time);
|
||||
void resolveRequest();
|
||||
bool setStart(const std::string &fname, bool bsearch);
|
||||
|
||||
bool resolveNet(std::string &path,
|
||||
const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Seiscomp::Core::Time &requestStartTime,
|
||||
int doy, int year, bool first);
|
||||
bool resolveSta(std::string &path,
|
||||
const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Seiscomp::Core::Time &requestStartTime,
|
||||
int doy, int year, bool first);
|
||||
bool resolveLoc(std::string &path,
|
||||
const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Seiscomp::Core::Time &requestStartTime,
|
||||
int doy, int year, bool first);
|
||||
bool resolveCha(std::string &path,
|
||||
const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Seiscomp::Core::Time &requestStartTime,
|
||||
int doy, int year, bool first);
|
||||
|
||||
bool resolveFiles(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Seiscomp::Core::Time &requestStartTime,
|
||||
int doy, int year, bool first);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
195
include/seiscomp/io/recordstream/slconnection.h
Normal file
195
include/seiscomp/io/recordstream/slconnection.h
Normal file
@ -0,0 +1,195 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_SLINK_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_SLINK_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <signal.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
#include <seiscomp/io/socket.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SeedlinkException: public Seiscomp::IO::RecordStreamException {
|
||||
public:
|
||||
SeedlinkException(): RecordStreamException("Seedlink exception") {}
|
||||
SeedlinkException(const std::string& what): RecordStreamException(what) {}
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API SeedlinkCommandException: public SeedlinkException {
|
||||
public:
|
||||
SeedlinkCommandException(): SeedlinkException("command not accepted") {}
|
||||
SeedlinkCommandException(const std::string& what): SeedlinkException(what) {}
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SLStreamIdx {
|
||||
public:
|
||||
SLStreamIdx();
|
||||
|
||||
SLStreamIdx(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha);
|
||||
|
||||
SLStreamIdx(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Seiscomp::Core::Time &stime,
|
||||
const Seiscomp::Core::Time &etime);
|
||||
|
||||
SLStreamIdx& operator=(const SLStreamIdx &other);
|
||||
|
||||
bool operator<(const SLStreamIdx &other) const;
|
||||
bool operator==(const SLStreamIdx &other) const;
|
||||
|
||||
//! Returns the network code
|
||||
const std::string &network() const;
|
||||
|
||||
//! Returns the station code
|
||||
const std::string &station() const;
|
||||
|
||||
//! Returns the channel code
|
||||
const std::string &channel() const;
|
||||
|
||||
//! Returns the location code
|
||||
const std::string &location() const;
|
||||
|
||||
//! Returns the selector in <location><channel>.D notation
|
||||
//! * wildcards are substituted by a corresponding number of ?
|
||||
std::string selector() const;
|
||||
|
||||
//! Returns the start time
|
||||
Core::Time startTime() const;
|
||||
|
||||
//! Returns the end time
|
||||
Core::Time endTime() const;
|
||||
|
||||
//! Returns the most recent record end time
|
||||
Seiscomp::Core::Time timestamp() const;
|
||||
|
||||
//! Sets the time stamp
|
||||
void setTimestamp(Seiscomp::Core::Time &rectime) const;
|
||||
|
||||
private:
|
||||
const std::string _net;
|
||||
const std::string _sta;
|
||||
const std::string _loc;
|
||||
const std::string _cha;
|
||||
const Core::Time _stime;
|
||||
const Core::Time _etime;
|
||||
mutable Core::Time _timestamp;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SLConnection);
|
||||
|
||||
class SC_SYSTEM_CORE_API SLConnection : public Seiscomp::IO::RecordStream {
|
||||
DECLARE_SC_CLASS(SLConnection);
|
||||
|
||||
public:
|
||||
//! C'tor
|
||||
SLConnection();
|
||||
|
||||
//! Initializing Constructor
|
||||
SLConnection(std::string serverloc);
|
||||
|
||||
//! Destructor
|
||||
virtual ~SLConnection();
|
||||
|
||||
public:
|
||||
//! The recordtype cannot be selected when using a seedlink
|
||||
//! connection. It will always create MiniSeed records
|
||||
virtual bool setRecordType(const char*);
|
||||
|
||||
//! Initialize the seedlink connection.
|
||||
virtual bool setSource(const std::string &source);
|
||||
|
||||
//! Adds the given stream to the server connection description
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode);
|
||||
|
||||
//! Adds a seismic stream request to the record stream (not implemented)
|
||||
virtual bool addStream(const std::string &networkCode,
|
||||
const std::string &stationCode,
|
||||
const std::string &locationCode,
|
||||
const std::string &channelCode,
|
||||
const Seiscomp::Core::Time &startTime,
|
||||
const Seiscomp::Core::Time &endTime);
|
||||
|
||||
//! Adds the given start time to the server connection description
|
||||
virtual bool setStartTime(const Seiscomp::Core::Time &startTime);
|
||||
|
||||
//! Adds the given end time to the server connection description
|
||||
virtual bool setEndTime(const Seiscomp::Core::Time &endTime);
|
||||
|
||||
//! Sets timeout
|
||||
virtual bool setTimeout(int seconds);
|
||||
|
||||
//! Disconnects and terminates (!) the seedlink connection.
|
||||
virtual void close();
|
||||
|
||||
//! Reads the data stream
|
||||
virtual Record *next();
|
||||
|
||||
//! Removes all stream list, time window, etc. -entries from the connection description object.
|
||||
bool clear();
|
||||
|
||||
//! Reconnects a terminated seedlink connection.
|
||||
bool reconnect();
|
||||
|
||||
|
||||
private:
|
||||
void handshake();
|
||||
|
||||
|
||||
private:
|
||||
class StreamBuffer : public std::streambuf {
|
||||
public:
|
||||
StreamBuffer();
|
||||
std::streambuf *setbuf(char *s, std::streamsize n);
|
||||
};
|
||||
|
||||
StreamBuffer _streambuf;
|
||||
std::string _serverloc;
|
||||
std::string _slrecord;
|
||||
IO::Socket _sock;
|
||||
std::set<SLStreamIdx> _streams;
|
||||
Core::Time _stime;
|
||||
Core::Time _etime;
|
||||
bool _readingData;
|
||||
bool _useBatch;
|
||||
int _maxRetries;
|
||||
int _retriesLeft;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
92
include/seiscomp/io/recordstream/streamidx.h
Normal file
92
include/seiscomp/io/recordstream/streamidx.h
Normal file
@ -0,0 +1,92 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAM_STREAMIDX_H
|
||||
#define SEISCOMP_IO_RECORDSTREAM_STREAMIDX_H
|
||||
|
||||
#include <string>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace RecordStream {
|
||||
|
||||
class SC_SYSTEM_CORE_API StreamIdx {
|
||||
public:
|
||||
StreamIdx();
|
||||
|
||||
StreamIdx(const std::string& net, const std::string& sta,
|
||||
const std::string& loc, const std::string& cha);
|
||||
|
||||
StreamIdx(const std::string& net, const std::string& sta,
|
||||
const std::string& loc, const std::string& cha,
|
||||
const Seiscomp::Core::Time& stime,
|
||||
const Seiscomp::Core::Time& etime);
|
||||
|
||||
StreamIdx& operator=(const StreamIdx &other);
|
||||
|
||||
bool operator<(const StreamIdx &other) const;
|
||||
|
||||
bool operator!=(const StreamIdx &other) const;
|
||||
|
||||
bool operator==(const StreamIdx &other) const;
|
||||
|
||||
bool operator>=(const StreamIdx &other) const;
|
||||
|
||||
bool operator>(const StreamIdx &other) const;
|
||||
|
||||
bool operator<=(const StreamIdx &other) const;
|
||||
|
||||
//! Returns the network code
|
||||
const std::string &network() const;
|
||||
|
||||
//! Returns the station code
|
||||
const std::string &station() const;
|
||||
|
||||
//! Returns the channel code
|
||||
const std::string &channel() const;
|
||||
|
||||
//! Returns the location code
|
||||
const std::string &location() const;
|
||||
|
||||
//! Returns the start time
|
||||
Core::Time startTime() const;
|
||||
|
||||
//! Returns the end time
|
||||
Core::Time endTime() const;
|
||||
|
||||
//! Returns a string: <sTime> <eTime> <network> <station> <channel> <location>
|
||||
//! <*Time> in format: %Y,%m,%d,%H,%M,%S
|
||||
std::string str(const Seiscomp::Core::Time& stime,
|
||||
const Seiscomp::Core::Time& etime) const;
|
||||
|
||||
|
||||
private:
|
||||
const std::string _net;
|
||||
const std::string _sta;
|
||||
const std::string _loc;
|
||||
const std::string _cha;
|
||||
const Seiscomp::Core::Time _stime;
|
||||
const Seiscomp::Core::Time _etime;
|
||||
};
|
||||
|
||||
} // namespace RecordStream
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
48
include/seiscomp/io/recordstreamexceptions.h
Normal file
48
include/seiscomp/io/recordstreamexceptions.h
Normal file
@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_RECORDSTREAMEXCEPTIONS_H
|
||||
#define SEISCOMP_IO_RECORDSTREAMEXCEPTIONS_H
|
||||
|
||||
#include <seiscomp/core/exceptions.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API RecordStreamException: public Seiscomp::Core::StreamException {
|
||||
public:
|
||||
RecordStreamException(): Seiscomp::Core::StreamException("RecordStream exception") {}
|
||||
RecordStreamException(const std::string& what): StreamException(what) {}
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API RecordStreamTimeout: public RecordStreamException {
|
||||
public:
|
||||
RecordStreamTimeout(): RecordStreamException("timeout") {}
|
||||
RecordStreamTimeout(const std::string& what): RecordStreamException(what) {}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
151
include/seiscomp/io/socket.h
Normal file
151
include/seiscomp/io/socket.h
Normal file
@ -0,0 +1,151 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_SOCKET_H
|
||||
#define SEISCOMP_IO_SOCKET_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
#include <seiscomp/core/interruptible.h>
|
||||
#include <seiscomp/core/datetime.h>
|
||||
#include <seiscomp/utils/timer.h>
|
||||
#include <seiscomp/io/recordstream.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#define BUFSIZE 4096
|
||||
#define RECSIZE 512
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API SocketException: public Seiscomp::IO::RecordStreamException {
|
||||
public:
|
||||
SocketException(): RecordStreamException("Socket exception") {}
|
||||
SocketException(const std::string& what): RecordStreamException(what) {}
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API SocketCommandException: public SocketException {
|
||||
public:
|
||||
SocketCommandException(): SocketException("command not accepted") {}
|
||||
SocketCommandException(const std::string& what): SocketException(what) {}
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API SocketTimeout: public SocketException {
|
||||
public:
|
||||
SocketTimeout(): SocketException("timeout") {}
|
||||
SocketTimeout(const std::string& what): SocketException(what) {}
|
||||
};
|
||||
|
||||
class SC_SYSTEM_CORE_API SocketResolveError: public SocketException {
|
||||
public:
|
||||
SocketResolveError(): SocketException("cannot resolve hostname") {}
|
||||
SocketResolveError(const std::string& what): SocketException(what) {}
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(Socket);
|
||||
class SC_SYSTEM_CORE_API Socket: public Seiscomp::Core::InterruptibleObject {
|
||||
public:
|
||||
Socket();
|
||||
virtual ~Socket();
|
||||
|
||||
public:
|
||||
void setTimeout(int seconds);
|
||||
void startTimer();
|
||||
void stopTimer();
|
||||
virtual void open(const std::string& serverLocation);
|
||||
virtual void close();
|
||||
bool isOpen();
|
||||
bool tryReconnect();
|
||||
void write(const std::string& s);
|
||||
std::string readline();
|
||||
std::string read(int size);
|
||||
std::string sendRequest(const std::string& request, bool waitResponse);
|
||||
bool isInterrupted();
|
||||
void interrupt();
|
||||
int poll();
|
||||
|
||||
int takeFd();
|
||||
|
||||
protected:
|
||||
void handleInterrupt(int) throw();
|
||||
virtual int readImpl(char *buf, int count);
|
||||
virtual int writeImpl(const char *buf, int count);
|
||||
|
||||
protected:
|
||||
void fillbuf();
|
||||
int connectSocket(struct sockaddr *addr, int len);
|
||||
int nonblockSocket();
|
||||
int addrSocket(char *hostname, char *port, struct sockaddr *addr, size_t *len) ;
|
||||
|
||||
protected:
|
||||
int _sockfd;
|
||||
|
||||
private:
|
||||
enum { READ = 0, WRITE = 1 };
|
||||
int _pipefd[2];
|
||||
char _buf[BUFSIZE + 1];
|
||||
int _rp;
|
||||
int _wp;
|
||||
int _timeout;
|
||||
Util::StopWatch _timer;
|
||||
bool _interrupt;
|
||||
bool _reconnect;
|
||||
std::string _eol;
|
||||
};
|
||||
|
||||
|
||||
DEFINE_SMARTPOINTER(SSLSocket);
|
||||
class SC_SYSTEM_CORE_API SSLSocket: public Socket {
|
||||
public:
|
||||
SSLSocket();
|
||||
~SSLSocket() override;
|
||||
|
||||
void open(const std::string& serverLocation) override;
|
||||
void close() override;
|
||||
|
||||
void setFd(int fd);
|
||||
|
||||
protected:
|
||||
int readImpl(char *buf, int count) override;
|
||||
int writeImpl(const char *buf, int count) override;
|
||||
|
||||
private:
|
||||
void cleanUp();
|
||||
|
||||
private:
|
||||
BIO *_bio;
|
||||
SSL *_ssl;
|
||||
SSL_CTX *_ctx;
|
||||
char _errBuf[120];
|
||||
};
|
||||
|
||||
|
||||
} // namespace IO
|
||||
} // namespace Seiscomp
|
||||
|
||||
#endif
|
||||
|
236
include/seiscomp/io/streams/filter/lz4.h
Normal file
236
include/seiscomp/io/streams/filter/lz4.h
Normal file
@ -0,0 +1,236 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_STREAMS_FILTER_LZ4_H
|
||||
#define SEISCOMP_IO_STREAMS_FILTER_LZ4_H
|
||||
|
||||
|
||||
#include <boost/iostreams/categories.hpp>
|
||||
#include <boost/iostreams/operations.hpp>
|
||||
#include <boost/iostreams/pipeline.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <lz4/lz4frame_static.h>
|
||||
|
||||
|
||||
namespace ext {
|
||||
namespace boost {
|
||||
namespace iostreams {
|
||||
|
||||
|
||||
using namespace ::boost::iostreams;
|
||||
|
||||
|
||||
struct lz4_base {
|
||||
lz4_base(size_t inputBufferSize);
|
||||
~lz4_base();
|
||||
|
||||
void cleanup_();
|
||||
|
||||
size_t _inputBufferSize;
|
||||
size_t _outputBufferSize;
|
||||
char *_outputBuffer;
|
||||
std::streamsize _outputBuffered;
|
||||
};
|
||||
|
||||
|
||||
struct lz4_compress_base : lz4_base {
|
||||
lz4_compress_base(size_t inputBufferSize);
|
||||
~lz4_compress_base();
|
||||
|
||||
void cleanup_();
|
||||
|
||||
bool init();
|
||||
bool compress(const char *s, std::streamsize n);
|
||||
void done();
|
||||
|
||||
LZ4F_cctx *_ctx;
|
||||
LZ4F_preferences_t _prefs;
|
||||
};
|
||||
|
||||
|
||||
template <typename Ch>
|
||||
class basic_l4z_compressor : private lz4_compress_base {
|
||||
public:
|
||||
typedef char char_type;
|
||||
struct category
|
||||
: dual_use
|
||||
, filter_tag
|
||||
, multichar_tag
|
||||
, closable_tag
|
||||
, optimally_buffered_tag
|
||||
{};
|
||||
|
||||
explicit basic_l4z_compressor(size_t bufferSize = 128)
|
||||
: lz4_compress_base(bufferSize), _bufferSize(bufferSize) {}
|
||||
|
||||
std::streamsize optimal_buffer_size() const { return _bufferSize; }
|
||||
|
||||
template<typename Source>
|
||||
std::streamsize read(Source &, char_type *, std::streamsize) {
|
||||
// Read is not supported
|
||||
return -1;
|
||||
}
|
||||
|
||||
template<typename Sink>
|
||||
std::streamsize write(Sink &snk, const char_type *s, std::streamsize n) {
|
||||
if ( !_ctx ) {
|
||||
if ( !init() )
|
||||
return -1;
|
||||
|
||||
if ( _outputBuffered )
|
||||
::boost::iostreams::write(snk, _outputBuffer, _outputBuffered);
|
||||
}
|
||||
|
||||
if ( !compress((const char*)s, n * sizeof(char_type)) )
|
||||
return -1;
|
||||
|
||||
if ( _outputBuffered )
|
||||
::boost::iostreams::write(snk, _outputBuffer, _outputBuffered);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
template<typename Sink>
|
||||
void close(Sink &snk, std::ios_base::openmode) {
|
||||
done();
|
||||
|
||||
if ( _outputBuffered )
|
||||
::boost::iostreams::write(snk, _outputBuffer, _outputBuffered);
|
||||
|
||||
cleanup_();
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _bufferSize;
|
||||
};
|
||||
BOOST_IOSTREAMS_PIPABLE(basic_l4z_compressor, 1)
|
||||
|
||||
|
||||
typedef basic_l4z_compressor<char> lz4_compressor;
|
||||
|
||||
|
||||
|
||||
struct lz4_decompress_base : lz4_base {
|
||||
lz4_decompress_base(size_t inputBufferSize);
|
||||
~lz4_decompress_base();
|
||||
|
||||
void cleanup_();
|
||||
|
||||
bool init();
|
||||
bool decompress();
|
||||
|
||||
LZ4F_dctx *_ctx;
|
||||
char *_inputBuffer;
|
||||
std::streamsize _inputBufferPos;
|
||||
std::streamsize _inputBuffered;
|
||||
std::streamsize _outputBufferPos;
|
||||
};
|
||||
|
||||
|
||||
template <typename Ch>
|
||||
class basic_l4z_decompressor : private lz4_decompress_base {
|
||||
public:
|
||||
typedef char char_type;
|
||||
struct category
|
||||
: dual_use
|
||||
, filter_tag
|
||||
, multichar_tag
|
||||
{};
|
||||
|
||||
explicit basic_l4z_decompressor(size_t bufferSize = 128)
|
||||
: lz4_decompress_base(bufferSize), _bufferSize(bufferSize) {}
|
||||
|
||||
template<typename Source>
|
||||
std::streamsize read(Source &snk, char_type *s, std::streamsize n) {
|
||||
if ( !_ctx ) {
|
||||
if ( !init() )
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::streamsize remaining = n;
|
||||
while ( remaining ) {
|
||||
// Copy as much from the output buffer as possible
|
||||
std::streamsize toCopy = std::min(remaining, _outputBuffered - _outputBufferPos);
|
||||
if ( toCopy ) {
|
||||
/*
|
||||
std::cerr << "<<<<<<<< " << toCopy << std::endl;
|
||||
for ( size_t i = 0; i < toCopy; ++i )
|
||||
std::cerr << "s[" << (n - remaining + i) << "] = " << _outputBuffer[_outputBufferPos + i]
|
||||
<< " (" << int(_outputBuffer[_outputBufferPos + i]) << ")"
|
||||
<< std::endl;
|
||||
*/
|
||||
|
||||
std::copy(_outputBuffer + _outputBufferPos,
|
||||
_outputBuffer + _outputBufferPos + toCopy, s + n - remaining);
|
||||
_outputBufferPos += toCopy;
|
||||
remaining -= toCopy;
|
||||
}
|
||||
else {
|
||||
if ( _inputBufferPos ) {
|
||||
_inputBuffered = _inputBufferPos;
|
||||
if ( decompress() ) {
|
||||
if ( _outputBuffered ) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
return n-remaining;
|
||||
}
|
||||
|
||||
// Need more uncompressed data
|
||||
_inputBuffered = ::boost::iostreams::read(snk, _inputBuffer + _inputBufferPos, _inputBufferSize - _inputBufferPos);
|
||||
_inputBufferPos = 0;
|
||||
if ( _inputBuffered <= 0 )
|
||||
return n-remaining;
|
||||
|
||||
_inputBuffered += _inputBufferPos;
|
||||
|
||||
if ( !decompress() )
|
||||
return n-remaining;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
template<typename Sink>
|
||||
std::streamsize write(Sink &, const char_type *, std::streamsize) {
|
||||
// Write is not supported
|
||||
return -1;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t _bufferSize;
|
||||
};
|
||||
BOOST_IOSTREAMS_PIPABLE(basic_l4z_decompressor, 1)
|
||||
|
||||
|
||||
typedef basic_l4z_decompressor<char> lz4_decompressor;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
105
include/seiscomp/io/xml/exporter.h
Normal file
105
include/seiscomp/io/xml/exporter.h
Normal file
@ -0,0 +1,105 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_XMLEXPORTER_H
|
||||
#define SEISCOMP_IO_XMLEXPORTER_H
|
||||
|
||||
|
||||
#include <seiscomp/io/xml/handler.h>
|
||||
#include <seiscomp/io/exporter.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
namespace XML {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Exporter : public IO::Exporter, public OutputHandler {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Exporter();
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Public Interface
|
||||
// ----------------------------------------------------------------------
|
||||
public:
|
||||
TypeMap* typeMap();
|
||||
void setTypeMap(TypeMap *map);
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Protected interface
|
||||
// ------------------------------------------------------------------
|
||||
protected:
|
||||
//! Sets the required name of the root tag.
|
||||
//! If empty no header is used.
|
||||
void setRootName(std::string);
|
||||
|
||||
virtual void collectNamespaces(Core::BaseObject *);
|
||||
|
||||
//! Interface method that must be implemented by real exporters.
|
||||
virtual bool put(std::streambuf* buf, Core::BaseObject *);
|
||||
virtual bool put(std::streambuf* buf, const ExportObjectList &);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
void handle(Core::BaseObject *, const char *tag, const char *ns, NodeHandler *);
|
||||
bool openElement(const char *name, const char *ns);
|
||||
void addAttribute(const char *name, const char *ns, const char *value);
|
||||
void closeElement(const char *name, const char *ns);
|
||||
|
||||
void put(const char *content);
|
||||
|
||||
void writeString(const char *str);
|
||||
|
||||
|
||||
protected:
|
||||
// Maps a namespace to its prefix
|
||||
typedef std::map<std::string, std::string> NamespaceMap;
|
||||
|
||||
NamespaceMap _defaultNsMap;
|
||||
NamespaceMap _namespaces;
|
||||
|
||||
|
||||
private:
|
||||
std::string _headerNode;
|
||||
std::ostream _ostr;
|
||||
TypeMap *_typemap;
|
||||
int _lastTagState;
|
||||
int _indent;
|
||||
bool _tagOpen;
|
||||
bool _firstElement;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
354
include/seiscomp/io/xml/handler.h
Normal file
354
include/seiscomp/io/xml/handler.h
Normal file
@ -0,0 +1,354 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_XMLHANDLER_H
|
||||
#define SEISCOMP_IO_XMLHANDLER_H
|
||||
|
||||
|
||||
#include <seiscomp/io/importer.h>
|
||||
#include <seiscomp/core/strings.h>
|
||||
#include <seiscomp/core/metaproperty.h>
|
||||
#include <seiscomp/core.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
namespace XML {
|
||||
|
||||
|
||||
typedef std::vector<Core::BaseObject *> ChildList;
|
||||
typedef std::set<std::string> TagSet;
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API NodeHandler;
|
||||
|
||||
class SC_SYSTEM_CORE_API OutputHandler {
|
||||
public:
|
||||
virtual ~OutputHandler();
|
||||
|
||||
virtual void handle(Core::BaseObject *, const char *tag, const char *ns, NodeHandler * = nullptr) = 0;
|
||||
|
||||
virtual bool openElement(const char *name, const char *ns) = 0;
|
||||
virtual void addAttribute(const char *name, const char *ns, const char *value) = 0;
|
||||
virtual void closeElement(const char *name, const char *ns) = 0;
|
||||
|
||||
virtual void put(const char *content) = 0;
|
||||
};
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API MemberNodeHandler;
|
||||
|
||||
//! A NodeHandler handles nodes describing a class.
|
||||
struct SC_SYSTEM_CORE_API NodeHandler {
|
||||
virtual ~NodeHandler();
|
||||
|
||||
virtual bool init(Core::BaseObject *obj, void *n, TagSet &mandatoryTags) { return false; }
|
||||
// When called, object, next and newInstance are preset by the caller
|
||||
// object = nullptr
|
||||
// next = noneReader
|
||||
// newInstance = false
|
||||
// memberHandler = nullptr
|
||||
virtual std::string value(Core::BaseObject *obj) { return ""; }
|
||||
virtual bool put(Core::BaseObject *obj, const char *tag, const char *ns, OutputHandler *output) = 0;
|
||||
|
||||
virtual bool get(Core::BaseObject *obj, void *n) { return false; }
|
||||
virtual bool finalize(Core::BaseObject *obj, ChildList *) { return false; }
|
||||
|
||||
std::string content(void *n) const;
|
||||
bool equalsTag(void *n, const char *, const char *) const;
|
||||
|
||||
//! Reset all members to default values
|
||||
void propagate(Core::BaseObject *o, bool ni, bool opt);
|
||||
|
||||
Core::BaseObject *object;
|
||||
NodeHandler *childHandler;
|
||||
MemberNodeHandler *memberHandler;
|
||||
bool newInstance;
|
||||
bool isOptional;
|
||||
bool isAnyType;
|
||||
|
||||
static bool strictNsCheck;
|
||||
};
|
||||
|
||||
|
||||
//! A MemberHandler handles setting of members of a class. Members can
|
||||
//! be optional, mandatory and childs.
|
||||
struct SC_SYSTEM_CORE_API MemberHandler {
|
||||
virtual ~MemberHandler();
|
||||
|
||||
virtual std::string value(Core::BaseObject *obj) = 0;
|
||||
virtual bool put(Core::BaseObject *object, const char *tag, const char *ns,
|
||||
bool opt, OutputHandler *output, NodeHandler *h);
|
||||
|
||||
//! Get a "node" to the member of an object.
|
||||
virtual bool get(Core::BaseObject *object, void *node, NodeHandler *h) = 0;
|
||||
|
||||
//! Finalizes the read member object (can be nullptr).
|
||||
virtual bool finalize(Core::BaseObject *parent, Core::BaseObject *member) { return true; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
class PropertyHandler : public MemberHandler {
|
||||
public:
|
||||
PropertyHandler(const Core::MetaProperty *prop)
|
||||
: _property(prop) {}
|
||||
|
||||
std::string value(Core::BaseObject *obj) {
|
||||
try {
|
||||
return _property->readString(obj);
|
||||
}
|
||||
catch ( ... ) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool put(Core::BaseObject *object, const char *tag, const char *ns,
|
||||
bool opt, OutputHandler *output, NodeHandler *h) {
|
||||
if ( _property->isClass() ) {
|
||||
try {
|
||||
output->handle(boost::any_cast<Core::BaseObject*>(_property->read(object)), tag, ns);
|
||||
return true;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
}
|
||||
else
|
||||
return MemberHandler::put(object, tag, ns, opt, output, h);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get(Core::BaseObject *object, void *, NodeHandler *);
|
||||
bool finalize(Core::BaseObject *parent, Core::BaseObject *member);
|
||||
|
||||
private:
|
||||
const Core::MetaProperty *_property;
|
||||
};
|
||||
|
||||
|
||||
class ChildPropertyHandler : public MemberHandler {
|
||||
public:
|
||||
ChildPropertyHandler(const Core::MetaProperty *prop)
|
||||
: _property(prop) {}
|
||||
|
||||
std::string value(Core::BaseObject *obj) { return ""; }
|
||||
|
||||
bool put(Core::BaseObject *object, const char *tag, const char *ns,
|
||||
bool opt, OutputHandler *output, NodeHandler *h) {
|
||||
size_t count = _property->arrayElementCount(object);
|
||||
for ( size_t i = 0; i < count; ++i ) {
|
||||
output->handle(_property->arrayObject(object, i), tag, ns);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get(Core::BaseObject *object, void *, NodeHandler *h) {
|
||||
h->propagate(_property->createClass(), true, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool finalize(Core::BaseObject *parent, Core::BaseObject *child) {
|
||||
if ( child )
|
||||
return _property->arrayAddObject(parent, child);
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
const Core::MetaProperty *_property;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API TypeHandler {
|
||||
TypeHandler(NodeHandler *nh) : nodeHandler(nh) {}
|
||||
virtual ~TypeHandler();
|
||||
|
||||
virtual Core::BaseObject *createClass() = 0;
|
||||
virtual const char *className() = 0;
|
||||
|
||||
NodeHandler *nodeHandler;
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API TypeNameHandler : public TypeHandler {
|
||||
TypeNameHandler(NodeHandler *nh, const char *cn)
|
||||
: TypeHandler(nh), classname(cn) {}
|
||||
|
||||
Core::BaseObject *createClass() {
|
||||
return Core::ClassFactory::Create(classname.c_str());
|
||||
}
|
||||
|
||||
const char *className() {
|
||||
return classname.c_str();
|
||||
}
|
||||
|
||||
std::string classname;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypeStaticHandler : public TypeHandler {
|
||||
TypeStaticHandler(NodeHandler *nh) : TypeHandler(nh) {}
|
||||
|
||||
Core::BaseObject *createClass() {
|
||||
return new T();
|
||||
}
|
||||
|
||||
const char *className() {
|
||||
return T::ClassName();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API TypeMap {
|
||||
struct Tag {
|
||||
Tag();
|
||||
Tag(const std::string &, const std::string &);
|
||||
|
||||
bool operator<(const Tag &other) const;
|
||||
|
||||
std::string name;
|
||||
std::string ns;
|
||||
};
|
||||
|
||||
// Maps a tag to a classname
|
||||
typedef std::map<Tag, std::string> TagMap;
|
||||
// Maps a tag without namespace to a classname
|
||||
typedef std::map<std::string, std::string> RawTagMap;
|
||||
// Maps a classname to a tag
|
||||
typedef std::map<std::string, Tag> ClassMap;
|
||||
// Maps a classname to a handler
|
||||
typedef std::map<std::string, TypeHandler*> HandlerMap;
|
||||
|
||||
TagMap tags;
|
||||
RawTagMap tagsWithoutNs;
|
||||
ClassMap classes;
|
||||
HandlerMap handlers;
|
||||
|
||||
TypeMap();
|
||||
~TypeMap();
|
||||
|
||||
void registerMapping(const char *tag, const char *ns, const char *classname, NodeHandler *handler);
|
||||
|
||||
template <typename T>
|
||||
void registerMapping(const char *tag, const char *ns, NodeHandler *handler);
|
||||
|
||||
const char *getClassname(const char *tag, const char *ns, bool strictNsCheck);
|
||||
const Tag *getTag(const char *classname);
|
||||
|
||||
NodeHandler *getHandler(const char *classname);
|
||||
Core::BaseObject *createClass(const char *classname);
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API MemberNodeHandler {
|
||||
MemberNodeHandler() {}
|
||||
|
||||
MemberNodeHandler(const char *t, const char *ns, bool opt)
|
||||
: tag(t), nameSpace(ns), optional(opt) {}
|
||||
|
||||
MemberNodeHandler(const char *t, const char *ns, bool opt, MemberHandler *s);
|
||||
|
||||
std::string value(Core::BaseObject *obj) { return setter->value(obj); }
|
||||
bool put(Core::BaseObject *obj, OutputHandler *output, NodeHandler *h);
|
||||
|
||||
bool get(Core::BaseObject *obj, void *, NodeHandler *h);
|
||||
bool finalize(Core::BaseObject *parent, Core::BaseObject *child);
|
||||
|
||||
std::string tag;
|
||||
std::string nameSpace;
|
||||
bool optional;
|
||||
std::shared_ptr<MemberHandler> setter;
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API NoneHandler : public NodeHandler {
|
||||
bool put(Core::BaseObject *obj, const char *tag, const char *ns, OutputHandler *output);
|
||||
bool get(Core::BaseObject *obj, void *n);
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API GenericHandler : public NodeHandler {
|
||||
bool put(Core::BaseObject *obj, const char *tag, const char *ns, OutputHandler *output);
|
||||
bool get(Core::BaseObject *, void *n);
|
||||
|
||||
TypeMap *mapper;
|
||||
};
|
||||
|
||||
|
||||
struct SC_SYSTEM_CORE_API ClassHandler : public NodeHandler {
|
||||
typedef std::list<MemberNodeHandler> MemberList;
|
||||
typedef std::list<MemberNodeHandler*> MemberRefList;
|
||||
|
||||
enum Location {
|
||||
Attribute,
|
||||
Element,
|
||||
CDATA
|
||||
};
|
||||
|
||||
enum Type {
|
||||
Mandatory = 0,
|
||||
Optional = 1
|
||||
};
|
||||
|
||||
ClassHandler() { cdataUsed = false; }
|
||||
|
||||
template <class C, typename R, typename T>
|
||||
void addMember(const char *t, const char *ns, Type opt, Location l, R (C::*s)(T));
|
||||
|
||||
template <class C, typename T1, typename T2, typename R>
|
||||
void addMember(const char *t, const char *ns, Type opt, R (C::*s)(T1), T2 (C::*g)());
|
||||
|
||||
void addMember(const char *t, const char *ns, Type opt, Location l, MemberHandler *s);
|
||||
void addChild(const char *t, const char *ns, MemberHandler *s);
|
||||
|
||||
bool init(Core::BaseObject *obj, void *n, TagSet &mandatoryTags);
|
||||
bool get(Core::BaseObject *obj, void *n);
|
||||
bool put(Core::BaseObject *obj, const char *tag, const char *ns, OutputHandler *output);
|
||||
|
||||
MemberRefList orderedMembers;
|
||||
MemberList attributes;
|
||||
MemberList elements;
|
||||
MemberList childs;
|
||||
MemberNodeHandler cdata;
|
||||
bool cdataUsed;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct TypedClassHandler : public ClassHandler {
|
||||
void addProperty(const char *t, const char *ns, Type opt, Location l, const Core::MetaProperty *prop);
|
||||
void addProperty(const char *t, const char *ns, Type opt, Location l, const char *property);
|
||||
|
||||
void addChildProperty(const char *t, const char *ns, const char *property);
|
||||
};
|
||||
|
||||
|
||||
#include <seiscomp/io/xml/handler.ipp>
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
108
include/seiscomp/io/xml/handler.ipp
Normal file
108
include/seiscomp/io/xml/handler.ipp
Normal file
@ -0,0 +1,108 @@
|
||||
/***************************************************************************
|
||||
* 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 TypedClassHandler<T>::addProperty(const char *t, const char *ns, Type opt, Location l, const Core::MetaProperty *prop) {
|
||||
addMember(t, ns, opt, l, new PropertyHandler(prop));
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void TypedClassHandler<T>::addProperty(const char *t, const char *ns, Type opt, Location l, const char *property) {
|
||||
const Core::MetaObject *obj = T::Meta();
|
||||
if ( obj == nullptr )
|
||||
throw Core::TypeException(std::string(T::ClassName()) + ": no metaobject");
|
||||
|
||||
const Core::MetaProperty *prop = nullptr;
|
||||
|
||||
while ( obj && prop == nullptr ) {
|
||||
prop = obj->property(property);
|
||||
obj = obj->base();
|
||||
}
|
||||
|
||||
if ( prop == nullptr )
|
||||
throw Core::TypeException(std::string(T::ClassName()) + ": no metaproperty " + property);
|
||||
|
||||
addProperty(t, ns, opt, l, prop);
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void TypedClassHandler<T>::addChildProperty(const char *t, const char *ns, const char *property) {
|
||||
const Core::MetaObject *obj = T::Meta();
|
||||
if ( obj == nullptr )
|
||||
throw Core::TypeException(std::string(T::ClassName()) + ": no metaobject");
|
||||
|
||||
const Core::MetaProperty *prop = nullptr;
|
||||
|
||||
while ( obj && prop == nullptr ) {
|
||||
prop = obj->property(property);
|
||||
obj = obj->base();
|
||||
}
|
||||
|
||||
if ( prop == nullptr )
|
||||
throw Core::TypeException(std::string(T::ClassName()) + ": no metaproperty " + property);
|
||||
|
||||
if ( !prop->isArray() )
|
||||
throw Core::TypeException(std::string(T::ClassName()) + ": " + property + " property is not an array");
|
||||
|
||||
addChild(t, ns, new ChildPropertyHandler(prop));
|
||||
}
|
||||
|
||||
|
||||
template <class C, typename R, typename T>
|
||||
void ClassHandler::addMember(const char *t, const char *ns, Type opt, Location l, R (C::*s)(T)) {
|
||||
switch ( l ) {
|
||||
case Attribute:
|
||||
attributes.push_back(MemberNodeHandler(t, ns, (bool)opt, s));
|
||||
break;
|
||||
case Element:
|
||||
elements.push_back(MemberNodeHandler(t, ns, (bool)opt, s));
|
||||
orderedMembers.push_back(&elements.back());
|
||||
break;
|
||||
case CDATA:
|
||||
cdata = MemberNodeHandler(t, ns, (bool)opt, s);
|
||||
cdataUsed = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class C, typename T1, typename T2, typename R>
|
||||
void ClassHandler::addMember(const char *t, const char *ns, Type opt, R (C::*s)(T1), T2 (C::*g)()) {
|
||||
elements.push_back(MemberNodeHandler(t, ns, (bool)opt, g, s));
|
||||
orderedMembers.push_back(&childs.back());
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
void TypeMap::registerMapping(const char *tag, const char *ns, NodeHandler *handler) {
|
||||
TypeHandler *h = new TypeStaticHandler<T>(handler);
|
||||
tags[Tag(tag, ns)] = h->className();
|
||||
|
||||
std::pair<RawTagMap::iterator,bool> itp;
|
||||
itp = tagsWithoutNs.insert(RawTagMap::value_type(tag, h->className()));
|
||||
|
||||
// Tag exists already -> set invalid classname
|
||||
if ( !itp.second ) itp.first->second.clear();
|
||||
|
||||
classes[h->className()] = Tag(tag, ns);
|
||||
handlers[h->className()] = h;
|
||||
}
|
94
include/seiscomp/io/xml/importer.h
Normal file
94
include/seiscomp/io/xml/importer.h
Normal file
@ -0,0 +1,94 @@
|
||||
/***************************************************************************
|
||||
* 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_IO_XMLIMPORTER_H
|
||||
#define SEISCOMP_IO_XMLIMPORTER_H
|
||||
|
||||
|
||||
#include <seiscomp/io/xml/handler.h>
|
||||
#include <seiscomp/io/importer.h>
|
||||
|
||||
|
||||
namespace Seiscomp {
|
||||
namespace IO {
|
||||
namespace XML {
|
||||
|
||||
|
||||
class SC_SYSTEM_CORE_API Importer : public IO::Importer {
|
||||
// ------------------------------------------------------------------
|
||||
// Xstruction
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
//! C'tor
|
||||
Importer();
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Public interface
|
||||
// ------------------------------------------------------------------
|
||||
public:
|
||||
TypeMap* typeMap();
|
||||
void setTypeMap(TypeMap *map);
|
||||
|
||||
//! Enables/disables strict namespace checking.
|
||||
//! If disabled, tags will be accepted even if the
|
||||
//! registered namespace doesn't match and the tag
|
||||
//! is only registered with one namespace. Tags with
|
||||
//! multiple namespaces will still fail.
|
||||
void setStrictNamespaceCheck(bool);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Protected Inteface
|
||||
// ----------------------------------------------------------------------
|
||||
protected:
|
||||
|
||||
//! Sets the required name of the root tag.
|
||||
//! If empty no header is used.
|
||||
void setRootName(std::string);
|
||||
|
||||
//! Interface method that must be implemented by real importers.
|
||||
virtual Core::BaseObject *get(std::streambuf* buf);
|
||||
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Private interface
|
||||
// ------------------------------------------------------------------
|
||||
private:
|
||||
bool traverse(NodeHandler *handler,
|
||||
void *node, void *childs,
|
||||
Core::BaseObject *target);
|
||||
|
||||
|
||||
private:
|
||||
static NoneHandler _none;
|
||||
GenericHandler _any;
|
||||
bool _strictNamespaceCheck;
|
||||
|
||||
Core::BaseObject *_result;
|
||||
std::string _headerNode;
|
||||
TypeMap *_typemap;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user