#ifndef CDUTILS_INTERFACE_H
#define CDUTILS_INTERFACE_H

#include "cdutils_types.h"
#include "piobject.h"


namespace CDUtils {

class CDCore;


class Interface: public PIObject
{
	PIOBJECT(CDUtils::Interface)
public:
	Interface(CDType::cdT type_);

	bool test(int v);
	CDType & operator [](int v);
	const CDType operator [](int v) const;
	CDType & operator [](const PIString & name_);
	const CDType operator [](const PIString & name_) const;
	CDType & operator [](const PIDeque<int> & path_);
	const CDType operator [](const PIDeque<int> & path_) const;
	CDSection & section(int v);
	const CDSection section(int v) const;
	CDSection & section(const PIDeque<int> & path);
	CDSection & root();
	const CDSection & root() const;

	int count(bool recursive = true) const;
	const PIString file() const {return file_;}
	int fileSize() const {return file_size;}
	CDType::cdT cdType() const {return type;}
	bool exists(PIDeque<int> path) const;

	void setFileName(const PIString & _file);
	bool configure(const PIString & config);
	void reinitConnection(const PIString & configuration);
	void releaseConnection();
	void write(PIIODevice * d);
	void read(PIIODevice * d);
	void parse(PIIODevice * d);
	void update(PIIODevice * d, UpdateModeFlags mode = SaveByName);
	void calculate();

	PIString appConfig();
	PIString pultConfig();

	void readFile();
	void writeFile();
	bool inProgress();

	EVENT(sended)
	EVENT(sendFailed)
	EVENT(received)
	EVENT(receiveFailed)
	EVENT(changedGlobal)
	EVENT_HANDLER(void, send);
	EVENT_HANDLER(void, request);

protected:
	CDCore * core;
	CDSection * s;
	CDType::cdT type;
	PIString file_;
	int file_size;

};


}


#endif // CDUTILS_INTERFACE_H
