Fixing defects found in the review of Route, RouteSegment & RoutingService
[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       Sami Rämö - sami.ramo@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #ifndef ROUTINGSERVICE_H
24 #define ROUTINGSERVICE_H
25
26 #include <QObject>
27
28 #include "location.h"
29 #include "route.h"
30
31 class QNetworkReply;
32 class QNetworkRequest;
33 class QUrl;
34
35 class GeoCoordinate;
36 class NetworkAccessManager;
37
38 /**
39 * @brief RoutingService class for communicating with CloudMade server
40 *        and parsing routing data
41 *
42 * @author Henri Lampela - henri.lampela@ixonos.com
43 * @author Sami Rämö - sami.ramo@ixonos.com
44 */
45 class RoutingService : public QObject
46 {
47     Q_OBJECT
48
49 public:
50     /**
51     * @brief Default constructor
52     *
53     * @param parent instance of parent
54     */
55     RoutingService(QObject *parent = 0);
56
57 /*******************************************************************************
58  * MEMBER FUNCTIONS AND SLOTS
59  ******************************************************************************/
60 public slots:
61     /**
62     * @brief Public slot, which indicates when http request has been completed
63     *
64     * @param reply storage for http reply
65     */
66     void requestFinished(QNetworkReply *reply);
67
68     /**
69     * @brief Request routing information from the server
70     *
71     * @param from Start point of the route
72     * @param to End point of the route
73     */
74     void requestRoute(const GeoCoordinate &from, const GeoCoordinate &to);
75
76     /**
77     * @brief Request location information from the server
78     *
79     * @param location location (address, city etc.)
80     */
81     void requestLocation(const QString &location);
82
83 private:
84     /**
85     * @brief Parses routing data from JSON string
86     *
87     * @param jsonReply JSON string
88     */
89     void parseRouteData(const QByteArray &jsonReply);
90
91     /**
92     * @brief Parses location data from JSON string
93     *
94     * @param jsonReply JSON string
95     */
96     void parseSearchResults(const QByteArray &jsonReply);
97
98     /**
99     * @brief Request authorization token
100     *
101     */
102     void requestAuthorizationToken();
103
104     /**
105     * @brief Sends http request
106     *
107     * @param url destination
108     */
109     void sendRequest(const QUrl &url);
110
111 /*******************************************************************************
112  * SIGNALS
113  ******************************************************************************/
114 signals:
115     /**
116     * @brief Signals error
117     *
118     * @param context error context
119     * @param error error code
120     */
121     void error(const int context, const int error);
122
123     /**
124     * @brief Emited when route is parsed and is ready for further processing
125     *
126     * @param route Route item containing parsed route details
127     */
128     void routeParsed(Route &route);
129
130     /**
131     * @brief Emited when location request is parsed and is ready for further processing
132     *
133     * @param result List of Location items
134     */
135     void locationDataParsed(QList<Location> &result);
136
137 /*******************************************************************************
138  * DATA MEMBERS
139  ******************************************************************************/
140 private:
141     QList<QNetworkReply *> m_currentRequests;   ///< List of current http requests
142     QList<Location> m_searchResults;            ///< List of search results
143
144     QString m_pendingRequest;                   ///< Placeholder for pending route request
145     QString m_token;                            ///< Placeholder for authentication token
146
147     NetworkAccessManager *m_networkManager;     ///< Pointer to QNetworkAccessManager
148 };
149
150 #endif // ROUTINGSERVICE_H