Update to version 3.2
This commit is contained in:
@@ -16,98 +16,153 @@
|
||||
#ifndef GEMPA_CAPS_PLUGINAPPLICATION_H
|
||||
#define GEMPA_CAPS_PLUGINAPPLICATION_H
|
||||
|
||||
|
||||
#include <gempa/caps/api.h>
|
||||
#include <gempa/caps/plugin.h>
|
||||
|
||||
#include <seiscomp3/client/streamapplication.h>
|
||||
#include <seiscomp3/logging/filerotator.h>
|
||||
#include <seiscomp3/utils/timer.h>
|
||||
#include <seiscomp/core/version.h>
|
||||
#include <seiscomp/client/streamapplication.h>
|
||||
#if SC_API_VERSION < SC_API_VERSION_CHECK(17, 0, 0)
|
||||
#include <seiscomp/logging/filerotator.h>
|
||||
#else
|
||||
#include <seiscomp/logging/output/filerotator.h>
|
||||
#endif
|
||||
#include <seiscomp/system/hostinfo.h>
|
||||
#include <seiscomp/utils/timer.h>
|
||||
|
||||
|
||||
namespace Gempa::CAPS {
|
||||
|
||||
namespace Gempa {
|
||||
namespace CAPS {
|
||||
|
||||
class SC_GEMPA_CAPS_API PluginApplication : public Seiscomp::Client::StreamApplication {
|
||||
public:
|
||||
PluginApplication(int argc, char **argv,
|
||||
const std::string &desc = "");
|
||||
const std::string &name = "");
|
||||
|
||||
protected:
|
||||
struct Statistics {
|
||||
Statistics() = default;
|
||||
|
||||
uint32_t records{0};
|
||||
uint32_t samples{0};
|
||||
Time startTime;
|
||||
Time endTime;
|
||||
uint32_t gaps{0};
|
||||
uint32_t files{0};
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The MseedEncoding enum defines supported MSEED encodings.
|
||||
*/
|
||||
enum MseedEncoding {Uncompressed, Steim1, Steim2};
|
||||
|
||||
/**
|
||||
* @brief Adds common plugin commandline options.
|
||||
*/
|
||||
virtual void createCommandLineDescription();
|
||||
void createCommandLineDescription() override;
|
||||
|
||||
virtual void done();
|
||||
/**
|
||||
* @brief Cleanup method called before exec() returns.
|
||||
*/
|
||||
void done() override;
|
||||
|
||||
virtual void exit(int returnCode);
|
||||
/**
|
||||
* @brief This method is called before the applications exits.
|
||||
* @param returnCode The exit code
|
||||
*/
|
||||
void exit(int returnCode) override;
|
||||
|
||||
virtual void handleRecord(Seiscomp::Record *record) {}
|
||||
virtual void handleTimeout();
|
||||
/**
|
||||
* @brief Handles records. This is dummy implemenation as the base
|
||||
* class requires to implement the method.
|
||||
* @param record Pointer to record
|
||||
*/
|
||||
void handleRecord(Seiscomp::Record *record) override {}
|
||||
|
||||
/**
|
||||
* @brief Handles timer events. For instance writes the plugin states
|
||||
* information to file.
|
||||
*/
|
||||
void handleTimeout() override;
|
||||
|
||||
/**
|
||||
* @brief Initialization method.
|
||||
*/
|
||||
virtual bool init();
|
||||
bool init() override;
|
||||
|
||||
/**
|
||||
* @brief Reads common plugin configuration options.
|
||||
*/
|
||||
virtual bool initConfiguration();
|
||||
bool initConfiguration() override;
|
||||
|
||||
/**
|
||||
* @brief Validates command line parameters.
|
||||
*/
|
||||
virtual bool validateParameters();
|
||||
bool validateParameters() override;
|
||||
|
||||
protected:
|
||||
struct Statistics {
|
||||
uint32_t records;
|
||||
uint32_t samples;
|
||||
Time startTime;
|
||||
Time endTime;
|
||||
uint32_t gaps;
|
||||
uint32_t files;
|
||||
|
||||
Statistics() : records(0), samples(0), gaps(0), files(0) {}
|
||||
};
|
||||
|
||||
enum MseedEncoding {Uncompressed, Steim1, Steim2};
|
||||
|
||||
bool fromString(MseedEncoding &enc, std::string str);
|
||||
|
||||
protected:
|
||||
class FileRotator : public Seiscomp::Logging::FileRotatorOutput {
|
||||
public:
|
||||
std::ofstream& stream() { return _stream; }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get MSEED encoding value from string
|
||||
* @param enc The encoding
|
||||
* @param str The encoding as string
|
||||
* @return True on success
|
||||
*/
|
||||
static bool fromString(MseedEncoding &enc, std::string str);
|
||||
|
||||
/**
|
||||
* @brief Get host information like total mem or OS
|
||||
* @param hostInfo Host info struct
|
||||
* @return True on success
|
||||
*/
|
||||
bool getHostInfo(Plugin::HostInfo &hostInfo);
|
||||
|
||||
/**
|
||||
* @brief Get runtime information
|
||||
*/
|
||||
void updateRuntimeInfo();
|
||||
|
||||
virtual void sendRuntimeInfo();
|
||||
|
||||
protected:
|
||||
Plugin _plugin;
|
||||
std::string _strAddr;
|
||||
size_t _bufferSize;
|
||||
size_t _backfillingBufferSize;
|
||||
bool _mseed;
|
||||
std::string _journalFile;
|
||||
int _flushInterval;
|
||||
int _ackTimeout;
|
||||
int _lastAckTimeout;
|
||||
int _sendTimeout;
|
||||
int _maxFutureEndTime;
|
||||
Statistics _stats;
|
||||
bool _mseedEnabled;
|
||||
MseedEncoding _mseedEncoding;
|
||||
uint _mseedRecordLength;
|
||||
std::string _strMseedEncoding;
|
||||
std::string _strPacketType;
|
||||
Seiscomp::Util::Timer _timer;
|
||||
FileRotator _statusFile;
|
||||
bool _logStatus;
|
||||
uint _statusFlushInterval;
|
||||
bool _dumpPackets;
|
||||
std::string _agent;
|
||||
struct Host {
|
||||
std::string agent;
|
||||
std::string storage{"@LOGDIR@"};
|
||||
std::string os;
|
||||
};
|
||||
|
||||
Plugin _plugin;
|
||||
std::string _strAddr{"localhost:18003"};
|
||||
size_t _bufferSize{1 << 20};
|
||||
size_t _backfillingBufferSize{180};
|
||||
bool _mseed;
|
||||
std::string _journalFile;
|
||||
int _flushInterval{10};
|
||||
int _ackTimeout{60};
|
||||
int _lastAckTimeout{5};
|
||||
int _sendTimeout{60};
|
||||
int _connectionTimeout{30};
|
||||
int _maxFutureEndTime{120};
|
||||
Statistics _stats;
|
||||
bool _mseedEnabled{false};
|
||||
MseedEncoding _mseedEncoding{Steim2};
|
||||
uint _mseedRecordLength{9};
|
||||
std::string _strMseedEncoding{"Steim2"};
|
||||
std::string _strPacketType;
|
||||
Seiscomp::Util::Timer _timer;
|
||||
FileRotator _statusFile;
|
||||
bool _logStatus{false};
|
||||
uint _statusFlushInterval{10};
|
||||
bool _dumpPackets{false};
|
||||
Seiscomp::System::HostInfo _hostInfo;
|
||||
Host _host;
|
||||
Plugin::RuntimeInfo _runtimeInfo;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user