Kill the public Sodep class prefix. Now use a Jolie namespace.
svn path=/branches/work/~ervin/qtjolie/; revision=959030
This commit is contained in:
parent
cac82a3792
commit
e3a59c40e2
@ -4,7 +4,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${QT_INCLUDE_DIR})
|
||||
|
||||
set(qtjolie_LIB_SRCS sodepclient.cpp sodepclientthread.cpp sodepvalue.cpp sodepfault.cpp sodepmessage.cpp sodeppendingcall.cpp)
|
||||
set(qtjolie_LIB_SRCS client.cpp clientthread.cpp value.cpp fault.cpp message.cpp pendingcall.cpp)
|
||||
|
||||
kde4_add_library(QtJolie SHARED ${qtjolie_LIB_SRCS})
|
||||
|
||||
@ -16,9 +16,9 @@ install(TARGETS QtJolie
|
||||
set_target_properties(QtJolie PROPERTIES VERSION 1.0.0 SOVERSION 1)
|
||||
|
||||
install(FILES
|
||||
sodepclient.h
|
||||
sodepvalue.h
|
||||
sodepfault.h
|
||||
sodepmessage.h
|
||||
sodeppendingcall.h
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR})
|
||||
client.h
|
||||
value.h
|
||||
fault.h
|
||||
message.h
|
||||
pendingcall.h
|
||||
DESTINATION ${INCLUDE_INSTALL_DIR}/qtjolie)
|
||||
|
@ -18,59 +18,61 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "sodepclient.h"
|
||||
#include "sodepclient_p.h"
|
||||
#include "client.h"
|
||||
#include "client_p.h"
|
||||
|
||||
#include "sodepclientthread_p.h"
|
||||
#include "sodepmessage.h"
|
||||
#include "sodeppendingcall.h"
|
||||
#include "clientthread_p.h"
|
||||
#include "message.h"
|
||||
#include "pendingcall.h"
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
SodepClient::SodepClient(const QString &hostName, quint16 port)
|
||||
: d(new SodepClientPrivate(this))
|
||||
Client::Client(const QString &hostName, quint16 port)
|
||||
: d(new ClientPrivate(this))
|
||||
{
|
||||
d->readerThread = new SodepClientThread(hostName, port, d);
|
||||
d->readerThread = new ClientThread(hostName, port, d);
|
||||
d->readerThread->start();
|
||||
}
|
||||
|
||||
SodepClient::~SodepClient()
|
||||
Client::~Client()
|
||||
{
|
||||
delete d->readerThread;
|
||||
delete d;
|
||||
}
|
||||
|
||||
SodepClient::Error SodepClient::error() const
|
||||
Client::Error Client::error() const
|
||||
{
|
||||
return d->error;
|
||||
}
|
||||
|
||||
QString SodepClient::errorString() const
|
||||
QString Client::errorString() const
|
||||
{
|
||||
return d->errorString;
|
||||
}
|
||||
|
||||
SodepPendingCall SodepClient::asyncCall(const SodepMessage &message)
|
||||
PendingCall Client::asyncCall(const Message &message)
|
||||
{
|
||||
Q_ASSERT(!d->pendingCalls.contains(message.id()));
|
||||
d->pendingCalls[message.id()] = new SodepPendingCallPrivate(message);
|
||||
d->pendingCalls[message.id()] = new PendingCallPrivate(message);
|
||||
d->readerThread->sendMessage(message);
|
||||
return SodepPendingCall(d->pendingCalls[message.id()]);
|
||||
return PendingCall(d->pendingCalls[message.id()]);
|
||||
}
|
||||
|
||||
SodepMessage SodepClient::call(const SodepMessage &message)
|
||||
Message Client::call(const Message &message)
|
||||
{
|
||||
SodepPendingCall pending = asyncCall(message);
|
||||
PendingCall pending = asyncCall(message);
|
||||
pending.waitForFinished();
|
||||
return pending.reply();
|
||||
}
|
||||
|
||||
void SodepClient::callNoReply(const SodepMessage &message)
|
||||
void Client::callNoReply(const Message &message)
|
||||
{
|
||||
d->readerThread->sendMessage(message);
|
||||
}
|
||||
|
||||
void SodepClientPrivate::messageReceived(const SodepMessage &message)
|
||||
void ClientPrivate::messageReceived(const Message &message)
|
||||
{
|
||||
QExplicitlySharedDataPointer<SodepPendingCallPrivate> pending = pendingCalls.take(message.id());
|
||||
QExplicitlySharedDataPointer<PendingCallPrivate> pending = pendingCalls.take(message.id());
|
||||
pending->setReply(message);
|
||||
}
|
||||
|
@ -18,19 +18,21 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPCLIENT_H
|
||||
#define SODEPCLIENT_H
|
||||
#ifndef QTJOLIE_CLIENT_H
|
||||
#define QTJOLIE_CLIENT_H
|
||||
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
class QIODevice;
|
||||
class QObject;
|
||||
|
||||
class SodepClientPrivate;
|
||||
class SodepMessage;
|
||||
class SodepPendingCall;
|
||||
namespace Jolie
|
||||
{
|
||||
class ClientPrivate;
|
||||
class Message;
|
||||
class PendingCall;
|
||||
|
||||
class Q_DECL_EXPORT SodepClient
|
||||
class Q_DECL_EXPORT Client
|
||||
{
|
||||
public:
|
||||
enum Error
|
||||
@ -40,19 +42,22 @@ public:
|
||||
UnkownError
|
||||
};
|
||||
|
||||
explicit SodepClient(const QString &hostName, quint16 port);
|
||||
~SodepClient();
|
||||
explicit Client(const QString &hostName, quint16 port);
|
||||
~Client();
|
||||
|
||||
Error error() const;
|
||||
QString errorString() const;
|
||||
|
||||
SodepPendingCall asyncCall(const SodepMessage &message);
|
||||
SodepMessage call(const SodepMessage &message);
|
||||
void callNoReply(const SodepMessage &message);
|
||||
PendingCall asyncCall(const Message &message);
|
||||
Message call(const Message &message);
|
||||
void callNoReply(const Message &message);
|
||||
|
||||
private:
|
||||
friend class SodepClientPrivate;
|
||||
SodepClientPrivate * const d;
|
||||
friend class ClientPrivate;
|
||||
ClientPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,36 +18,42 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPCLIENT_P_H
|
||||
#define SODEPCLIENT_P_H
|
||||
#ifndef QTJOLIE_CLIENT_P_H
|
||||
#define QTJOLIE_CLIENT_P_H
|
||||
|
||||
#include "sodepclient.h"
|
||||
#include "sodeppendingcall_p.h"
|
||||
#include "client.h"
|
||||
#include "pendingcall_p.h"
|
||||
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class SodepClientThread;
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
class SodepClientPrivate : public QObject
|
||||
class ClientThread;
|
||||
|
||||
class ClientPrivate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SodepClientPrivate(SodepClient *client)
|
||||
ClientPrivate(Client *client)
|
||||
: q(client),
|
||||
error(SodepClient::NoError) {}
|
||||
error(Client::NoError) {}
|
||||
|
||||
public slots:
|
||||
void messageReceived(const SodepMessage &message);
|
||||
void messageReceived(const Jolie::Message &message);
|
||||
|
||||
private:
|
||||
friend class SodepClient;
|
||||
SodepClient * const q;
|
||||
SodepClientThread *readerThread;
|
||||
friend class Client;
|
||||
Client * const q;
|
||||
ClientThread *readerThread;
|
||||
|
||||
SodepClient::Error error;
|
||||
Client::Error error;
|
||||
QString errorString;
|
||||
QMap<int, QExplicitlySharedDataPointer<SodepPendingCallPrivate> > pendingCalls;
|
||||
QMap<int, QExplicitlySharedDataPointer<PendingCallPrivate> > pendingCalls;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,28 +18,30 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "sodepclientthread_p.h"
|
||||
#include "clientthread_p.h"
|
||||
|
||||
#include <QtCore/QTimer>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
|
||||
#include "sodepclient_p.h"
|
||||
#include "sodepmessage.h"
|
||||
#include "client_p.h"
|
||||
#include "message.h"
|
||||
#include "sodephelpers_p.h"
|
||||
|
||||
SodepClientThread::SodepClientThread(const QString &hostName, quint16 port, SodepClientPrivate *client)
|
||||
using namespace Jolie;
|
||||
|
||||
ClientThread::ClientThread(const QString &hostName, quint16 port, ClientPrivate *client)
|
||||
: QThread(), m_hostName(hostName), m_port(port), m_socket(0), m_client(client)
|
||||
{
|
||||
moveToThread(this);
|
||||
}
|
||||
|
||||
SodepClientThread::~SodepClientThread()
|
||||
ClientThread::~ClientThread()
|
||||
{
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
|
||||
void SodepClientThread::sendMessage(const SodepMessage &message)
|
||||
void ClientThread::sendMessage(const Message &message)
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
@ -47,7 +49,7 @@ void SodepClientThread::sendMessage(const SodepMessage &message)
|
||||
QTimer::singleShot(0, this, SLOT(writeMessageQueue()));
|
||||
}
|
||||
|
||||
void SodepClientThread::writeMessageQueue()
|
||||
void ClientThread::writeMessageQueue()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
||||
@ -56,13 +58,13 @@ void SodepClientThread::writeMessageQueue()
|
||||
}
|
||||
}
|
||||
|
||||
void SodepClientThread::readMessage()
|
||||
void ClientThread::readMessage()
|
||||
{
|
||||
if (m_socket->bytesAvailable()==0) {
|
||||
return;
|
||||
}
|
||||
|
||||
SodepMessage message = sodepReadMessage(*m_socket);
|
||||
Message message = sodepReadMessage(*m_socket);
|
||||
emit messageReceived(message);
|
||||
|
||||
if (m_socket->bytesAvailable()>0) {
|
||||
@ -70,14 +72,14 @@ void SodepClientThread::readMessage()
|
||||
}
|
||||
}
|
||||
|
||||
void SodepClientThread::run()
|
||||
void ClientThread::run()
|
||||
{
|
||||
m_socket = new QTcpSocket;
|
||||
|
||||
connect(m_socket, SIGNAL(readyRead()),
|
||||
this, SLOT(readMessage()), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(messageReceived(SodepMessage)),
|
||||
m_client, SLOT(messageReceived(SodepMessage)));
|
||||
connect(this, SIGNAL(messageReceived(Jolie::Message)),
|
||||
m_client, SLOT(messageReceived(Jolie::Message)));
|
||||
|
||||
m_socket->connectToHost(m_hostName, m_port);
|
||||
m_socket->waitForConnected(30000);
|
||||
@ -89,4 +91,4 @@ void SodepClientThread::run()
|
||||
delete m_socket;
|
||||
}
|
||||
|
||||
#include "sodepclientthread_p.moc"
|
||||
#include "clientthread_p.moc"
|
@ -18,8 +18,8 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPCLIENTTHREAD_P_H
|
||||
#define SODEPCLIENTTHREAD_P_H
|
||||
#ifndef QTJOLIE_CLIENTTHREAD_P_H
|
||||
#define QTJOLIE_CLIENTTHREAD_P_H
|
||||
|
||||
#include <QtCore/QThread>
|
||||
#include <QtCore/QMutex>
|
||||
@ -27,23 +27,25 @@
|
||||
|
||||
class QAbstractSocket;
|
||||
|
||||
class SodepMessage;
|
||||
class SodepClientPrivate;
|
||||
namespace Jolie
|
||||
{
|
||||
class Message;
|
||||
class ClientPrivate;
|
||||
|
||||
class SodepClientThread : public QThread
|
||||
class ClientThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SodepClientThread(const QString &hostName, quint16 port, SodepClientPrivate *client);
|
||||
~SodepClientThread();
|
||||
explicit ClientThread(const QString &hostName, quint16 port, ClientPrivate *client);
|
||||
~ClientThread();
|
||||
|
||||
void run();
|
||||
|
||||
void sendMessage(const SodepMessage &message);
|
||||
void sendMessage(const Message &message);
|
||||
|
||||
signals:
|
||||
void messageReceived(const SodepMessage &message);
|
||||
void messageReceived(const Jolie::Message &message);
|
||||
|
||||
private slots:
|
||||
void readMessage();
|
||||
@ -54,11 +56,14 @@ private:
|
||||
quint16 m_port;
|
||||
|
||||
QAbstractSocket *m_socket;
|
||||
SodepClientPrivate *m_client;
|
||||
ClientPrivate *m_client;
|
||||
|
||||
QQueue<SodepMessage> m_messageQueue;
|
||||
QQueue<Message> m_messageQueue;
|
||||
|
||||
QMutex m_mutex;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,61 +18,68 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "sodepfault.h"
|
||||
#include "fault.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include "sodephelpers_p.h"
|
||||
|
||||
class SodepFaultPrivate
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
class FaultPrivate
|
||||
{
|
||||
public:
|
||||
QString name;
|
||||
SodepValue data;
|
||||
Value data;
|
||||
};
|
||||
|
||||
SodepFault::SodepFault()
|
||||
: d(new SodepFaultPrivate)
|
||||
} // namespace Jolie
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
Fault::Fault()
|
||||
: d(new FaultPrivate)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SodepFault::SodepFault(const QString &name, const SodepValue &data)
|
||||
: d(new SodepFaultPrivate)
|
||||
Fault::Fault(const QString &name, const Value &data)
|
||||
: d(new FaultPrivate)
|
||||
{
|
||||
d->name = name;
|
||||
d->data = data;
|
||||
}
|
||||
|
||||
SodepFault::SodepFault(const SodepFault &other)
|
||||
: d(new SodepFaultPrivate)
|
||||
Fault::Fault(const Fault &other)
|
||||
: d(new FaultPrivate)
|
||||
{
|
||||
*d = *other.d;
|
||||
}
|
||||
|
||||
SodepFault::~SodepFault()
|
||||
Fault::~Fault()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
SodepFault &SodepFault::operator=(const SodepFault &other)
|
||||
Fault &Fault::operator=(const Fault &other)
|
||||
{
|
||||
*d = *other.d;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
QString SodepFault::name() const
|
||||
QString Fault::name() const
|
||||
{
|
||||
return d->name;
|
||||
}
|
||||
|
||||
SodepValue SodepFault::data() const
|
||||
Value Fault::data() const
|
||||
{
|
||||
return d->data;
|
||||
}
|
||||
|
||||
bool SodepFault::isValid() const
|
||||
bool Fault::isValid() const
|
||||
{
|
||||
return !d->name.isEmpty();
|
||||
}
|
@ -18,32 +18,37 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPFAULT_H
|
||||
#define SODEPFAULT_H
|
||||
#ifndef QTJOLIE_FAULT_H
|
||||
#define QTJOLIE_FAULT_H
|
||||
|
||||
#include <qtjolie/sodepvalue.h>
|
||||
#include <qtjolie/value.h>
|
||||
|
||||
class SodepFaultPrivate;
|
||||
namespace Jolie
|
||||
{
|
||||
class FaultPrivate;
|
||||
|
||||
class Q_DECL_EXPORT SodepFault
|
||||
class Q_DECL_EXPORT Fault
|
||||
{
|
||||
public:
|
||||
SodepFault();
|
||||
explicit SodepFault(const QString &name, const SodepValue &data = SodepValue());
|
||||
Fault();
|
||||
explicit Fault(const QString &name, const Value &data = Value());
|
||||
|
||||
SodepFault(const SodepFault &other);
|
||||
Fault(const Fault &other);
|
||||
|
||||
~SodepFault();
|
||||
~Fault();
|
||||
|
||||
SodepFault &operator=(const SodepFault &other);
|
||||
Fault &operator=(const Fault &other);
|
||||
|
||||
QString name() const;
|
||||
SodepValue data() const;
|
||||
Value data() const;
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
SodepFaultPrivate * const d;
|
||||
FaultPrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,31 +18,38 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "sodepmessage.h"
|
||||
#include "message.h"
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include "sodephelpers_p.h"
|
||||
|
||||
class SodepMessagePrivate
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
class MessagePrivate
|
||||
{
|
||||
public:
|
||||
SodepMessagePrivate() : id(0) {}
|
||||
MessagePrivate() : id(0) {}
|
||||
|
||||
qint64 id;
|
||||
QString resourcePath;
|
||||
QString operationName;
|
||||
SodepFault fault;
|
||||
SodepValue data;
|
||||
Fault fault;
|
||||
Value data;
|
||||
};
|
||||
|
||||
SodepMessage::SodepMessage()
|
||||
: d(new SodepMessagePrivate)
|
||||
} // namespace Jolie
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
Message::Message()
|
||||
: d(new MessagePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
SodepMessage::SodepMessage(const QString &resourcePath, const QString &operationName, qint64 id)
|
||||
: d(new SodepMessagePrivate)
|
||||
Message::Message(const QString &resourcePath, const QString &operationName, qint64 id)
|
||||
: d(new MessagePrivate)
|
||||
{
|
||||
static qint64 lastId = 0;
|
||||
|
||||
@ -55,60 +62,60 @@ SodepMessage::SodepMessage(const QString &resourcePath, const QString &operation
|
||||
d->operationName = operationName;
|
||||
}
|
||||
|
||||
SodepMessage::SodepMessage(const SodepMessage &other)
|
||||
: d(new SodepMessagePrivate)
|
||||
Message::Message(const Message &other)
|
||||
: d(new MessagePrivate)
|
||||
{
|
||||
*d = *other.d;
|
||||
}
|
||||
|
||||
SodepMessage::~SodepMessage()
|
||||
Message::~Message()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
SodepMessage &SodepMessage::operator=(const SodepMessage &other)
|
||||
Message &Message::operator=(const Message &other)
|
||||
{
|
||||
*d = *other.d;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
qint64 SodepMessage::id() const
|
||||
qint64 Message::id() const
|
||||
{
|
||||
return d->id;
|
||||
}
|
||||
|
||||
QString SodepMessage::resourcePath() const
|
||||
QString Message::resourcePath() const
|
||||
{
|
||||
return d->resourcePath;
|
||||
}
|
||||
|
||||
QString SodepMessage::operationName() const
|
||||
QString Message::operationName() const
|
||||
{
|
||||
return d->operationName;
|
||||
}
|
||||
|
||||
SodepFault SodepMessage::fault() const
|
||||
Fault Message::fault() const
|
||||
{
|
||||
return d->fault;
|
||||
}
|
||||
|
||||
void SodepMessage::setFault(const SodepFault &fault)
|
||||
void Message::setFault(const Fault &fault)
|
||||
{
|
||||
d->fault = fault;
|
||||
}
|
||||
|
||||
SodepValue SodepMessage::data() const
|
||||
Value Message::data() const
|
||||
{
|
||||
return d->data;
|
||||
}
|
||||
|
||||
void SodepMessage::setData(const SodepValue &data)
|
||||
void Message::setData(const Value &data)
|
||||
{
|
||||
d->data = data;
|
||||
}
|
||||
|
||||
bool SodepMessage::isValid()
|
||||
bool Message::isValid()
|
||||
{
|
||||
return !d->resourcePath.isEmpty() && !d->operationName.isEmpty();
|
||||
}
|
@ -18,41 +18,46 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPMESSAGE_H
|
||||
#define SODEPMESSAGE_H
|
||||
#ifndef QTJOLIE_MESSAGE_H
|
||||
#define QTJOLIE_MESSAGE_H
|
||||
|
||||
#include <qtjolie/sodepvalue.h>
|
||||
#include <qtjolie/sodepfault.h>
|
||||
#include <qtjolie/value.h>
|
||||
#include <qtjolie/fault.h>
|
||||
|
||||
class SodepMessagePrivate;
|
||||
namespace Jolie
|
||||
{
|
||||
class MessagePrivate;
|
||||
|
||||
class Q_DECL_EXPORT SodepMessage
|
||||
class Q_DECL_EXPORT Message
|
||||
{
|
||||
public:
|
||||
SodepMessage();
|
||||
explicit SodepMessage(const QString &resourcePath,
|
||||
Message();
|
||||
explicit Message(const QString &resourcePath,
|
||||
const QString &operationName,
|
||||
qint64 id = 0);
|
||||
SodepMessage(const SodepMessage &other);
|
||||
~SodepMessage();
|
||||
Message(const Message &other);
|
||||
~Message();
|
||||
|
||||
SodepMessage &operator=(const SodepMessage &other);
|
||||
Message &operator=(const Message &other);
|
||||
|
||||
qint64 id() const;
|
||||
|
||||
QString resourcePath() const;
|
||||
QString operationName() const;
|
||||
|
||||
SodepFault fault() const;
|
||||
void setFault(const SodepFault &fault);
|
||||
Fault fault() const;
|
||||
void setFault(const Fault &fault);
|
||||
|
||||
SodepValue data() const;
|
||||
void setData(const SodepValue &data);
|
||||
Value data() const;
|
||||
void setData(const Value &data);
|
||||
|
||||
bool isValid();
|
||||
|
||||
private:
|
||||
SodepMessagePrivate * const d;
|
||||
MessagePrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,62 +18,64 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "sodeppendingcall.h"
|
||||
#include "sodeppendingcall_p.h"
|
||||
#include "pendingcall.h"
|
||||
#include "pendingcall_p.h"
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
SodepPendingCall::SodepPendingCall(const SodepPendingCall &other)
|
||||
PendingCall::PendingCall(const PendingCall &other)
|
||||
: d(other.d)
|
||||
{
|
||||
}
|
||||
|
||||
SodepPendingCall::SodepPendingCall(QExplicitlySharedDataPointer<SodepPendingCallPrivate> dd)
|
||||
PendingCall::PendingCall(QExplicitlySharedDataPointer<PendingCallPrivate> dd)
|
||||
: d(dd)
|
||||
{
|
||||
}
|
||||
|
||||
SodepPendingCall::~SodepPendingCall()
|
||||
PendingCall::~PendingCall()
|
||||
{
|
||||
}
|
||||
|
||||
SodepPendingCall &SodepPendingCall::operator=(const SodepPendingCall &other)
|
||||
PendingCall &PendingCall::operator=(const PendingCall &other)
|
||||
{
|
||||
d = other.d;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool SodepPendingCall::isFinished() const
|
||||
bool PendingCall::isFinished() const
|
||||
{
|
||||
return d->isFinished;
|
||||
}
|
||||
|
||||
SodepMessage SodepPendingCall::reply() const
|
||||
Message PendingCall::reply() const
|
||||
{
|
||||
return d->reply;
|
||||
}
|
||||
|
||||
void SodepPendingCall::waitForFinished()
|
||||
void PendingCall::waitForFinished()
|
||||
{
|
||||
SodepPendingCallWaiter waiter;
|
||||
PendingCallWaiter waiter;
|
||||
waiter.waitForFinished(d.data());
|
||||
}
|
||||
|
||||
void SodepPendingCallPrivate::setReply(const SodepMessage &message)
|
||||
void PendingCallPrivate::setReply(const Message &message)
|
||||
{
|
||||
Q_ASSERT(message.id()==id);
|
||||
isFinished = true;
|
||||
reply = message;
|
||||
|
||||
foreach (SodepPendingCallWaiter *waiter, waiters) {
|
||||
foreach (PendingCallWaiter *waiter, waiters) {
|
||||
waiter->eventLoop.quit();
|
||||
}
|
||||
|
||||
waiters.clear();
|
||||
}
|
||||
|
||||
void SodepPendingCallWaiter::waitForFinished(SodepPendingCallPrivate *pendingCall)
|
||||
void PendingCallWaiter::waitForFinished(PendingCallPrivate *pendingCall)
|
||||
{
|
||||
pendingCall->waiters << this;
|
||||
eventLoop.exec();
|
||||
}
|
||||
|
@ -18,35 +18,40 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPPENDINGCALL_H
|
||||
#define SODEPPENDINGCALL_H
|
||||
#ifndef QTJOLIE_PENDINGCALL_H
|
||||
#define QTJOLIE_PENDINGCALL_H
|
||||
|
||||
#include <QtCore/QExplicitlySharedDataPointer>
|
||||
|
||||
class SodepClient;
|
||||
class SodepPendingCallPrivate;
|
||||
class SodepMessage;
|
||||
namespace Jolie
|
||||
{
|
||||
class Client;
|
||||
class PendingCallPrivate;
|
||||
class Message;
|
||||
|
||||
class Q_DECL_EXPORT SodepPendingCall
|
||||
class Q_DECL_EXPORT PendingCall
|
||||
{
|
||||
public:
|
||||
SodepPendingCall(const SodepPendingCall &other);
|
||||
~SodepPendingCall();
|
||||
PendingCall(const PendingCall &other);
|
||||
~PendingCall();
|
||||
|
||||
SodepPendingCall &operator=(const SodepPendingCall &other);
|
||||
PendingCall &operator=(const PendingCall &other);
|
||||
|
||||
bool isFinished() const;
|
||||
SodepMessage reply() const;
|
||||
Message reply() const;
|
||||
|
||||
void waitForFinished();
|
||||
|
||||
private:
|
||||
friend class SodepClient;
|
||||
friend class Client;
|
||||
|
||||
SodepPendingCall(); // Not defined
|
||||
SodepPendingCall(QExplicitlySharedDataPointer<SodepPendingCallPrivate> dd);
|
||||
PendingCall(); // Not defined
|
||||
PendingCall(QExplicitlySharedDataPointer<PendingCallPrivate> dd);
|
||||
|
||||
QExplicitlySharedDataPointer<SodepPendingCallPrivate> d;
|
||||
QExplicitlySharedDataPointer<PendingCallPrivate> d;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,44 +18,49 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPPENDINGCALL_P_H
|
||||
#define SODEPPENDINGCALL_P_H
|
||||
#ifndef QTJOLIE_PENDINGCALL_P_H
|
||||
#define QTJOLIE_PENDINGCALL_P_H
|
||||
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSharedData>
|
||||
|
||||
#include "sodepmessage.h"
|
||||
#include "message.h"
|
||||
|
||||
class SodepPendingCallPrivate;
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
class SodepPendingCallWaiter
|
||||
class PendingCallPrivate;
|
||||
|
||||
class PendingCallWaiter
|
||||
{
|
||||
public:
|
||||
void waitForFinished(SodepPendingCallPrivate *pendingCall);
|
||||
void waitForFinished(PendingCallPrivate *pendingCall);
|
||||
|
||||
private:
|
||||
friend class SodepPendingCallPrivate;
|
||||
friend class PendingCallPrivate;
|
||||
QEventLoop eventLoop;
|
||||
};
|
||||
|
||||
class SodepPendingCallPrivate : public QSharedData
|
||||
class PendingCallPrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
SodepPendingCallPrivate(const SodepMessage &message)
|
||||
PendingCallPrivate(const Message &message)
|
||||
: id(message.id()), isFinished(false) {}
|
||||
|
||||
void setReply(const SodepMessage &message);
|
||||
void setReply(const Message &message);
|
||||
|
||||
private:
|
||||
friend class SodepPendingCall;
|
||||
friend class SodepPendingCallWaiter;
|
||||
friend class PendingCall;
|
||||
friend class PendingCallWaiter;
|
||||
|
||||
qint64 id;
|
||||
bool isFinished;
|
||||
SodepMessage reply;
|
||||
QList<SodepPendingCallWaiter*> waiters;
|
||||
Message reply;
|
||||
QList<PendingCallWaiter*> waiters;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -18,16 +18,19 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPHELPERS_P_H
|
||||
#define SODEPHELPERS_P_H
|
||||
#ifndef QTJOLIE_SODEPHELPERS_P_H
|
||||
#define QTJOLIE_SODEPHELPERS_P_H
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
#include "sodepvalue.h"
|
||||
#include "sodepfault.h"
|
||||
#include "sodepmessage.h"
|
||||
#include "value.h"
|
||||
#include "fault.h"
|
||||
#include "message.h"
|
||||
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
inline void sodepWrite(QIODevice &io, double value)
|
||||
{
|
||||
@ -72,7 +75,7 @@ inline void sodepWrite(QIODevice &io, const QString &value)
|
||||
io.write(data);
|
||||
}
|
||||
|
||||
inline void sodepWrite(QIODevice &io, const SodepValue &value)
|
||||
inline void sodepWrite(QIODevice &io, const Value &value)
|
||||
{
|
||||
if (value.isDouble()) {
|
||||
io.putChar(3);
|
||||
@ -92,7 +95,7 @@ inline void sodepWrite(QIODevice &io, const SodepValue &value)
|
||||
foreach (const QString &name, value.childrenNames()) {
|
||||
sodepWrite(io, name);
|
||||
|
||||
QList<SodepValue> values = value.children(name);
|
||||
QList<Value> values = value.children(name);
|
||||
qint32 valueCount = values.size();
|
||||
sodepWrite(io, valueCount);
|
||||
for (int j=0; j<valueCount; ++j) {
|
||||
@ -102,7 +105,7 @@ inline void sodepWrite(QIODevice &io, const SodepValue &value)
|
||||
|
||||
}
|
||||
|
||||
inline void sodepWrite(QIODevice &io, const SodepFault &fault)
|
||||
inline void sodepWrite(QIODevice &io, const Fault &fault)
|
||||
{
|
||||
if (!fault.isValid()) {
|
||||
io.putChar(0);
|
||||
@ -114,7 +117,7 @@ inline void sodepWrite(QIODevice &io, const SodepFault &fault)
|
||||
sodepWrite(io, fault.data());
|
||||
}
|
||||
|
||||
inline void sodepWrite(QIODevice &io, const SodepMessage &message)
|
||||
inline void sodepWrite(QIODevice &io, const Message &message)
|
||||
{
|
||||
sodepWrite(io, message.id());
|
||||
sodepWrite(io, message.resourcePath());
|
||||
@ -198,9 +201,9 @@ inline QString sodepReadString(QIODevice &io)
|
||||
return result;
|
||||
}
|
||||
|
||||
inline SodepValue sodepReadValue(QIODevice &io)
|
||||
inline Value sodepReadValue(QIODevice &io)
|
||||
{
|
||||
SodepValue result;
|
||||
Value result;
|
||||
|
||||
while (io.bytesAvailable()<1) {
|
||||
io.waitForReadyRead(-1);
|
||||
@ -211,15 +214,15 @@ inline SodepValue sodepReadValue(QIODevice &io)
|
||||
|
||||
switch(code) {
|
||||
case 3: {
|
||||
result = SodepValue(sodepReadDouble(io));
|
||||
result = Value(sodepReadDouble(io));
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
result = SodepValue(sodepReadInt32(io));
|
||||
result = Value(sodepReadInt32(io));
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
result = SodepValue(sodepReadString(io));
|
||||
result = Value(sodepReadString(io));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -240,7 +243,7 @@ inline SodepValue sodepReadValue(QIODevice &io)
|
||||
return result;
|
||||
}
|
||||
|
||||
inline SodepFault sodepReadFault(QIODevice &io)
|
||||
inline Fault sodepReadFault(QIODevice &io)
|
||||
{
|
||||
while (io.bytesAvailable()<1) {
|
||||
io.waitForReadyRead(-1);
|
||||
@ -250,22 +253,22 @@ inline SodepFault sodepReadFault(QIODevice &io)
|
||||
io.getChar(&code);
|
||||
|
||||
if (code!=1) {
|
||||
return SodepFault();
|
||||
return Fault();
|
||||
}
|
||||
|
||||
QString name = sodepReadString(io);
|
||||
SodepValue data = sodepReadValue(io);
|
||||
Value data = sodepReadValue(io);
|
||||
|
||||
return SodepFault(name, data);
|
||||
return Fault(name, data);
|
||||
}
|
||||
|
||||
inline SodepMessage sodepReadMessage(QIODevice &io)
|
||||
inline Message sodepReadMessage(QIODevice &io)
|
||||
{
|
||||
qint64 id = sodepReadInt64(io);
|
||||
QString resourcePath = sodepReadString(io);
|
||||
QString operationName = sodepReadString(io);
|
||||
|
||||
SodepMessage result(resourcePath, operationName, id);
|
||||
Message result(resourcePath, operationName, id);
|
||||
|
||||
result.setFault(sodepReadFault(io));
|
||||
result.setData(sodepReadValue(io));
|
||||
@ -273,4 +276,7 @@ inline SodepMessage sodepReadMessage(QIODevice &io)
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -18,77 +18,84 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "sodepvalue.h"
|
||||
#include "value.h"
|
||||
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
#include "sodephelpers_p.h"
|
||||
|
||||
class SodepValuePrivate
|
||||
namespace Jolie
|
||||
{
|
||||
|
||||
class ValuePrivate
|
||||
{
|
||||
public:
|
||||
QVariant content;
|
||||
QMap<QString, QList<SodepValue> > children;
|
||||
QMap<QString, QList<Value> > children;
|
||||
};
|
||||
|
||||
SodepValue::SodepValue()
|
||||
: d(new SodepValuePrivate)
|
||||
} // namespace Jolie
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
Value::Value()
|
||||
: d(new ValuePrivate)
|
||||
{
|
||||
}
|
||||
|
||||
SodepValue::SodepValue(const QString &content)
|
||||
: d(new SodepValuePrivate)
|
||||
Value::Value(const QString &content)
|
||||
: d(new ValuePrivate)
|
||||
{
|
||||
d->content = content;
|
||||
}
|
||||
|
||||
SodepValue::SodepValue(qint32 content)
|
||||
: d(new SodepValuePrivate)
|
||||
Value::Value(qint32 content)
|
||||
: d(new ValuePrivate)
|
||||
{
|
||||
d->content = content;
|
||||
}
|
||||
|
||||
SodepValue::SodepValue(double content)
|
||||
: d(new SodepValuePrivate)
|
||||
Value::Value(double content)
|
||||
: d(new ValuePrivate)
|
||||
{
|
||||
d->content = content;
|
||||
}
|
||||
|
||||
SodepValue::SodepValue(const SodepValue &other)
|
||||
: d(new SodepValuePrivate)
|
||||
Value::Value(const Value &other)
|
||||
: d(new ValuePrivate)
|
||||
{
|
||||
*d = *other.d;
|
||||
}
|
||||
|
||||
SodepValue::~SodepValue()
|
||||
Value::~Value()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
SodepValue &SodepValue::operator=(const SodepValue &other)
|
||||
Value &Value::operator=(const Value &other)
|
||||
{
|
||||
*d = *other.d;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
QStringList SodepValue::childrenNames() const
|
||||
QStringList Value::childrenNames() const
|
||||
{
|
||||
return d->children.keys();
|
||||
}
|
||||
|
||||
QList<SodepValue> & SodepValue::children(const QString &name)
|
||||
QList<Value> & Value::children(const QString &name)
|
||||
{
|
||||
return d->children[name];
|
||||
}
|
||||
|
||||
const QList<SodepValue> & SodepValue::children(const QString &name) const
|
||||
const QList<Value> & Value::children(const QString &name) const
|
||||
{
|
||||
return d->children[name];
|
||||
}
|
||||
|
||||
QString SodepValue::toString() const
|
||||
QString Value::toString() const
|
||||
{
|
||||
if (isString()) {
|
||||
return d->content.toString();
|
||||
@ -97,7 +104,7 @@ QString SodepValue::toString() const
|
||||
}
|
||||
}
|
||||
|
||||
qint32 SodepValue::toInt() const
|
||||
qint32 Value::toInt() const
|
||||
{
|
||||
if (isInt()) {
|
||||
return d->content.toInt();
|
||||
@ -106,7 +113,7 @@ qint32 SodepValue::toInt() const
|
||||
}
|
||||
}
|
||||
|
||||
double SodepValue::toDouble() const
|
||||
double Value::toDouble() const
|
||||
{
|
||||
if (isDouble()) {
|
||||
return d->content.toDouble();
|
||||
@ -115,22 +122,23 @@ double SodepValue::toDouble() const
|
||||
}
|
||||
}
|
||||
|
||||
bool SodepValue::isString() const
|
||||
bool Value::isString() const
|
||||
{
|
||||
return d->content.type()==QVariant::String;
|
||||
}
|
||||
|
||||
bool SodepValue::isInt() const
|
||||
bool Value::isInt() const
|
||||
{
|
||||
return d->content.type()==QVariant::Int;
|
||||
}
|
||||
|
||||
bool SodepValue::isDouble() const
|
||||
bool Value::isDouble() const
|
||||
{
|
||||
return d->content.type()==QVariant::Double;
|
||||
}
|
||||
|
||||
bool SodepValue::isValid() const
|
||||
bool Value::isValid() const
|
||||
{
|
||||
return isString() || isInt() || isDouble();
|
||||
}
|
||||
|
@ -18,32 +18,34 @@
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef SODEPVALUE_H
|
||||
#define SODEPVALUE_H
|
||||
#ifndef QTJOLIE_VALUE_H
|
||||
#define QTJOLIE_VALUE_H
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QList>
|
||||
|
||||
class SodepValuePrivate;
|
||||
namespace Jolie
|
||||
{
|
||||
class ValuePrivate;
|
||||
|
||||
class Q_DECL_EXPORT SodepValue
|
||||
class Q_DECL_EXPORT Value
|
||||
{
|
||||
public:
|
||||
SodepValue();
|
||||
Value();
|
||||
|
||||
explicit SodepValue(const QString &content);
|
||||
explicit SodepValue(qint32 content);
|
||||
explicit SodepValue(double content);
|
||||
explicit Value(const QString &content);
|
||||
explicit Value(qint32 content);
|
||||
explicit Value(double content);
|
||||
|
||||
SodepValue(const SodepValue &other);
|
||||
Value(const Value &other);
|
||||
|
||||
~SodepValue();
|
||||
~Value();
|
||||
|
||||
SodepValue &operator=(const SodepValue &other);
|
||||
Value &operator=(const Value &other);
|
||||
|
||||
QStringList childrenNames() const;
|
||||
QList<SodepValue> &children(const QString &name);
|
||||
const QList<SodepValue> &children(const QString &name) const;
|
||||
QList<Value> &children(const QString &name);
|
||||
const QList<Value> &children(const QString &name) const;
|
||||
|
||||
QString toString() const;
|
||||
qint32 toInt() const;
|
||||
@ -56,7 +58,10 @@ public:
|
||||
bool isValid() const;
|
||||
|
||||
private:
|
||||
SodepValuePrivate * const d;
|
||||
ValuePrivate * const d;
|
||||
};
|
||||
|
||||
} // namespace Jolie
|
||||
|
||||
#endif
|
||||
|
@ -17,12 +17,12 @@ MACRO(SODEP_EXECUTABLE_TESTS)
|
||||
ENDMACRO(SODEP_EXECUTABLE_TESTS)
|
||||
|
||||
SODEP_UNIT_TESTS(
|
||||
sodepvaluetest
|
||||
sodepfaulttest
|
||||
sodepmessagetest
|
||||
sodepmetaservicetest
|
||||
testvalue
|
||||
testfault
|
||||
testmessage
|
||||
testmetaservice
|
||||
)
|
||||
|
||||
SODEP_EXECUTABLE_TESTS(
|
||||
sodepprintertest
|
||||
testprinter
|
||||
)
|
||||
|
@ -21,17 +21,19 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <qtjolie/sodepfault.h>
|
||||
#include "sodeptesthelpers.h"
|
||||
#include <qtjolie/fault.h>
|
||||
#include "testhelpers.h"
|
||||
|
||||
class SodepFaultTest : public QObject
|
||||
using namespace Jolie;
|
||||
|
||||
class TestFault : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void shouldHandleInvalids()
|
||||
{
|
||||
SodepFault f;
|
||||
Fault f;
|
||||
|
||||
QCOMPARE(f.name(), QString());
|
||||
QVERIFY(!f.data().isValid());
|
||||
@ -40,7 +42,7 @@ private slots:
|
||||
}
|
||||
void shouldVerifyInitialState()
|
||||
{
|
||||
SodepFault f1("blup"), f2("blop", SodepValue(42));
|
||||
Fault f1("blup"), f2("blop", Value(42));
|
||||
|
||||
QCOMPARE(f1.name(), QString("blup"));
|
||||
QVERIFY(!f1.data().isValid());
|
||||
@ -58,18 +60,18 @@ private slots:
|
||||
|
||||
void shouldBeSerializable_data()
|
||||
{
|
||||
SodepValue v(42);
|
||||
Value v(42);
|
||||
QByteArray vSerial = QByteArray::fromHex("020000002A00000000");
|
||||
|
||||
QTest::addColumn<SodepFault>("original");
|
||||
QTest::addColumn<Fault>("original");
|
||||
QTest::addColumn<QByteArray>("serialized");
|
||||
|
||||
QTest::newRow("empty fault") << SodepFault()
|
||||
QTest::newRow("empty fault") << Fault()
|
||||
<< QByteArray::fromHex("00");
|
||||
QTest::newRow("no value fault") << SodepFault("foo")
|
||||
QTest::newRow("no value fault") << Fault("foo")
|
||||
<< QByteArray::fromHex("0100000003")+QByteArray("foo")
|
||||
+ QByteArray::fromHex("0000000000");
|
||||
QTest::newRow("value fault") << SodepFault("bar", v)
|
||||
QTest::newRow("value fault") << Fault("bar", v)
|
||||
<< QByteArray::fromHex("0100000003")+QByteArray("bar")
|
||||
+ vSerial;
|
||||
}
|
||||
@ -78,9 +80,9 @@ private slots:
|
||||
{
|
||||
QBuffer buffer;
|
||||
|
||||
QFETCH(SodepFault, original);
|
||||
QFETCH(Fault, original);
|
||||
QFETCH(QByteArray, serialized);
|
||||
SodepFault result;
|
||||
Fault result;
|
||||
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
sodepWrite(buffer, original);
|
||||
@ -95,6 +97,6 @@ private slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(SodepFaultTest)
|
||||
QTEST_MAIN(TestFault)
|
||||
|
||||
#include "sodepfaulttest.moc"
|
||||
#include "testfault.moc"
|
@ -23,14 +23,14 @@
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <qtjolie/sodepfault.h>
|
||||
#include <qtjolie/sodepmessage.h>
|
||||
#include <qtjolie/sodepvalue.h>
|
||||
#include <qtjolie/fault.h>
|
||||
#include <qtjolie/message.h>
|
||||
#include <qtjolie/value.h>
|
||||
#include <qtjolie/sodephelpers_p.h>
|
||||
|
||||
Q_DECLARE_METATYPE(SodepValue);
|
||||
Q_DECLARE_METATYPE(Jolie::Value);
|
||||
|
||||
inline void sodepCompare(const SodepValue &v1, const SodepValue &v2)
|
||||
inline void sodepCompare(const Jolie::Value &v1, const Jolie::Value &v2)
|
||||
{
|
||||
QCOMPARE(v1.isValid(), v2.isValid());
|
||||
|
||||
@ -47,8 +47,8 @@ inline void sodepCompare(const SodepValue &v1, const SodepValue &v2)
|
||||
QCOMPARE(v1Names, v2Names);
|
||||
|
||||
foreach (const QString &name, v1Names) {
|
||||
QList<SodepValue> v1Values = v1.children(name);
|
||||
QList<SodepValue> v2Values = v2.children(name);
|
||||
QList<Jolie::Value> v1Values = v1.children(name);
|
||||
QList<Jolie::Value> v2Values = v2.children(name);
|
||||
|
||||
QCOMPARE(v1Values.size(), v2Values.size());
|
||||
|
||||
@ -58,18 +58,18 @@ inline void sodepCompare(const SodepValue &v1, const SodepValue &v2)
|
||||
}
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(SodepFault);
|
||||
Q_DECLARE_METATYPE(Jolie::Fault);
|
||||
|
||||
inline void sodepCompare(const SodepFault &f1, const SodepFault &f2)
|
||||
inline void sodepCompare(const Jolie::Fault &f1, const Jolie::Fault &f2)
|
||||
{
|
||||
QCOMPARE(f1.isValid(), f2.isValid());
|
||||
QCOMPARE(f1.name(), f2.name());
|
||||
sodepCompare(f1.data(), f2.data());
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(SodepMessage);
|
||||
Q_DECLARE_METATYPE(Jolie::Message);
|
||||
|
||||
inline void sodepCompare(const SodepMessage &m1, const SodepMessage &m2)
|
||||
inline void sodepCompare(const Jolie::Message &m1, const Jolie::Message &m2)
|
||||
{
|
||||
QCOMPARE(m1.resourcePath(), m2.resourcePath());
|
||||
QCOMPARE(m1.operationName(), m2.operationName());
|
@ -21,18 +21,20 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <qtjolie/sodepmessage.h>
|
||||
#include "sodeptesthelpers.h"
|
||||
#include <qtjolie/message.h>
|
||||
#include "testhelpers.h"
|
||||
|
||||
class SodepMessageTest : public QObject
|
||||
using namespace Jolie;
|
||||
|
||||
class TestMessage : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void shouldVerifyInitialState()
|
||||
{
|
||||
SodepMessage m1("/foo", "bar", 1);
|
||||
SodepMessage m2("/pata/pata", "pon", 2);
|
||||
Message m1("/foo", "bar", 1);
|
||||
Message m2("/pata/pata", "pon", 2);
|
||||
|
||||
QCOMPARE(m1.resourcePath(), QString("/foo"));
|
||||
QCOMPARE(m1.operationName(), QString("bar"));
|
||||
@ -51,23 +53,23 @@ private slots:
|
||||
|
||||
void shouldBeSerializable_data()
|
||||
{
|
||||
SodepValue v(42);
|
||||
Value v(42);
|
||||
QByteArray vSerial = QByteArray::fromHex("020000002A00000000");
|
||||
SodepFault f("foo");
|
||||
Fault f("foo");
|
||||
QByteArray fSerial = QByteArray::fromHex("0100000003")+QByteArray("foo")
|
||||
+ QByteArray::fromHex("0000000000");
|
||||
|
||||
QTest::addColumn<SodepMessage>("original");
|
||||
QTest::addColumn<Message>("original");
|
||||
QTest::addColumn<QByteArray>("serialized");
|
||||
|
||||
QTest::newRow("no payload message") << SodepMessage("/pata", "pon", 1)
|
||||
QTest::newRow("no payload message") << Message("/pata", "pon", 1)
|
||||
<< QByteArray::fromHex("0000000000000001")
|
||||
+ QByteArray::fromHex("00000005")+QByteArray("/pata")
|
||||
+ QByteArray::fromHex("00000003")+QByteArray("pon")
|
||||
+ QByteArray::fromHex("00")
|
||||
+ QByteArray::fromHex("0000000000");
|
||||
|
||||
SodepMessage payload("/pata", "pon", 1);
|
||||
Message payload("/pata", "pon", 1);
|
||||
payload.setFault(f);
|
||||
payload.setData(v);
|
||||
QTest::newRow("payload message") << payload
|
||||
@ -77,7 +79,7 @@ private slots:
|
||||
+ fSerial
|
||||
+ vSerial;
|
||||
|
||||
SodepMessage payloadId("/pata", "pon", 42);
|
||||
Message payloadId("/pata", "pon", 42);
|
||||
payloadId.setFault(f);
|
||||
payloadId.setData(v);
|
||||
QTest::newRow("payload and id message") << payloadId
|
||||
@ -92,9 +94,9 @@ private slots:
|
||||
{
|
||||
QBuffer buffer;
|
||||
|
||||
QFETCH(SodepMessage, original);
|
||||
QFETCH(Message, original);
|
||||
QFETCH(QByteArray, serialized);
|
||||
SodepMessage result;
|
||||
Message result;
|
||||
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
sodepWrite(buffer, original);
|
||||
@ -109,6 +111,6 @@ private slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(SodepMessageTest)
|
||||
QTEST_MAIN(TestMessage)
|
||||
|
||||
#include "sodepmessagetest.moc"
|
||||
#include "testmessage.moc"
|
@ -22,17 +22,18 @@
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <qtjolie/sodepclient.h>
|
||||
#include <qtjolie/sodepmessage.h>
|
||||
#include <qtjolie/sodeppendingcall.h>
|
||||
#include "sodeptesthelpers.h"
|
||||
#include <qtjolie/client.h>
|
||||
#include <qtjolie/message.h>
|
||||
#include <qtjolie/pendingcall.h>
|
||||
#include "testhelpers.h"
|
||||
|
||||
#ifndef DATA_DIR
|
||||
#error "DATA_DIR is not set. A directory containing test jolie scripts is required for this test"
|
||||
#endif
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
void dump(const SodepValue &value, int level)
|
||||
void dump(const Value &value, int level)
|
||||
{
|
||||
QString indent;
|
||||
|
||||
@ -43,15 +44,15 @@ void dump(const SodepValue &value, int level)
|
||||
|
||||
qDebug() << (indent+value.toString()) << value.toInt() << value.toDouble();
|
||||
foreach (const QString &name, value.childrenNames()) {
|
||||
QList<SodepValue> children = value.children(name);
|
||||
QList<Value> children = value.children(name);
|
||||
qDebug() << (indent+"Children:") << name;
|
||||
foreach (const SodepValue &child, children) {
|
||||
foreach (const Value &child, children) {
|
||||
dump(child, level+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dump(const SodepMessage &message)
|
||||
void dump(const Message &message)
|
||||
{
|
||||
qDebug() << "Resource :" << message.resourcePath();
|
||||
qDebug() << "Operation:" << message.operationName();
|
||||
@ -61,18 +62,18 @@ void dump(const SodepMessage &message)
|
||||
dump(message.data(), 1);
|
||||
}
|
||||
|
||||
class SodepMetaServiceTest : public QObject
|
||||
class TestMetaService : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
QProcess m_metaserviceProcess;
|
||||
SodepClient *m_client;
|
||||
Client *m_client;
|
||||
|
||||
public:
|
||||
SodepMetaServiceTest()
|
||||
TestMetaService()
|
||||
: QObject()
|
||||
{
|
||||
qRegisterMetaType<SodepMessage>();
|
||||
qRegisterMetaType<Message>();
|
||||
}
|
||||
|
||||
private slots:
|
||||
@ -82,12 +83,12 @@ private slots:
|
||||
QVERIFY2(m_metaserviceProcess.waitForStarted(), "Looks like you don't have Jolie's metaservice command");
|
||||
QTest::qWait(1000);
|
||||
|
||||
m_client = new SodepClient("localhost", 9000);
|
||||
m_client = new Client("localhost", 9000);
|
||||
}
|
||||
|
||||
void cleanupTestCase()
|
||||
{
|
||||
SodepMessage message("/", "shutdown");
|
||||
Message message("/", "shutdown");
|
||||
m_client->callNoReply(message);
|
||||
delete m_client;
|
||||
|
||||
@ -108,34 +109,34 @@ private slots:
|
||||
QFETCH(QString, resourcePrefix);
|
||||
QFETCH(QString, fileName);
|
||||
|
||||
SodepMessage message("/", "loadEmbeddedJolieService");
|
||||
SodepValue value;
|
||||
value.children("resourcePrefix") << SodepValue(resourcePrefix);
|
||||
value.children("filepath") << SodepValue(QString(DATA_DIR"/")+fileName);
|
||||
Message message("/", "loadEmbeddedJolieService");
|
||||
Value value;
|
||||
value.children("resourcePrefix") << Value(resourcePrefix);
|
||||
value.children("filepath") << Value(QString(DATA_DIR"/")+fileName);
|
||||
message.setData(value);
|
||||
|
||||
SodepMessage reply = m_client->call(message);
|
||||
Message reply = m_client->call(message);
|
||||
|
||||
SodepMessage expected("/", "loadEmbeddedJolieService");
|
||||
expected.setData(SodepValue(resourcePrefix));
|
||||
Message expected("/", "loadEmbeddedJolieService");
|
||||
expected.setData(Value(resourcePrefix));
|
||||
|
||||
sodepCompare(reply, expected);
|
||||
}
|
||||
|
||||
void shouldListServices()
|
||||
{
|
||||
SodepMessage message("/", "getServices");
|
||||
Message message("/", "getServices");
|
||||
|
||||
SodepMessage reply = m_client->call(message);
|
||||
SodepMessage expected("/", "getServices");
|
||||
SodepValue value;
|
||||
Message reply = m_client->call(message);
|
||||
Message expected("/", "getServices");
|
||||
Value value;
|
||||
|
||||
SodepValue s1;
|
||||
s1.children("isEmbedded") << SodepValue(1);
|
||||
s1.children("resourceName") << SodepValue("Math");
|
||||
SodepValue s2;
|
||||
s2.children("isEmbedded") << SodepValue(1);
|
||||
s2.children("resourceName") << SodepValue("Printer");
|
||||
Value s1;
|
||||
s1.children("isEmbedded") << Value(1);
|
||||
s1.children("resourceName") << Value("Math");
|
||||
Value s2;
|
||||
s2.children("isEmbedded") << Value(1);
|
||||
s2.children("resourceName") << Value("Printer");
|
||||
|
||||
value.children("service") << s1 << s2;
|
||||
expected.setData(value);
|
||||
@ -147,26 +148,26 @@ private slots:
|
||||
{
|
||||
QTest::addColumn<QString>("path");
|
||||
QTest::addColumn<QString>("method");
|
||||
QTest::addColumn<SodepValue>("data");
|
||||
QTest::addColumn<SodepValue>("replyData");
|
||||
QTest::addColumn<Value>("data");
|
||||
QTest::addColumn<Value>("replyData");
|
||||
|
||||
QTest::newRow("printer service") << "/Printer" << "printInput" << SodepValue("Patapatapon!") << SodepValue("success");
|
||||
QTest::newRow("math service") << "/Math" << "twice" << SodepValue(10.5) << SodepValue(21.0);
|
||||
QTest::newRow("printer service") << "/Printer" << "printInput" << Value("Patapatapon!") << Value("success");
|
||||
QTest::newRow("math service") << "/Math" << "twice" << Value(10.5) << Value(21.0);
|
||||
}
|
||||
|
||||
void shouldPlaceServiceCalls()
|
||||
{
|
||||
QFETCH(QString, path);
|
||||
QFETCH(QString, method);
|
||||
QFETCH(SodepValue, data);
|
||||
QFETCH(SodepValue, replyData);
|
||||
QFETCH(Value, data);
|
||||
QFETCH(Value, replyData);
|
||||
|
||||
SodepMessage message(path, method);
|
||||
Message message(path, method);
|
||||
message.setData(data);
|
||||
|
||||
SodepMessage reply = m_client->call(message);
|
||||
Message reply = m_client->call(message);
|
||||
|
||||
SodepMessage expected("/", method);
|
||||
Message expected("/", method);
|
||||
expected.setData(replyData);
|
||||
|
||||
sodepCompare(reply, expected);
|
||||
@ -184,18 +185,18 @@ private slots:
|
||||
{
|
||||
QFETCH(QString, serviceName);
|
||||
|
||||
SodepMessage message("/", "unloadEmbeddedService");
|
||||
SodepValue value(serviceName);
|
||||
Message message("/", "unloadEmbeddedService");
|
||||
Value value(serviceName);
|
||||
message.setData(value);
|
||||
|
||||
SodepMessage reply = m_client->call(message);
|
||||
Message reply = m_client->call(message);
|
||||
|
||||
SodepMessage expected("/", "unloadEmbeddedService");
|
||||
Message expected("/", "unloadEmbeddedService");
|
||||
|
||||
sodepCompare(reply, expected);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(SodepMetaServiceTest)
|
||||
QTEST_MAIN(TestMetaService)
|
||||
|
||||
#include "sodepmetaservicetest.moc"
|
||||
#include "testmetaservice.moc"
|
@ -25,10 +25,12 @@
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtNetwork/QTcpSocket>
|
||||
|
||||
#include <qtjolie/sodepmessage.h>
|
||||
#include <qtjolie/sodepvalue.h>
|
||||
#include <qtjolie/message.h>
|
||||
#include <qtjolie/value.h>
|
||||
#include <qtjolie/sodephelpers_p.h>
|
||||
|
||||
using namespace Jolie;
|
||||
|
||||
class MainWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -56,8 +58,8 @@ public:
|
||||
private slots:
|
||||
void sendMessage()
|
||||
{
|
||||
SodepMessage message("/", "printInput");
|
||||
message.setData(SodepValue(m_lineEdit->text()));
|
||||
Message message("/", "printInput");
|
||||
message.setData(Value(m_lineEdit->text()));
|
||||
sodepWrite(m_socket, message);
|
||||
|
||||
qDebug("Message sent:");
|
||||
@ -90,4 +92,4 @@ int main(int argc, char **argv)
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
#include "sodepprintertest.moc"
|
||||
#include "testprinter.moc"
|
@ -21,18 +21,20 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include <qtjolie/sodepvalue.h>
|
||||
#include <qtjolie/value.h>
|
||||
|
||||
#include "sodeptesthelpers.h"
|
||||
#include "testhelpers.h"
|
||||
|
||||
class SodepValueTest : public QObject
|
||||
using namespace Jolie;
|
||||
|
||||
class TestValue : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void shouldHandleInvalids()
|
||||
{
|
||||
SodepValue v;
|
||||
Value v;
|
||||
|
||||
QCOMPARE(v.toInt(), 0);
|
||||
QCOMPARE(v.toDouble(), 0.0);
|
||||
@ -47,7 +49,7 @@ private slots:
|
||||
|
||||
void shouldRespectIntValues()
|
||||
{
|
||||
SodepValue v1(42), v2;
|
||||
Value v1(42), v2;
|
||||
|
||||
QCOMPARE(v1.toInt(), 42);
|
||||
QCOMPARE(v2.toInt(), 0);
|
||||
@ -66,7 +68,7 @@ private slots:
|
||||
|
||||
void shouldRespectDoubleValues()
|
||||
{
|
||||
SodepValue v1(0.42), v2;
|
||||
Value v1(0.42), v2;
|
||||
|
||||
QCOMPARE(v1.toDouble(), 0.42);
|
||||
QCOMPARE(v2.toDouble(), 0.0);
|
||||
@ -85,7 +87,7 @@ private slots:
|
||||
|
||||
void shouldRespectStringValues()
|
||||
{
|
||||
SodepValue v1("42"), v2;
|
||||
Value v1("42"), v2;
|
||||
|
||||
QCOMPARE(v1.toString(), QString("42"));
|
||||
QCOMPARE(v2.toString(), QString());
|
||||
@ -104,10 +106,10 @@ private slots:
|
||||
|
||||
void shouldHandleChildren()
|
||||
{
|
||||
SodepValue v;
|
||||
Value v;
|
||||
|
||||
v.children("first") << SodepValue(7) << SodepValue(8);
|
||||
v.children("second") << SodepValue(42);
|
||||
v.children("first") << Value(7) << Value(8);
|
||||
v.children("second") << Value(42);
|
||||
|
||||
QCOMPARE(v.children("second").size(), 1);
|
||||
QCOMPARE(v.children("second")[0].toInt(), 42);
|
||||
@ -121,22 +123,22 @@ private slots:
|
||||
|
||||
void shouldBeSerializable_data()
|
||||
{
|
||||
QTest::addColumn<SodepValue>("original");
|
||||
QTest::addColumn<Value>("original");
|
||||
QTest::addColumn<QByteArray>("serialized");
|
||||
|
||||
QTest::newRow("empty value") << SodepValue()
|
||||
QTest::newRow("empty value") << Value()
|
||||
<< QByteArray::fromHex("0000000000");
|
||||
QTest::newRow("double value") << SodepValue(0.42)
|
||||
QTest::newRow("double value") << Value(0.42)
|
||||
<< QByteArray::fromHex("033FDAE147AE147AE100000000");
|
||||
QTest::newRow("int value") << SodepValue(42)
|
||||
QTest::newRow("int value") << Value(42)
|
||||
<< QByteArray::fromHex("020000002A00000000");
|
||||
QTest::newRow("string value") << SodepValue("foo")
|
||||
QTest::newRow("string value") << Value("foo")
|
||||
<< QByteArray::fromHex("0100000003")+QByteArray("foo")
|
||||
+ QByteArray::fromHex("00000000");
|
||||
|
||||
SodepValue complex("complex");
|
||||
complex.children("foo") << SodepValue(42);
|
||||
complex.children("bar") << SodepValue(0.42);
|
||||
Value complex("complex");
|
||||
complex.children("foo") << Value(42);
|
||||
complex.children("bar") << Value(0.42);
|
||||
QTest::newRow("complex value") << complex
|
||||
<< QByteArray::fromHex("0100000007")+QByteArray("complex")
|
||||
+ QByteArray::fromHex("00000002") // two children
|
||||
@ -152,9 +154,9 @@ private slots:
|
||||
{
|
||||
QBuffer buffer;
|
||||
|
||||
QFETCH(SodepValue, original);
|
||||
QFETCH(Value, original);
|
||||
QFETCH(QByteArray, serialized);
|
||||
SodepValue result;
|
||||
Value result;
|
||||
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
sodepWrite(buffer, original);
|
||||
@ -169,6 +171,6 @@ private slots:
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(SodepValueTest)
|
||||
QTEST_MAIN(TestValue)
|
||||
|
||||
#include "sodepvaluetest.moc"
|
||||
#include "testvalue.moc"
|
Loading…
Reference in New Issue
Block a user