mirror of
https://github.com/ChronosX88/Influence-cjdns.git
synced 2024-11-08 08:51:00 +00:00
Changed the structure of the Handler class, for convenient addition of new methods.
This commit is contained in:
parent
c82cf387f1
commit
1d68c85c0e
@ -8,18 +8,29 @@ Handler::Handler()
|
||||
|
||||
|
||||
void Handler::handle(QJsonObject jsonReceived)
|
||||
{
|
||||
using namespace std::placeholders;
|
||||
std::map<QString, std::function<void(QJsonObject)>> handlers = {
|
||||
{"createSession", std::bind(&Handler::createSession, this, _1)}
|
||||
};
|
||||
|
||||
QString action = jsonReceived["action"].toString();
|
||||
handlers[action](jsonReceived);
|
||||
}
|
||||
|
||||
void Handler::createSession(QJsonObject jsonReceived)
|
||||
{
|
||||
QJsonObject jsonSend;
|
||||
if(jsonReceived["action"] == "createSession" && !jsonReceived.contains("status"))
|
||||
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
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
emit createSessionSuccess();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class Handler : public QObject
|
||||
void createSessionSuccess();
|
||||
private:
|
||||
Network *network;
|
||||
void createSession(QJsonObject jsonReceived);
|
||||
private slots:
|
||||
void handle(QJsonObject jsonReceived);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user