Stellarium 0.15.2
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 
26 class ErrorMessage : public SyncMessage
27 {
28 public:
29  ErrorMessage();
30  ErrorMessage(const QString& msg);
31 
32  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::ERROR; }
33  void serialize(QDataStream& stream) const Q_DECL_OVERRIDE;
34  bool deserialize(QDataStream& stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
35 
36  QString message;
37 };
38 
40 {
41 public:
44 
45  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::SERVER_CHALLENGE; }
46  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
47  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
48 
49  quint8 protocolVersion;
50  quint32 remoteSyncVersion;
51  quint32 stellariumVersion;
52  QUuid clientId; //The ID the server has assigned to the client, working as a very basic challenge value
53 };
54 
56 {
57 public:
60 
61  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::CLIENT_CHALLENGE_RESPONSE; }
62  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
63  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
64 
65  //basically the same as the challenge, without magic string and proto version
66  quint32 remoteSyncVersion;
67  quint32 stellariumVersion;
68  QUuid clientId; //Must match the server challenge ID
69 };
70 
73 {
74 public:
75  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::SERVER_CHALLENGERESPONSEVALID; }
76 };
77 
78 class Time : public SyncMessage
79 {
80 public:
81  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::TIME; }
82 
83  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
84  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
85 
86  //TODO implement network delay compensation (also for other message types where it makes sense)
87  //TODO maybe split up so that each message is only for 1 thing?
88  qint64 lastTimeSyncTime; //corresponds to StelCore::milliSecondsOfLastJDayUpdate
89  double jDay; //current jDay, without any time zone/deltaT adjustments
90  double timeRate; //current time rate
91 
92 };
93 
94 class Location : public SyncMessage
95 {
96 public:
97  Location();
98 
99  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::LOCATION; }
100 
101  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
102  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
103 
104  StelLocation stelLocation;
105  double totalDuration;
106  double timeToGo;
107 };
108 
109 class Selection : public SyncMessage
110 {
111 public:
112  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::SELECTION; }
113 
114  void serialize(QDataStream &stream) const Q_DECL_OVERRIDE;
115  bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE;
116 
117  QList<QString> selectedObjectNames;
118 };
119 
120 class Alive : public SyncMessage
121 {
122 public:
123  SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE { return SyncProtocol::ALIVE; }
124 };
125 
126 
127 #endif
SyncProtocol::SyncMessageType getMessageType() const Q_DECL_OVERRIDE
Subclasses must return the message type this message represents.
Store the informations for a location on a planet.
void serialize(QDataStream &stream) const Q_DECL_OVERRIDE
Subclasses should override this to serialize their contents to 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.
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.
bool deserialize(QDataStream &stream, SyncProtocol::tPayloadSize dataSize) Q_DECL_OVERRIDE
Subclasses should override this to load their contents from the data stream.
SyncMessageType
Contains the possible message types.
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.
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.