5eecb31bff89b9f728c6a542af784be05d2e181f
[quassel.git] / network / server.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel Team                             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef _SERVER_H_
22 #define _SERVER_H_
23
24 #include <QtCore>
25 #include <QtNetwork>
26
27 #include "quassel.h"
28 #include "message.h"
29
30 #define DEFAULT_PORT 6667
31
32 /**
33  * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
34  * We have this run in its own thread mainly to not block other server objects or the core if something goes wrong,
35  * e.g. if some scripts starts running wild...
36  */
37
38 class Server : public QThread {
39   Q_OBJECT
40
41   public:
42     Server();
43     ~Server();
44     static void init();
45
46     void run();
47
48     // serverState state();
49
50   public slots:
51     // void setServerOptions();
52     void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT);
53     void disconnectFromIrc();
54
55     void putRawLine(const QString &input /*, Buffer *source = 0 */);
56
57   signals:
58     //void outputLine(const QString & /*, Buffer *target = 0 */);
59
60     void recvRawServerMsg(QString);
61     void recvLine(QString); // temp, should send a message to the GUI
62
63   private slots:
64     void socketHasData();
65     void socketError(QAbstractSocket::SocketError);
66     void socketConnected();
67     void socketDisconnected();
68     void socketStateChanged(QAbstractSocket::SocketState);
69
70   private:
71     QTcpSocket *socket;
72     QTextStream stream;
73
74     void handleServerMsg(Message *);
75     QString handleUserMsg(Message *);
76     static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
77     static inline void dispatchUserMsg(Message *msg)   { msg->getServer()->handleUserMsg(msg); }
78
79     class ParseError : public Exception {
80       public:
81         ParseError(Message *msg);
82     };
83
84     class UnknownCmdError : public Exception {
85       public:
86         UnknownCmdError(Message *msg);
87     };
88 };
89
90 class Buffer {};
91
92 /*
93 class TcpConnection : public QThread {
94   Q_OBJECT
95
96
97   public:
98     void run();
99     QAbstractSocket::SocketState state() const;
100
101   public slots:
102     void connectToHost(const QString &host, quint16 port = DEFAULT_PORT);
103     void disconnectFromHost();
104     void sendLine(const QString &);
105
106   signals:
107     void recvLine(QString);
108     void error(QAbstractSocket::SocketError);
109     void connected();
110     void disconnected();
111     void stateChanged(QAbstractSocket::SocketState);
112
113   private:
114     QTcpSocket socket;
115     QTextStream stream;
116 };
117 */
118
119 #endif