b2131112699bad1544aa97f0e8ec852f10360329
[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 "message.h"
28
29 #define DEFAULT_PORT 6667
30
31 /**
32  * This is a server object, managing a single connection to an IRC server, handling the associated channels and so on.
33  * We have this run in its own thread mainly to not block other server objects or the core if something goes wrong,
34  * e.g. if some scripts starts running wild...
35  */
36
37 class Server : public QThread {
38   Q_OBJECT
39
40   public:
41     Server();
42     ~Server();
43     static void init();
44
45     void run();
46
47     // serverState state();
48
49   public slots:
50     // void setServerOptions();
51     void connectToIrc(const QString &host, quint16 port = DEFAULT_PORT);
52     void disconnectFromIrc();
53
54     void putRawLine(const QString &input /*, Buffer *source = 0 */);
55
56   signals:
57     //void outputLine(const QString & /*, Buffer *target = 0 */);
58
59     void recvRawServerMsg(QString);
60     void recvLine(QString); // temp, should send a message to the GUI
61
62   private slots:
63     void socketHasData();
64     void socketError(QAbstractSocket::SocketError);
65     void socketConnected();
66     void socketDisconnected();
67     void socketStateChanged(QAbstractSocket::SocketState);
68
69   private:
70     QTcpSocket *socket;
71     QTextStream stream;
72
73     void handleServerMsg(Message *);
74     void handleUserMsg(Message *);
75     static inline void dispatchServerMsg(Message *msg) { msg->getServer()->handleServerMsg(msg); }
76     static inline void dispatchUserMsg(Message *msg)   { msg->getServer()->handleUserMsg(msg); }
77
78 };
79
80 class Buffer {};
81
82 /*
83 class TcpConnection : public QThread {
84   Q_OBJECT
85
86
87   public:
88     void run();
89     QAbstractSocket::SocketState state() const;
90
91   public slots:
92     void connectToHost(const QString &host, quint16 port = DEFAULT_PORT);
93     void disconnectFromHost();
94     void sendLine(const QString &);
95
96   signals:
97     void recvLine(QString);
98     void error(QAbstractSocket::SocketError);
99     void connected();
100     void disconnected();
101     void stateChanged(QAbstractSocket::SocketState);
102
103   private:
104     QTcpSocket socket;
105     QTextStream stream;
106 };
107 */
108
109 #endif