1 #ifndef COMMUNICATION_H_
2 #define COMMUNICATION_H_
8 class ConnectionSettings;
10 //! Class for handling HTTP requests and responses.
12 * This class uses the QHttp class to make HTTP requests. HTTP responses are
13 * returned as QByteArray.
15 * NOTE! Currently this class does NOT support multiple simultaneuos requests.
17 class Communication : public QObject
24 * \param aConnection Reference to ConnectionSettings which holds
25 * the server to connect to and authentication information.
27 Communication( const ConnectionSettings &aConnection );
29 virtual ~Communication();
30 //! Returns the response of a request identified by aRequestId.
32 * NOTE! Currently the last request response is returned as the multiple
33 * request support is not implemented.
34 * \param aRequestId Request id number.
36 const QByteArray& response( int aRequestId );
38 //! Makes a HTTP request to the server defined in the constructor.
40 * Returns a request id number if successful, otherwise zero.
41 * \param aCommand Content type string of the HTTP header.
42 * \param aContent Content body of the HTTP POST request.
44 int request( const QString &aCommand, const QByteArray &aContent );
47 //! Emitted when a request ongoing. Reports the bytes read from the server.
49 * \param aRequestId Request id number.
50 * \param aDone Bytes read from the server.
51 * \param aTotal Bytes total of the response.
53 void readProgress( int aRequestId, int aDone, int aTotal );
54 //! Emitted when a request is started.
56 * \param aRequestId Request id number.
58 void requestStarted( int aRequestId );
59 //! Emitted when a request is finished.
61 * \param aRequestId Request id number.
62 * \param aError Error code of the request finished.
64 void requestFinished( int aRequestId, QHttp::Error aError );
67 //! Connected to QHttp::readyRead to read the response buffer.
68 void processResponse( const QHttpResponseHeader& aHeader );
69 //! Connected to QHttp::authenticationRequired to provide the user name and password defined in ConnectionSettings
70 void handleAuthentication( const QString& aHost, quint16 aPort, QAuthenticator* aAuthenticator );
71 //! Connected to QHttp::requestFinished
72 void handleResults( int aId, bool aError );
73 //! Connected to QHttp::requestStarted
74 void handleRequestStarted( int aRequestId );
75 //! Connected to QHttp::dataReadProgress
76 void handleReadProgress( int aDone, int aTotal );
80 * Instance of Connection settings of the communication
82 ConnectionSettings *iConnectionSettings;
90 QByteArray* iResponse;
92 * ID number of a request currently ongoing
96 * Counter how many times auhentication was failed to the server
101 #endif /*COMMUNICATION_H_*/