Fixed seg fault on logout.
[situare] / src / gps / liblocationwrapper.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 LIBLOCATIONWRAPPER_H
23 #define LIBLOCATIONWRAPPER_H
24
25 #include <QObject>
26 #include "geopositioninfo.h"
27
28 extern "C"
29 {
30     #include <location/location-gps-device.h>
31     #include <location/location-gpsd-control.h>
32 }
33
34 /**
35 * @brief LiblocationWrapper class is a wrapper for liblocation library.
36 */
37 class LiblocationWrapper : public QObject
38 {
39     Q_OBJECT
40
41 public:
42     /**
43     * @brief Constructor.
44     */
45     LiblocationWrapper(QObject *parent);
46
47     /**
48     * @brief Destructor.
49     *
50     * Releases m_control and m_device objects.
51     */
52     ~LiblocationWrapper();
53
54     /**
55     * GPS state.
56     */
57     enum State {Undefined, Initialized, Running};
58
59 /******************************************************************************
60 * MEMBER FUNCTIONS AND SLOTS
61 ******************************************************************************/
62     /**
63     * @brief Checks if GPS is running.
64     *
65     * @return true if running, false otherwise
66     */
67     bool isRunning();
68
69     /**
70     * @brief Returns last known position.
71     *
72     * @return GeoPositionInfo
73     */
74     GeoPositionInfo lastKnownPosition() const;
75
76     /**
77     * @brief Starts GPS updates.
78     */
79     void startUpdates();
80
81     /**
82     * @brief Sets last known position.
83     *
84     * @param positionInfo GeoPositionInfo
85     */
86     void setLastKnownPosition(const GeoPositionInfo &positionInfo);
87
88     /**
89     * @brief Initializes GPS with update interval.
90     *
91     * @param updateInterval update interval in milliseconds
92     */
93     void init(int updateInterval);
94
95     /**
96     * @brief Stops GPS updates.
97     */
98     void stopUpdates();
99
100 private:
101     /**
102     * @brief Called from liblocation when GPS location changes.
103     *
104     * @param device LocationGPSDevice
105     * @param data qpointer
106     */
107     static void changed(LocationGPSDevice *device, gpointer data);
108
109     /**
110     * @brief Called from liblocation when there is an error on GPS.
111     *
112     * @param device LocationGPSDevice
113     * @param data qpointer
114     */
115     static void error(LocationGPSDevice *device, gpointer data);
116
117     /**
118     * @brief Sets state.
119     *
120     * @param state State
121     */
122     void setState(int state);
123
124     /**
125     * Returns state.
126     *
127     * State state
128     */
129     int state();
130
131 /******************************************************************************
132 * SIGNALS
133 ******************************************************************************/
134 signals:
135     /**
136     * @brief Signal for location change.
137     *
138     * @param positionInfo GeoPositionInfo
139     */
140     void locationChanged(const GeoPositionInfo &positionInfo);
141
142     /**
143     * @brief Signal for error.
144     *
145     * @param message error message
146     */
147     void errorMessage(const QString &message);
148
149
150 /******************************************************************************
151 * DATA MEMBERS
152 ******************************************************************************/
153 private:
154     LocationGPSDControl *m_control;         ///< LocationGPSDControl pointer
155     LocationGPSDevice *m_device;            ///< LocationGPSDevice pointer
156     GeoPositionInfo m_lastKnownPosition;    ///< GeoPositionInfo data
157     int m_state;                            ///< GPS state
158 };
159
160 #endif // LIBLOCATIONWRAPPER_H