/* 
 * Thomas Pantzer: t_runtime_obj.h, v0.4.7  8.6.99 16:32 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */



#ifndef _T_RUNTIME_OBJ_H
#define _T_RUNTIME_OBJ_H

#include "forms.h"

#include "khepera.h"
#include "xdemo.h"

#define _s_started    	0
#define _s_running    	1
#define _s_halted     	2
#define _s_cleared    	3
#define _s_undefined	4
#define _s_paused	5


#define _p_calc		(1 << 0)       //  does something to control the robot
#define _p_control	(1 << 1)       //  needs calculations
#define _p_show		(1 << 2)       //  has a method to show something in graphic window
#define _p_extras	(1 << 3)       //  uses user settable parameters
#define _p_logctl	(1 << 4)       //  customize logging

#define _bt_load	0
#define _bt_save	1
#define _bt_reset	2
#define _bt_pause	3

#define _sl_logival	0
#define _sl_logavg	1

#define _bt_num		4		// default checkboxes
#define _sl_num		2		// 	   sliders	
#define _ch_num		0		// no default choices


#ifndef MAX_RUNTIME_OBJS
#define MAX_RUNTIME_OBJS 12
#endif


typedef struct {
		int fd,step,wival;
		double average;
	        char data[4096];
	       } t_logrec;	 	
		


class t_runtime_object {
public:
	char Name[256];
	int id;
	
	char active_ctl, active_calc;
//, pre_state, paused, _niced;

	char   visible ,state, props;
	unsigned long cntl_age, calc_age;
	RobotContext *Robot;
	

	virtual void Init(char *name, RobotContext *robot);
	virtual void Init(char *name, RobotContext *robot,
				int ps,int nsld,int nbox,int nchc,
				char **sldn,char **boxn,char **chnam);

	virtual void Done(void);

// spezific methods (have to be overloaded)
	virtual char calculate_module(char allow_learn, char any_new);
	virtual char control_module(void);
	virtual char start_module(void);
	virtual char stop_module(void);
	virtual void pause_module(char);

	virtual void make_logdata(void);
	virtual void make_logstring(void);
	

	virtual void Show(void);
	virtual void Reset(void);
	virtual void Save(int fd);
	virtual void Load(char *to_parse);

// Xforms methods
	virtual void button_cb(FL_OBJECT *ob,long data);
	virtual void slider_cb(FL_OBJECT *ob,long data);
	virtual void choice_cb(FL_OBJECT *ob,long data);

	virtual void Interactions(char show);

// readonly:
	FD_demo *fd_demo;
	int nsliders;

// protected:
	int ncboxes, nchoices;

	char **SliderName;
	char **BoxName;
	char **ChoiceName;

	t_logrec Logs;
	int openfile(char *envvar, char *rcpath, char *type, char *Name, char load);

//	int *sl_prec;
};





class t_runtime_root {
public:
	t_runtime_object *RunObj[MAX_RUNTIME_OBJS];
	char state;
	int number;

	void Init(void);
	void Add(t_runtime_object *o);
	void Remove(t_runtime_object *o);
	void Done(void);

// general runtime methods
	int Execute_Calc(char Do, char allow_learn, char any_new);
	int Execute_Cntl(char Do,char Pause);
	void Show(void);

	void do_slider(FL_OBJECT *ob, long data);
	void do_button(FL_OBJECT *ob, long data);
	void do_choice(FL_OBJECT *ob, long data);

	char **find_slidername(FL_OBJECT *ob, int &ron);

	char NeedCanvas(void);


private:
	int calculate(char allow_learn, char any_new);
	int control(void);
	void pause(char);
	void start(void);
	void stop(void);

};












#ifdef _T_RUNTIME_OBJ_G
#define m_extern
#else 
#define m_extern extern
#endif

// extern accessible vars


#undef m_extern

#endif







/**/
/**/
/**/
/**/
/**/
/**/
/**/
/**/
/*****  End Of File  ****************************/
