X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Finternalconnection.cpp;fp=src%2Fcommon%2Finternalconnection.cpp;h=0000000000000000000000000000000000000000;hb=1cc49e5bd7542366995f501adf60da4ad90869e2;hp=2dda138293e7e5225324f1f3f36a397ee47c13fd;hpb=8834ebbb9e03ed09bd3509e5f8634769ff68bb48;p=quassel.git diff --git a/src/common/internalconnection.cpp b/src/common/internalconnection.cpp deleted file mode 100644 index 2dda1382..00000000 --- a/src/common/internalconnection.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * - * devel@quassel-irc.org * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) version 3. * - * * - * This program 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 General Public License for more details. * - * * - * 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., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#include -#include - -#include "internalconnection.h" - -using namespace Protocol; - -template -class PeerMessageEvent : public QEvent -{ -public: - PeerMessageEvent(InternalConnection *sender, InternalConnection::EventType eventType, const T &message) - : QEvent(QEvent::Type(eventType)), sender(sender), message(message) {} - InternalConnection *sender; - T message; -}; - - -InternalConnection::InternalConnection(QObject *parent) - : SignalProxy::AbstractPeer(parent), - _proxy(0), - _peer(0), - _isOpen(true) -{ - -} - - -InternalConnection::~InternalConnection() -{ - if (_isOpen) - emit disconnected(); -} - - -QString InternalConnection::description() const -{ - return tr("internal connection"); -} - - -bool InternalConnection::isOpen() const -{ - return true; -} - - -bool InternalConnection::isSecure() const -{ - return true; -} - - -bool InternalConnection::isLocal() const -{ - return true; -} - - -void InternalConnection::close(const QString &reason) -{ - // FIXME - Q_UNUSED(reason) - qWarning() << "closing not implemented!"; -} - - -int InternalConnection::lag() const -{ - return 0; -} - - -void InternalConnection::setSignalProxy(SignalProxy *proxy) -{ - if (!proxy && _proxy) { - _proxy = 0; - if (_isOpen) { - _isOpen = false; - emit disconnected(); - } - return; - } - - if (proxy && !_proxy) { - _proxy = proxy; - return; - } - - qWarning() << Q_FUNC_INFO << "Changing the SignalProxy is not supported!"; -} - - -void InternalConnection::setPeer(InternalConnection *peer) -{ - if (_peer) { - qWarning() << Q_FUNC_INFO << "Peer already set, ignoring!"; - return; - } - _peer = peer; - connect(peer, SIGNAL(disconnected()), SLOT(peerDisconnected())); -} - - -void InternalConnection::peerDisconnected() -{ - disconnect(_peer, 0, this, 0); - _peer = 0; - if (_isOpen) { - _isOpen = false; - emit disconnected(); - } -} - - -void InternalConnection::dispatch(const SyncMessage &msg) -{ - dispatch(SyncMessageEvent, msg); -} - - -void InternalConnection::dispatch(const RpcCall &msg) -{ - dispatch(RpcCallEvent, msg); -} - - -void InternalConnection::dispatch(const InitRequest &msg) -{ - dispatch(InitRequestEvent, msg); -} - - -void InternalConnection::dispatch(const InitData &msg) -{ - dispatch(InitDataEvent, msg); -} - - -template -void InternalConnection::dispatch(EventType eventType, const T &msg) -{ - if (!_peer) { - qWarning() << Q_FUNC_INFO << "Cannot dispatch a message without a peer!"; - return; - } - - if(QThread::currentThread() == _peer->thread()) - _peer->handle(msg); - else - QCoreApplication::postEvent(_peer, new PeerMessageEvent(this, eventType, msg)); -} - - -template -void InternalConnection::handle(const T &msg) -{ - if (!_proxy) { - qWarning() << Q_FUNC_INFO << "Cannot handle a message without having a signal proxy set!"; - return; - } - - _proxy->handle(this, msg); -} - - -void InternalConnection::customEvent(QEvent *event) -{ - switch ((int)event->type()) { - case SyncMessageEvent: { - PeerMessageEvent *e = static_cast *>(event); - handle(e->message); - break; - } - case RpcCallEvent: { - PeerMessageEvent *e = static_cast *>(event); - handle(e->message); - break; - } - case InitRequestEvent: { - PeerMessageEvent *e = static_cast *>(event); - handle(e->message); - break; - } - case InitDataEvent: { - PeerMessageEvent *e = static_cast *>(event); - handle(e->message); - break; - } - - default: - qWarning() << Q_FUNC_INFO << "Received unknown custom event:" << event->type(); - return; - } - - event->accept(); -}