1 #ifndef COMMUNICATION_H_
2 #define COMMUNICATION_H_
9 class ConnectionSettings;
11 //! Class for handling HTTP requests and responses.
13 * This class uses the QHttp class to make HTTP requests. HTTP responses are
14 * returned as QByteArray.
16 class Communication : public QObject
23 * \param aConnection Reference to ConnectionSettings which holds
24 * the server to connect to and authentication information.
26 Communication(/* const ConnectionSettings &aConnection*/ );
28 virtual ~Communication();
29 //! Returns the response of a request identified by aRequestId.
31 * \param aRequestId Request id number.
33 QByteArray* response( int aRequestId );
35 //! Makes a HTTP request to the server defined in the constructor.
37 * Returns a request id number if successful, otherwise zero.
38 * \param aCommand Content type string of the HTTP header.
39 * \param aContent Content body of the HTTP POST request.
41 int request( const QString &aCommand, const QByteArray &aContent );
46 //! Emitted when a request ongoing. Reports the bytes read from the server.
48 * \param aRequestId Request id number.
49 * \param aDone Bytes read from the server.
50 * \param aTotal Bytes total of the response.
52 void readProgress( int aRequestId, int aDone, int aTotal );
53 //! Emitted when a request is started.
55 * \param aRequestId Request id number.
57 void requestStarted( int aRequestId );
58 //! Emitted when a request is finished.
60 * \param aRequestId Request id number.
61 * \param aError Error code of the request finished.
63 void requestFinished( int aRequestId, int aError );
66 //! Connected to QHttp::readyRead to read the response buffer.
67 void processResponse( const QHttpResponseHeader& aHeader );
68 //! Connected to QHttp::authenticationRequired to provide the user name and password defined in ConnectionSettings
69 void handleAuthentication( const QString& aHost, quint16 aPort, QAuthenticator* aAuthenticator );
70 //! Connected to QHttp::requestFinished
71 void handleResults( int aId, bool aError );
72 //! Connected to QHttp::requestStarted
73 void handleRequestStarted( int aRequestId );
74 //! Connected to QHttp::dataReadProgress
75 void handleReadProgress( int aDone, int aTotal );
76 //!Called when the settings are changed by the user
77 void configurationChanged();
82 * Instance of Connection settings of the communication
84 //ConnectionSettings *iConnectionSettings;
90 * QHash of requests and response buffers
92 QHash<int, QByteArray*> iResponses;
94 * ID number of a request currently ongoing
98 * Counter how many times auhentication was failed to the server
103 #endif /*COMMUNICATION_H_*/