• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • plugins
  • runner
  • monav
signals.h
Go to the documentation of this file.
1 /*
2 Copyright 2010 Christian Vetter veaac.fdirct@gmail.com
3 
4 This file is part of MoNav.
5 
6 MoNav is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 MoNav is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with MoNav. If not, see <http://www.gnu.org/licenses/>.
18 
19 Alternatively, this file may be used under the terms of the GNU
20 Library General Public License as published by the Free Software
21 Foundation; either version 2 of the License, or (at your option)
22 any later version.
23 */
24 
25 #ifndef SIGNALS_H
26 #define SIGNALS_H
27 
28 #include <QString>
29 #include <QVector>
30 #include <QDataStream>
31 #include <QStringList>
32 #include <QLocalSocket>
33 
34 namespace MoNav {
35 
36  // has to be send before each command to identify the following command type
37  struct CommandType {
38  enum Type{
39  RoutingCommand = 0,
40  UnpackCommand = 1
41  } value;
42 
43  void post( QIODevice* out )
44  {
45  qint32 temp = value;
46  out->write( ( const char* ) &temp, sizeof( qint32 ) );
47  }
48 
49  bool read( QLocalSocket* in )
50  {
51  while ( in->bytesAvailable() < ( int ) sizeof( qint32 ) ) {
52  if ( in->state() != QLocalSocket::ConnectedState )
53  return false;
54  in->waitForReadyRead( 100 );
55  }
56 
57  qint32 temp;
58  in->read( ( char* ) &temp, sizeof( qint32 ) );
59  value = ( Type ) temp;
60 
61  return true;
62  }
63  };
64 
65  struct Node {
66  double latitude;
67  double longitude;
68 
69  friend QDataStream& operator<< ( QDataStream& out, const Node& node )
70  {
71  out << node.latitude;
72  out << node.longitude;
73  return out;
74  }
75 
76  friend QDataStream& operator>> ( QDataStream& in, Node& node )
77  {
78  in >> node.latitude;
79  in >> node.longitude;
80  return in;
81  }
82  };
83 
84  struct Edge {
85  unsigned length; // length of the edge == number of edges it represents == number of nodes - 1
86  unsigned name; // name ID of the edge
87  unsigned type; // type ID of the edge
88  unsigned seconds; // travel time metric for the edge
89  bool branchingPossible; // is it possible to choose between more than one subsequent edge ( turning around on bidirectional edges does not count )
90 
91  friend QDataStream& operator<< ( QDataStream& out, const Edge& edge )
92  {
93  out << edge.length;
94  out << edge.name;
95  out << edge.type;
96  out << edge.seconds;
97  out << edge.branchingPossible;
98  return out;
99  }
100 
101  friend QDataStream& operator>> ( QDataStream& in, Edge& edge )
102  {
103  in >> edge.length;
104  in >> edge.name;
105  in >> edge.type;
106  in >> edge.seconds;
107  in >> edge.branchingPossible;
108  return in;
109  }
110  };
111 
112  class RoutingCommand {
113 
114  public:
115 
116  RoutingCommand()
117  {
118  lookupRadius = 10000; // 10km should suffice for most applications
119  lookupStrings = false;
120  }
121 
122  // waypoint edge lookup radius in meters
123  double lookupRadius;
124  // lookup street name / type strings?
125  bool lookupStrings;
126  // a valid routing module directory
127  QString dataDirectory;
128  // waypoints of the route
129  QVector< Node > waypoints;
130 
131  void post( QIODevice* out )
132  {
133  QByteArray buffer;
134  QDataStream stream( &buffer, QIODevice::WriteOnly );
135  stream << lookupRadius;
136  stream << lookupStrings;
137  stream << dataDirectory;
138  stream << waypoints;
139  qint32 size = buffer.size();
140  out->write( ( const char* ) &size, sizeof( qint32 ) );
141  out->write( buffer.data(), size );
142  }
143 
144  bool read( QLocalSocket* in )
145  {
146  qint32 size;
147  while ( in->bytesAvailable() < ( int ) sizeof( qint32 ) ) {
148  if ( in->state() != QLocalSocket::ConnectedState )
149  return false;
150  in->waitForReadyRead( 100 );
151  }
152 
153  in->read( ( char* ) &size, sizeof( quint32 ) );
154 
155  while ( in->bytesAvailable() < size ) {
156  if ( in->state() != QLocalSocket::ConnectedState )
157  return false;
158  in->waitForReadyRead( 100 );
159  }
160 
161  QByteArray buffer= in->read( size );
162  QDataStream stream( buffer );
163  stream >> lookupRadius;
164  stream >> lookupStrings;
165  stream >> dataDirectory;
166  stream >> waypoints;
167 
168  return true;
169  }
170 
171  };
172 
173  class RoutingResult {
174 
175  public:
176 
177  enum ResultType {
178  LoadFailed = 1, RouteFailed = 2, NameLookupFailed = 3, TypeLookupFailed = 4, Success = 5
179  } type;
180 
181  double seconds;
182  QVector< Node > pathNodes;
183  QVector< Edge > pathEdges;
184  QStringList nameStrings;
185  QStringList typeStrings;
186 
187  void post( QIODevice* out )
188  {
189  QByteArray buffer;
190  QDataStream stream( &buffer, QIODevice::WriteOnly );
191  stream << qint32( type );
192  stream << seconds;
193  stream << pathNodes;
194  stream << pathEdges;
195  stream << nameStrings;
196  stream << typeStrings;
197  qint32 size = buffer.size();
198  out->write( ( const char* ) &size, sizeof( qint32 ) );
199  out->write( buffer.data(), size );
200  }
201 
202  bool read( QLocalSocket* in )
203  {
204  qint32 size;
205  while ( in->bytesAvailable() < ( int ) sizeof( qint32 ) ) {
206  if ( in->state() != QLocalSocket::ConnectedState )
207  return false;
208  in->waitForReadyRead( 100 );
209  }
210 
211  in->read( ( char* ) &size, sizeof( quint32 ) );
212 
213  while ( in->bytesAvailable() < size ) {
214  if ( in->state() != QLocalSocket::ConnectedState )
215  return false;
216  in->waitForReadyRead( 100 );
217  }
218 
219  QByteArray buffer= in->read( size );
220  QDataStream stream( buffer );
221  qint32 temp;
222  stream >> temp;
223  type = ( ResultType ) temp;
224  stream >> seconds;
225  stream >> pathNodes;
226  stream >> pathEdges;
227  stream >> nameStrings;
228  stream >> typeStrings;
229 
230  return true;
231  }
232 
233  };
234 
235  class UnpackCommand
236  {
237  public:
238 
239  UnpackCommand()
240  {
241  deleteFile = false;
242  }
243 
244  // MoNav Map Module file to be unpacked
245  // it will be unpacked in the directory of the same name
246  // e.g. test.mmm -> test/
247  QString mapModuleFile;
248  // delete file after unpacking?
249  bool deleteFile;
250 
251  void post( QIODevice* out )
252  {
253  QByteArray buffer;
254  QDataStream stream( &buffer, QIODevice::WriteOnly );
255  stream << mapModuleFile;
256  stream << deleteFile;
257  qint32 size = buffer.size();
258  out->write( ( const char* ) &size, sizeof( qint32 ) );
259  out->write( buffer.data(), size );
260  }
261 
262  bool read( QLocalSocket* in )
263  {
264  qint32 size;
265  while ( in->bytesAvailable() < ( int ) sizeof( qint32 ) ) {
266  if ( in->state() != QLocalSocket::ConnectedState )
267  return false;
268  in->waitForReadyRead( 100 );
269  }
270 
271  in->read( ( char* ) &size, sizeof( quint32 ) );
272 
273  while ( in->bytesAvailable() < size ) {
274  if ( in->state() != QLocalSocket::ConnectedState )
275  return false;
276  in->waitForReadyRead( 100 );
277  }
278 
279  QByteArray buffer= in->read( size );
280  QDataStream stream( buffer );
281  stream >> mapModuleFile;
282  stream >> deleteFile;
283 
284  return true;
285  }
286  };
287 
288  class UnpackResult
289  {
290  public:
291 
292  enum ResultType {
293  FailUnpacking = 1, Success = 2
294  } type;
295 
296  void post( QIODevice* out )
297  {
298  qint32 temp = type;
299  out->write( ( const char* ) &temp, sizeof( qint32 ) );
300  }
301 
302  bool read( QLocalSocket* in )
303  {
304  while ( in->bytesAvailable() < ( int ) sizeof( qint32 ) ) {
305  if ( in->state() != QLocalSocket::ConnectedState )
306  return false;
307  in->waitForReadyRead( 100 );
308  }
309 
310  qint32 temp;
311  in->read( ( char* ) &temp, sizeof( qint32 ) );
312  type = ResultType( temp );
313 
314  return true;
315  }
316  };
317 
318 }
319 
320 #endif // SIGNALS_H
QIODevice
QLocalSocket::waitForReadyRead
virtual bool waitForReadyRead(int msecs)
MoNav::UnpackCommand::read
bool read(QLocalSocket *in)
Definition: signals.h:262
MoNav::UnpackCommand::deleteFile
bool deleteFile
Definition: signals.h:249
MoNav::CommandType::post
void post(QIODevice *out)
Definition: signals.h:43
MoNav::UnpackCommand::UnpackCommand
UnpackCommand()
Definition: signals.h:239
MoNav::CommandType
Definition: signals.h:37
MoNav::RoutingResult::read
bool read(QLocalSocket *in)
Definition: signals.h:202
MoNav::UnpackCommand::mapModuleFile
QString mapModuleFile
Definition: signals.h:247
MoNav::UnpackCommand::post
void post(QIODevice *out)
Definition: signals.h:251
MoNav::RoutingResult::nameStrings
QStringList nameStrings
Definition: signals.h:184
QByteArray
MoNav::Edge
Definition: signals.h:84
QDataStream
MoNav::UnpackResult::post
void post(QIODevice *out)
Definition: signals.h:296
MoNav::RoutingResult::post
void post(QIODevice *out)
Definition: signals.h:187
MoNav::Node::operator>>
friend QDataStream & operator>>(QDataStream &in, Node &node)
Definition: signals.h:76
MoNav::RoutingResult
Definition: signals.h:173
MoNav::Node::latitude
double latitude
Definition: signals.h:66
MoNav::CommandType::Type
Type
Definition: signals.h:38
MoNav::RoutingCommand::read
bool read(QLocalSocket *in)
Definition: signals.h:144
MoNav::UnpackResult::read
bool read(QLocalSocket *in)
Definition: signals.h:302
MoNav::Edge::length
unsigned length
Definition: signals.h:85
MoNav::UnpackResult::Success
Definition: signals.h:293
MoNav::CommandType::value
enum MoNav::CommandType::Type value
MoNav::UnpackResult::ResultType
ResultType
Definition: signals.h:292
MoNav::UnpackResult::type
enum MoNav::UnpackResult::ResultType type
MoNav::RoutingCommand::dataDirectory
QString dataDirectory
Definition: signals.h:127
QLocalSocket::bytesAvailable
virtual qint64 bytesAvailable() const
MoNav::CommandType::read
bool read(QLocalSocket *in)
Definition: signals.h:49
QIODevice::read
qint64 read(char *data, qint64 maxSize)
MoNav::RoutingCommand::RoutingCommand
RoutingCommand()
Definition: signals.h:116
MoNav::Node::longitude
double longitude
Definition: signals.h:67
QString
QStringList
MoNav::RoutingResult::typeStrings
QStringList typeStrings
Definition: signals.h:185
MoNav::Edge::name
unsigned name
Definition: signals.h:86
MoNav::Node::operator<<
friend QDataStream & operator<<(QDataStream &out, const Node &node)
Definition: signals.h:69
MoNav::Edge::branchingPossible
bool branchingPossible
Definition: signals.h:89
MoNav::RoutingCommand
Definition: signals.h:112
MoNav::RoutingCommand::post
void post(QIODevice *out)
Definition: signals.h:131
MoNav::RoutingCommand::lookupRadius
double lookupRadius
Definition: signals.h:123
MoNav::RoutingCommand::lookupStrings
bool lookupStrings
Definition: signals.h:125
MoNav::RoutingResult::TypeLookupFailed
Definition: signals.h:178
MoNav::RoutingResult::pathEdges
QVector< Edge > pathEdges
Definition: signals.h:183
MoNav::UnpackCommand
Definition: signals.h:235
MoNav::RoutingResult::NameLookupFailed
Definition: signals.h:178
MoNav::Edge::type
unsigned type
Definition: signals.h:87
MoNav::RoutingResult::type
enum MoNav::RoutingResult::ResultType type
QVector
QByteArray::data
char * data()
MoNav::Edge::operator<<
friend QDataStream & operator<<(QDataStream &out, const Edge &edge)
Definition: signals.h:91
QIODevice::write
qint64 write(const char *data, qint64 maxSize)
MoNav::Edge::operator>>
friend QDataStream & operator>>(QDataStream &in, Edge &edge)
Definition: signals.h:101
MoNav::Node
Definition: signals.h:65
MoNav::RoutingResult::RouteFailed
Definition: signals.h:178
MoNav::RoutingResult::pathNodes
QVector< Node > pathNodes
Definition: signals.h:182
QByteArray::size
int size() const
MoNav::RoutingResult::Success
Definition: signals.h:178
MoNav::RoutingResult::LoadFailed
Definition: signals.h:178
MoNav::RoutingResult::seconds
double seconds
Definition: signals.h:181
MoNav::RoutingResult::ResultType
ResultType
Definition: signals.h:177
QLocalSocket
MoNav::RoutingCommand::waypoints
QVector< Node > waypoints
Definition: signals.h:129
MoNav::UnpackResult
Definition: signals.h:288
QLocalSocket::state
LocalSocketState state() const
MoNav::Edge::seconds
unsigned seconds
Definition: signals.h:88
MoNav::UnpackResult::FailUnpacking
Definition: signals.h:293
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:42 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal