69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
#include "TCPSession.h"
|
|
#include "Exception.h"
|
|
#include "Log.h"
|
|
#include "TCPServer.h"
|
|
#include "uuid/uuid.h"
|
|
|
|
namespace core
|
|
{
|
|
|
|
TCPSession::TCPSession(EPoll &ePoll, TCPServer &server, std::string text) : TCPSocket(ePoll, server.ctx, text), server(server) {
|
|
uuid_t uuidObject;
|
|
uuid_generate(uuidObject);
|
|
coreutils::Log(coreutils::LOG_DEBUG_1) << uuidObject;
|
|
alias = (void *)uuidObject;
|
|
}
|
|
|
|
TCPSession::~TCPSession() {
|
|
server.removeFromSessionList(this);
|
|
server.subscriptions.removeSessionSubscriptions(*this);
|
|
}
|
|
|
|
void TCPSession::output(std::stringstream &data) {
|
|
data << "|" << ipAddress.getClientAddressAndPort();
|
|
}
|
|
|
|
void TCPSession::protocol(coreutils::ZString &data) {
|
|
if (data.getLength() != 0) {
|
|
if (!server.commands.processRequest(data, *this)) {
|
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Received data could not be parsed: " << data.str();
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TCPSession::compareAlias(void *alias) {
|
|
return this->alias = alias;
|
|
}
|
|
|
|
void TCPSession::outputAlias(std::stringstream &out) {
|
|
out << alias;
|
|
}
|
|
|
|
void TCPSession::onRegistered() {
|
|
onConnected();
|
|
send();
|
|
if (term)
|
|
shutdown("termination requested");
|
|
}
|
|
|
|
void TCPSession::onConnected() {}
|
|
|
|
void TCPSession::onLineReceived(coreutils::ZString &line) {
|
|
protocol(line);
|
|
send();
|
|
if (term)
|
|
shutdown("termination requested");
|
|
}
|
|
|
|
void TCPSession::send() {
|
|
if(out.tellp() > 0)
|
|
write(out.str());
|
|
out.str("");
|
|
}
|
|
|
|
void TCPSession::terminate() {
|
|
term = true;
|
|
}
|
|
|
|
}
|