You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.0 KiB
C++

/***************************************************************************
* Copyright (C) 2013 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_SESSIONTABLE_H
#define GEMPA_CAPS_SESSIONTABLE_H
#include "packet.h"
#include <map>
#include <string>
#include <functional>
namespace Gempa {
namespace CAPS {
struct SessionTableItem {
SessionTableItem() : samplingFrequency(0), samplingFrequencyDivider(0),
fSamplingFrequency(0.0), dataType(DT_Unknown),
dataSize(0), userData(NULL) {}
std::string streamID;
std::string net;
std::string sta;
std::string loc;
std::string cha;
uint16_t samplingFrequency;
uint16_t samplingFrequencyDivider;
double fSamplingFrequency;
PacketType type;
DataType dataType;
int dataSize;
UOM uom;
Time startTime;
Time endTime;
void *userData;
bool splitStreamID();
};
class SC_GEMPA_CAPS_API SessionTable : public std::map<int, SessionTableItem> {
public:
enum Status {Success, Error, EOD};
typedef std::function<void (SessionTableItem*)> CallbackFunc;
public:
//! Default constructor
SessionTable();
virtual ~SessionTable() {}
//! Resets state
void reset();
SessionTableItem* getItem(int id) {
SessionTable::iterator it = find(id);
if ( it == end() ) return NULL;
return &it->second;
}
Status handleResponse(const char *src_data, int data_len);
void setItemAddedFunc(const CallbackFunc &func) { _itemAddedFunc = func; }
void setItemAboutToBeRemovedFunc(const CallbackFunc &func) {
_itemAboutToBeRemovedFunc = func;
}
private:
enum ResponseState {
Unspecific,
Requests
};
typedef std::map<std::string, int> StreamIDLookupTable;
private:
void registerItem(int id, SessionTableItem &item);
void removeStream(const std::string & streamID);
private:
ResponseState _state;
StreamIDLookupTable _streamIDLookup;
CallbackFunc _itemAddedFunc;
CallbackFunc _itemAboutToBeRemovedFunc;
};
}
}
#endif