core can now accept a signalproxy as a client
authorMarcus Eggenberger <egs@quassel-irc.org>
Mon, 20 Oct 2008 15:26:48 +0000 (17:26 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 21 Oct 2008 16:52:52 +0000 (18:52 +0200)
src/core/core.cpp
src/core/core.h
src/core/coresession.cpp
src/core/coresession.h
src/core/sessionthread.cpp
src/core/sessionthread.h

index 8320dc0..9c41b56 100644 (file)
@@ -592,6 +592,17 @@ void Core::setupClientSession(QTcpSocket *socket, UserId uid) {
   sess->addClient(socket);
 }
 
   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!";
 SessionThread *Core::createSession(UserId uid, bool restore) {
   if(sessions.contains(uid)) {
     quWarning() << "Calling createSession() when a session for the user already exists!";
index beb7b89..26a22db 100644 (file)
@@ -42,6 +42,7 @@
 
 class CoreSession;
 class SessionThread;
 
 class CoreSession;
 class SessionThread;
+class SignalProxy;
 class Storage;
 struct NetworkInfo;
 
 class Storage;
 struct NetworkInfo;
 
@@ -288,7 +289,7 @@ class Core : public QObject {
     /** \note This method is threadsafe.
      */
     void syncStorage();
     /** \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);
   signals:
     //! Sent when a BufferInfo is updated in storage.
     void bufferInfoUpdated(UserId user, const BufferInfo &info);
index ded76ef..f287ac2 100644 (file)
@@ -229,8 +229,7 @@ void CoreSession::disconnectFromNetwork(NetworkId id) {
 void CoreSession::networkStateRequested() {
 }
 
 void CoreSession::networkStateRequested() {
 }
 
-void CoreSession::addClient(QObject *dev) { // this is QObject* so we can use it in signal connections
-  QIODevice *device = qobject_cast<QIODevice *>(dev);
+void CoreSession::addClient(QIODevice *device) {
   if(!device) {
     quError() << "Invoking CoreSession::addClient with a QObject that is not a QIODevice!";
   } else {
   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<QTcpSocket *>(iodev);
   if(socket)
 void CoreSession::removeClient(QIODevice *iodev) {
   QTcpSocket *socket = qobject_cast<QTcpSocket *>(iodev);
   if(socket)
index 492208a..d032187 100644 (file)
@@ -71,7 +71,8 @@ public:
 public slots:
   void networkStateRequested();
 
 public slots:
   void networkStateRequested();
 
-  void addClient(QObject *socket);
+  void addClient(QIODevice *device);
+  void addClient(SignalProxy *proxy);
 
   void connectToNetwork(NetworkId);
   void disconnectFromNetwork(NetworkId id);
 
   void connectToNetwork(NetworkId);
   void disconnectFromNetwork(NetworkId id);
@@ -118,6 +119,7 @@ public slots:
 
 signals:
   void initialized();
 
 signals:
   void initialized();
+  void sessionState(const QVariant &);
 
   //void msgFromGui(uint netid, QString buf, QString message);
   void displayMsg(Message message);
 
   //void msgFromGui(uint netid, QString buf, QString message);
   void displayMsg(Message message);
index d178c2b..cee4c8d 100644 (file)
 #include <QMutexLocker>
 
 #include "sessionthread.h"
 #include <QMutexLocker>
 
 #include "sessionthread.h"
-
+#include "signalproxy.h"
 #include "coresession.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() {
 }
 
 SessionThread::~SessionThread() {
@@ -52,31 +54,50 @@ bool SessionThread::isSessionInitialized() {
 
 void SessionThread::setSessionInitialized() {
   _sessionInitialized = true;
 
 void SessionThread::setSessionInitialized() {
   _sessionInitialized = true;
-  foreach(QIODevice *socket, clientQueue) {
-    addClientToSession(socket);
+  foreach(QObject *peer, clientQueue) {
+    addClientToSession(peer);
   }
   clientQueue.clear();
 }
 
   }
   clientQueue.clear();
 }
 
-void SessionThread::addClient(QIODevice *socket) {
+void SessionThread::addClient(QObject *peer) {
   if(isSessionInitialized()) {
   if(isSessionInitialized()) {
-    addClientToSession(socket);
+    addClientToSession(peer);
   } else {
   } else {
-    clientQueue.append(socket);
+    clientQueue.append(peer);
+  }
+}
+
+void SessionThread::addClientToSession(QObject *peer) {
+  QIODevice *socket = qobject_cast<QIODevice *>(peer);
+  if(socket) {
+    addRemoteClientToSession(socket);
+    return;
+  }
+
+  SignalProxy *proxy = qobject_cast<SignalProxy *>(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());
   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);
 }
 
 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;
   emit initialized();
   exec();
   delete _session;
index b6c340a..e5c41c2 100644 (file)
@@ -18,8 +18,8 @@
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _SESSIONTHREAD_H_
-#define _SESSIONTHREAD_H_
+#ifndef SESSIONTHREAD_H
+#define SESSIONTHREAD_H
 
 #include <QMutex>
 #include <QThread>
 
 #include <QMutex>
 #include <QThread>
 
 class CoreSession;
 class QIODevice;
 
 class CoreSession;
 class QIODevice;
+class SignalProxy;
 
 class SessionThread : public QThread {
   Q_OBJECT
 
 
 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<QIODevice *> clientQueue;
-    bool _sessionInitialized;
-    bool _restoreState;
+  void addRemoteClient(QIODevice *);
+  void addInternalClient(SignalProxy *);
 
 
-    bool isSessionInitialized();
-    void addClientToSession(QIODevice *socket);
+private:
+  CoreSession *_session;
+  UserId _user;
+  QList<QObject *> clientQueue;
+  bool _sessionInitialized;
+  bool _restoreState;
+
+  bool isSessionInitialized();
+  void addClientToSession(QObject *peer);
+  void addRemoteClientToSession(QIODevice *socket);
+  void addInternalClientToSession(SignalProxy *proxy);
 };
 
 #endif
 };
 
 #endif