X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcore%2Fsessionthread.cpp;h=a56c42b29ccb9ef06b6e0c3ada4cbc4ec159ec57;hb=42bade02f5352701d4603c72a341f04ea05922c5;hp=d178c2bb81de4f36b3a7172dc694353170de4e8d;hpb=6f2f1723f5bb3d26908f6dd297890f6fba43793b;p=quassel.git diff --git a/src/core/sessionthread.cpp b/src/core/sessionthread.cpp index d178c2bb..a56c42b2 100644 --- a/src/core/sessionthread.cpp +++ b/src/core/sessionthread.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel IRC Team * + * Copyright (C) 2005-2012 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,70 +15,113 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include #include "sessionthread.h" - +#include "signalproxy.h" #include "coresession.h" +#include "core.h" -SessionThread::SessionThread(UserId uid, bool restoreState, QObject *parent) : QThread(parent) { - _user = uid; - _session = 0; - _sessionInitialized = false; - _restoreState = restoreState, +SessionThread::SessionThread(UserId uid, bool restoreState, QObject *parent) + : QThread(parent), + _session(0), + _user(uid), + _sessionInitialized(false), + _restoreState(restoreState) +{ connect(this, SIGNAL(initialized()), this, SLOT(setSessionInitialized())); } -SessionThread::~SessionThread() { - // shut down thread gracefully - quit(); - wait(); + +SessionThread::~SessionThread() +{ + // shut down thread gracefully + quit(); + wait(); +} + + +CoreSession *SessionThread::session() +{ + return _session; } -CoreSession *SessionThread::session() { - return _session; + +UserId SessionThread::user() +{ + return _user; } -UserId SessionThread::user() { - return _user; + +bool SessionThread::isSessionInitialized() +{ + return _sessionInitialized; } -bool SessionThread::isSessionInitialized() { - return _sessionInitialized; + +void SessionThread::setSessionInitialized() +{ + _sessionInitialized = true; + foreach(QObject *peer, clientQueue) { + addClientToSession(peer); + } + clientQueue.clear(); } -void SessionThread::setSessionInitialized() { - _sessionInitialized = true; - foreach(QIODevice *socket, clientQueue) { - addClientToSession(socket); - } - clientQueue.clear(); + +void SessionThread::addClient(QObject *peer) +{ + if (isSessionInitialized()) { + addClientToSession(peer); + } + else { + clientQueue.append(peer); + } } -void SessionThread::addClient(QIODevice *socket) { - if(isSessionInitialized()) { - addClientToSession(socket); - } else { - clientQueue.append(socket); - } + +void SessionThread::addClientToSession(QObject *peer) +{ + QIODevice *socket = qobject_cast(peer); + if (socket) { + addRemoteClientToSession(socket); + return; + } + + SignalProxy *proxy = qobject_cast(peer); + if (proxy) { + addInternalClientToSession(proxy); + return; + } + + qWarning() << "SessionThread::addClient() received neither QIODevice nor SignalProxy as peer!" << peer; } -void SessionThread::addClientToSession(QIODevice *socket) { - socket->setParent(0); - socket->moveToThread(session()->thread()); - if(!QMetaObject::invokeMethod(session(), "addClient", Q_ARG(QObject *, socket))) { - qWarning() << qPrintable(tr("Could not initialize session!")); - socket->close(); - } + +void SessionThread::addRemoteClientToSession(QIODevice *socket) +{ + socket->setParent(0); + socket->moveToThread(session()->thread()); + emit addRemoteClient(socket); } -void SessionThread::run() { - _session = new CoreSession(user(), _restoreState); - emit initialized(); - exec(); - delete _session; + +void SessionThread::addInternalClientToSession(SignalProxy *proxy) +{ + emit addInternalClient(proxy); } + +void SessionThread::run() +{ + _session = new CoreSession(user(), _restoreState); + connect(this, SIGNAL(addRemoteClient(QIODevice *)), _session, SLOT(addClient(QIODevice *))); + connect(this, SIGNAL(addInternalClient(SignalProxy *)), _session, SLOT(addClient(SignalProxy *))); + connect(_session, SIGNAL(sessionState(const QVariant &)), Core::instance(), SIGNAL(sessionState(const QVariant &))); + emit initialized(); + exec(); + delete _session; +}