Update to version 3.2
This commit is contained in:
@@ -16,8 +16,9 @@
|
||||
#ifndef GEMPA_CAPS_PLUGIN_H
|
||||
#define GEMPA_CAPS_PLUGIN_H
|
||||
|
||||
|
||||
/*
|
||||
// Enable/disable journal
|
||||
// Enable/disable journal
|
||||
#define CAPS_FEATURES_JOURNAL 1
|
||||
// Enable/disable backfilling of packets
|
||||
#define CAPS_FEATURES_BACKFILLING 1
|
||||
@@ -36,7 +37,6 @@
|
||||
#include <gempa/caps/socket.h>
|
||||
#include <gempa/caps/url.h>
|
||||
#include <gempa/caps/version.h>
|
||||
|
||||
#include <gempa/caps/pluginpacket.h>
|
||||
|
||||
#include <boost/function.hpp>
|
||||
@@ -50,10 +50,10 @@
|
||||
#include <list>
|
||||
|
||||
|
||||
|
||||
namespace Gempa {
|
||||
namespace CAPS {
|
||||
|
||||
|
||||
class SC_GEMPA_CAPS_API Plugin {
|
||||
public:
|
||||
enum Status {
|
||||
@@ -71,6 +71,22 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
size_t maxBytesBuffered;
|
||||
};
|
||||
|
||||
struct HostInfo {
|
||||
std::string agent;
|
||||
std::string agentVersion;
|
||||
std::string os;
|
||||
int64_t totalMem{-1};
|
||||
int64_t totalDisc{-1};
|
||||
};
|
||||
|
||||
struct RuntimeInfo {
|
||||
int64_t availableMem{-1};
|
||||
int64_t procUsedMem{-1};
|
||||
int64_t availableDisc{-1};
|
||||
int cpuUsage{-1};
|
||||
double systemLoad{-1};
|
||||
};
|
||||
|
||||
typedef std::vector<char> Buffer;
|
||||
typedef boost::shared_ptr<Buffer> BufferPtr;
|
||||
typedef std::deque<PacketPtr> PacketBuffer;
|
||||
@@ -90,13 +106,15 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
typedef std::map<std::string, StreamState> StreamStates;
|
||||
|
||||
typedef boost::function<void (const std::string &, const CAPS::Time &,
|
||||
const CAPS::Time &)> PacketAckFunc;
|
||||
const CAPS::Time &, void *context)> PacketAckFunc;
|
||||
typedef boost::function<void ()> ConnectedCallback;
|
||||
typedef boost::function<void ()> DisconnectedCallback;
|
||||
|
||||
|
||||
public:
|
||||
Plugin(const std::string &name, const std::string &options = "",
|
||||
const std::string &description = "");
|
||||
~Plugin();
|
||||
virtual ~Plugin();
|
||||
|
||||
void close();
|
||||
void quit();
|
||||
@@ -186,15 +204,31 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
|
||||
void setPacketAckFunc(const PacketAckFunc &func) { _packetAckFunc = func; }
|
||||
|
||||
void setSendTimeout(int timeout) {
|
||||
_sendTimeout = timeout;
|
||||
/**
|
||||
* @brief Sets the connection timout used when the plugin
|
||||
* tries to establish a connection to CAPS
|
||||
* @param sec The seconds
|
||||
*/
|
||||
void setConnectionTimeout(int sec) {
|
||||
_connectionTimeout = sec;
|
||||
}
|
||||
|
||||
void setTimeouts(int ack, int lastAck) {
|
||||
_ackTimeout = ack;
|
||||
_lastAckTimeout = lastAck;
|
||||
/**
|
||||
* @brief Sets the maximum number of seconds to wait until
|
||||
* the file descriptor is ready for writing.
|
||||
* @param sec The seconds
|
||||
*/
|
||||
void setSendTimeout(int sec) {
|
||||
_sendTimeout = sec;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets timeout values
|
||||
* @param ack The acknowledgement message value
|
||||
* @param lastAck The last acknowledgement message value
|
||||
* @param send See setSendTimeout
|
||||
* @
|
||||
*/
|
||||
void setTimeouts(int ack, int lastAck, int send) {
|
||||
_ackTimeout = ack;
|
||||
_lastAckTimeout = lastAck;
|
||||
@@ -209,11 +243,18 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
const StreamStates &streamStates() const { return _states; }
|
||||
bool writeJournal();
|
||||
bool writeJournal(std::ostream &ostream);
|
||||
|
||||
/**
|
||||
* @brief Gets end time of the last acknowledged packet
|
||||
* @param id The stream ID, e.g., GE.APE..BHZ
|
||||
* @return The last end time or an invalid time
|
||||
*/
|
||||
Gempa::CAPS::Time lastEndTime(const std::string &id);
|
||||
#endif
|
||||
Status push(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
DataRecordPtr rec, const std::string &uom,
|
||||
int timingQuality = -1);
|
||||
int timingQuality = -1, void *context = nullptr);
|
||||
|
||||
Status push(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
@@ -221,10 +262,56 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
uint16_t numerator, uint16_t denominator,
|
||||
const std::string &uom,
|
||||
void *data, size_t count,
|
||||
DataType dt, int timingQuality = -1);
|
||||
DataType dt, int timingQuality = -1,
|
||||
void *context = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Sends CAPS data record to CAPS
|
||||
* @param net Network code
|
||||
* @param sta Station code
|
||||
* @param loc Location code
|
||||
* @param cha Channel code
|
||||
* @param rec CAPS data record
|
||||
* @param uom Unit of measurement
|
||||
* @param timingQuality Data timing quality. Ususally between 0 and 100 or -1
|
||||
* if unset
|
||||
* @param context Pointer to user-defined context data
|
||||
* @return Status Packet status
|
||||
*/
|
||||
Status pushRecord(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
DataRecordPtr rec, const std::string &uom,
|
||||
int timingQuality = -1, void *context = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Sends C array data as RAW record to CAPS
|
||||
* @param net Network code
|
||||
* @param sta Station code
|
||||
* @param loc Location code
|
||||
* @param cha Channel code
|
||||
* @param stime Packet start time
|
||||
* @param numerator Sampling frequency numerator
|
||||
* @param denominator Sampling frequency denominator
|
||||
* @param uom Unit of measurement
|
||||
* @param data Pointer to data array
|
||||
* @param count Number of samples
|
||||
* @param dt Data type, e.g., DT_DOUBLE
|
||||
* @param timingQuality Data timing quality. Ususally between 0 and 100 or -1
|
||||
* if unset
|
||||
* @param context Pointer to user-defined context data
|
||||
* @return Status Packet status
|
||||
*/
|
||||
Status pushRaw(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Time &stime,
|
||||
uint16_t numerator, uint16_t denominator,
|
||||
const std::string &uom,
|
||||
void *data, size_t count,
|
||||
DataType dt, int timingQuality = -1,
|
||||
void *context = nullptr);
|
||||
|
||||
/*
|
||||
* Sends given data as any packet. Before sending the data will be
|
||||
* Sends given data as any packet. Before sending the data will be
|
||||
* copied into an internal buffer. We introduced this method
|
||||
* to simplify the creation of the python wrappers.
|
||||
*/
|
||||
@@ -233,13 +320,62 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Time &stime, uint16_t numerator,
|
||||
uint16_t denominator, const std::string &format,
|
||||
char *data, size_t count);
|
||||
char *data, size_t count, void *context = nullptr);
|
||||
|
||||
Status push(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Time &stime, uint16_t numerator,
|
||||
uint16_t denominator, const std::string &format,
|
||||
const std::string &data);
|
||||
const std::string &data, void *context = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Sends C array data as any record to CAPS
|
||||
* @param net Network code
|
||||
* @param sta Station code
|
||||
* @param loc Location code
|
||||
* @param cha Channel code
|
||||
* @param stime Packet start time
|
||||
* @param etime Packet end time
|
||||
* @param numerator Sampling frequency numerator. Use 1 / 0
|
||||
* for packets without sampling frequency.
|
||||
* @param denominator Sampling frequency denominator
|
||||
* @param format Data format of the provided data
|
||||
* @param uom Unit of measurement, e.g., px
|
||||
* @param data Pointer to data array
|
||||
* @param count Number of data elements
|
||||
* @param context Pointer to user-defined context data
|
||||
* @return Status Packet status
|
||||
*/
|
||||
Status pushAny(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Time &stime, const Time &etime,
|
||||
uint16_t numerator, uint16_t denominator,
|
||||
const std::string &format, const std::string &uom,
|
||||
char *data, size_t count, void *context = nullptr);
|
||||
|
||||
/**
|
||||
* @brief Sends STL string as any record to CAPS
|
||||
* @param net Network code
|
||||
* @param sta Station code
|
||||
* @param loc Location code
|
||||
* @param cha Channel code
|
||||
* @param stime Packet start time
|
||||
* @param etime Packet end time
|
||||
* @param numerator Sampling frequency numerator. Use 1 / 0
|
||||
* for packets without sampling frequency.
|
||||
* @param denominator Sampling frequency denominator
|
||||
* @param format Data format of the provided data
|
||||
* @param uom Unit of measurement, e.g., px
|
||||
* @param data Data as string
|
||||
* @param context Pointer to user-defined context data
|
||||
* @return Status Packet status
|
||||
*/
|
||||
Status pushAny(const std::string &net, const std::string &sta,
|
||||
const std::string &loc, const std::string &cha,
|
||||
const Time &stime, const Time &etime,
|
||||
uint16_t numerator, uint16_t denominator,
|
||||
const std::string &format, const std::string &uom,
|
||||
const std::string &data, void *context = nullptr);
|
||||
#endif
|
||||
|
||||
void flushEncoders();
|
||||
@@ -256,12 +392,51 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
return _packetBuffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the agent string. Allows the server to
|
||||
* identify the application that sends data.
|
||||
* @param agent The agent string
|
||||
* @brief Set host information like agent or total mem
|
||||
* @param info The host info struct
|
||||
*/
|
||||
void setAgent(const std::string &agent);
|
||||
void setHostInfo(const HostInfo &info);
|
||||
|
||||
/**
|
||||
* @brief Set runtime information like CPU load or process memory usage.
|
||||
* This methods blocks until sent.
|
||||
* @param info The runtime info struct
|
||||
*/
|
||||
void setRuntimeInfo(const RuntimeInfo &info);
|
||||
|
||||
/**
|
||||
* @brief Sets the connection ID. If not set, the server generates an ID
|
||||
* during the first connection attempt.
|
||||
* @param id The connection ID string
|
||||
*/
|
||||
void setConnectionID(const std::string &id);
|
||||
|
||||
/**
|
||||
* @brief Set the connection ID file to read the connection ID from
|
||||
* @param filename The filename
|
||||
* @return True if the connection could be read from the given file
|
||||
*/
|
||||
bool setConnectionIDFile(const std::string &filename);
|
||||
|
||||
/**
|
||||
* @brief Returns the connection ID
|
||||
* @return Returns the connection ID
|
||||
*/
|
||||
const std::string &connectionID() const;
|
||||
|
||||
/**
|
||||
* @brief Set function that gets called if the connection to the server
|
||||
* has been established.
|
||||
*/
|
||||
void setConnectedCallback(ConnectedCallback f);
|
||||
|
||||
/**
|
||||
* @brief Set function that gets called if the connection to the server
|
||||
* was disconnected.
|
||||
*/
|
||||
void setDisconnectedCallback(DisconnectedCallback f);
|
||||
|
||||
const char *version() {
|
||||
return LIB_CAPS_VERSION_NAME;
|
||||
@@ -277,13 +452,25 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
*/
|
||||
bool getAPIVersion(int &version);
|
||||
|
||||
/**
|
||||
* @brief Get connection ID from server. If the plugin sends no
|
||||
* connection ID the server generates one.
|
||||
* @return True on success
|
||||
*/
|
||||
bool getConnectionID();
|
||||
|
||||
/**
|
||||
* brief Send runtime information
|
||||
*/
|
||||
void sendRuntimeInfo();
|
||||
|
||||
private:
|
||||
typedef boost::shared_ptr<Encoder> EncoderPtr;
|
||||
|
||||
struct EncoderItem {
|
||||
EncoderItem() : dataType(DT_Unknown) {}
|
||||
EncoderPtr encoder;
|
||||
DataType dataType;
|
||||
EncoderPtr encoder;
|
||||
DataType dataType;
|
||||
};
|
||||
typedef std::map<std::string, EncoderItem> EncoderItems;
|
||||
|
||||
@@ -324,6 +511,8 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
fd_set _readFDs;
|
||||
fd_set _writeFDs;
|
||||
int _sendTimeout;
|
||||
int _readTimeout;
|
||||
int _connectionTimeout;
|
||||
#if !defined(CAPS_FEATURES_JOURNAL) || CAPS_FEATURES_JOURNAL
|
||||
std::string _journalFile;
|
||||
bool _journalDirty;
|
||||
@@ -352,10 +541,17 @@ class SC_GEMPA_CAPS_API Plugin {
|
||||
TimeSpan _maxFutureEndTime;
|
||||
|
||||
bool _dumpPackets;
|
||||
std::string _agent;
|
||||
HostInfo _hostInfo;
|
||||
RuntimeInfo _runtimeInfo;
|
||||
std::string _connectionID;
|
||||
std::string _connectionIDFile;
|
||||
ConnectedCallback _connectedCallback;
|
||||
DisconnectedCallback _disconnectedCallback;
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<Plugin> PluginPtr;
|
||||
|
||||
using PluginPtr = boost::shared_ptr<Plugin>;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user