|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #ifndef QNMEAPOSITIONINFOSOURCE_P_H |
|
42 #define QNMEAPOSITIONINFOSOURCE_P_H |
|
43 |
|
44 // |
|
45 // W A R N I N G |
|
46 // ------------- |
|
47 // |
|
48 // This file is not part of the Qt API. It exists purely as an |
|
49 // implementation detail. This header file may change from version to |
|
50 // version without notice, or even be removed. |
|
51 // |
|
52 // We mean it. |
|
53 // |
|
54 |
|
55 #include "qnmeapositioninfosource.h" |
|
56 #include "qgeopositioninfo.h" |
|
57 |
|
58 #include <QObject> |
|
59 #include <QQueue> |
|
60 #include <QPointer> |
|
61 |
|
62 QT_BEGIN_NAMESPACE |
|
63 class QBasicTimer; |
|
64 class QTimerEvent; |
|
65 class QTimer; |
|
66 QT_END_NAMESPACE |
|
67 |
|
68 QT_BEGIN_HEADER |
|
69 |
|
70 QTM_BEGIN_NAMESPACE |
|
71 |
|
72 class QNmeaReader; |
|
73 struct QPendingGeoPositionInfo { |
|
74 QGeoPositionInfo info; |
|
75 bool hasFix; |
|
76 }; |
|
77 |
|
78 |
|
79 class QNmeaPositionInfoSourcePrivate : public QObject |
|
80 { |
|
81 Q_OBJECT |
|
82 public: |
|
83 explicit QNmeaPositionInfoSourcePrivate(QNmeaPositionInfoSource *parent); |
|
84 ~QNmeaPositionInfoSourcePrivate(); |
|
85 |
|
86 void startUpdates(); |
|
87 void stopUpdates(); |
|
88 void requestUpdate(int msec); |
|
89 |
|
90 bool parsePosInfoFromNmeaData(const char *data, |
|
91 int size, |
|
92 QGeoPositionInfo *posInfo, |
|
93 bool *hasFix); |
|
94 |
|
95 void notifyNewUpdate(QGeoPositionInfo *update, bool fixStatus); |
|
96 |
|
97 QNmeaPositionInfoSource::UpdateMode m_updateMode; |
|
98 QPointer<QIODevice> m_device; |
|
99 QGeoPositionInfo m_lastUpdate; |
|
100 bool m_invokedStart; |
|
101 |
|
102 public Q_SLOTS: |
|
103 void readyRead(); |
|
104 |
|
105 protected: |
|
106 void timerEvent(QTimerEvent *event); |
|
107 |
|
108 private Q_SLOTS: |
|
109 void emitPendingUpdate(); |
|
110 void sourceDataClosed(); |
|
111 void updateRequestTimeout(); |
|
112 |
|
113 private: |
|
114 bool openSourceDevice(); |
|
115 bool initialize(); |
|
116 void prepareSourceDevice(); |
|
117 void emitUpdated(const QGeoPositionInfo &update); |
|
118 |
|
119 QNmeaPositionInfoSource *m_source; |
|
120 QNmeaReader *m_nmeaReader; |
|
121 QBasicTimer *m_updateTimer; |
|
122 QGeoPositionInfo m_pendingUpdate; |
|
123 QDate m_currentDate; |
|
124 QTimer *m_requestTimer; |
|
125 bool m_noUpdateLastInterval; |
|
126 bool m_updateTimeoutSent; |
|
127 bool m_connectedReadyRead; |
|
128 }; |
|
129 |
|
130 |
|
131 class QNmeaReader |
|
132 { |
|
133 public: |
|
134 explicit QNmeaReader(QNmeaPositionInfoSourcePrivate *sourcePrivate) |
|
135 : m_proxy(sourcePrivate) {} |
|
136 virtual ~QNmeaReader() {} |
|
137 |
|
138 virtual void readAvailableData() = 0; |
|
139 |
|
140 protected: |
|
141 QNmeaPositionInfoSourcePrivate *m_proxy; |
|
142 }; |
|
143 |
|
144 |
|
145 class QNmeaRealTimeReader : public QNmeaReader |
|
146 { |
|
147 public: |
|
148 explicit QNmeaRealTimeReader(QNmeaPositionInfoSourcePrivate *sourcePrivate); |
|
149 virtual void readAvailableData(); |
|
150 }; |
|
151 |
|
152 |
|
153 class QNmeaSimulatedReader : public QObject, public QNmeaReader |
|
154 { |
|
155 Q_OBJECT |
|
156 public: |
|
157 explicit QNmeaSimulatedReader(QNmeaPositionInfoSourcePrivate *sourcePrivate); |
|
158 ~QNmeaSimulatedReader(); |
|
159 virtual void readAvailableData(); |
|
160 |
|
161 protected: |
|
162 virtual void timerEvent(QTimerEvent *event); |
|
163 |
|
164 private Q_SLOTS: |
|
165 void simulatePendingUpdate(); |
|
166 |
|
167 private: |
|
168 bool setFirstDateTime(); |
|
169 void processNextSentence(); |
|
170 |
|
171 QQueue<QPendingGeoPositionInfo> m_pendingUpdates; |
|
172 int m_currTimerId; |
|
173 bool m_hasValidDateTime; |
|
174 }; |
|
175 |
|
176 QTM_END_NAMESPACE |
|
177 |
|
178 QT_END_HEADER |
|
179 |
|
180 #endif |