We have a working message parser now, and a framework for handler functions!
[quassel.git] / network / server.h
index cc46899..5eecb31 100644 (file)
 #include <QtCore>
 #include <QtNetwork>
 
 #include <QtCore>
 #include <QtNetwork>
 
-class Server {
+#include "quassel.h"
+#include "message.h"
+
+#define DEFAULT_PORT 6667
+
+/**
+ * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
+ * We have this run in its own thread mainly to not block other server objects or the core if something goes wrong,
+ * e.g. if some scripts starts running wild...
+ */
+
+class Server : public QThread {
   Q_OBJECT
 
   Q_OBJECT
 
+  public:
+    Server();
+    ~Server();
+    static void init();
+
+    void run();
+
+    // serverState state();
+
+  public slots:
+    // void setServerOptions();
+    void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT);
+    void disconnectFromIrc();
+
+    void putRawLine(const QString &input /*, Buffer *source = 0 */);
+
+  signals:
+    //void outputLine(const QString & /*, Buffer *target = 0 */);
+
+    void recvRawServerMsg(QString);
+    void recvLine(QString); // temp, should send a message to the GUI
 
 
+  private slots:
+    void socketHasData();
+    void socketError(QAbstractSocket::SocketError);
+    void socketConnected();
+    void socketDisconnected();
+    void socketStateChanged(QAbstractSocket::SocketState);
 
   private:
 
   private:
+    QTcpSocket *socket;
+    QTextStream stream;
 
 
+    void handleServerMsg(Message *);
+    QString handleUserMsg(Message *);
+    static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
+    static inline void dispatchUserMsg(Message *msg)   { msg->getServer()->handleUserMsg(msg); }
+
+    class ParseError : public Exception {
+      public:
+        ParseError(Message *msg);
+    };
+
+    class UnknownCmdError : public Exception {
+      public:
+        UnknownCmdError(Message *msg);
+    };
 };
 
 };
 
-class Connection : public QThread {
+class Buffer {};
 
 
+/*
+class TcpConnection : public QThread {
+  Q_OBJECT
 
 
 
 
-};
+  public:
+    void run();
+    QAbstractSocket::SocketState state() const;
 
 
+  public slots:
+    void connectToHost(const QString &host, quint16 port = DEFAULT_PORT);
+    void disconnectFromHost();
+    void sendLine(const QString &);
+
+  signals:
+    void recvLine(QString);
+    void error(QAbstractSocket::SocketError);
+    void connected();
+    void disconnected();
+    void stateChanged(QAbstractSocket::SocketState);
+
+  private:
+    QTcpSocket socket;
+    QTextStream stream;
+};
+*/
 
 #endif
 
 #endif