Introduce NetworkEvent and children
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 12 Sep 2010 13:58:25 +0000 (15:58 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 13 Oct 2010 23:06:31 +0000 (01:06 +0200)
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
src/common/event.h
src/common/eventmanager.h
src/common/networkevent.cpp [new file with mode: 0644]
src/common/networkevent.h [new file with mode: 0644]
src/core/coresessioneventprocessor.h

index b27a2f1..c5da750 100644 (file)
@@ -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
index b3fa8f5..a0e82d7 100644 (file)
@@ -21,8 +21,6 @@
 #ifndef EVENT_H
 #define EVENT_H
 
-#include <QStringList>
-
 #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
index b19e8ee..54d2721 100644 (file)
@@ -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 (file)
index 0000000..fa1184b
--- /dev/null
@@ -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 (file)
index 0000000..dfa492d
--- /dev/null
@@ -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 <QStringList>
+#include <QVariantList>
+
+#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
index 5113f1b..7ed9fe4 100644 (file)
@@ -24,6 +24,7 @@
 #include <QObject>
 
 class CoreSession;
+class Event;
 
 class CoreSessionEventProcessor : public QObject {
   Q_OBJECT