#include "ConfigConnection.h"
#define CBUFFSIZE 4096


ConfigConnection::ConfigConnection(BufferedFile f): Connection<char>::Connection(f) {
	//Connection<char>::Connection();
	file = f;
	init(file,"");
	buffer = new char[CBUFFSIZE+1];
}
ConfigConnection::~ConfigConnection() {
	delete buffer;
}
bool ConfigConnection::isMessage() {
		return file.readReady();
}
Message ConfigConnection::getMessage() {
	int total = read(buffer,CBUFFSIZE);
	buffer[total] = '\0';
	string xml = ""+ string(buffer);
	while (total == CBUFFSIZE) {
		total = read(buffer,CBUFFSIZE);
		xml += buffer;
	}
	return Message(xml);
}
string ConfigConnection::getType() {
	return "config";
}
int ConfigConnection::write(const char * data, int size) {
	return Connection<char>::write(data,size);
}
void ConfigConnection::setType(string type) {};
void ConfigConnection::update() {
	//Why does this exist
	//Foreach connection make the XML and send!
	//vector<Connection<class T> *> * connectionList = Connector.getConnector()->getConnections();
	//vector<Connection<class T> *>::iterator iter;
	//char * str = "<update>";
	//int size = strlen(str);
	//this.write(str,size);
	//for (iter = connectionList->begin(); iter < connectionList->end(); iter++) {
	//	 str = (*iter)->getXML()->c_str();
	//	 size = strlen(str);
	//	 this.write(str,size);
	//}
	//string s = "<time>"+Connector.lastUpdate()+"</time></update>";
	//str = s.c_str();
	//int size = strlen(str);
	//this.write(str,size);
}

