From 85fb228631cfb087ce80f4b778fae5f1c3877008 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 12 Sep 2010 15:58:25 +0200 Subject: [PATCH] Introduce NetworkEvent and children This family of events encapsulates network-related events: * NetworkConnectionEvent handles the network's connection state * NetworkDataEvent handles raw data sent from or to the network socket CoreNetwork now sends a data event to the session's EventManager. --- src/common/CMakeLists.txt | 2 + src/common/event.h | 6 +-- src/common/eventmanager.h | 1 + src/common/networkevent.cpp | 21 ++++++++ src/common/networkevent.h | 75 ++++++++++++++++++++++++++++ src/core/coresessioneventprocessor.h | 1 + 6 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/common/networkevent.cpp create mode 100644 src/common/networkevent.h diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index b27a2f12..c5da7506 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -23,6 +23,7 @@ set(SOURCES message.cpp network.cpp networkconfig.cpp + networkevent.cpp quassel.cpp settings.cpp signalproxy.cpp @@ -54,6 +55,7 @@ set(HEADERS ${MOC_HDRS} bufferinfo.h cliparser.h event.h + networkevent.h logger.h message.h types.h diff --git a/src/common/event.h b/src/common/event.h index b3fa8f5d..a0e82d70 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -21,8 +21,6 @@ #ifndef EVENT_H #define EVENT_H -#include - #include "eventmanager.h" class Event { @@ -33,10 +31,10 @@ public: inline EventManager::EventType type() const { return _type; } - //virtual QStringList params() const; - private: EventManager::EventType _type; }; +/*******/ + #endif diff --git a/src/common/eventmanager.h b/src/common/eventmanager.h index b19e8eee..54d27214 100644 --- a/src/common/eventmanager.h +++ b/src/common/eventmanager.h @@ -68,6 +68,7 @@ public: IrcServerEvent = 0x00020000, IrcServerIncoming, + IrcServerParseError, IrcEvent = 0x00030000, IrcEventCap, diff --git a/src/common/networkevent.cpp b/src/common/networkevent.cpp new file mode 100644 index 00000000..fa1184be --- /dev/null +++ b/src/common/networkevent.cpp @@ -0,0 +1,21 @@ +/*************************************************************************** + * Copyright (C) 2005-2010 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "networkevent.h" diff --git a/src/common/networkevent.h b/src/common/networkevent.h new file mode 100644 index 00000000..dfa492d7 --- /dev/null +++ b/src/common/networkevent.h @@ -0,0 +1,75 @@ +/*************************************************************************** + * Copyright (C) 2005-2010 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef NETWORKEVENT_H +#define NETWORKEVENT_H + +#include +#include + +#include "event.h" +#include "network.h" + +class NetworkEvent : public Event { + +public: + explicit NetworkEvent(EventManager::EventType type, Network *network) + : Event(type), + _network(network) + {} + + inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); } + inline Network *network() const { return _network; } + +private: + Network *_network; +}; + +class NetworkConnectionEvent : public NetworkEvent { + +public: + explicit NetworkConnectionEvent(EventManager::EventType type, Network *network, Network::ConnectionState state) + : NetworkEvent(type, network), + _state(state) + {} + + inline Network::ConnectionState connectionState() const { return _state; } + inline void setConnectionState(Network::ConnectionState state) { _state = state; } + +private: + Network::ConnectionState _state; +}; + +class NetworkDataEvent : public NetworkEvent { + +public: + explicit NetworkDataEvent(EventManager::EventType type, Network *network, const QByteArray &data) + : NetworkEvent(type, network), + _data(data) + {} + + inline QByteArray data() const { return _data; } + inline void setData(const QByteArray &data) { _data = data; } + +private: + QByteArray _data; +}; + +#endif diff --git a/src/core/coresessioneventprocessor.h b/src/core/coresessioneventprocessor.h index 5113f1bc..7ed9fe46 100644 --- a/src/core/coresessioneventprocessor.h +++ b/src/core/coresessioneventprocessor.h @@ -24,6 +24,7 @@ #include class CoreSession; +class Event; class CoreSessionEventProcessor : public QObject { Q_OBJECT -- 2.20.1