Added unit tests to gps.
[situare] / src / gps / gpsposition.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
7    Situare is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License
9    version 2 as published by the Free Software Foundation.
10
11    Situare 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 Situare; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
19    USA.
20 */
21
22 #ifndef GPSPOSITION_H
23 #define GPSPOSITION_H
24
25 #include <QGeoPositionInfo>
26 #include <QGeoPositionInfoSource>
27 #include <QNmeaPositionInfoSource>
28 #include <QPointF>
29
30 #include "gpspositioninterface.h"
31
32 QTM_USE_NAMESPACE
33
34 /**
35 * @brief GPSPosition class use GPS to receive location information.
36 *
37 * @class GPSPosition gpsposition.h "gps/gpsposition.h"
38 */
39 class GPSPosition : public GPSPositionInterface
40 {
41     Q_OBJECT
42
43 public:
44     /**
45     * @brief Constructor creates GPS source.
46     *
47     * @param parent QObject
48     */
49     GPSPosition(QObject *parent = 0);
50
51     /**
52     * @brief Destructor stops GPS.
53     */
54     ~GPSPosition();
55
56 /******************************************************************************
57 * MEMBER FUNCTIONS AND SLOTS
58 ******************************************************************************/
59 public:
60     /**
61     * @brief Checks if GPS is running.
62     *
63     * @return true if GPS running, false otherwise
64     */
65     bool isRunning();
66
67     /**
68     * @brief Informs gps to emit last known position.
69     */
70     void lastPosition();
71
72     /**
73     * @brief Set GPS mode.
74     *
75     * Modes: default and simulation.
76     * @param mode GPS mode
77     * @param filePath file path to NMEA file if simulation mode is used
78     */
79     void setMode(Mode mode, const QString &filePath = 0);
80
81     /**
82     * @brief Set GPS update interval
83     *
84     * @return interval interval in milliseconds
85     */
86     void setUpdateInterval(int interval);
87
88     /**
89     * @brief Start GPS.
90     */
91     void start();
92
93     /**
94     * @brief Stop GPS.
95     */
96     void stop();
97
98 private:
99     /**
100     * @brief Return bigger accuracy value from latitude and longitude values.
101     *
102     * @param positionInfo geo position info
103     * @return bigger accuracy value, -1 if undefined
104     */
105     qreal biggerAccuracy(QGeoPositionInfo positionInfo);
106
107 private slots:
108
109     /**
110     * @brief Slot for received position update.
111     *
112     * @param positionInfo Geo position info.
113     */
114     void positionUpdated(QGeoPositionInfo positionInfo);
115
116     /**
117     * @brief Slot for GPS update request.
118     */
119     void update();
120
121     /**
122     * @brief Slot for update timeout.
123     *
124     * Called when request timeout occurs.
125     */
126     void updateTimeout();
127
128 private:
129     QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
130     bool m_running;                             ///< GPS is running
131     int m_updateInterval;                       ///< GPS update interval
132 };
133
134 const int ACCURACY_UNDEFINED = 1;               ///< Undefined accuracy
135 const int DEFAULT_UPDATE_INTERVAL = 5000;       ///< Default update interval
136
137 #endif // GPSPOSITION_H