locationmanager/ReverseGeocode/inc/clientengine.h
changeset 54 a3cc46f37772
parent 36 aa5a574040a4
equal deleted inserted replaced
36:aa5a574040a4 54:a3cc46f37772
     1 /*
       
     2 * Copyright (c) 2006-2009 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:  HTTP client engine, which takes of doing an Http GET request for
       
    15 * the maps server.
       
    16 */
       
    17 
       
    18 #ifndef __CLIENTENGINE_H__
       
    19 #define __CLIENTENGINE_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 #include <etel.h>
       
    27 #include <etelmm.h>
       
    28 
       
    29 #include "reversegeocode.h"
       
    30 
       
    31 class RHTTPSession;
       
    32 class RHTTPTransaction;
       
    33 
       
    34 const TInt KDefaultBufferSize = 256;
       
    35 
       
    36 /*
       
    37  *  Enumration for the different states of HTTP GET request.
       
    38  */
       
    39 enum THttpStatus
       
    40     {
       
    41         EHttpSessionError =0,
       
    42         EHttpExitingApp,
       
    43         EHttpConnecting,
       
    44         EHttpTxCancelled,
       
    45         EHttpHdrReceived,
       
    46         EHttpBytesReceieved,
       
    47         EHttpBodyReceieved,
       
    48         EHttpTxCompleted,
       
    49         EHttpTxSuccess,
       
    50         EHttpTxFailed,
       
    51         EHttpConnectionFailure,
       
    52         EHttpUnknownEvent,
       
    53         EHttpMhfRunError,
       
    54         EHttpAuthNote,
       
    55         EHttpAuthFailed,
       
    56         EHttpAuthRequired,
       
    57     };
       
    58 
       
    59 enum TMobileRoamingStatus
       
    60     {
       
    61     EMobileNotRegistered = 0x00,
       
    62     EMobileRegHomeNetwork, // home network
       
    63     EMobileNationalRoaming,
       
    64     EMobileInternationalRoaming
       
    65     };
       
    66 
       
    67 /*
       
    68 * MClientObserver
       
    69 * CClientEngine passes events and responses body data with this interface.
       
    70 * An instance of this class must be provided for construction of CClientEngine.
       
    71 */
       
    72 class MClientObserver
       
    73     {
       
    74     public:
       
    75     /*
       
    76     * ClientEvent()
       
    77     *
       
    78     * Called when event occurs in CClientEngine.
       
    79     *
       
    80     * @params aEvent Status of the event.
       
    81     */
       
    82     virtual void ClientEvent( const THttpStatus& aEvent ) = 0;
       
    83     
       
    84     /*
       
    85     * ClientBodyReceived()
       
    86     *
       
    87     * Called when a part of the HTTP body is received.
       
    88     *
       
    89     * @param aBodyData Part of the body data received. (e.g. part of
       
    90     *         the received HTML page)
       
    91     */
       
    92     virtual void ClientBodyReceived( const TDesC8& aBodyData ) = 0;
       
    93 
       
    94     /*
       
    95     * Get registrer network country code
       
    96     *
       
    97     * @return current register n/w info
       
    98     */
       
    99     virtual RMobilePhone::TMobilePhoneNetworkInfoV2& GetCurrentRegisterNw() = 0;
       
   100 
       
   101     /*
       
   102     * UE is registered to home network?
       
   103     *
       
   104     * @return ETrue if UE is registered at home network else EFalse
       
   105     */
       
   106     virtual TBool IsRegisteredAtHomeNetwork() = 0;
       
   107 
       
   108     /*
       
   109     * Get home network country code
       
   110     * @param aHomeNwInfoAvailableFlag ETrue if home n/w info available else EFalse
       
   111     * @return user home n/w info
       
   112     */
       
   113     virtual const RMobilePhone::TMobilePhoneNetworkInfoV1& 
       
   114         GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag) = 0;
       
   115     };
       
   116 
       
   117 
       
   118 /*
       
   119 * Provides simple interface to HTTP Client API.
       
   120 */
       
   121 NONSHARABLE_CLASS( CClientEngine ): public CActive,
       
   122                                     public MHTTPTransactionCallback,
       
   123                                     public MMobilityProtocolResp
       
   124     {
       
   125 
       
   126     //Internal Engine state
       
   127     enum TEngineState
       
   128     {
       
   129     EIdle = 0,
       
   130     EGet
       
   131     };
       
   132 
       
   133     public:
       
   134     /*
       
   135      * Create a CClientEngine object.
       
   136      *
       
   137      * @params iObserver refernce to the MClientObservers implementation
       
   138      *
       
   139      * @returns A pointer to the created instance of CClientEngine
       
   140      */
       
   141     static CClientEngine* NewL( MClientObserver& iObserver );
       
   142 
       
   143     /*
       
   144      * Create a CClientEngine object. This leaves the object on the clean up
       
   145      * stack.
       
   146      *
       
   147      * @params iObserver refernce to the MClientObservers implementation
       
   148      *
       
   149      * @returns A pointer to the created instance of CClientEngine
       
   150      */
       
   151     static CClientEngine* NewLC( MClientObserver& iObserver );
       
   152 
       
   153     /*
       
   154      * Destroy the object
       
   155      *
       
   156      */
       
   157     ~CClientEngine();
       
   158 
       
   159     /*
       
   160      * Starts a new HTTP GET transaction.
       
   161      *
       
   162      * @param aUri URI to get request. (e.g. http://host.org")
       
   163      */
       
   164     void IssueHTTPGetL( const TDesC8& aUri, const TConnectionOption aOption );
       
   165 
       
   166     /*
       
   167      * Closes currently running transaction and frees resources related to it.
       
   168      */
       
   169     void CancelTransaction();
       
   170     
       
   171 	/*
       
   172 	* Closes the connection
       
   173 	*/
       
   174     void CloseConnection();
       
   175 
       
   176 
       
   177 	/*
       
   178 	* checks if silent connection is allowed
       
   179 	* @return ETrue if silent connection is allowed
       
   180 	*/
       
   181     TBool SilentConnectionAllowed();
       
   182     
       
   183     private:
       
   184     /*
       
   185      * Perform the second phase construction of a CClientEngine object.
       
   186      */
       
   187     void ConstructL();
       
   188 
       
   189     /*
       
   190      * Performs the first phase of two phase construction.
       
   191      * @param iObserver The observer that is notified after the HTTP transcation is over
       
   192      */
       
   193     CClientEngine( MClientObserver& iObserver );
       
   194 
       
   195     /*
       
   196      * Sets header value of an HTTP request.
       
   197      *
       
   198      * @param aHeaders Headers of the HTTP request
       
   199      * @param aHdrField Enumerated HTTP header field, e.g. HTTP::EUserAgent
       
   200      * @param aHdrValue New value for header field.
       
   201      */
       
   202     void SetHeaderL( RHTTPHeaders aHeaders, TInt aHdrField,
       
   203                      const TDesC8& aHdrValue );
       
   204 
       
   205     /*
       
   206      * Sets up the connection
       
   207      * @param aOption The connection option
       
   208      */
       
   209     void SetupConnectionL( const TConnectionOption aOption );
       
   210 
       
   211     private:
       
   212     //From MHTTPSessionEventCallback
       
   213     /*
       
   214      * Called by framework to notify about transaction events.
       
   215      *
       
   216      * @param aTransaction Transaction, where the event occured.
       
   217      * @param aEvent Occured event.
       
   218      */
       
   219     void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   220 
       
   221     /*
       
   222      * Called by framework to notify about transaction events.
       
   223      *
       
   224      * @param aTransaction Transaction, where the event occured.
       
   225      * @param aError Error status code.
       
   226      * @param aEvent The event that was being processed when leave occured.
       
   227      * 
       
   228      * @retuen    KErrNone, if the error was handled. Otherwise the value of aError, or
       
   229      *   some other error value. Returning error value causes causes
       
   230      *   HTTP-CORE 6 panic.
       
   231      */
       
   232     TInt MHFRunError( TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
   233 
       
   234     private:
       
   235     // from MMobilityProtocolResp
       
   236     void PreferredCarrierAvailable( TAccessPointInfo aOldAPInfo,
       
   237                                     TAccessPointInfo aNewAPInfo,
       
   238                                     TBool aIsUpgrade,
       
   239                                     TBool aIsSeamless );
       
   240     void NewCarrierActive( TAccessPointInfo aNewAPInfo, TBool aIsSeamless );
       
   241     void Error( TInt aError );
       
   242 
       
   243 	TBool IsDataConnectionAskAlwaysL();
       
   244 	TMobileRoamingStatus UeRegNetworkStatus();
       
   245     TBool IsVisitorNetwork(const TMobileRoamingStatus& aRoamingStatus) const;
       
   246     TBool IsWlanOnly(const TMobileRoamingStatus& aRoamingStatus,
       
   247                 const TCmGenConnSettings& aGenConnSettings) const;
       
   248     
       
   249 private: // from CActive
       
   250 
       
   251 	/**
       
   252 	  * RunL
       
   253 	  * This method is called on completion of the active object request
       
   254 	  */
       
   255 
       
   256     void RunL();
       
   257 
       
   258 	/**
       
   259 	  * DoCancel
       
   260 	  * Cancels any outstanding requests
       
   261 	  */	
       
   262     void DoCancel();
       
   263 
       
   264 	/**
       
   265 	  * This method is called if the RunL leaves
       
   266 	  *  @param aError The errcode with which it leaves
       
   267 	  */	
       
   268     TInt RunError(TInt aError);
       
   269 
       
   270 private:
       
   271 
       
   272 	/**
       
   273 	  * Submits a HTTP transaction
       
   274 	  */
       
   275     void DoHTTPGetL();
       
   276    
       
   277 private:
       
   278   // declare members
       
   279     RSocketServ                 iSocketServ;
       
   280     RConnection                 iConnection;
       
   281     TUint32                     iSelectedIap;
       
   282 
       
   283     RHTTPSession                iSession;
       
   284     RHTTPTransaction            iTransaction;
       
   285 
       
   286     MClientObserver&            iObserver;  // Used for passing body data and events to UI
       
   287     TBool                       iRunning;   // ETrue, if transaction running
       
   288     TBool                       iConnectionSetupDone;
       
   289     
       
   290     TInt                        iPrevProfileId;
       
   291     
       
   292     CActiveCommsMobilityApiExt* iMobility;
       
   293     TBool                       iTransactionOpen;
       
   294     TEngineState                 iEngineState;
       
   295     HBufC8*                     iUri;
       
   296 	RCmManager                  iCmManager;
       
   297     
       
   298     };
       
   299 
       
   300 #endif // __CLIENTENGINE_H__
       
   301 
       
   302 // End of file