Stellarium 0.15.2
SyncClient.hpp
1 /*
2  * Stellarium Remote Sync plugin
3  * Copyright (C) 2015 Florian Schaukowitsch
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (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 Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef SYNCCLIENT_HPP_
21 #define SYNCCLIENT_HPP_
22 
23 #include <QObject>
24 #include <QTcpSocket>
25 
26 class SyncMessageHandler;
27 class SyncRemotePeer;
28 
30 class SyncClient : public QObject
31 {
32  Q_OBJECT
33 public:
34  SyncClient(QObject* parent = 0);
35  virtual ~SyncClient();
36 
38  bool isConnected() const;
39  QString errorString() const { return errorStr; }
40 
41 public slots:
42  void connectToServer(const QString& host, const int port);
43  void disconnectFromServer();
44 
45 protected:
46  void timerEvent(QTimerEvent* evt) Q_DECL_OVERRIDE;
47 signals:
48  void connected();
49  void disconnected();
50  void connectionError();
51 private slots:
52  void dataReceived();
53  void socketConnected();
54  void socketDisconnected();
55  void socketError(QAbstractSocket::SocketError err);
56  void emitError(const QString& msg);
57 
58 private:
59  void checkTimeout();
60 
61  QString errorStr;
62  bool isConnecting;
63  SyncRemotePeer* server;
64  int timeoutTimerId;
65  QVector<SyncMessageHandler*> handlerList;
66 
67  friend class ClientErrorHandler;
68 };
69 
70 
71 #endif
A client which can connect to a SyncServer to receive state changes, and apply them.
Definition: SyncClient.hpp:30
bool isConnected() const
True if the connection has been established completely.
Base interface for message handlers, i.e. reacting to messages.
Handling the connection to a remote peer (i.e. all clients on the server, and the server on the clien...