Skip to content
Base_Monitor.h 744 B
Newer Older
Valerio Pastore's avatar
Valerio Pastore committed
/*
 *
 *  Created on: Mar 1, 2021
 *      Author: astrisw
 *
 */

Valerio Pastore's avatar
Valerio Pastore committed
#pragma once
Valerio Pastore's avatar
Valerio Pastore committed
#include <string>
Valerio Pastore's avatar
Valerio Pastore committed
#include <Base_Packet.h>
Valerio Pastore's avatar
Valerio Pastore committed
#include <map>
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
namespace inaf::oasbo::PacketMonitors{
Valerio Pastore's avatar
Valerio Pastore committed
class BasePacketMonitor{
Valerio Pastore's avatar
Valerio Pastore committed
protected:
	std::map<std::string, std::string> stats;
Valerio Pastore's avatar
Valerio Pastore committed
public:
Valerio Pastore's avatar
Valerio Pastore committed
	virtual void monit(PacketLib::BasePacket &) = 0;
Valerio Pastore's avatar
Valerio Pastore committed
	virtual void printStats()=0;
Valerio Pastore's avatar
Valerio Pastore committed
	virtual void reset() = 0;
Valerio Pastore's avatar
Valerio Pastore committed
    virtual std::map<std::string, std::string> getStatsMap() const { return stats;}
    std::optional<std::string> getStat(std::string stat) const {
		try {
			return this->stats.at(stat);
		} catch (const std::out_of_range &) {
			std::cerr << "No stat with name " << stat << std::endl;
			return std::nullopt;
		}
    }

Valerio Pastore's avatar
Valerio Pastore committed
	virtual ~BasePacketMonitor() = default;
Valerio Pastore's avatar
Valerio Pastore committed

Valerio Pastore's avatar
Valerio Pastore committed
};
Valerio Pastore's avatar
Valerio Pastore committed
}