Stellarium  0.90.0
SyncMessages.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 SYNCMESSAGES_HPP_
21 #define SYNCMESSAGES_HPP_
22 
23 #include "SyncProtocol.hpp"
24 #include "StelLocation.hpp"
25 #include "VecMath.hpp"
26 
27 namespace SyncProtocol
28 {
29 
30 class ErrorMessage : public SyncMessage
31 {
32 public:
33  ErrorMessage();
34  ErrorMessage(const QString& msg);
35 
36  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::ERROR; }
37  void serialize(QDataStream& stream) const Q_DECL_OVERRIDE;
38  bool deserialize(QDataStream& stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
39 
40  QString message;
41 };
42 
44 {
45 public:
48 
49  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::SERVER_CHALLENGE; }
50  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
51  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
52 
53  quint8 protocolVersion;
54  quint32 remoteSyncVersion;
55  quint32 stellariumVersion;
56  QUuid clientId; //The ID the server has assigned to the client, working as a very basic challenge value
57 };
58 
60 {
61 public:
64 
65  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::CLIENT_CHALLENGE_RESPONSE; }
66  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
67  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
68 
69  //basically the same as the challenge, without magic string and proto version
70  quint32 remoteSyncVersion;
71  quint32 stellariumVersion;
72  QUuid clientId; //Must match the server challenge ID
73 };
74 
77 {
78 public:
79  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::SERVER_CHALLENGERESPONSEVALID; }
80 };
81 
82 class Time : public SyncMessage
83 {
84 public:
85  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::TIME; }
86 
87  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
88  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
89 
90  //TODO implement network delay compensation (also for other message types where it makes sense)
91  //TODO maybe split up so that each message is only for 1 thing?
92  qint64 lastTimeSyncTime; //corresponds to StelCore::milliSecondsOfLastJDayUpdate
93  double jDay; //current jDay, without any time zone/deltaT adjustments
94  double timeRate; //current time rate
95 
96 };
97 
98 class Location : public SyncMessage
99 {
100 public:
101  Location();
102 
103  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::LOCATION; }
104 
105  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
106  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
107 
108  StelLocation stelLocation;
109  double totalDuration;
110  double timeToGo;
111 };
112 
113 class Selection : public SyncMessage
114 {
115 public:
116  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::SELECTION; }
117 
118  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
119  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
120 
121  QDebug debugOutput(QDebug dbg) const Q_DECL_OVERRIDE
122  {
123  return dbg<<selectedObjects;
124  }
125 
126  //list of type/ID pairs
127  QList< QPair<QString,QString> > selectedObjects;
128 };
129 
130 class Alive : public SyncMessage
131 {
132 public:
133  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::ALIVE; }
134 };
135 
137 {
138 public:
139  SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::STELPROPERTY; }
140 
141  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
142  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
143 
144  QDebug debugOutput(QDebug dbg) const Q_DECL_OVERRIDE
145  {
146  return dbg<<propId<<value;
147  }
148 
149  QString propId;
150  QVariant value;
151 };
152 
153 class View : public SyncMessage
154 {
155 public:
156  SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::VIEW; }
157 
158  void serialize(QDataStream& stream) const Q_DECL_OVERRIDE;
159  bool deserialize(QDataStream &stream, tPayloadSize dataSize) Q_DECL_OVERRIDE;
160 
161  Vec3d viewAltAz;
162 };
163 
164 class Fov : public SyncMessage
165 {
166 public:
167  SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::FOV; }
168 
169  void serialize(QDataStream& stream) const Q_DECL_OVERRIDE;
170  bool deserialize(QDataStream &stream, tPayloadSize dataSize) Q_DECL_OVERRIDE;
171 
172  double fov;
173 };
174 
175 }
176 
177 #endif
Store the informations for a location on a planet.
QDebug debugOutput(QDebug dbg) const Q_DECL_OVERRIDE
Subclasses can override this to provide proper debug output.
bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE
Subclasses should override this to load their contents from the data stream.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
Base interface for the messages themselves, allowing to serialize/deserialize them.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
Contains sync protocol data definitions shared between client and server.
SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
QDebug debugOutput(QDebug dbg) const Q_DECL_OVERRIDE
Subclasses can override this to provide proper debug output.
SyncMessageType
Contains the possible message types.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
This is just a notify message with no data, so no serialize/deserialize.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
void serialize(QDataStream &stream) const Q_DECL_OVERRIDE
Subclasses should override this to serialize their contents to the data stream.