From 8c4bdbe3ae37b826f388ae4700d66517467c0a28 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Mon, 10 Feb 2014 00:06:34 +0100 Subject: [PATCH] fixed snore frontend --- src/core/plugins/snorefrontend.h | 4 +-- .../frontends/snarlnetwork/snarlnetwork.cpp | 31 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/core/plugins/snorefrontend.h b/src/core/plugins/snorefrontend.h index cb19527..ece3c7a 100644 --- a/src/core/plugins/snorefrontend.h +++ b/src/core/plugins/snorefrontend.h @@ -39,8 +39,8 @@ class SNORE_EXPORT SnoreFrontend:public SnorePlugin public: SnoreFrontend ( const QString &name); virtual ~SnoreFrontend(); - virtual void actionInvoked( Snore::Notification notification )=0; - virtual void notificationClosed( Snore::Notification notification )=0; + virtual void actionInvoked( Snore::Notification notification ) = 0; + virtual void notificationClosed( Snore::Notification notification ) = 0; }; } diff --git a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp index 0dee1fa..a96ea3e 100644 --- a/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/frontends/snarlnetwork/snarlnetwork.cpp @@ -39,12 +39,13 @@ SnarlNetworkFrontend::SnarlNetworkFrontend(): SnarlNetworkFrontend::~SnarlNetworkFrontend(){ } -bool SnarlNetworkFrontend::initialize(SnoreCore *snore){ +bool SnarlNetworkFrontend::initialize(SnoreCore *snore) +{ parser = new Parser(this); tcpServer = new QTcpServer(this); if(!tcpServer->listen(QHostAddress::Any,port)) { - snoreDebug( SNORE_DEBUG )<<"The port is already used"; + snoreDebug( SNORE_DEBUG ) << "The port is already used"; return false; } else @@ -72,25 +73,23 @@ bool SnarlNetworkFrontend::deinitialize() void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification) { - //TODO:fix callback - if(notification.actionInvoked().id() == 1 ) - { - callback(notification,"SNP/1.1/304/Notification acknowledged/"); - } - else if(notification.actionInvoked().id() == 2) - { - callback(notification,"SNP/1.1/302/Notification cancelled/"); - } + snoreDebug( SNORE_DEBUG ) << notification.closeReason(); + callback(notification,"SNP/1.1/304/Notification acknowledged/"); } + void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification) { - if(notification.closeReason() == Notification::TIMED_OUT) + switch(notification.closeReason()) { + case Notification::TIMED_OUT: callback(notification, "SNP/1.1/303/Notification timed out/"); - } - else - { + break; + case Notification::CLOSED: callback(notification, "SNP/1.1/307/Notification closed/"); + break; + case Notification::DISMISSED: + callback(notification,"SNP/1.1/302/Notification cancelled/"); + break; } } @@ -129,7 +128,7 @@ void SnarlNetworkFrontend::handleMessages() void SnarlNetworkFrontend::callback(Notification &sn, const QString msg) { - QTcpSocket *client = (QTcpSocket*)qvariant_cast(sn.hints().privateValue(this, "clientSocket")); + QTcpSocket *client = (QTcpSocket*)qvariant_cast(sn.hints().privateValue(this, "clientSocket")); if(client && !msg.isEmpty()) { write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id())));