Merge pull request #14 from mdhooge/master
GCC complains about missing virtual destructor
This commit is contained in:
commit
2506a91092
19
qamqp.pro
19
qamqp.pro
|
|
@ -1,14 +1,15 @@
|
|||
TEMPLATE = app
|
||||
TARGET = qamqp
|
||||
DEPENDPATH += . \
|
||||
src
|
||||
|
||||
DEPENDPATH += . src
|
||||
|
||||
INCLUDEPATH += . ./src
|
||||
|
||||
# Input
|
||||
HEADERS += src/test.h
|
||||
HEADERS += \
|
||||
src/QamqpApp.h \
|
||||
src/sendreceive/Receive.h \
|
||||
src/sendreceive/Send.h \
|
||||
|
||||
SOURCES += src/main.cpp \
|
||||
src/test.cpp
|
||||
|
||||
include(src/qamqp/qamqp.pri)
|
||||
SOURCES += \
|
||||
src/main.cpp \
|
||||
|
||||
include(src/qamqp/qamqp.pri)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,122 @@
|
|||
#ifndef QAMQPAPP_H
|
||||
#define QAMQPAPP_H
|
||||
|
||||
#include <stdexcept>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QStringList>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
|
||||
#include "qamqp/amqp.h"
|
||||
#include "qamqp/amqp_exchange.h"
|
||||
#include "qamqp/amqp_queue.h"
|
||||
|
||||
#include "sendreceive/Send.h"
|
||||
#include "sendreceive/Receive.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
namespace samples
|
||||
{
|
||||
|
||||
class QamqpApp : public QCoreApplication
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
typedef QCoreApplication super;
|
||||
|
||||
public:
|
||||
explicit QamqpApp(int& argc, char** argv)
|
||||
: super(argc, argv)
|
||||
{
|
||||
QTimer::singleShot(0, this, SLOT(run()));
|
||||
}
|
||||
|
||||
bool notify(QObject *obj, QEvent *event)
|
||||
{
|
||||
try
|
||||
{
|
||||
return super::notify(obj, event);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
qWarning() << ex.what();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void run()
|
||||
{
|
||||
QTextStream cout(stdout);
|
||||
try
|
||||
{
|
||||
QStringList args = arguments();
|
||||
|
||||
if (args.size() == 1 || "-h" == args[1] || "--help" == args[1])
|
||||
{
|
||||
printUsage(cout);
|
||||
quit();
|
||||
return;
|
||||
}
|
||||
|
||||
QString command = args[1];
|
||||
QRunnable* commandImpl = 0;
|
||||
|
||||
if ("send" == command)
|
||||
{
|
||||
if (args.size() < 4)
|
||||
throw std::runtime_error("Mandatory argument(s) missing!");
|
||||
|
||||
QString url = args[2];
|
||||
QString msg = args[3];
|
||||
commandImpl = new Send(url, msg, this);
|
||||
}
|
||||
else if ("receive" == command)
|
||||
{
|
||||
if (args.size() < 3)
|
||||
throw std::runtime_error("Mandatory argument(s) missing!");
|
||||
|
||||
QString url = args[2];
|
||||
commandImpl = new Receive(url, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error(QString("Unknown command: '%1'").arg(command).toStdString());
|
||||
}
|
||||
|
||||
// Run command.
|
||||
commandImpl->run();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
qWarning() << ex.what();
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
void printUsage(QTextStream& out)
|
||||
{
|
||||
QString executable = arguments().at(0);
|
||||
out << QString(
|
||||
"\n\
|
||||
USAGE: %1 [-h|--help] -- Show this help message.\n\
|
||||
\n\
|
||||
USAGE: %1 send <server-url> <message> -- Send a message.\n\
|
||||
%1 receive <server-url> -- Receive messages.\n\
|
||||
\n\
|
||||
Send-Receive Sample:\n\
|
||||
* Producer: %1 send amqp://guest:guest@127.0.0.1:5672/ \"Hello World\"\n\
|
||||
* Consumer: %1 receive amqp://guest:guest@127.0.0.1:5672/\n\
|
||||
\n").arg(executable);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // QAMQPAPP_H
|
||||
34
src/main.cpp
34
src/main.cpp
|
|
@ -1,39 +1,11 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include "test.h"
|
||||
|
||||
void myMessageOutput(QtMsgType type, const char *msg)
|
||||
{
|
||||
switch (type) {
|
||||
case QtDebugMsg:
|
||||
#include "QamqpApp.h"
|
||||
|
||||
fprintf(stderr, "# %s\n", msg);
|
||||
|
||||
break;
|
||||
case QtWarningMsg:
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
break;
|
||||
case QtCriticalMsg:
|
||||
fprintf(stderr, "Critical: %s\n", msg);
|
||||
break;
|
||||
case QtFatalMsg:
|
||||
fprintf(stderr, "Fatal: %s\n", msg);
|
||||
abort();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
qInstallMsgHandler(myMessageOutput);
|
||||
QCoreApplication a(argc, argv);
|
||||
QAMQP::samples::QamqpApp qamqpApp(argc, argv);
|
||||
|
||||
|
||||
Test test[1];
|
||||
Q_UNUSED(test);
|
||||
|
||||
return a.exec();
|
||||
return qamqpApp.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ Exchange::~Exchange()
|
|||
void Exchange::onOpen()
|
||||
{
|
||||
P_D(Exchange);
|
||||
if(d->deleyedDeclare)
|
||||
if(d->delayedDeclare)
|
||||
{
|
||||
d->declare();
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ void Exchange::publish( const QByteArray & message, const QString & key, const Q
|
|||
|
||||
ExchangePrivate::ExchangePrivate(Exchange * q)
|
||||
:ChannelPrivate(q)
|
||||
, deleyedDeclare(false)
|
||||
, delayedDeclare(false)
|
||||
, declared(false)
|
||||
{
|
||||
}
|
||||
|
|
@ -177,7 +177,7 @@ void ExchangePrivate::declare( )
|
|||
{
|
||||
if(!opened)
|
||||
{
|
||||
deleyedDeclare = true;
|
||||
delayedDeclare = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ void ExchangePrivate::declare( )
|
|||
|
||||
frame.setArguments(arguments_);
|
||||
sendFrame(frame);
|
||||
deleyedDeclare = false;
|
||||
delayedDeclare = false;
|
||||
}
|
||||
|
||||
void ExchangePrivate::remove( bool ifUnused /*= true*/, bool noWait /*= true*/ )
|
||||
|
|
@ -271,6 +271,6 @@ void ExchangePrivate::_q_disconnected()
|
|||
{
|
||||
ChannelPrivate::_q_disconnected();
|
||||
qDebug() << "Exchange " << name << " disconnected";
|
||||
deleyedDeclare = false;
|
||||
delayedDeclare = false;
|
||||
declared = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ namespace QAMQP
|
|||
bool _q_method(const QAMQP::Frame::Method & frame);
|
||||
void _q_disconnected();
|
||||
|
||||
bool deleyedDeclare;
|
||||
bool delayedDeclare;
|
||||
bool declared;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ Type Base::type() const
|
|||
return Type(type_);
|
||||
}
|
||||
|
||||
Base::~Base()
|
||||
{}
|
||||
|
||||
void Base::setChannel( qint16 channel )
|
||||
{
|
||||
channel_ = channel;
|
||||
|
|
@ -343,7 +346,7 @@ void QAMQP::Frame::writeField( qint8 valueType, QDataStream &s, const QVariant &
|
|||
{
|
||||
QByteArray tmp;
|
||||
if(withType)
|
||||
s << valueType; // Запишем тип поля
|
||||
s << valueType;
|
||||
|
||||
switch(valueType)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -109,6 +109,11 @@ namespace QAMQP
|
|||
*/
|
||||
Base(QDataStream& raw);
|
||||
|
||||
/*!
|
||||
Base class virtual destructor
|
||||
*/
|
||||
virtual ~Base();
|
||||
|
||||
/*!
|
||||
Frame type
|
||||
@detailed Return type of current frame.
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ Queue::~Queue()
|
|||
void Queue::onOpen()
|
||||
{
|
||||
P_D(Queue);
|
||||
if(d->deleyedDeclare)
|
||||
if(d->delayedDeclare)
|
||||
{
|
||||
d->declare();
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ void Queue::ack( const MessagePtr & message )
|
|||
|
||||
QueuePrivate::QueuePrivate(Queue * q)
|
||||
:ChannelPrivate(q)
|
||||
, deleyedDeclare(false)
|
||||
, delayedDeclare(false)
|
||||
, declared(false)
|
||||
, noAck(true)
|
||||
, recievingMessage(false)
|
||||
|
|
@ -296,7 +296,7 @@ void QueuePrivate::declare()
|
|||
{
|
||||
if(!opened)
|
||||
{
|
||||
deleyedDeclare = true;
|
||||
delayedDeclare = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +311,7 @@ void QueuePrivate::declare()
|
|||
|
||||
frame.setArguments(arguments_);
|
||||
sendFrame(frame);
|
||||
deleyedDeclare = false;
|
||||
delayedDeclare = false;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -562,6 +562,6 @@ void QueuePrivate::_q_body( int channeNumber, const QByteArray & body )
|
|||
|
||||
if(message->leftSize == 0 && messages_.size() == 1)
|
||||
{
|
||||
QMetaObject::invokeMethod(pq_func(), "messageRecieved");
|
||||
QMetaObject::invokeMethod(pq_func(), "messageReceived");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ namespace QAMQP
|
|||
void declared();
|
||||
void binded(bool);
|
||||
void removed();
|
||||
void messageRecieved();
|
||||
void messageReceived();
|
||||
void empty();
|
||||
|
||||
private:
|
||||
|
|
@ -88,4 +88,4 @@ namespace QAMQP
|
|||
#ifdef QAMQP_P_INCLUDE
|
||||
# include "amqp_queue_p.h"
|
||||
#endif
|
||||
#endif // amqp_queue_h__
|
||||
#endif // amqp_queue_h__
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace QAMQP
|
|||
|
||||
bool _q_method(const QAMQP::Frame::Method & frame);
|
||||
|
||||
bool deleyedDeclare;
|
||||
bool delayedDeclare;
|
||||
bool declared;
|
||||
bool noAck;
|
||||
QString consumerTag;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef RECEIVE_H
|
||||
#define RECEIVE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QRunnable>
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <QByteArray>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "qamqp/amqp.h"
|
||||
#include "qamqp/amqp_queue.h"
|
||||
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
namespace samples
|
||||
{
|
||||
|
||||
class Receive : public QObject, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
typedef QObject super;
|
||||
|
||||
public:
|
||||
explicit Receive(const QString& address, QObject* parent)
|
||||
: super(parent)
|
||||
{
|
||||
QAMQP::Client* client = new QAMQP::Client(this);
|
||||
client->open(QUrl(address));
|
||||
|
||||
queue_ = client->createQueue("hello");
|
||||
queue_->declare();
|
||||
connect(queue_, SIGNAL(declared()), this, SLOT(declared()));
|
||||
connect(queue_, SIGNAL(messageReceived()), this, SLOT(newMessage()));
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void declared()
|
||||
{
|
||||
queue_->consume();
|
||||
}
|
||||
|
||||
void newMessage()
|
||||
{
|
||||
while (queue_->hasMessage())
|
||||
{
|
||||
QAMQP::MessagePtr message = queue_->getMessage();
|
||||
qDebug() << "Receive::newMessage " << message->payload;
|
||||
if(!queue_->noAck())
|
||||
{
|
||||
queue_->ack(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
QAMQP::Queue* queue_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // RECEIVE_H
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
#ifndef SEND_H
|
||||
#define SEND_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QRunnable>
|
||||
#include <QDebug>
|
||||
#include <QList>
|
||||
#include <QByteArray>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "qamqp/amqp.h"
|
||||
#include "qamqp/amqp_exchange.h"
|
||||
#include "qamqp/amqp_queue.h"
|
||||
|
||||
namespace QAMQP
|
||||
{
|
||||
|
||||
namespace samples
|
||||
{
|
||||
|
||||
class Send : public QObject, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
typedef QObject super;
|
||||
|
||||
public:
|
||||
explicit Send(const QString& address, const QString& sendMsg, QObject *parent)
|
||||
: super(parent), sendMsg_(sendMsg)
|
||||
{
|
||||
// Create AMQP client
|
||||
QAMQP::Client* client = new QAMQP::Client(this);
|
||||
client->open(QUrl(address));
|
||||
|
||||
// Retrieve the "Default" exchange
|
||||
// No need to declare (i.e. to create), nor to bind to a queue
|
||||
exchange_ = client->createExchange();
|
||||
|
||||
// Create the "hello" queue
|
||||
// This isn't mandatory but if it doesn't exist, the messages are lost
|
||||
client
|
||||
->createQueue("hello", exchange_->channelNumber())
|
||||
->declare();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
QTimer* timer = new QTimer(this);
|
||||
timer->setInterval(2468);
|
||||
connect(timer, SIGNAL(timeout()), SLOT(sendMessage()));
|
||||
timer->start();
|
||||
}
|
||||
|
||||
protected slots:
|
||||
void sendMessage()
|
||||
{
|
||||
static quint64 counter = 0;
|
||||
|
||||
QString message(QString("[%1: %2] %3")
|
||||
.arg(++counter)
|
||||
.arg(QDateTime::currentDateTime().toString(Qt::ISODate))
|
||||
.arg(sendMsg_));
|
||||
qDebug() << "Send::sendMessage " << message;
|
||||
|
||||
exchange_->publish(message, "hello");
|
||||
}
|
||||
|
||||
private:
|
||||
QString sendMsg_;
|
||||
|
||||
QAMQP::Exchange* exchange_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // SEND_H
|
||||
|
|
@ -21,8 +21,8 @@ Test::Test()
|
|||
|
||||
connect(queue2_, SIGNAL(declared()), this, SLOT(declared()));
|
||||
|
||||
connect(queue_, SIGNAL(messageRecieved()), this, SLOT(newMessage()));
|
||||
connect(queue2_, SIGNAL(messageRecieved()), this, SLOT(newMessage()));
|
||||
connect(queue_, SIGNAL(messageReceived()), this, SLOT(newMessage()));
|
||||
connect(queue2_, SIGNAL(messageReceived()), this, SLOT(newMessage()));
|
||||
}
|
||||
|
||||
Test::~Test()
|
||||
|
|
|
|||
Loading…
Reference in New Issue