From 3e4778b576286be1b44a088f70942327bf71920e Mon Sep 17 00:00:00 2001 From: Denis Davydov Date: Fri, 6 Jul 2018 15:38:45 +0300 Subject: [PATCH] Changed the structure of the class Handler (in particular, rewrite the structure of createSession) --- src/kernel/handler.cpp | 24 +++++++++++------------- src/kernel/handler.hpp | 1 + 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/kernel/handler.cpp b/src/kernel/handler.cpp index 6550151..32ce270 100644 --- a/src/kernel/handler.cpp +++ b/src/kernel/handler.cpp @@ -5,7 +5,8 @@ Handler::Handler() using namespace std::placeholders; handlers = { - {"createSession", std::bind(&Handler::createSession, this, _1)} + {"createSession", std::bind(&Handler::createSession, this, _1)}, + {"createSessionSuccess", std::bind(&Handler::createSessionSuccessMethod, this, _1)} }; network = new Network(); connect(network, &Network::json_received, this, &Handler::handle); @@ -21,16 +22,13 @@ void Handler::handle(QJsonObject jsonReceived) void Handler::createSession(QJsonObject jsonReceived) { QJsonObject jsonSend; - if(jsonReceived.contains("status") != true) - { - jsonSend["peerID"] = my_ipv6; - jsonSend["action"] = "createSession"; - jsonSend["status"] = true; - QString peerReceiver = jsonReceived["peerID"].toString(); - network->sendDatagram(jsonSend, peerReceiver); - } - else - { - emit createSessionSuccess(); - } + jsonSend["peerID"] = my_ipv6; + jsonSend["action"] = "createSessionSuccess"; + QString peerReceiver = jsonReceived["peerID"].toString(); + network->sendDatagram(jsonSend, peerReceiver); +} + +void Handler::createSessionSuccessMethod(QJsonObject jsonReceived) +{ + emit createSessionSuccess(); } diff --git a/src/kernel/handler.hpp b/src/kernel/handler.hpp index a16be97..15f380c 100644 --- a/src/kernel/handler.hpp +++ b/src/kernel/handler.hpp @@ -17,6 +17,7 @@ class Handler : public QObject Network *network; void createSession(QJsonObject jsonReceived); std::map> handlers; + void createSessionSuccessMethod(QJsonObject jsonReceived); private slots: void handle(QJsonObject jsonReceived); };