qWarning() << "Cannot connect to internal core in client-only mode!";
return;
}
- emit startInternalCore();
InternalPeer *peer = new InternalPeer();
_peer = peer;
Client::instance()->signalProxy()->addPeer(peer); // sigproxy will take ownership
emit connectToInternalCore(peer);
setState(Connected);
-
return;
}
void coreSetupSuccess();
void coreSetupFailed(const QString &error);
- void startInternalCore();
- void connectToInternalCore(InternalPeer *connection);
+ void connectToInternalCore(QPointer<InternalPeer> connection);
// These signals MUST be handled synchronously!
void userAuthenticationRequired(CoreAccount *, bool *valid, const QString &errorMessage = QString());
: Peer(nullptr, parent)
{
static bool registered = []() {
+ qRegisterMetaType<QPointer<InternalPeer>>();
qRegisterMetaType<Protocol::SyncMessage>();
qRegisterMetaType<Protocol::RpcCall>();
qRegisterMetaType<Protocol::InitRequest>();
#pragma once
+#include <QPointer>
#include <QString>
#include "peer.h"
SignalProxy *_proxy{nullptr};
bool _isOpen{false};
};
+
+Q_DECLARE_METATYPE(QPointer<InternalPeer>)
Core::restoreState();
}
+ _initialized = true;
+
+ if (_pendingInternalConnection) {
+ connectInternalPeer(_pendingInternalConnection);
+ _pendingInternalConnection = {};
+ }
+
return true;
}
}
-void Core::setupInternalClientSession(InternalPeer *clientPeer)
+void Core::connectInternalPeer(QPointer<InternalPeer> peer)
+{
+ if (_initialized && peer) {
+ setupInternalClientSession(peer);
+ }
+ else {
+ _pendingInternalConnection = peer;
+ }
+}
+
+
+void Core::setupInternalClientSession(QPointer<InternalPeer> clientPeer)
{
if (!_configured) {
stopListening();
}
else {
quWarning() << "Core::setupInternalClientSession(): You're trying to run monolithic Quassel with an unusable Backend! Go fix it!";
+ QCoreApplication::exit(EXIT_FAILURE);
+ return;
+ }
+
+ if (!clientPeer) {
+ quWarning() << "Client peer went away, not starting a session";
return;
}
#include <vector>
#include <QDateTime>
+#include <QPointer>
#include <QString>
#include <QVariant>
#include <QTimer>
class CoreAuthHandler;
class CoreSession;
-struct NetworkInfo;
+class InternalPeer;
class SessionThread;
class SignalProxy;
+struct NetworkInfo;
+
class AbstractSqlMigrationReader;
class AbstractSqlMigrationWriter;
static const int AddClientEventId;
+signals:
+ //! Sent when a BufferInfo is updated in storage.
+ void bufferInfoUpdated(UserId user, const BufferInfo &info);
+
+ //! Relay from CoreSession::sessionState(). Used for internal connection only
+ void sessionState(const Protocol::SessionState &sessionState);
+
public slots:
bool init();
void cacheSysIdent();
- void setupInternalClientSession(InternalPeer *clientConnection);
QString setupCore(const QString &adminUser, const QString &adminPassword, const QString &backend, const QVariantMap &setupData, const QString &authenticator, const QVariantMap &authSetupMap);
-signals:
- //! Sent when a BufferInfo is updated in storage.
- void bufferInfoUpdated(UserId user, const BufferInfo &info);
-
- //! Relay from CoreSession::sessionState(). Used for internal connection only
- void sessionState(const Protocol::SessionState &sessionState);
+ void connectInternalPeer(QPointer<InternalPeer> peer);
protected:
void customEvent(QEvent *event) override;
void addClientHelper(RemotePeer *peer, UserId uid);
//void processCoreSetup(QTcpSocket *socket, QVariantMap &msg);
QString setupCoreForInternalUsage();
+ void setupInternalClientSession(QPointer<InternalPeer> peer);
bool createUser();
QDateTime _startTime;
- bool _configured;
+ bool _initialized{false};
+ bool _configured{false};
+
+ QPointer<InternalPeer> _pendingInternalConnection;
/// Whether or not strict ident mode is enabled, locking users' idents to Quassel username
bool _strictIdentEnabled;
#include "coreapplication.h"
#include "client.h"
#include "core.h"
+#include "internalpeer.h"
#include "qtui.h"
class InternalPeer;
if (!QtUiApplication::init())
return false;
- connect(Client::coreConnection(), SIGNAL(startInternalCore()), SLOT(startInternalCore()));
+ connect(Client::coreConnection(), SIGNAL(connectToInternalCore(QPointer<InternalPeer>)), this, SLOT(onConnectionRequest(QPointer<InternalPeer>)));
+
+ // If port is set, start internal core directly so external clients can connect
+ // This is useful in case the mono client re-gains remote connection capability,
+ // in which case the internal core would not have to be started by default.
+ if (Quassel::isOptionSet("port")) {
+ startInternalCore();
+ }
return true;
}
{
// Client needs to be destroyed first
Client::destroy();
- _core.reset();
+ _coreThread.quit();
+ _coreThread.wait();
Quassel::destroy();
}
void MonolithicApplication::startInternalCore()
+{
+ if (_core) {
+ // Already started
+ return;
+ }
+
+ // Start internal core in a separate thread, so it doesn't block the UI
+ _core = new Core{};
+ _core->moveToThread(&_coreThread);
+ connect(&_coreThread, SIGNAL(started()), _core, SLOT(init()));
+ connect(&_coreThread, SIGNAL(finished()), _core, SLOT(deleteLater()));
+
+ connect(this, SIGNAL(connectInternalPeer(QPointer<InternalPeer>)), _core, SLOT(connectInternalPeer(QPointer<InternalPeer>)));
+ connect(_core, SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState)));
+
+ _coreThread.start();
+}
+
+
+void MonolithicApplication::onConnectionRequest(QPointer<InternalPeer> peer)
{
if (!_core) {
- _core.reset(new Core{}); // FIXME C++14: std::make_unique
- Core::instance()->init();
+ startInternalCore();
}
- connect(Client::coreConnection(), SIGNAL(connectToInternalCore(InternalPeer*)), Core::instance(), SLOT(setupInternalClientSession(InternalPeer*)));
- connect(Core::instance(), SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState)));
+
+ // While starting the core may take a while, the object itself is instantiated synchronously and the connections
+ // established, so it's safe to emit this immediately. The core will take care of queueing the request until
+ // initialization is complete.
+ emit connectInternalPeer(peer);
}
#pragma once
-#include <memory>
+#include <QPointer>
+#include <QThread>
#include "qtuiapplication.h"
class Core;
+class InternalPeer;
class MonolithicApplication : public QtUiApplication
{
Q_OBJECT
+
public:
MonolithicApplication(int &, char **);
~MonolithicApplication() override;
bool init() override;
+signals:
+ void connectInternalPeer(QPointer<InternalPeer> peer);
+
private slots:
+ void onConnectionRequest(QPointer<InternalPeer> peer);
+
+private:
void startInternalCore();
private:
- std::unique_ptr<Core> _core;
+ QPointer<Core> _core;
+ QThread _coreThread;
};