Provide (de)serialization for all event types
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 21 May 2012 21:30:56 +0000 (23:30 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 21 May 2012 21:36:14 +0000 (23:36 +0200)
This allows to (de)serialize events to/from QVariantMap (using only primitive
types), a prerequisite for sending events over the wire.

Use the following functions:

void EventManager::createEvent(const QVariantMap &)
QVariantMap Event::toVariantMap()

Note that there is only rudimentary plausibility checking, so for now we assume
that the QVariantMaps are created by Quassel. Before we allow these to go on the wire,
we need to make sure that this can't be tinkered with in annoying ways.

15 files changed:
src/common/ctcpevent.cpp
src/common/ctcpevent.h
src/common/event.cpp
src/common/event.h
src/common/eventmanager.cpp
src/common/eventmanager.h
src/common/ircevent.cpp
src/common/ircevent.h
src/common/messageevent.cpp
src/common/messageevent.h
src/common/networkevent.cpp
src/common/networkevent.h
src/core/CMakeLists.txt
src/core/coreeventmanager.h [new file with mode: 0644]
src/core/coresession.cpp

index 1c6546f..780cda5 100644 (file)
  ***************************************************************************/
 
 #include "ctcpevent.h"
  ***************************************************************************/
 
 #include "ctcpevent.h"
+
+Event *CtcpEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+  if(type == EventManager::CtcpEvent || type == EventManager::CtcpEventFlush)
+    return new CtcpEvent(type, map, network);
+
+  return 0;
+}
+
+
+CtcpEvent::CtcpEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : IrcEvent(type, map, network)
+{
+  _ctcpType = static_cast<CtcpType>(map.take("ctcpType").toInt());
+  _ctcpCmd = map.take("ctcpCmd").toString();
+  _target = map.take("target").toString();
+  _param = map.take("param").toString();
+  _reply = map.take("repy").toString();
+  _uuid = map.take("uuid").toString();
+}
+
+
+void CtcpEvent::toVariantMap(QVariantMap &map) const {
+  IrcEvent::toVariantMap(map);
+  map["ctcpType"] = ctcpType();
+  map["ctcpCmd"] = ctcpCmd();
+  map["target"] = target();
+  map["param"] = param();
+  map["reply"] = reply();
+  map["uuid"] = uuid().toString();
+}
index 925bb3e..42d8995 100644 (file)
@@ -64,7 +64,12 @@ public:
   inline QUuid uuid() const { return _uuid; }
   inline void setUuid(const QUuid &uuid) { _uuid = uuid; }
 
   inline QUuid uuid() const { return _uuid; }
   inline void setUuid(const QUuid &uuid) { _uuid = uuid; }
 
+  static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
 protected:
 protected:
+  explicit CtcpEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "CtcpEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
   virtual inline QString className() const { return "CtcpEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
index 57e7996..19b56a7 100644 (file)
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#include "event.h"
+#include "ctcpevent.h"
+#include "ircevent.h"
+#include "networkevent.h"
+#include "messageevent.h"
 
 Event::Event(EventManager::EventType type)
   : _type(type)
 
 Event::Event(EventManager::EventType type)
   : _type(type)
+  , _valid(true)
 {
 
 }
 
 {
 
 }
 
+
+Event::Event(EventManager::EventType type, QVariantMap &map)
+  : _type(type)
+  , _valid(true)
+{
+  if(!map.contains("flags") || !map.contains("timestamp")) {
+    qWarning() << "Received invalid serialized event:" << map;
+    setValid(false);
+    return;
+  }
+
+  setFlags(static_cast<EventManager::EventFlags>(map.take("flags").toInt())); // TODO sanity check?
+  setTimestamp(QDateTime::fromTime_t(map.take("timestamp").toUInt()));
+}
+
+
+void Event::toVariantMap(QVariantMap &map) const {
+  map["type"] = static_cast<int>(type());
+  map["flags"] = static_cast<int>(flags());
+  map["timestamp"] = timestamp().toTime_t();
+}
+
+
+QVariantMap Event::toVariantMap() const {
+  QVariantMap map;
+  toVariantMap(map);
+  return map;
+}
+
+
+Event *Event::fromVariantMap(QVariantMap &map, Network *network) {
+  int inttype = map.take("type").toInt();
+  // sanity check if we have a valid enum value
+  if(EventManager::enumName(inttype).isEmpty()) {
+    qWarning() << "Received a serialized event with unknown type" << inttype;
+    return 0;
+  }
+
+  EventManager::EventType type = static_cast<EventManager::EventType>(inttype);
+  if(type == EventManager::Invalid || type == EventManager::GenericEvent)
+    return 0;
+
+  EventManager::EventType group = static_cast<EventManager::EventType>(type & EventManager::EventGroupMask);
+
+  Event *e = 0;
+
+  // we use static create() functions to keep group-specific special cases in the files they belong
+  // e.g. IrcEventRawMessage
+  switch(group) {
+  case EventManager::NetworkEvent:
+    e = NetworkEvent::create(type, map, network);
+    break;
+  case EventManager::IrcServerEvent:
+    // not in use!
+    break;
+  case EventManager::IrcEvent:
+    e = IrcEvent::create(type, map, network);
+    break;
+  case EventManager::MessageEvent:
+    e = MessageEvent::create(type, map, network);
+    break;
+  case EventManager::CtcpEvent:
+    e = CtcpEvent::create(type, map, network);
+    break;
+  default:
+    break;
+  }
+
+  if(!e) {
+    qWarning() << "Can't create event of type" << type;
+    return 0;
+  }
+
+  if(!map.isEmpty()) {
+    qWarning() << "Event creation from map did not consume all data:" << map;
+  }
+
+  return e;
+}
+
+
 QDebug operator<<(QDebug dbg, Event *e) {
   dbg.nospace() << qPrintable(e->className()) << "("
                 << "type = 0x" << qPrintable(QString::number(e->type(), 16));
 QDebug operator<<(QDebug dbg, Event *e) {
   dbg.nospace() << qPrintable(e->className()) << "("
                 << "type = 0x" << qPrintable(QString::number(e->type(), 16));
index 85081c5..e0fb8e3 100644 (file)
 
 #include "eventmanager.h"
 
 
 #include "eventmanager.h"
 
+class Network;
+
 class Event {
 
 public:
   explicit Event(EventManager::EventType type = EventManager::Invalid);
 class Event {
 
 public:
   explicit Event(EventManager::EventType type = EventManager::Invalid);
-  virtual ~Event() {};
+  virtual ~Event() {}
 
   inline EventManager::EventType type() const { return _type; }
 
 
   inline EventManager::EventType type() const { return _type; }
 
@@ -39,6 +41,7 @@ public:
   inline bool testFlag(EventManager::EventFlag flag) { return _flags.testFlag(flag); }
   inline EventManager::EventFlags flags() const { return _flags; }
 
   inline bool testFlag(EventManager::EventFlag flag) { return _flags.testFlag(flag); }
   inline EventManager::EventFlags flags() const { return _flags; }
 
+  inline bool isValid() const { return _valid; }
   inline void stop() { setFlag(EventManager::Stopped); }
   inline bool isStopped() { return _flags.testFlag(EventManager::Stopped); }
 
   inline void stop() { setFlag(EventManager::Stopped); }
   inline bool isStopped() { return _flags.testFlag(EventManager::Stopped); }
 
@@ -48,15 +51,28 @@ public:
   //inline void setData(const QVariant &data) { _data = data; }
   //inline QVariant data() const { return _data; }
 
   //inline void setData(const QVariant &data) { _data = data; }
   //inline QVariant data() const { return _data; }
 
+  // call EventManager::createEvent(map) instead!
+  static Event *fromVariantMap(QVariantMap &map, Network *network);
+  QVariantMap toVariantMap() const;
+
 protected:
   virtual inline QString className() const { return "Event"; }
   virtual inline void debugInfo(QDebug &dbg) const { Q_UNUSED(dbg); }
 
 protected:
   virtual inline QString className() const { return "Event"; }
   virtual inline void debugInfo(QDebug &dbg) const { Q_UNUSED(dbg); }
 
+  explicit Event(EventManager::EventType type, QVariantMap &map);
+
+  // must only use primitive types: string, int, double, list, hash
+  // we want to convert this to JSON in the future!
+  virtual void toVariantMap(QVariantMap &map) const;
+
+  inline void setValid(bool valid) { _valid = valid; }
+
 private:
   EventManager::EventType _type;
   EventManager::EventFlags _flags;
   QDateTime _timestamp;
   //QVariant _data;
 private:
   EventManager::EventType _type;
   EventManager::EventFlags _flags;
   QDateTime _timestamp;
   //QVariant _data;
+  bool _valid;
 
   friend QDebug operator<<(QDebug dbg, Event *e);
 };
 
   friend QDebug operator<<(QDebug dbg, Event *e);
 };
index 03e891f..03c04df 100644 (file)
@@ -72,6 +72,13 @@ QString EventManager::enumName(int type) {
   return eventEnum().valueToKey(type);
 }
 
   return eventEnum().valueToKey(type);
 }
 
+Event *EventManager::createEvent(const QVariantMap &map) {
+  QVariantMap m = map;
+
+  Network *net = networkById(m.take("network").toInt());
+  return Event::fromVariantMap(m, net);
+}
+
 /* NOTE:
    Registering and calling handlers works fine even if they specify a subclass of Event as their parameter.
    However, this most probably is a result from a reinterpret_cast somewhere deep inside Qt, so there is *no*
 /* NOTE:
    Registering and calling handlers works fine even if they specify a subclass of Event as their parameter.
    However, this most probably is a result from a reinterpret_cast somewhere deep inside Qt, so there is *no*
index 7ead8ba..eb31921 100644 (file)
 
 #include <QMetaEnum>
 
 
 #include <QMetaEnum>
 
+#include "types.h"
+
 class Event;
 class Event;
+class Network;
 
 class EventManager : public QObject {
   Q_OBJECT
 
 class EventManager : public QObject {
   Q_OBJECT
@@ -53,7 +56,7 @@ public:
     Silent   = 0x40, ///< Don't generate a MessageEvent
     Stopped  = 0x80
   };
     Silent   = 0x40, ///< Don't generate a MessageEvent
     Stopped  = 0x80
   };
-  Q_DECLARE_FLAGS(EventFlags, EventFlag);
+  Q_DECLARE_FLAGS(EventFlags, EventFlag)
 
   /*
 
 
   /*
 
@@ -107,7 +110,7 @@ public:
     MessageEvent                = 0x00040000, ///< Stringified event suitable for converting to Message
 
     CtcpEvent                   = 0x00050000,
     MessageEvent                = 0x00040000, ///< Stringified event suitable for converting to Message
 
     CtcpEvent                   = 0x00050000,
-    CtcpEventFlush,
+    CtcpEventFlush
   };
 
   EventManager(QObject *parent = 0);
   };
 
   EventManager(QObject *parent = 0);
@@ -117,6 +120,8 @@ public:
   static QString enumName(EventType type);
   static QString enumName(int type); // for sanity tests
 
   static QString enumName(EventType type);
   static QString enumName(int type); // for sanity tests
 
+  Event *createEvent(const QVariantMap &map);
+
 public slots:
   void registerObject(QObject *object, Priority priority = NormalPriority,
                       const QString &methodPrefix = "process",
 public slots:
   void registerObject(QObject *object, Priority priority = NormalPriority,
                       const QString &methodPrefix = "process",
@@ -137,6 +142,7 @@ public slots:
   void postEvent(Event *event);
 
 protected:
   void postEvent(Event *event);
 
 protected:
+  virtual Network *networkById(NetworkId id) const = 0;
   virtual void customEvent(QEvent *event);
 
 private:
   virtual void customEvent(QEvent *event);
 
 private:
index 9757c28..b9f7e45 100644 (file)
  ***************************************************************************/
 
 #include "ircevent.h"
  ***************************************************************************/
 
 #include "ircevent.h"
+
+Event *IrcEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+  if((type & EventManager::IrcEventNumericMask) == EventManager::IrcEventNumeric)
+    return new IrcEventNumeric(type, map, network);
+
+  if((type & EventManager::EventGroupMask) != EventManager::IrcEvent)
+    return 0;
+
+  switch(type) {
+  case EventManager::IrcEventRawPrivmsg:
+  case EventManager::IrcEventRawNotice:
+    return new IrcEventRawMessage(type, map, network);
+
+  default:
+    return new IrcEvent(type, map, network);
+  }
+}
+
+
+IrcEvent::IrcEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : NetworkEvent(type, map, network)
+{
+  _prefix = map.take("prefix").toString();
+  _params = map.take("params").toStringList();
+}
+
+
+void IrcEvent::toVariantMap(QVariantMap &map) const {
+  NetworkEvent::toVariantMap(map);
+  map["prefix"] = prefix();
+  map["params"] = params();
+}
+
+
+IrcEventNumeric::IrcEventNumeric(EventManager::EventType type, QVariantMap &map, Network *network)
+  : IrcEvent(type, map, network)
+{
+  _number = map.take("number").toUInt();
+  _target = map.take("target").toString();
+}
+
+
+void IrcEventNumeric::toVariantMap(QVariantMap &map) const {
+  IrcEvent::toVariantMap(map);
+  map["number"] = number();
+  map["target"] = target();
+}
+
+
+IrcEventRawMessage::IrcEventRawMessage(EventManager::EventType type, QVariantMap &map, Network *network)
+  : IrcEvent(type, map, network)
+{
+  _rawMessage = map.take("rawMessage").toByteArray();
+}
+
+
+void IrcEventRawMessage::toVariantMap(QVariantMap &map) const {
+  IrcEvent::toVariantMap(map);
+  map["rawMessage"] = rawMessage();
+}
index 5b93d61..71e4ad2 100644 (file)
@@ -40,7 +40,12 @@ public:
   inline QStringList params() const { return _params; }
   inline void setParams(const QStringList &params) { _params = params; }
 
   inline QStringList params() const { return _params; }
   inline void setParams(const QStringList &params) { _params = params; }
 
+  static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
 protected:
 protected:
+  explicit IrcEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "IrcEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
   virtual inline QString className() const { return "IrcEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
@@ -68,6 +73,9 @@ public:
   inline void setTarget(const QString &target) { _target = target; }
 
 protected:
   inline void setTarget(const QString &target) { _target = target; }
 
 protected:
+  explicit IrcEventNumeric(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "IrcEventNumeric"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     dbg << ", num = " << number();
   virtual inline QString className() const { return "IrcEventNumeric"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     dbg << ", num = " << number();
@@ -81,6 +89,7 @@ private:
   uint _number;
   QString _target;
 
   uint _number;
   QString _target;
 
+  friend class IrcEvent;
 };
 
 class IrcEventRawMessage : public IrcEvent {
 };
 
 class IrcEventRawMessage : public IrcEvent {
@@ -101,6 +110,9 @@ public:
   inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; }
 
 protected:
   inline void setRawMessage(const QByteArray &rawMessage) { _rawMessage = rawMessage; }
 
 protected:
+  explicit IrcEventRawMessage(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "IrcEventRawMessage"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
   virtual inline QString className() const { return "IrcEventRawMessage"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
@@ -112,6 +124,8 @@ protected:
 
 private:
   QByteArray _rawMessage;
 
 private:
   QByteArray _rawMessage;
+
+  friend class IrcEvent;
 };
 
 #endif
 };
 
 #endif
index 6c36715..606103e 100644 (file)
 
 #include "messageevent.h"
 
 
 #include "messageevent.h"
 
+Event *MessageEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+  if(type == EventManager::MessageEvent)
+    return new MessageEvent(type, map, network);
+
+  return 0;
+}
+
 
 MessageEvent::MessageEvent(Message::Type msgType, Network *net, const QString &msg, const QString &sender, const QString &target,
                            Message::Flags flags, const QDateTime &timestamp)
 
 MessageEvent::MessageEvent(Message::Type msgType, Network *net, const QString &msg, const QString &sender, const QString &target,
                            Message::Flags flags, const QDateTime &timestamp)
@@ -47,6 +54,30 @@ MessageEvent::MessageEvent(Message::Type msgType, Network *net, const QString &m
     setTimestamp(QDateTime::currentDateTime());
 }
 
     setTimestamp(QDateTime::currentDateTime());
 }
 
+
+MessageEvent::MessageEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : NetworkEvent(type, map, network)
+{
+  _msgType = static_cast<Message::Type>(map.take("messageType").toInt());
+  _msgFlags = static_cast<Message::Flags>(map.take("messageFlags").toInt());
+  _bufferType = static_cast<BufferInfo::Type>(map.take("bufferType").toInt());
+  _text = map.take("text").toString();
+  _sender = map.take("sender").toString();
+  _target = map.take("target").toString();
+}
+
+
+void MessageEvent::toVariantMap(QVariantMap &map) const {
+  NetworkEvent::toVariantMap(map);
+  map["messageType"] = msgType();
+  map["messageFlags"] = (int)msgFlags();
+  map["bufferType"] = bufferType();
+  map["text"] = text();
+  map["sender"] = sender();
+  map["target"] = target();
+}
+
+
 BufferInfo::Type MessageEvent::bufferTypeByTarget(const QString &target) const {
   if(target.isEmpty())
     return BufferInfo::StatusBuffer;
 BufferInfo::Type MessageEvent::bufferTypeByTarget(const QString &target) const {
   if(target.isEmpty())
     return BufferInfo::StatusBuffer;
index cf77dce..e93794c 100644 (file)
@@ -53,7 +53,12 @@ public:
   inline void setMsgFlag(Message::Flag flag) { _msgFlags |= flag; }
   inline void setMsgFlags(Message::Flags flags) { _msgFlags = flags; }
 
   inline void setMsgFlag(Message::Flag flag) { _msgFlags |= flag; }
   inline void setMsgFlags(Message::Flags flags) { _msgFlags = flags; }
 
+  static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
 protected:
 protected:
+  explicit MessageEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "MessageEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
   virtual inline QString className() const { return "MessageEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
index d723b19..1752b58 100644 (file)
  ***************************************************************************/
 
 #include "networkevent.h"
  ***************************************************************************/
 
 #include "networkevent.h"
+
+Event *NetworkEvent::create(EventManager::EventType type, QVariantMap &map, Network *network) {
+  switch(type) {
+  case EventManager::NetworkIncoming:
+    return new NetworkDataEvent(type, map, network);
+
+  case EventManager::NetworkConnecting:
+  case EventManager::NetworkInitializing:
+  case EventManager::NetworkInitialized:
+  case EventManager::NetworkReconnecting:
+  case EventManager::NetworkDisconnecting:
+  case EventManager::NetworkDisconnected:
+    return new NetworkConnectionEvent(type, map, network);
+
+  case EventManager::NetworkSplitJoin:
+  case EventManager::NetworkSplitQuit:
+    return new NetworkSplitEvent(type, map, network);
+
+  default:
+    return 0;
+  }
+}
+
+
+NetworkEvent::NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : Event(type, map)
+  , _network(network)
+{
+
+}
+
+
+void NetworkEvent::toVariantMap(QVariantMap &map) const {
+  Event::toVariantMap(map);
+  map["network"] = networkId().toInt();
+}
+
+
+NetworkDataEvent::NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : NetworkEvent(type, map, network)
+{
+  _data = map.take("data").toByteArray();
+}
+
+
+void NetworkDataEvent::toVariantMap(QVariantMap &map) const {
+  NetworkEvent::toVariantMap(map);
+  map["data"] = data();
+}
+
+
+NetworkConnectionEvent::NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : NetworkEvent(type, map, network)
+{
+  _state = static_cast<Network::ConnectionState>(map.take("state").toInt()); // FIXME: check enum plausibility
+}
+
+
+void NetworkConnectionEvent::toVariantMap(QVariantMap &map) const {
+  NetworkEvent::toVariantMap(map);
+  map["state"] = connectionState();
+}
+
+
+NetworkSplitEvent::NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network)
+  : NetworkEvent(type, map, network)
+{
+  _channel = map.take("channel").toString();
+  _users = map.take("users").toStringList();
+  _quitMsg = map.take("quitMessage").toString();
+}
+
+
+void NetworkSplitEvent::toVariantMap(QVariantMap &map) const
+{
+  NetworkEvent::toVariantMap(map);
+  map["channel"] = channel();
+  map["users"] = users();
+  map["quitMessage"] = quitMessage();
+}
index 5a08733..7e46984 100644 (file)
@@ -38,7 +38,12 @@ public:
   inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); }
   inline Network *network() const { return _network; }
 
   inline NetworkId networkId() const { return network()? network()->networkId() : NetworkId(); }
   inline Network *network() const { return _network; }
 
+  static Event *create(EventManager::EventType type, QVariantMap &map, Network *network);
+
 protected:
 protected:
+  explicit NetworkEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "NetworkEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); }
 
   virtual inline QString className() const { return "NetworkEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const { dbg.nospace() << ", net = " << qPrintable(_network->networkName()); }
 
@@ -46,6 +51,8 @@ private:
   Network *_network;
 };
 
   Network *_network;
 };
 
+/*****************************************************************************/
+
 class NetworkConnectionEvent : public NetworkEvent {
 
 public:
 class NetworkConnectionEvent : public NetworkEvent {
 
 public:
@@ -58,6 +65,9 @@ public:
   inline void setConnectionState(Network::ConnectionState state) { _state = state; }
 
 protected:
   inline void setConnectionState(Network::ConnectionState state) { _state = state; }
 
 protected:
+  explicit NetworkConnectionEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "NetworkConnectionEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
   virtual inline QString className() const { return "NetworkConnectionEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
@@ -66,6 +76,8 @@ protected:
 
 private:
   Network::ConnectionState _state;
 
 private:
   Network::ConnectionState _state;
+
+  friend class NetworkEvent;
 };
 
 class NetworkDataEvent : public NetworkEvent {
 };
 
 class NetworkDataEvent : public NetworkEvent {
@@ -80,6 +92,9 @@ public:
   inline void setData(const QByteArray &data) { _data = data; }
 
 protected:
   inline void setData(const QByteArray &data) { _data = data; }
 
 protected:
+  explicit NetworkDataEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
   virtual inline QString className() const { return "NetworkDataEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
   virtual inline QString className() const { return "NetworkDataEvent"; }
   virtual inline void debugInfo(QDebug &dbg) const {
     NetworkEvent::debugInfo(dbg);
@@ -88,6 +103,8 @@ protected:
 
 private:
   QByteArray _data;
 
 private:
   QByteArray _data;
+
+  friend class NetworkEvent;
 };
 
 class NetworkSplitEvent : public NetworkEvent {
 };
 
 class NetworkSplitEvent : public NetworkEvent {
@@ -108,10 +125,24 @@ public:
   inline QStringList users() const { return _users; }
   inline QString quitMessage() const { return _quitMsg; }
 
   inline QStringList users() const { return _users; }
   inline QString quitMessage() const { return _quitMsg; }
 
+protected:
+  explicit NetworkSplitEvent(EventManager::EventType type, QVariantMap &map, Network *network);
+  void toVariantMap(QVariantMap &map) const;
+
+  virtual inline QString className() const { return "NetworkSplitEvent"; }
+  virtual inline void debugInfo(QDebug &dbg) const {
+    NetworkEvent::debugInfo(dbg);
+    dbg.nospace() << ", channel = " << qPrintable(channel())
+                  << ", users = " << users()
+                  << ", quitmsg = " << quitMessage();
+  }
+
 private:
   QString _channel;
   QStringList _users;
   QString _quitMsg;
 private:
   QString _channel;
   QStringList _users;
   QString _quitMsg;
+
+  friend class NetworkEvent;
 };
 
 
 };
 
 
index 5c6f0b6..6df50bf 100644 (file)
@@ -46,6 +46,7 @@ set(MOC_HDRS
     corebufferviewconfig.h
     corebufferviewmanager.h
     corecoreinfo.h
     corebufferviewconfig.h
     corebufferviewmanager.h
     corecoreinfo.h
+    coreeventmanager.h
     coreidentity.h
     coreignorelistmanager.h
     coreircchannel.h
     coreidentity.h
     coreignorelistmanager.h
     coreircchannel.h
diff --git a/src/core/coreeventmanager.h b/src/core/coreeventmanager.h
new file mode 100644 (file)
index 0000000..41e5f1c
--- /dev/null
@@ -0,0 +1,47 @@
+/***************************************************************************
+ *   Copyright (C) 2005-2012 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 COREEVENTMANAGER_H
+#define COREEVENTMANAGER_H
+
+#include "corenetwork.h"
+#include "coresession.h"
+#include "eventmanager.h"
+
+class CoreSession;
+
+class CoreEventManager : public EventManager
+{
+  Q_OBJECT
+
+public:
+  CoreEventManager(CoreSession *session)
+    : EventManager(session)
+    , _coreSession(session)
+  { }
+
+protected:
+  inline Network *networkById(NetworkId id) const { return _coreSession->network(id); }
+
+private:
+  CoreSession *_coreSession;
+};
+
+#endif
index 603d291..6c0c5e1 100644 (file)
@@ -27,6 +27,7 @@
 #include "corebuffersyncer.h"
 #include "corebacklogmanager.h"
 #include "corebufferviewmanager.h"
 #include "corebuffersyncer.h"
 #include "corebacklogmanager.h"
 #include "corebufferviewmanager.h"
+#include "coreeventmanager.h"
 #include "coreidentity.h"
 #include "coreignorelistmanager.h"
 #include "coreirclisthelper.h"
 #include "coreidentity.h"
 #include "coreignorelistmanager.h"
 #include "coreirclisthelper.h"
@@ -35,7 +36,6 @@
 #include "coresessioneventprocessor.h"
 #include "coreusersettings.h"
 #include "ctcpparser.h"
 #include "coresessioneventprocessor.h"
 #include "coreusersettings.h"
 #include "ctcpparser.h"
-#include "eventmanager.h"
 #include "eventstringifier.h"
 #include "ircchannel.h"
 #include "ircparser.h"
 #include "eventstringifier.h"
 #include "ircchannel.h"
 #include "ircparser.h"
@@ -62,7 +62,7 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
     _ircListHelper(new CoreIrcListHelper(this)),
     _networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this)),
     _coreInfo(this),
     _ircListHelper(new CoreIrcListHelper(this)),
     _networkConfig(new CoreNetworkConfig("GlobalNetworkConfig", this)),
     _coreInfo(this),
-    _eventManager(new EventManager(this)),
+    _eventManager(new CoreEventManager(this)),
     _eventStringifier(new EventStringifier(this)),
     _sessionEventProcessor(new CoreSessionEventProcessor(this)),
     _ctcpParser(new CtcpParser(this)),
     _eventStringifier(new EventStringifier(this)),
     _sessionEventProcessor(new CoreSessionEventProcessor(this)),
     _ctcpParser(new CtcpParser(this)),