Stellarium 0.15.2
SyncServerEventSenders.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 SYNCSERVEREVENTSENDERS_HPP_
21 #define SYNCSERVEREVENTSENDERS_HPP_
22 
23 #include "SyncProtocol.hpp"
24 #include "SyncMessages.hpp"
25 
26 class SyncServer;
27 class StelCore;
28 class StelObjectMgr;
29 
31 class SyncServerEventSender : public QObject
32 {
33  Q_OBJECT
34 public:
36  virtual ~SyncServerEventSender() {}
37 
38 protected slots:
39 
44  virtual void reactToStellariumEvent() { isDirty = true; }
45 
49  virtual void newClientConnected(SyncRemotePeer& client) { Q_UNUSED(client); }
50 protected:
54  virtual void update() {}
55 
57  void broadcastMessage(const SyncMessage& msg);
59  bool isDirty;
62 private:
63  SyncServer* server;
64  friend class SyncServer;
65 };
66 
68 template<class T>
70 {
71 protected:
74  virtual T constructMessage() = 0;
75 
77  virtual void newClientConnected(SyncRemotePeer& client) Q_DECL_OVERRIDE;
78 
81  virtual void update() Q_DECL_OVERRIDE;
82 };
83 
84 template<class T>
86 {
87  client.writeMessage(constructMessage());
88 }
89 
90 template<class T>
92 {
93  if(isDirty)
94  {
95  broadcastMessage(constructMessage());
96  isDirty = false;
97  }
98 }
99 
102 {
103  Q_OBJECT
104 
105 public:
106  TimeEventSender();
107 protected:
108  Time constructMessage() Q_DECL_OVERRIDE;
109 };
110 
112 {
113  Q_OBJECT
114 public:
116 protected:
117  Location constructMessage() Q_DECL_OVERRIDE;
118 };
119 
121 {
122  Q_OBJECT
123 public:
125 protected:
126  Selection constructMessage() Q_DECL_OVERRIDE;
127 private:
128  StelObjectMgr* objMgr;
129 };
130 
131 #endif
virtual void update() Q_DECL_OVERRIDE
If isDirty is true, broadcasts a message to all using constructMessage() and broadcastMessage, and resets isDirty.
This class provides a semi-automatic event sender using a specific message type.
virtual void newClientConnected(SyncRemotePeer &client) Q_DECL_OVERRIDE
Uses constructMessage() to send a message to the new client.
Handling the connection to a remote peer (i.e. all clients on the server, and the server on the clien...
void writeMessage(const SyncMessage &msg)
Sends a message to this peer.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
bool isDirty
Free to use by sublasses. Recommendation: use to track if update() should broadcast a message...
Subclasses of this class notify clients of state changes.
virtual void update()
This is guaranteed to be called once per frame (usually after all other StelModules have been updated...
virtual void reactToStellariumEvent()
This may be used to react to Stellarium application events and queue a broadcast or store the changed...
StelCore * core
Direct access to StelCore.
virtual void newClientConnected(SyncRemotePeer &client)
This is automatically called by the SyncServer whenever a new client connects.
void broadcastMessage(const SyncMessage &msg)
Subclasses can call this to broadcast a message to all valid connected clients.
Base interface for the messages themselves, allowing to serialize/deserialize them.
Manage the selection and queries on one or more StelObjects.
Notifies clients of simulation time jumps and time scale changes.
Implements a server to which SyncClients can connect and receive state changes.
Definition: SyncServer.hpp:33