#include "ConfigConnection.h"
/**
 * The Buffer size for the ConfigConnection
 */
#define CBUFFSIZE 4096


ConfigConnection::ConfigConnection(BufferedFile * f): Connection<char>::Connection() {
	//Connection<char>::Connection();
	init(f,string(""));
	buffer = new char[CBUFFSIZE+1];
}
bool ConfigConnection::readReady() {
	return file->readReady();
}
bool ConfigConnection::writeReady() {
	return file->writeReady();
}
int ConfigConnection::getFileHandle() {
	return file->getFileHandle();
}
ConfigConnection::~ConfigConnection() {
	delete [] buffer;
}
bool ConfigConnection::isMessage() {
	return this->readReady();
}
Message * ConfigConnection::getMessage() {
	int total = this->read(buffer,CBUFFSIZE);
	if (total <= 0) {
		disconnect();
		throw new string("Connection Closed");
	}
	buffer[total] = '\0';
	string xml = ""+ string(buffer);
	while (total == CBUFFSIZE) {
		total = this->read(buffer,CBUFFSIZE);
		xml += buffer;
	}
	return new 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);
}
