fixed snore frontend
This commit is contained in:
parent
f6331884c5
commit
8c4bdbe3ae
|
@ -39,8 +39,8 @@ class SNORE_EXPORT SnoreFrontend:public SnorePlugin
|
||||||
public:
|
public:
|
||||||
SnoreFrontend ( const QString &name);
|
SnoreFrontend ( const QString &name);
|
||||||
virtual ~SnoreFrontend();
|
virtual ~SnoreFrontend();
|
||||||
virtual void actionInvoked( Snore::Notification notification )=0;
|
virtual void actionInvoked( Snore::Notification notification ) = 0;
|
||||||
virtual void notificationClosed( Snore::Notification notification )=0;
|
virtual void notificationClosed( Snore::Notification notification ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,12 +39,13 @@ SnarlNetworkFrontend::SnarlNetworkFrontend():
|
||||||
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
|
SnarlNetworkFrontend::~SnarlNetworkFrontend(){
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SnarlNetworkFrontend::initialize(SnoreCore *snore){
|
bool SnarlNetworkFrontend::initialize(SnoreCore *snore)
|
||||||
|
{
|
||||||
parser = new Parser(this);
|
parser = new Parser(this);
|
||||||
tcpServer = new QTcpServer(this);
|
tcpServer = new QTcpServer(this);
|
||||||
if(!tcpServer->listen(QHostAddress::Any,port))
|
if(!tcpServer->listen(QHostAddress::Any,port))
|
||||||
{
|
{
|
||||||
snoreDebug( SNORE_DEBUG )<<"The port is already used";
|
snoreDebug( SNORE_DEBUG ) << "The port is already used";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -72,25 +73,23 @@ bool SnarlNetworkFrontend::deinitialize()
|
||||||
|
|
||||||
void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
|
void SnarlNetworkFrontend::actionInvoked(Snore::Notification notification)
|
||||||
{
|
{
|
||||||
//TODO:fix callback
|
snoreDebug( SNORE_DEBUG ) << notification.closeReason();
|
||||||
if(notification.actionInvoked().id() == 1 )
|
callback(notification,"SNP/1.1/304/Notification acknowledged/");
|
||||||
{
|
|
||||||
callback(notification,"SNP/1.1/304/Notification acknowledged/");
|
|
||||||
}
|
|
||||||
else if(notification.actionInvoked().id() == 2)
|
|
||||||
{
|
|
||||||
callback(notification,"SNP/1.1/302/Notification cancelled/");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SnarlNetworkFrontend::notificationClosed(Snore::Notification notification)
|
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/");
|
callback(notification, "SNP/1.1/303/Notification timed out/");
|
||||||
}
|
break;
|
||||||
else
|
case Notification::CLOSED:
|
||||||
{
|
|
||||||
callback(notification, "SNP/1.1/307/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)
|
void SnarlNetworkFrontend::callback(Notification &sn, const QString msg)
|
||||||
{
|
{
|
||||||
QTcpSocket *client = (QTcpSocket*)qvariant_cast<void*>(sn.hints().privateValue(this, "clientSocket"));
|
QTcpSocket *client = (QTcpSocket*)qvariant_cast<QObject*>(sn.hints().privateValue(this, "clientSocket"));
|
||||||
if(client && !msg.isEmpty())
|
if(client && !msg.isEmpty())
|
||||||
{
|
{
|
||||||
write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id())));
|
write(client, QString("%1%2\r\n").arg(msg, QString::number(sn.id())));
|
||||||
|
|
Loading…
Reference in New Issue