#ifndef IMAGERHANDLER_H_
#define IMAGERHANDLER_H_

//#define COMMON_EXCEPTIONS // comment this line after releasing project and adding MyExceptions.h to project

#include <Windows.h>
#include <IRImager.h>

#ifdef COMMON_EXCEPTIONS
#include "..\..\MyExceptions.h"
#else
#include "MyExceptions.h"
#endif

namespace PIseries {


	/**
	* @class ImagerHandler
	* @brief ImagerHandler for acquiring data, IRImager
	* libirimager is used from url:
	* http://documentation.evocortex.com/libirimager2/html/index.html
	* @author Matej Roman (student of BUT)
	*/
	class ImagerHandler : public evo::IRImagerClient
	{
	public:

		/////////////////////////////////// Constructors ///////////////////////////////

		/**
		* Standard constructor
		*/
		ImagerHandler(): 
			_irImager(NULL), 
			_isIrImagerSet(false),
			_isInit(false),
			_rawDataBuffer(0),
			_hData(NULL)
		{}

		/**
		* Standard constructor with a parameter 
		*/
		ImagerHandler(evo::IRImager* irImager);


		/////////////////////////////////// Methods ///////////////////////////////////

		/**
		* Method loading address where thermal data will be inserted during streaming
		* After that method ImagerHandler will be initialized
		* @param[in] *data is address from class abstract VideoCapture where the data from camera will be saved
		*/
		bool LoadDataHandler(unsigned short** data);

		/**
		* Callback method when thermal data is received. From IRImagerClient class
		*/
		virtual void onThermalFrame(unsigned short* data, unsigned int w, unsigned int h, evo::IRFrameMetadata meta, void* arg);

		/**
		* Callback method when thermal data is received. From IRImagerClient class
		*/
		virtual void onRawFrame(unsigned char* data, int size);

		/**
		* Callback method for flag state events. The method is called when the flag state changes.
		*/
		virtual void onFlagStateChange(evo::EnumFlagState fs, void* arg) {};

		/////////////////////////////////// Setters ///////////////////////////////////

		/**
		* Set IRImager
		*/
		void setIRImager(evo::IRImager* irImager);

		/////////////////////////////////// Getters ///////////////////////////////////

		bool isInitIrimager() { return _isInit; }

	private:

		bool _isIrImagerSet;
		bool _isInit;

		unsigned int _rawDataBuffer;

		unsigned short** _hData;

		evo::IRImager* _irImager;

		template <typename T>
		BOOL _isValid(T* data);

		BOOL _setirImager(evo::IRImager** irImager);

	};

}

#endif
