#ifndef OS_TYPES_H
#define OS_TYPES_H

#include "GLCD_types.h"
#include "GR_types.h"
#include "GR_screen.h"


#define M_TASK_NOT_INITIALIZED 0	//Uloha neinicializovana
#define M_TASK_RUNNING 50			//Uloha bezi
#define M_TASK_RESTART 60			//Uloha se restartuje
#define M_TASK_READY 70				//Uloha je pripravena
#define M_TASK_WAITING 80			//Uloha ceka
#define M_TASK_DIALOG_WAITING 90	//Cekani na dialog
#define M_TASK_FAILED 100			//uloha selhala

//Priorita aplikace
typedef enum PRIORITY
{
	IMMEDIATELY = 0,
	MOST = 1,
	HIGHER,
	HIGH,
	NORMAL,
	LOW,
	LOWER,
	LEAST,
}PRIORITY;

//Stav aplikace
typedef enum STATE
{
	RUNNING,
	STOPPED,
}STATE;

//jadro zpravy
typedef enum MESSAGE_CORE
{
	RUN = 10,
	STOP,
	CONFIG,
	WAIT,
	INIT,
	GET_STATE,
	SET_MASK,
	SET_NUMERIC_MODE,
	APP_CLICK,
	FORCE_REFRESH,
	GET_RESULT,

}MESSAGE_CORE;

//Struktura reprezentujici zpravu
typedef struct MESSAGE
{
	MESSAGE_CORE msg;	//zpprava
	void* data;			//ukazatel na data
}MESSAGE;

//Typ ulohy
typedef enum TASK_TYPE
{
	RUN_ONCE,
	RUN_FOREVER,
}TASK_TYPE;


//Vysledek aplikace
typedef enum RESULT
{
	PASSED,
	FAILED,
}RESULT;

//ID aplikace
typedef enum TASK_NAME
{
	NONE,
	OS_MONITOR,
	KEYBOARD,
	MAIN_MENU,
	STATUS_BAR,
	CONSOLE,
	DESKTOP,
	DIALOG,
	SPECIALS,
	NET_SETUP,
	NETWORK_NAMES,
	CONNECTOR,
	DRV_WIFI,
	ABOUT,
	TIME_SETUP,
	SERIAL_SETUP,
	BACKLIGHT_SETUP,
	DRV_SERIAL,
}TASK_NAME;


//Casova znamka
typedef unsigned long TIME_STAMP;

//Stav kurzoru
typedef struct CURSOR_STATE
{
	ANSWER active;
	ANSWER blink;
	ANSWER changed;
}CURSOR_STATE;


class TApplicationInternal
{
private:
	TIME_STAMP CursorStamp;				//Casova znamka aplikace
	ANSWER dialogShown;					//Otazka, jestli je zobrazen dialog
	char oldState;						//minuly stav
	CURSOR_STATE Cursor;				//Kurzor
public:
	char State;							//Stav aplikace
	TRect Area;							//Oblast aplikace
	TASK_NAME Name;						//Jmeno aplikace
	TASK_NAME WaitForTask;				//Uloha, na kterou se ceka
	POSITION ClickPosition;				//Pozice kliknuti
	ANSWER StatusBar;					//pouziva aplikace status bar
	TScreen *Screen;					//Obrazovka aplikace
	RESULT RegisterArea(void);			//Registruje oblast aplikace
	RESULT UnregisterArea(void);		//Odregistruje oblast aplikace
	int (*translateClickPosition)(POSITION*);//prekladac kliknuti
	RESULT RunApplication(TASK_NAME task);//spusti aplikaci
	//konstruktory
	TApplicationInternal(TASK_NAME name, int xa, int ya, int xc, int yc, TScreen* AppScreen, int(*ClickTranslator)(POSITION*));
	TApplicationInternal(TASK_NAME name, int xa, int ya, int xc, int yc, TScreen* AppScreen, int(*ClickTranslator)(POSITION*), ANSWER useStatusBar);
	TApplicationInternal(void){};
	//Inicializace struktury (nahrada konstruktoru)
	void Init(TASK_NAME name, int xa, int ya, int xc, int yc, TScreen* AppScreen, int(*ClickTranslator)(POSITION*), ANSWER useStatusBar);
	void SetCursor(ANSWER active, ANSWER blink);//nastaveni kurzoru
	RESULT Startup(void);				//Spusteni aplikace
	TASK_NAME TryToResume(void);		//POkus o obnoveni aplikace
	int ProceedClick(void);				//zpracovani kliknuti
	void ProceedCursor(void);			//zpracovani kurzoru
	void Stop(void);					//Zastaveni aplikace
	ANSWER GetAnswer(char *text);		//Ziskani odpovedi
	void WaitForDialogStop(void);		//Cekani na ukonceni dialogu
};






extern MESSAGE DEFAULT_MSG_RUN;
extern MESSAGE DEFAULT_MSG_STOP;
extern MESSAGE DEFAULT_MSG_INIT;
extern MESSAGE DEFAULT_MSG_GET_STATE;
extern MESSAGE DEFAULT_MSG_WAIT;
extern MESSAGE DEFAULT_MSG_NUMERIC_ONLY;
extern MESSAGE DEFAULT_MSG_SET_MASK;
extern MESSAGE DEFAULT_MSG_REFRESH;
extern MESSAGE DEFAULT_MSG_GET_RESULT; 
#endif