smf/smfservermodule/smfserver/transportmgr/smftransportmanagerutil.h
changeset 7 be09cf1f39dd
equal deleted inserted replaced
6:c39a6cfd1fb9 7:be09cf1f39dd
       
     1 /**
       
     2  * Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the "Eclipse Public License v1.0" 
       
     6  * which accompanies  this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html"
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
       
    11  *
       
    12  * Contributors:
       
    13  * Manasij Roy, Nalina Hariharan
       
    14  * 
       
    15  * Description:
       
    16  * The Transport Manager Utility class provides the http/https transaction 
       
    17  * methods for the smf framework
       
    18  *
       
    19  */
       
    20 
       
    21 #ifndef SMFTRANSPORTMANAGERUTIL_H_
       
    22 #define SMFTRANSPORTMANAGERUTIL_H_
       
    23 
       
    24 #include <QNetworkReply>
       
    25 #include <smfglobal.h>
       
    26 #include <smfserverglobal.h>
       
    27 
       
    28 // Forward declaration
       
    29 class QNetworkAccessManager;
       
    30 class QSettings;
       
    31 
       
    32 /**
       
    33  * The Transport Manager Utility class provides the http/https transaction 
       
    34  * methods for the smf framework
       
    35  * 
       
    36  */
       
    37 class SmfTransportManagerUtil : public QObject
       
    38 	{
       
    39 	Q_OBJECT
       
    40 	
       
    41 public:
       
    42 	/**
       
    43 	 * Method to get the instance of SmfTransportManagerUtil class
       
    44 	 * @return The instance of SmfTransportManagerUtil class
       
    45 	 */
       
    46 	static SmfTransportManagerUtil* getInstance ( );
       
    47 	
       
    48 	/**
       
    49 	 * Destructor
       
    50 	 */
       
    51 	~SmfTransportManagerUtil ( );
       
    52 	
       
    53 
       
    54 public:
       
    55 	/**
       
    56 	 * Method that does a http GET request. Returns the unique QNetworkReply
       
    57 	 * instance for this transaction to the plugin manager to trace the 
       
    58 	 * proper response.
       
    59 	 * @param aRequest The request formed by the plugin
       
    60 	 * @param aUrlList The list of accessible Urls for this plugin
       
    61 	 * @param aSOPCompliant [out] Output parameter indicating Same Origin 
       
    62 	 * Policy Compliance. Contains true if the request complies to the policy,
       
    63 	 * else false. If it is false, the network request will not performed
       
    64 	 * @return The unique QNetworkReply instance for this transaction
       
    65 	 */
       
    66     QNetworkReply* get ( QNetworkRequest &aRequest,
       
    67     		const QList<QUrl> &aUrlList,
       
    68     		bool &aSOPCompliant );
       
    69 
       
    70 	/**
       
    71 	 * Method that does a http POST request. Returns the unique QNetworkReply
       
    72 	 * instance for this transaction to the plugin manager to trace the 
       
    73 	 * proper response.
       
    74 	 * @param aRequest The request formed by the plugin
       
    75 	 * @param aPostData The data to be posted via http POST request
       
    76 	 * @param aUrlList The list of accessible Urls for this plugin
       
    77 	 * @param aSOPCompliant [out] Output parameter indicating Same Origin 
       
    78 	 * Policy Compliance. Contains true if the request complies to the policy,
       
    79 	 * else false. If it is false, the network request will not performed
       
    80 	 * @return The unique QNetworkReply instance for this transaction
       
    81 	 */
       
    82     QNetworkReply* post ( QNetworkRequest &aRequest, 
       
    83     		const QByteArray& aPostData,
       
    84     		const QList<QUrl> &aUrlList,
       
    85     		bool &aSOPCompliant );
       
    86     
       
    87 	/**
       
    88 	 * Method that does a http HEAD request. Returns the unique QNetworkReply
       
    89 	 * instance for this transaction to the plugin manager to trace the 
       
    90 	 * proper response.
       
    91 	 * @param aRequest The request formed by the plugin
       
    92 	 * @param aUrlList The list of accessible Urls for this plugin
       
    93 	 * @param aSOPCompliant [out] Output parameter indicating Same Origin 
       
    94 	 * Policy Compliance. Contains true if the request complies to the policy,
       
    95 	 * else false. If it is false, the network request will not performed
       
    96 	 * @return The unique QNetworkReply instance for this transaction
       
    97 	 */
       
    98     QNetworkReply* head ( QNetworkRequest &aRequest,
       
    99     		const QList<QUrl> &aUrlList,
       
   100     		bool &aSOPCompliant );
       
   101     
       
   102 	/**
       
   103 	 * Method that does a http PUT request. Returns the unique QNetworkReply
       
   104 	 * instance for this transaction to the plugin manager to trace the 
       
   105 	 * proper response.
       
   106 	 * @param aRequest The request formed by the plugin
       
   107 	 * @param aPostData The data to be posted via http PUT request
       
   108 	 * @param aUrlList The list of accessible Urls for this plugin
       
   109 	 * @param aSOPCompliant [out] Output parameter indicating Same Origin 
       
   110 	 * Policy Compliance. Contains true if the request complies to the policy,
       
   111 	 * else false. If it is false, the network request will not performed
       
   112 	 * @return The unique QNetworkReply instance for this transaction
       
   113 	 */
       
   114     QNetworkReply* put ( QNetworkRequest &aRequest,
       
   115     		const QByteArray& aPostData,
       
   116     		const QList<QUrl> &aUrlList,
       
   117     		bool &aSOPCompliant );
       
   118 	
       
   119 	/**
       
   120 	 * Method that does a http DELETE request. Returns the unique QNetworkReply
       
   121 	 * instance for this transaction to the plugin manager to trace the 
       
   122 	 * proper response.
       
   123 	 * @param aRequest The request formed by the plugin
       
   124 	 * @param aUrlList The list of accessible Urls for this plugin
       
   125 	 * @param aSOPCompliant [out] Output parameter indicating Same Origin 
       
   126 	 * Policy Compliance. Contains true if the request complies to the policy,
       
   127 	 * else false. If it is false, the network request will not performed
       
   128 	 * @return The unique QNetworkReply instance for this transaction
       
   129 	 */
       
   130     QNetworkReply* deleteResource ( QNetworkRequest &aRequest,
       
   131     		const QList<QUrl> &aUrlList,
       
   132     		bool &aSOPCompliant );
       
   133     
       
   134 	/**
       
   135 	 * Method that cancels the service request by cancelling the current 
       
   136 	 * http transaction.
       
   137 	 * @param aCancelReply The QNetworkReply instance whose transaction 
       
   138 	 * has to be cancelled
       
   139 	 * @return Returns true for success, else false 
       
   140 	 */
       
   141 	bool cancelRequest ( QNetworkReply *aCancelReply );
       
   142 	
       
   143 public slots:
       
   144 	/*
       
   145 	 * Method that is called whenever a new network configuration is added to the system.
       
   146 	 * @param aResult SmfTransportResult
       
   147 	 */
       
   148 	void configurationAdded ( const SmfTransportResult &aResult );
       
   149 
       
   150 	/*
       
   151 	 * Method that is called when the state of the network configuration changes.
       
   152 	 * @param aResult SmfTransportResult
       
   153 	 */
       
   154 	void configurationChanged ( const SmfTransportResult &aResult );
       
   155 
       
   156 	/*
       
   157 	 * Method that is called when a configuration is about to be removed from the system.
       
   158 	 * The removed configuration is invalid but retains name and identifier.
       
   159 	 * @param aResult SmfTransportResult
       
   160 	 */
       
   161 	void configurationRemoved ( const SmfTransportResult &aResult );
       
   162 	
       
   163 private slots:
       
   164 	/**
       
   165 	 * Method to indicate http transaction has finished.
       
   166 	 * @param aNetworkReply The QNetworkReply instance for which the http 
       
   167 	 * transaction was made
       
   168 	 */
       
   169 	void networkReplyFinished ( QNetworkReply *aNetworkReply );
       
   170 	
       
   171 	/**
       
   172 	 * Method called when the QNetworkReply detects an error in processing.
       
   173 	 * @param aError The QNetworkReply error code 
       
   174 	 */
       
   175 	void networkReplyError ( QNetworkReply::NetworkError aError );
       
   176 	
       
   177 private:
       
   178 	/**
       
   179 	 * Method to convert QNetworkReply Error to the type SmfTransportResult 
       
   180 	 * QNetworkRequest received before executing the web query.
       
   181 	 * @param aError The QNetworkReply Error
       
   182 	 * @param aResult [out] The SmfTransportResult error
       
   183 	 */
       
   184 	void convertErrorType( const QNetworkReply::NetworkError &aError,  
       
   185 			SmfTransportResult &aResult );
       
   186 	
       
   187 	/**
       
   188 	 * Method to deflate a gzipped network response. Once this method is called, 
       
   189 	 * QNetworkReply internal buffer for holding network response is emptied.
       
   190 	 * @param aResponse The QByteArray instance holding the gzip encoded data
       
   191 	 * @param aError Argument indicating error
       
   192 	 * @return a QByteArray* containing the deflated data. If deflating fails, 
       
   193 	 * the encoded data itself without deflation is returned.
       
   194 	 */
       
   195 	QByteArray* inflateResponse ( QByteArray &aResponse, int& aError );
       
   196 	
       
   197 private:
       
   198 	/**
       
   199 	 * Constructor with default argument
       
   200 	 */
       
   201 	SmfTransportManagerUtil ( );
       
   202 	
       
   203 	/**
       
   204 	 * Copy Constructor
       
   205 	 * @param aOther The reference object
       
   206 	 */
       
   207 	SmfTransportManagerUtil ( const SmfTransportManagerUtil &aOther );
       
   208 	
       
   209 private:
       
   210 	/**
       
   211 	 * The single instance of SmfTransportManagerUtil
       
   212 	 */
       
   213 	static SmfTransportManagerUtil* m_myInstance;
       
   214 	
       
   215 	/**
       
   216 	 * Member variable - QNetworkAccessManager instance
       
   217 	 */
       
   218 	QNetworkAccessManager m_networkAccessManager;
       
   219 	
       
   220 	/**
       
   221 	 * Member variable - List of QNetworkReply awaiting response
       
   222 	 */
       
   223 	QList<QNetworkReply *> m_activeNetwReplyList;
       
   224 	
       
   225 	/**
       
   226 	 * Member variable - instance of QSettings that stores network 
       
   227 	 * data usage of Smf
       
   228 	 */
       
   229 	QSettings *m_settings;
       
   230 	};
       
   231 
       
   232 
       
   233 #endif /* SMFTRANSPORTMANAGERUTIL_H_ */