From: Marcus Eggenberger Date: Mon, 20 Oct 2008 15:26:48 +0000 (+0200) Subject: core can now accept a signalproxy as a client X-Git-Tag: 0.3.1~146 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=70f360989331414e89072122a038d1675b7581b0 core can now accept a signalproxy as a client --- diff --git a/src/core/core.cpp b/src/core/core.cpp index 8320dc08..9c41b560 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -592,6 +592,17 @@ void Core::setupClientSession(QTcpSocket *socket, UserId uid) { sess->addClient(socket); } +void Core::setupInternalClientSession(SignalProxy *proxy) { + UserId uid = 3; // FIXME!!!11 + // Find or create session for validated user + SessionThread *sess; + if(sessions.contains(uid)) + sess = sessions[uid]; + else + sess = createSession(uid); + sess->addClient(proxy); +} + SessionThread *Core::createSession(UserId uid, bool restore) { if(sessions.contains(uid)) { quWarning() << "Calling createSession() when a session for the user already exists!"; diff --git a/src/core/core.h b/src/core/core.h index beb7b891..26a22db9 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -42,6 +42,7 @@ class CoreSession; class SessionThread; +class SignalProxy; class Storage; struct NetworkInfo; @@ -288,7 +289,7 @@ class Core : public QObject { /** \note This method is threadsafe. */ void syncStorage(); - + void setupInternalClientSession(SignalProxy *proxy); signals: //! Sent when a BufferInfo is updated in storage. void bufferInfoUpdated(UserId user, const BufferInfo &info); diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index ded76eff..f287ac20 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -229,8 +229,7 @@ void CoreSession::disconnectFromNetwork(NetworkId id) { void CoreSession::networkStateRequested() { } -void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it in signal connections - QIODevice *device = qobject_cast(dev); +void CoreSession::addClient(QIODevice *device) { if(!device) { quError() << "Invoking CoreSession::addClient with a QObject that is not a QIODevice!"; } else { @@ -242,6 +241,11 @@ void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it } } +void CoreSession::addClient(SignalProxy *proxy) { + signalProxy()->addPeer(proxy); + emit sessionState(sessionState()); +} + void CoreSession::removeClient(QIODevice *iodev) { QTcpSocket *socket = qobject_cast(iodev); if(socket) diff --git a/src/core/coresession.h b/src/core/coresession.h index 492208ae..d032187d 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -71,7 +71,8 @@ public: public slots: void networkStateRequested(); - void addClient(QObject *socket); + void addClient(QIODevice *device); + void addClient(SignalProxy *proxy); void connectToNetwork(NetworkId); void disconnectFromNetwork(NetworkId id); @@ -118,6 +119,7 @@ public slots: signals: void initialized(); + void sessionState(const QVariant &); //void msgFromGui(uint netid, QString buf, QString message); void displayMsg(Message message); diff --git a/src/core/sessionthread.cpp b/src/core/sessionthread.cpp index d178c2bb..cee4c8db 100644 --- a/src/core/sessionthread.cpp +++ b/src/core/sessionthread.cpp @@ -21,15 +21,17 @@ #include #include "sessionthread.h" - +#include "signalproxy.h" #include "coresession.h" -SessionThread::SessionThread(UserId uid, bool restoreState, QObject *parent) : QThread(parent) { - _user = uid; - _session = 0; - _sessionInitialized = false; - _restoreState = restoreState, - connect(this, SIGNAL(initialized()), this, SLOT(setSessionInitialized())); +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() { @@ -52,31 +54,50 @@ bool SessionThread::isSessionInitialized() { void SessionThread::setSessionInitialized() { _sessionInitialized = true; - foreach(QIODevice *socket, clientQueue) { - addClientToSession(socket); + foreach(QObject *peer, clientQueue) { + addClientToSession(peer); } clientQueue.clear(); } -void SessionThread::addClient(QIODevice *socket) { +void SessionThread::addClient(QObject *peer) { if(isSessionInitialized()) { - addClientToSession(socket); + addClientToSession(peer); } else { - clientQueue.append(socket); + clientQueue.append(peer); + } +} + +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) { +void SessionThread::addRemoteClientToSession(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(); - } + emit addRemoteClient(socket); +} + +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 *))); emit initialized(); exec(); delete _session; diff --git a/src/core/sessionthread.h b/src/core/sessionthread.h index b6c340a3..e5c41c28 100644 --- a/src/core/sessionthread.h +++ b/src/core/sessionthread.h @@ -18,8 +18,8 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _SESSIONTHREAD_H_ -#define _SESSIONTHREAD_H_ +#ifndef SESSIONTHREAD_H +#define SESSIONTHREAD_H #include #include @@ -28,38 +28,44 @@ class CoreSession; class QIODevice; +class SignalProxy; class SessionThread : public QThread { Q_OBJECT - public: - SessionThread(UserId user, bool restoreState, QObject *parent = 0); - ~SessionThread(); +public: + SessionThread(UserId user, bool restoreState, QObject *parent = 0); + ~SessionThread(); - void run(); + void run(); - CoreSession *session(); - UserId user(); + CoreSession *session(); + UserId user(); - public slots: - void addClient(QIODevice *socket); +public slots: + void addClient(QObject *peer); - private slots: - void setSessionInitialized(); +private slots: + void setSessionInitialized(); - signals: - void initialized(); - void shutdown(); +signals: + void initialized(); + void shutdown(); - private: - CoreSession *_session; - UserId _user; - QList clientQueue; - bool _sessionInitialized; - bool _restoreState; + void addRemoteClient(QIODevice *); + void addInternalClient(SignalProxy *); - bool isSessionInitialized(); - void addClientToSession(QIODevice *socket); +private: + CoreSession *_session; + UserId _user; + QList clientQueue; + bool _sessionInitialized; + bool _restoreState; + + bool isSessionInitialized(); + void addClientToSession(QObject *peer); + void addRemoteClientToSession(QIODevice *socket); + void addInternalClientToSession(SignalProxy *proxy); }; #endif