/*----- PROTECTED REGION ID(TestDevice.h) ENABLED START -----*/
//=============================================================================
//
// file :        TestDevice.h
//
// description : Include for the TestDevice class.
//
// $Author: graziano $
//
//
//=============================================================================
//                This file is generated by POGO
//        (Program Obviously used to Generate tango Object)
//=============================================================================


#ifndef TestDevice_H
#define TestDevice_H


#include <tango/tango.h>

#define MAX_ATTR_SIZE 3000
#define MAX_SPECTRUM_SIZE	100

#ifndef TANGO_LOG
#define TANGO_LOG cout
#endif
#ifndef TANGO_LOG_INFO
#define TANGO_LOG_INFO cout2
#endif
#ifndef TANGO_LOG_DEBUG
#define TANGO_LOG_DEBUG cout4
#endif

/*----- PROTECTED REGION END -----*/


/**
 *	TestDevice class Description:
 *	
 */

namespace TestDevice_ns
{
	/*----- PROTECTED REGION ID(TestDevice::Additional Class Declarations) ENABLED START -----*/
    using namespace std;

	//		Additional Class Declarations
typedef struct {
	void *value;			//pointer to values
	unsigned int size1;		//actual size of dimension 1
	unsigned int size2;		//actual size of dimension 2
	unsigned int max1;		//max size of dimension 1
	unsigned int max2;		//max size of dimension 2
	long type;				//data type
	unsigned char cmd_attr_type;	//if data for attribute or for command
	struct timeval ts;
} map_data_t;

enum { typeDouble, typeLong, typeBool, typeString, typeUchar};
	/*----- PROTECTED REGION END -----*/	//	TestDevice::Additional Class Declarations


class TestDevice : public TANGO_BASE_CLASS
{
	friend class CmdClass;
	/*----- PROTECTED REGION ID(TestDevice::Data Members) ENABLED START -----*/

	//		Add your own data members
protected:

	map<std::string,map_data_t> attr_data_map;

    void string_explode(string, string, vector<string>*);
    void save_configuration();
    void create_dynamic_attribute(vector<string> config);
    long create_dynamic_command(const char* cmd_name, Tango::CmdArgType type_in, Tango::CmdArgType type_out, long size_in, long size_out);

    template <typename Attr_type> void set_write_value(Attr_type *value, string attrname, long x = 1);
    void set_write_value(Tango::DevString value, string attrname);

    timeval last_read;
    int numAttr;
    char ref_array[1024][256];
	double dlastDB;
	bool waitingDB;
    //Tango::DevString ref_ptr[1024];

	/*----- PROTECTED REGION END -----*/	//	TestDevice::Data Members


//	Device property data members
public:
	//	Attr_config:	
	vector<string>	attr_config;
	//	MinSaveDBPeriod:
	Tango::DevLong	minSaveDBPeriod;
	

//	Attribute data members
public:
	Tango::DevString	*attr_ScalarDyn_read;
	Tango::DevString	attr_ScalarDyn_write;
	Tango::DevDouble	*attr_Ref_read;
	Tango::DevString	*attr_Values_read;


//	Constructors and destructors
public:
	/**
	 * Constructs a newly allocated Command object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	TestDevice(Tango::DeviceClass *cl,string &s);
	/**
	 * Constructs a newly allocated Command object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device Name
	 */
	TestDevice(Tango::DeviceClass *cl,const char *s);
	/**
	 * Constructs a newly allocated Command object.
	 *
	 *	@param cl	Class.
	 *	@param s 	Device name
	 *	@param d	Device description.
	 */
	TestDevice(Tango::DeviceClass *cl,const char *s,const char *d);
	/**
	 * The object destructor.
	 */	
	~TestDevice() {delete_device();};



//	Miscellaneous methods
public:
	/**
	 *	will be called at device destruction or at init command.
	 */
	void delete_device();
	/**
	 *	Initialize the device
	 */
	virtual void init_device();
	/**
	 *	Read the device properties from database
	 */
	 void get_device_property();
	/**
	 *	Always executed method before execution command method.
	 */
	virtual void always_executed_hook();


//	Attribute methods
public:
	/**
	 *	Method      : TestDevice::read_attr_hardware()
	 *	Description : Hardware acquisition for attributes.
	 */
	virtual void read_attr_hardware(vector<long> &attr_list);



	/**
	 *	ScalarDyn attribute related methods.
	 *	Description:
	 *
	 *	Data type:	Tango::DevString
	 *	Attr type:	Scalar
	 */
	virtual void read_ScalarDyn(Tango::Attribute &attr);
	virtual void write_ScalarDyn(Tango::WAttribute &attr);
	virtual bool is_ScalarDyn_allowed(Tango::AttReqType type);


	/**
	 *	SpectrumDyn attribute related methods.
	 *	Description:
	 *
	 *	Data type:	Tango::DevString
	 *	Attr type:	Spectrum
	 */
	virtual void read_SpectrumDyn(Tango::Attribute &attr);
	virtual void write_SpectrumDyn(Tango::WAttribute &attr);
	virtual bool is_SpectrumDyn_allowed(Tango::AttReqType type);


	/**
	 *	Ref attribute related methods.
	 *	Description:
	 *
	 *	Data type:	Tango::DevDouble
	 *	Attr type:	Spectrum
	 */
	virtual void read_Ref(Tango::Attribute &attr);
	virtual void write_Ref(Tango::WAttribute &attr);
	virtual bool is_Ref_allowed(Tango::AttReqType type);



	/**
	 *	Values attribute related methods.
	 *	Description:
	 *
	 *	Data type:	Tango::DevString
	 *	Attr type:	Spectrum
	 */
	virtual void read_Values(Tango::Attribute &attr);
	virtual void write_Values(Tango::WAttribute &attr);
	virtual bool is_Values_allowed(Tango::AttReqType type);



	/**
	 *	Method      : TestDevice::add_dynamic_attributes()
	 *	Description : Add dynamic attributes if any.
	 */
		void add_dynamic_attributes();

//	Command related methods
public: 


		/**
		 *	Command WriteAttrname related methods.
		 */
		void write_attrname(const Tango::DevVarDoubleStringArray *);
		virtual bool is_WriteAttrname_allowed(const CORBA::Any &any);

		/**
		 *	Command ReadAttrname related methods.
		 */
		Tango::DevVarDoubleArray *read_attrname(const Tango::DevVarStringArray *);
		virtual bool is_ReadAttrname_allowed(const CORBA::Any &any);

		/**
		 *	Command Config related methods.
		 */
		void config(const Tango::DevVarStringArray *);
		virtual bool is_Config_allowed(const CORBA::Any &any);

		/**
		 *	Command Add related methods.
		 */
		void add(const Tango::DevVarStringArray *);
		virtual bool is_Add_allowed(const CORBA::Any &any);

		/**
		 *	Command AddDouble related methods.
		 */
		void add_double(const Tango::DevVarStringArray *);
		virtual bool is_AddDouble_allowed(const CORBA::Any &any);

		/**
		 *	Command AddLong related methods.
		 */
		void add_long(const Tango::DevVarStringArray *);
		virtual bool is_AddLong_allowed(const CORBA::Any &any);

		/**
		 *	Command AddBool related methods.
		 */
		void add_bool(const Tango::DevVarStringArray *);
		virtual bool is_AddBool_allowed(const CORBA::Any &any);

		/**
		 *	Command AddString related methods.
		 */
		void add_string(const Tango::DevVarStringArray *);
		virtual bool is_AddString_allowed(const CORBA::Any &any);

		/**
		 *	Command Remove related methods.
		 */
		void remove(const Tango::DevVarStringArray *);
		virtual bool is_Remove_allowed(const CORBA::Any &any);



	/*----- PROTECTED REGION ID(TestDevice::Additional Method prototypes) ENABLED START -----*/

	//	Additional Method prototypes

	/*----- PROTECTED REGION END -----*/	//	TestDevice::Additional Method prototypes

};

	/*----- PROTECTED REGION ID(TestDevice::Additional Classes Definitions) ENABLED START -----*/

	//	Additional Classes definitions
class CmdClass : public Tango::Command
{
public:
	CmdClass(const char   *name,
	               Tango::CmdArgType in,
				   Tango::CmdArgType out,
				   const char        *in_desc,
				   const char        *out_desc,
				   Tango::DispLevel  level,
				   int size_in,
				   Tango::DeviceImpl *dev)
	:Command(name,in,out,in_desc,out_desc, level)	{_max_in=size_in; mydevice=(TestDevice *)dev;};

	CmdClass(const char   *name,
	               Tango::CmdArgType in,
				   Tango::CmdArgType out,
				   int size_in,
				   Tango::DeviceImpl *dev)
	:Command(name,in,out)	{_max_in=size_in; mydevice=(TestDevice *)dev;};
	~CmdClass() {};

	virtual CORBA::Any *execute (Tango::DeviceImpl *dev, const CORBA::Any &any);
	virtual bool is_allowed (Tango::DeviceImpl *dev, const CORBA::Any &any)
	{return true/*(static_cast<TangoLib *>(dev))->is_Cmd_allowed(any)*/;}

	int _max_in;
	TestDevice *mydevice;
};

	/*----- PROTECTED REGION END -----*/	//	TestDevice::Additional Classes Definitions

} //	namespace

#endif	//	TestDevice_H