| [d83a844] | 1 | /*
|
|---|
| 2 | Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 3 |
|
|---|
| 4 | This library is free software; you can redistribute it and/or
|
|---|
| 5 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 6 | License as published by the Free Software Foundation; either
|
|---|
| 7 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This library is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 12 | Lesser General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 15 | License along with this library; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|---|
| 17 | MA 02110-1301 USA.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | #ifndef SIWEBSERVICECLIENT_H
|
|---|
| 21 | #define SIWEBSERVICECLIENT_H
|
|---|
| 22 |
|
|---|
| 23 | #include <siglobal.h>
|
|---|
| 24 | #include <QObject>
|
|---|
| 25 |
|
|---|
| 26 | class QNetworkAccessManager;
|
|---|
| 27 | class QNetworkReply;
|
|---|
| 28 |
|
|---|
| 29 | #include <QPointer>
|
|---|
| 30 | #include <QUrl>
|
|---|
| 31 |
|
|---|
| 32 | namespace SiWeather {
|
|---|
| 33 | namespace Library {
|
|---|
| 34 |
|
|---|
| 35 | class SiWeatherStation;
|
|---|
| 36 |
|
|---|
| 37 | class SI_LIB_EXPORT SiWebserviceClient : public QObject
|
|---|
| 38 | {
|
|---|
| 39 | Q_OBJECT
|
|---|
| 40 | public:
|
|---|
| 41 | enum ReplyType{ Error = 1, StationsRegister = 2 };
|
|---|
| 42 |
|
|---|
| 43 | SiWebserviceClient(QUrl baseUrl, QObject *parent = NULL);
|
|---|
| 44 |
|
|---|
| 45 | static QString apiVersion();
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * @brief Registers a station at the server and emits error() or finishedStationsRegister() if finished.
|
|---|
| 49 | */
|
|---|
| [915dc18] | 50 | ReplyType stationsRegister(const SiWeather::Library::SiWeatherStation& station, QString& error);
|
|---|
| [d83a844] | 51 |
|
|---|
| 52 | signals:
|
|---|
| [915dc18] | 53 | void error(SiWeather::Library::SiWebserviceClient::ReplyType replyType, const QString &errorMessage) const;
|
|---|
| [d83a844] | 54 | /**
|
|---|
| 55 | * @brief Generic finish signal for all requests. Use specialized finished signals instead!
|
|---|
| 56 | *
|
|---|
| 57 | * @see finishedStationsRegister
|
|---|
| 58 | */
|
|---|
| [915dc18] | 59 | void finished(SiWeather::Library::SiWebserviceClient::ReplyType replyType, bool result, const QByteArray &data) const;
|
|---|
| [d83a844] | 60 | void finishedStationsRegister(bool result, const QUuid &uuid, const QString &message) const;
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | private slots:
|
|---|
| 64 | void replyStationsRegister();
|
|---|
| 65 |
|
|---|
| 66 | private:
|
|---|
| 67 | QNetworkReply* getNetworkReply(QObject *sender, ReplyType type) const;
|
|---|
| 68 | QUrl _baseUrl;
|
|---|
| 69 | QPointer<QNetworkAccessManager> _networkManager;
|
|---|
| 70 | };
|
|---|
| 71 | };
|
|---|
| 72 | };
|
|---|
| 73 | Q_DECLARE_METATYPE(SiWeather::Library::SiWebserviceClient::ReplyType)
|
|---|
| 74 |
|
|---|
| [915dc18] | 75 | #endif //SIWEBSERVICECLIENT_H
|
|---|