Changeset 915dc18 for src/lib


Ignore:
Timestamp:
Sep 17, 2015, 9:11:21 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
a2330fc
Parents:
e498070
Message:
  • Working c++ library webserviceclient class, which allows to register a station
    • Added tests for the webserviceclient class
    • Improved build system
    • Fixed some errors in Webservice Location.php and WebserviceApi.php
Location:
src/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/lib/silibconfig.h.in

    re498070 r915dc18  
    11/*
    2     Copyright (C) 2010 - 2012 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
     2    Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
    33
    44    This library is free software; you can redistribute it and/or
  • src/lib/siwebserviceclient.cpp

    re498070 r915dc18  
    4545}
    4646
    47 SiWebserviceClient::ReplyType SiWebserviceClient::stationsRegister(SiWeatherStation station, QString &error)
     47SiWebserviceClient::ReplyType SiWebserviceClient::stationsRegister(const SiWeatherStation &station, QString &error)
    4848{
    4949        if(!_networkManager)
    5050                return Error;
    5151
    52         if(station.name().isEmpty() || station.city().isEmpty() || station.eMail().isEmpty()){
     52        if(station.name().isEmpty() || station.city().isEmpty() || station.eMail().isEmpty() || station.type().isEmpty()){
    5353                error = tr("Station has empty name, city or eMail address. All of these are needed!");
    5454                return Error;
    … …  
    6161        jsonStation["latitude"] = Library::geoCoordinateToString(station.latitude());
    6262        jsonStation["email"] = station.eMail();
     63        jsonStation["type"] = station.type();
     64        jsonStation["typeUrl"] = station.typeUrl().toString();
    6365        QJsonDocument jsonDocument(jsonStation);
    6466
    6567        QNetworkRequest request;
    66         request.setUrl(QString("%1%2").arg(_baseUrl.toString()).arg("/stations/register"));
     68        request.setUrl(QString("%1%2").arg(_baseUrl.toString()).arg("index.php/stations/register"));
    6769        request.setRawHeader("User-Agent", QString("SiWeather Library %1").arg(Library::version()).toUtf8());
    6870        request.setHeader(QNetworkRequest::ContentTypeHeader,
    … …  
    8183       
    8284        QByteArray data = reply->readAll();
    83         QJsonDocument jsonDocument = QJsonDocument::fromBinaryData(data);
     85        reply->deleteLater();
     86
     87        QJsonDocument jsonDocument = QJsonDocument::fromJson(data);
    8488        QJsonObject json = jsonDocument.object();
    8589        if(!json.contains("result")){
    8690                emit finishedStationsRegister(false, "", tr("No result in response found"));
     91                emit finished(StationsRegister, false, data);
    8792                return;
    8893        }
    8994        if(json["result"].toString() != "success"){
    9095                emit finishedStationsRegister(false, "", tr("Operation failed for reason: %1").arg(json["message"].toString()));
     96                emit finished(StationsRegister, false, data);
    9197                return;
    9298        }
    9399        if(!json.contains("uuid")){
    94100                emit finishedStationsRegister(false, "", tr("No uuid in response found"));
     101                emit finished(StationsRegister, false, data);
    95102                return;
    96103        }
    97         emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), "");
    98         emit finished(StationsRegister, data);
    99         reply->deleteLater();
     104        emit finishedStationsRegister(true, QUuid(json["uuid"].toString()), json["message"].toString());
     105        emit finished(StationsRegister, false, data);
    100106}
    101107
    … …  
    120126        return reply;
    121127}
    122 
  • src/lib/siwebserviceclient.h

    re498070 r915dc18  
    4848                                 * @brief Registers a station at the server and emits error() or finishedStationsRegister() if finished.
    4949                                 */
    50                                 ReplyType stationsRegister(SiWeatherStation station, QString &error);
     50                                ReplyType stationsRegister(const SiWeather::Library::SiWeatherStation& station, QString& error);
    5151
    5252                        signals:
    53                                 void error(ReplyType replyType, const QString &errorMessage) const;
     53                                void error(SiWeather::Library::SiWebserviceClient::ReplyType replyType, const QString &errorMessage) const;
    5454                                /**
    5555                                 * @brief Generic finish signal for all requests. Use specialized finished signals instead!
    … …  
    5757                                 * @see finishedStationsRegister
    5858                                 */
    59                                 void finished(ReplyType replyType, const QByteArray &data) const;
     59                                void finished(SiWeather::Library::SiWebserviceClient::ReplyType replyType, bool result, const QByteArray &data) const;
    6060                                void finishedStationsRegister(bool result, const QUuid &uuid, const QString &message) const;
    6161                               
Note: See TracChangeset for help on using the changeset viewer.