2009-02-08 23:11:14 +01:00
|
|
|
/**
|
|
|
|
* This file is part of the KDE project
|
|
|
|
* Copyright (C) 2009 Kevin Ottens <ervin@kde.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public License
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "client.h"
|
|
|
|
#include "client_p.h"
|
2009-02-08 23:11:14 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
#include "clientthread_p.h"
|
|
|
|
#include "message.h"
|
|
|
|
#include "pendingcall.h"
|
2009-02-08 23:11:14 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
using namespace Jolie;
|
2009-02-08 23:11:14 +01:00
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Client::Client(const QString &hostName, quint16 port)
|
|
|
|
: d(new ClientPrivate(this))
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
d->readerThread = new ClientThread(hostName, port, d);
|
2009-04-13 14:39:26 +02:00
|
|
|
d->readerThread->start();
|
2009-02-08 23:11:14 +01:00
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Client::~Client()
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
2009-04-13 14:39:26 +02:00
|
|
|
delete d->readerThread;
|
2009-02-08 23:11:14 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Client::Error Client::error() const
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
|
|
|
return d->error;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
QString Client::errorString() const
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
|
|
|
return d->errorString;
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
PendingCall Client::asyncCall(const Message &message)
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
2009-04-13 14:39:26 +02:00
|
|
|
Q_ASSERT(!d->pendingCalls.contains(message.id()));
|
2009-04-25 15:50:35 +02:00
|
|
|
d->pendingCalls[message.id()] = new PendingCallPrivate(message);
|
2009-04-13 14:39:26 +02:00
|
|
|
d->readerThread->sendMessage(message);
|
2009-04-25 15:50:35 +02:00
|
|
|
return PendingCall(d->pendingCalls[message.id()]);
|
2009-02-08 23:11:14 +01:00
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
Message Client::call(const Message &message)
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
PendingCall pending = asyncCall(message);
|
2009-04-13 14:39:26 +02:00
|
|
|
pending.waitForFinished();
|
|
|
|
return pending.reply();
|
2009-02-08 23:11:14 +01:00
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
void Client::callNoReply(const Message &message)
|
2009-04-25 14:26:01 +02:00
|
|
|
{
|
|
|
|
d->readerThread->sendMessage(message);
|
|
|
|
}
|
|
|
|
|
2009-04-25 15:50:35 +02:00
|
|
|
void ClientPrivate::messageReceived(const Message &message)
|
2009-02-08 23:11:14 +01:00
|
|
|
{
|
2009-04-25 15:50:35 +02:00
|
|
|
QExplicitlySharedDataPointer<PendingCallPrivate> pending = pendingCalls.take(message.id());
|
2009-04-13 14:39:26 +02:00
|
|
|
pending->setReply(message);
|
2009-02-08 23:11:14 +01:00
|
|
|
}
|
2009-04-25 15:50:35 +02:00
|
|
|
|