1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtPositioning module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QGEOSATELLITEINFOSOURCE_GYPSY_H 41 #define QGEOSATELLITEINFOSOURCE_GYPSY_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include "qgeosatelliteinfosource.h" 55 #include "qgeosatelliteinfo.h" 56 #include <gypsy/gypsy-satellite.h> 57 #include <gypsy/gypsy-control.h> 58 #include <gypsy/gypsy-device.h> 59 #include <gconf/gconf-client.h> 60 #include <QTimer> 61 62 // #define Q_LOCATION_GYPSY_DEBUG 63 64 QT_BEGIN_NAMESPACE 65 66 // An engine that encapsulates all symbols we want 67 // to be able to mock (for unit/autotest purposes). 68 class SatelliteGypsyEngine 69 { 70 public: 71 SatelliteGypsyEngine(QGeoSatelliteInfoSource *parent = 0); 72 virtual ~SatelliteGypsyEngine(); 73 // Glib symbols 74 virtual gulong eng_g_signal_connect(gpointer instance, 75 const gchar *detailed_signal, 76 GCallback c_handler, 77 gpointer data); 78 virtual guint eng_g_signal_handlers_disconnect_by_func(gpointer instance, 79 gpointer func, 80 gpointer data); 81 virtual void eng_g_free(gpointer mem); 82 // Gypsy symbols 83 virtual GypsyControl *eng_gypsy_control_get_default (void); 84 virtual char *eng_gypsy_control_create (GypsyControl *control, const char *device_name, GError **error); 85 virtual GypsyDevice *eng_gypsy_device_new (const char *object_path); 86 virtual GypsySatellite *eng_gypsy_satellite_new (const char *object_path); 87 virtual gboolean eng_gypsy_device_start (GypsyDevice *device, GError **error); 88 virtual gboolean eng_gypsy_device_stop (GypsyDevice *device, GError **error); 89 virtual GypsyDeviceFixStatus eng_gypsy_device_get_fix_status (GypsyDevice *device, GError **error); 90 virtual GPtrArray *eng_gypsy_satellite_get_satellites (GypsySatellite *satellite, GError **error); 91 virtual void eng_gypsy_satellite_free_satellite_array (GPtrArray *satellites); 92 // GConf symbols (mockability due to X11 requirement) 93 virtual GConfClient *eng_gconf_client_get_default(void); 94 virtual gchar *eng_gconf_client_get_string(GConfClient *client, const gchar *key, GError** err); 95 protected: 96 QGeoSatelliteInfoSource *m_owner; 97 }; 98 99 class QGeoSatelliteInfoSourceGypsy : public QGeoSatelliteInfoSource 100 { 101 Q_OBJECT 102 103 public: 104 explicit QGeoSatelliteInfoSourceGypsy(QObject *parent = 0); 105 ~QGeoSatelliteInfoSourceGypsy(); 106 int init(); 107 108 int minimumUpdateInterval() const; 109 Error error() const; 110 111 public slots: 112 virtual void startUpdates(); 113 void stopUpdates(); 114 void requestUpdate(int timeout = 5000); 115 void satellitesChanged(GypsySatellite *satellite, GPtrArray *satellites); 116 117 signals: 118 void satellitesInViewUpdated(const QList<QGeoSatelliteInfo> &satellites); 119 void satellitesInUseUpdated(const QList<QGeoSatelliteInfo> &satellites); 120 121 private slots: 122 void requestUpdateTimeout(); 123 124 protected: 125 // Creates an engine which encapsulates all used symbols 126 // that we want to be also able to mock. 127 virtual void createEngine(); 128 SatelliteGypsyEngine *m_engine; 129 130 private: 131 Q_DISABLE_COPY(QGeoSatelliteInfoSourceGypsy) 132 GypsySatellite *m_satellite; 133 GypsyDevice *m_device; 134 QTimer m_requestTimer; 135 bool m_updatesOngoing; 136 bool m_requestOngoing; 137 }; 138 139 QT_END_NAMESPACE 140 141 #endif // QGEOSATELLITEINFOSOURCE_GYPSY_H 142