First draft of routing service
[situare] / src / routing / routingservice.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@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 ROUTINGSERVICE_H
23 #define ROUTINGSERVICE_H
24
25 #include <QObject>
26
27 class NetworkAccessManager;
28 class QNetworkReply;
29 class QNetworkRequest;
30 class QUrl;
31
32 /**
33 * @brief RoutingService class for communicating with CloudMade server
34 *        and parsing routing data
35 *
36 * @author Henri Lampela
37 * @class RoutingService routingservice.h "routingservice/routingservice.h"
38 */
39 class RoutingService : public QObject
40 {
41     Q_OBJECT
42
43 public:
44
45     /**
46     * @brief Default constructor
47     *
48     * @param parent instance of parent
49     */
50     RoutingService(QObject *parent = 0);
51
52     /**
53     * @brief Destructor
54     *
55     */
56     ~RoutingService();
57
58 /*******************************************************************************
59  * MEMBER FUNCTIONS AND SLOTS
60  ******************************************************************************/
61 public slots:
62
63     /**
64     * @brief Public slot, which indicates when http request has been completed
65     *
66     * @param reply storage for http reply
67     */
68     void requestFinished(QNetworkReply *reply);
69
70 private:
71
72     /**
73     * @brief Parses routing data from JSON string
74     *
75     * @param jsonReply JSON string
76     */
77     void parseRouteData(const QByteArray &jsonReply);
78
79     /**
80     * @brief Sends http request
81     *
82     * @param url destination
83     */
84     void sendRequest(const QUrl &url);
85
86 /*******************************************************************************
87  * SIGNALS
88  ******************************************************************************/
89
90 signals:
91
92     /**
93     * @brief Signals error
94     *
95     * @param context error context
96     * @param error error code
97     */
98     void error(const int context, const int error);
99
100 /*******************************************************************************
101  * DATA MEMBERS
102  ******************************************************************************/
103
104 private:
105
106     QList<QNetworkReply *> m_currentRequests;   ///< List of current http requests
107
108     NetworkAccessManager *m_networkManager;    ///< Pointer to QNetworkAccessManager
109 };
110
111 #endif // ROUTINGSERVICE_H