#ifndef CDUTILS_K_H
#define CDUTILS_K_H

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


namespace CDUtils {

class CDCore;


class KInterface: public PIObject
{
	PIOBJECT(CDUtils::KInterface)
public:
	KInterface();

	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 k_file;}
	int fileSize() const {return k_file_size;}

	EVENT(sended)
	EVENT(sendFailed)
	EVENT(received)
	EVENT(receiveFailed)
	EVENT1(keepNamesRequest, bool*, kn)
	EVENT_HANDLER(void, send);
	EVENT_HANDLER(void, request);
	void setFileName(const PIString & file) {k_file = file;}
	bool configure(const PIString & config, const PIString & sect = PIStringAscii("k"));
	void reinitConnection(const PIString & configuration);
	void startPing();
	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();

private:
	CDCore * core;
	PIString k_file;
	int k_file_size;

};


}

extern CDUtils::KInterface K;

#endif // CDUTILS_K_H
