locationsystemui/locationsysui/posindicator/posreversegeocodeplugin/inc/posrevgeocodehttpclientengine.h
branchRCL_3
changeset 44 2b4ea9893b66
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: Declaration of HTTP client engine class.
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef POSREVGEOCODEHTTPCLIENTENGINE_H
       
    19 #define POSREVGEOCODEHTTPCLIENTENGINE_H
       
    20 
       
    21 #include <http/mhttptransactioncallback.h>
       
    22 #include <http/mhttpauthenticationcallback.h>
       
    23 #include <es_sock.h>
       
    24 #include <cmmanager.h>
       
    25 #include <comms-infras/cs_mobility_apiext.h>
       
    26 
       
    27 
       
    28 
       
    29 class RHTTPSession;
       
    30 class RHTTPTransaction;
       
    31 
       
    32 const TInt KDefaultBufferSize = 256;
       
    33 
       
    34 /*
       
    35  *  Enumration for the different states of HTTP GET request.
       
    36  */
       
    37 enum THttpStatus
       
    38     {
       
    39     EHttpSessionError =0,
       
    40     EHttpExitingApp,
       
    41     EHttpConnecting,
       
    42     EHttpTxCancelled,
       
    43     EHttpHdrReceived,
       
    44     EHttpBytesReceieved,
       
    45     EHttpBodyReceieved,
       
    46     EHttpTxCompleted,
       
    47     EHttpTxSuccess,
       
    48     EHttpTxFailed,
       
    49     EHttpConnectionFailure,
       
    50     EHttpUnknownEvent,
       
    51     EHttpMhfRunError,
       
    52     EHttpAuthNote,
       
    53     EHttpAuthFailed,
       
    54     EHttpAuthRequired,
       
    55     };
       
    56 
       
    57 enum TMobileRoamingStatus
       
    58     {
       
    59     EMobileNotRegistered = 0x00,
       
    60     EMobileRegHomeNetwork, // home network
       
    61     EMobileNationalRoaming,
       
    62     EMobileInternationalRoaming
       
    63     };
       
    64 
       
    65 /**
       
    66  * MClientObserver
       
    67  * CPosRevGeoCodeHTTPClientEngine passes events and responses body data with this interface.
       
    68  * An instance of this class must be provided for construction of CPosRevGeoCodeHTTPClientEngine.
       
    69  */
       
    70 class MPosRevGeoCodeHTTPClientObserver
       
    71     {
       
    72     public:
       
    73     /*
       
    74     * ClientEvent()
       
    75     *
       
    76     * Called when event occurs in CClientEngine.
       
    77     *
       
    78     * @params aEvent Status of the event.
       
    79     */
       
    80     virtual void ClientEvent( const THttpStatus& aEvent ) = 0;
       
    81     
       
    82     /*
       
    83     * ClientBodyReceived()
       
    84     *
       
    85     * Called when a part of the HTTP body is received.
       
    86     *
       
    87     * @param aBodyData Part of the body data received. (e.g. part of
       
    88     *         the received HTML page)
       
    89     */
       
    90     virtual void ClientBodyReceived( const TDesC8& aBodyData ) = 0;
       
    91     };
       
    92 
       
    93 
       
    94 /*
       
    95  * This class provides interface to HTTP client APIs
       
    96  */
       
    97 class CPosRevGeoCodeHTTPClientEngine: public CActive,
       
    98                                       public MHTTPTransactionCallback,
       
    99                                       public MMobilityProtocolResp
       
   100     {
       
   101     /**
       
   102      * Internal Engine state 
       
   103      */
       
   104     enum TEngineState
       
   105         {
       
   106         EIdle = 0,
       
   107         EGet
       
   108         };
       
   109 public:
       
   110     /**
       
   111      * Factory method which creates instance of CPosRevGeoCodeHTTPClientEngine object.
       
   112      */
       
   113     static CPosRevGeoCodeHTTPClientEngine* NewL( MPosRevGeoCodeHTTPClientObserver& iObserver );
       
   114 
       
   115     /**
       
   116      * Destructor
       
   117      */
       
   118     ~CPosRevGeoCodeHTTPClientEngine();
       
   119 
       
   120     /**
       
   121      * Starts a new HTTP GET transaction.
       
   122      *
       
   123      * @param aUri URI to get request. (e.g. http://host.org")
       
   124      */
       
   125     void IssueHTTPGetL( const TDesC8& aUri );
       
   126 
       
   127     /**
       
   128      * Closes currently running transaction and frees resources related to it.
       
   129      */
       
   130     void CancelTransaction();
       
   131     
       
   132     /**
       
   133      * Closes the connection
       
   134      */
       
   135     void CloseConnection();
       
   136     
       
   137 private:
       
   138     /*
       
   139      * Symbian 2nd phase constructor
       
   140      */
       
   141     void ConstructL();
       
   142 
       
   143     /*
       
   144      * Constructor
       
   145      */
       
   146     CPosRevGeoCodeHTTPClientEngine( MPosRevGeoCodeHTTPClientObserver& iObserver );
       
   147 
       
   148     /**
       
   149      * Sets header value of an HTTP request.
       
   150      */
       
   151     void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField,
       
   152                      const TDesC8& aHdrValue );
       
   153 
       
   154     /**
       
   155      * Sets up the connection
       
   156      */
       
   157     void SetupConnectionL();
       
   158 
       
   159 private: //From MHTTPSessionEventCallback
       
   160 
       
   161     void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   162 
       
   163     TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   164 
       
   165 private:// From MMobilityProtocolResp
       
   166     void PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
       
   167                                     TAccessPointInfo aNewAPInfo,
       
   168                                     TBool aIsUpgrade,
       
   169                                     TBool aIsSeamless );
       
   170     
       
   171     void NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless );
       
   172     
       
   173     void Error( TInt aError );
       
   174 
       
   175 private: // from CActive
       
   176     void RunL();
       
   177     void DoCancel();
       
   178     TInt RunError(TInt aError);
       
   179 
       
   180 private:
       
   181     void DoHTTPGetL();
       
   182     
       
   183 private: // Data members
       
   184     RSocketServ                 iSocketServ;
       
   185     RConnection                 iConnection;
       
   186     TUint32                     iSelectedIap;
       
   187 
       
   188     RHTTPSession                iSession;
       
   189     RHTTPTransaction            iTransaction;
       
   190 
       
   191     MPosRevGeoCodeHTTPClientObserver&            iObserver;  // Used for passing body data and events to UI
       
   192     TBool                       iRunning;   // ETrue, if transaction running
       
   193     TBool                       iConnectionSetupDone;
       
   194     
       
   195     TInt                        iPrevProfileId;
       
   196     
       
   197     CActiveCommsMobilityApiExt* iMobility;
       
   198     TBool                       iTransactionOpen;
       
   199     TEngineState                 iEngineState;
       
   200     HBufC8*                     iUri;
       
   201     RCmManager                  iCmManager;
       
   202     };
       
   203 #endif /* POSREVGEOCODEHTTPCLIENTENGINE_H */