- Support to get/send binary data in Network::Socket
[dashstudio.git] / src / dashserver / connection.h
bloba485984178d0194d096f789df0fc661e707da374
1 /***************************************************************************
2 * Copyright (C) 2006 by David Cuadrado *
3 * krawek@gmail.com *
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 ***************************************************************************/
21 #ifndef DOMSERVERCONNECTION_H
22 #define DOMSERVERCONNECTION_H
24 #include <QThread>
25 #include <QTcpSocket>
26 #include <QDomDocument>
28 #include <dash/network/socketobserver.h>
29 #include <dash/network/package/error.h>
31 namespace Dash {
32 namespace Network {
33 class Socket;
38 namespace DashServer {
39 namespace Users {
40 class User;
43 class TcpServer;
45 /**
46 * Esta clase representa cada conexion de un cliente al servidor, es un hilo.
47 * @author David Cuadrado \<krawek@gmail.com\>
49 class Connection : public QThread, virtual protected Dash::Network::SocketObserver
51 Q_OBJECT;
53 public:
54 Connection(int socketDescriptor, DashServer::TcpServer *server);
55 ~Connection();
57 void sendToClient(const QString &xml, bool sign) const;
58 void sendToAll(const QString &xml, bool sign);
60 void sendToClient(QDomDocument &doc, bool sign);
61 void sendToAll(QDomDocument &doc, bool sign);
64 void setData(int key, const QVariant &value);
65 QVariant data(int key) const;
67 Dash::Network::Socket *client() const;
68 TcpServer *server() const;
70 void setUser(Users::User *user);
71 Users::User *user() const;
73 void generateSign();
75 QString sign() const;
76 QString signXml(const QString &xml) const;
78 void setValid(bool v);
79 bool isValid() const;
81 protected:
82 void run();
83 void readed(const QString &readed);
84 void dataReaded(const QByteArray &data);
86 public slots:
87 void close();
88 void sendError(const QString & message, Dash::Network::Package::Error::Level level);
90 private slots:
91 void removeConnection();
93 signals:
94 void error(QTcpSocket::SocketError socketError);
95 void requestSendToAll(const QString &msg);
96 void connectionClosed( DashServer::Connection *cnn);
97 void packageReaded(DashServer::Connection *cnn, const QString& root,const QString & packages );
100 private:
101 class Private;
102 Private *const d;
107 #endif