/* Web Polygraph       http://www.web-polygraph.org/
 * (C) 2003-2006 The Measurement Factory
 * Licensed under the Apache License, Version 2.0 */

#ifndef POLYGRAPH__BASE_SSLINTVLSTAT_H
#define POLYGRAPH__BASE_SSLINTVLSTAT_H

#include "base/HRStat.h"
#include "base/LevelStat.h"

// interval statistics for SSL
class SslIntvlStat {
	public:
		SslIntvlStat();

		void restart();
		void keepLevel(const SslIntvlStat &s);

		bool active() const;
		bool sane() const;

		double reqRate(Time duration) const;
		double repRate(Time duration) const;

		inline const HRStat &doneXacts() const;
		inline const LevelStat &xactLevel() const;
		inline const LevelStat &connLevel() const;
		inline int errXacts() const;

		inline HRStat &doneXacts();
		inline LevelStat &xactLevel();
		inline LevelStat &connLevel();
		inline void recordXactError();

		void merge(const SslIntvlStat &s);
		void concat(const SslIntvlStat &s);

		OLog &store(OLog &log) const;
		ILog &load(ILog &log);

		ostream &print(ostream &os, const String &pfx, Time duration) const;

	protected:
		void join(const SslIntvlStat &s);

	protected:
		HRStat theDoneXacts;    // successful SSL transactions (aggr)
		LevelStat theXactLvl;   // successful SSL transactions (level)
		LevelStat theConnLvl;   // open SSL connections (level)
		int theErrXacts;        // not successful SSL transactions (count)
};


inline OLog &operator <<(OLog &ol, const SslIntvlStat &s) { return s.store(ol); }
inline ILog &operator >>(ILog &il, SslIntvlStat &s) { return s.load(il); }

inline
const HRStat &SslIntvlStat::doneXacts() const {
	return theDoneXacts;
}

inline
const LevelStat &SslIntvlStat::xactLevel() const {
	return theXactLvl;
}

inline
const LevelStat &SslIntvlStat::connLevel() const {
	return theConnLvl;
}


inline
HRStat &SslIntvlStat::doneXacts() {
	return theDoneXacts;
}

inline
LevelStat &SslIntvlStat::xactLevel() {
	return theXactLvl;
}

inline
LevelStat &SslIntvlStat::connLevel() {
	return theConnLvl;
}

inline
void SslIntvlStat::recordXactError() {
	++theErrXacts;
}

inline
int SslIntvlStat::errXacts() const {
	return theErrXacts;
}

#endif


syntax highlighted by Code2HTML, v. 0.9.1