Stellarium  0.90.0
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 
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 
101 class TimeEventSender : public TypedSyncServerEventSender<SyncProtocol::Time>
102 {
103  Q_OBJECT
104 
105 public:
106  TimeEventSender();
107 protected:
108  SyncProtocol::Time constructMessage() Q_DECL_OVERRIDE;
109 };
110 
111 class LocationEventSender : public TypedSyncServerEventSender<SyncProtocol::Location>
112 {
113  Q_OBJECT
114 public:
116 protected:
117  SyncProtocol::Location constructMessage() Q_DECL_OVERRIDE;
118 };
119 
120 class SelectionEventSender : public TypedSyncServerEventSender<SyncProtocol::Selection>
121 {
122  Q_OBJECT
123 public:
125 protected:
126  SyncProtocol::Selection constructMessage() Q_DECL_OVERRIDE;
127 private:
128  StelObjectMgr* objMgr;
129 };
130 
131 class StelProperty;
132 class StelPropertyMgr;
134 {
135  Q_OBJECT
136 public:
138 protected slots:
140  virtual void newClientConnected(SyncRemotePeer& client) Q_DECL_OVERRIDE;
141  void sendStelPropChange(StelProperty* prop, const QVariant& val);
142 private:
143  StelPropertyMgr* propMgr;
144 };
145 
146 class StelMovementMgr;
147 class ViewEventSender : public TypedSyncServerEventSender<SyncProtocol::View>
148 {
149  Q_OBJECT
150 public:
151  ViewEventSender();
152 protected:
153  SyncProtocol::View constructMessage() Q_DECL_OVERRIDE;
154 
155  void update() Q_DECL_OVERRIDE;
156 private:
157  StelMovementMgr* mvMgr;
158  Vec3d lastView;
159 };
160 
161 class FovEventSender : public TypedSyncServerEventSender<SyncProtocol::Fov>
162 {
163  Q_OBJECT
164 public:
165  FovEventSender();
166 protected:
167  SyncProtocol::Fov constructMessage() Q_DECL_OVERRIDE;
168 
169  void update() Q_DECL_OVERRIDE;
170 private:
171  StelMovementMgr* mvMgr;
172  double lastFov;
173 };
174 
175 #endif
virtual void update() Q_DECL_OVERRIDE
If isDirty is true, broadcasts a message to all using constructMessage() and broadcastMessage, and resets isDirty.
Wrapper around a Q_PROPERTY (see the Qt property system for more information) of a specific object...
This class provides a semi-automatic event sender using a specific message type.
Base interface for the messages themselves, allowing to serialize/deserialize them.
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...
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.
void writeMessage(const SyncProtocol::SyncMessage &msg)
Sends a message to this peer.
virtual void newClientConnected(SyncRemotePeer &client)
This is automatically called by the SyncServer whenever a new client connects.
Manages the head movements and zoom operations.
Manages the registration of specific object properties with the StelProperty system.
Manage the selection and queries on one or more StelObjects.
void broadcastMessage(const SyncProtocol::SyncMessage &msg)
Subclasses can call this to broadcast a message to all valid connected clients.
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:36