170 lines
4.9 KiB
C++
170 lines
4.9 KiB
C++
/***************************************************************************
|
|
* Copyright (C) 2015 by gempa GmbH *
|
|
* *
|
|
* All Rights Reserved. *
|
|
* *
|
|
* NOTICE: All information contained herein is, and remains *
|
|
* the property of gempa GmbH and its suppliers, if any. The intellectual *
|
|
* and technical concepts contained herein are proprietary to gempa GmbH *
|
|
* and its suppliers. *
|
|
* Dissemination of this information or reproduction of this material *
|
|
* is strictly forbidden unless prior written permission is obtained *
|
|
* from gempa GmbH. *
|
|
***************************************************************************/
|
|
|
|
|
|
#ifndef GEMPA_CAPS_PLUGINAPPLICATION_H
|
|
#define GEMPA_CAPS_PLUGINAPPLICATION_H
|
|
|
|
|
|
#include <gempa/caps/api.h>
|
|
#include <gempa/caps/plugin.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 {
|
|
|
|
|
|
class SC_GEMPA_CAPS_API PluginApplication : public Seiscomp::Client::StreamApplication {
|
|
public:
|
|
PluginApplication(int argc, char **argv,
|
|
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.
|
|
*/
|
|
void createCommandLineDescription() override;
|
|
|
|
/**
|
|
* @brief Cleanup method called before exec() returns.
|
|
*/
|
|
void done() override;
|
|
|
|
/**
|
|
* @brief This method is called before the applications exits.
|
|
* @param returnCode The exit code
|
|
*/
|
|
void exit(int returnCode) override;
|
|
|
|
/**
|
|
* @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.
|
|
*/
|
|
bool init() override;
|
|
|
|
/**
|
|
* @brief Reads common plugin configuration options.
|
|
*/
|
|
bool initConfiguration() override;
|
|
|
|
/**
|
|
* @brief Validates command line parameters.
|
|
*/
|
|
bool validateParameters() override;
|
|
|
|
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:
|
|
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;
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|