browserutilities/downloadmgr/DownloadMgrServEng/Inc/HttpConnHandler.h
changeset 0 dd21522fd290
child 58 220a17280356
child 68 92a765b5b3e7
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 the License "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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef HTTPCONNHANDLER_H
       
    21 #define HTTPCONNHANDLER_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <es_sock.h>
       
    26 #include <http.h>
       
    27 #include <CommDbConnPref.h>
       
    28 
       
    29 // CONSTANTS
       
    30 //const ?type ?constant_var = ?constant;
       
    31 
       
    32 // MACROS
       
    33 //#define ?macro ?macro_def
       
    34 
       
    35 // DATA TYPES
       
    36 //enum ?declaration
       
    37 //typedef ?declaration
       
    38 //extern ?data_type;
       
    39 
       
    40 // FUNCTION PROTOTYPES
       
    41 //?type ?function_name(?arg_list);
       
    42 
       
    43 // FORWARD DECLARATIONS
       
    44 class CHttpClientAppInstance;
       
    45 class CHttpClientApp;
       
    46 class CHttpConnHandler;
       
    47 
       
    48 // CLASS DECLARATION
       
    49 
       
    50 class MConnectionCallback
       
    51     {
       
    52     public:
       
    53 
       
    54         virtual void Connected() = 0;
       
    55         virtual void Suspended() = 0;
       
    56         // called if the connection is closed
       
    57         // from outside (e.g. network loss)
       
    58         virtual void Disconnected() = 0;
       
    59         virtual void ConnectionFailed( TInt aError ) = 0;
       
    60     };
       
    61 
       
    62 class MShutdownObserver
       
    63     {
       
    64     public:
       
    65 
       
    66         virtual void ShutDown( TBool aFromDestructor = EFalse ) = 0;
       
    67     };
       
    68 
       
    69 /**
       
    70 *  Connection handler's shutdown timer.
       
    71 */
       
    72 NONSHARABLE_CLASS( CHttpConnShutdownTimer ) : public CActive
       
    73     {
       
    74     public: // Constructors and destructor
       
    75 
       
    76         /**
       
    77         * Two-phased constructor.
       
    78         */
       
    79         static CHttpConnShutdownTimer* NewL( MShutdownObserver* aObserver );
       
    80 
       
    81         /**
       
    82         * Destructor.
       
    83         */
       
    84         ~CHttpConnShutdownTimer();
       
    85 
       
    86     private:
       
    87 
       
    88         /**
       
    89         * C++ default constructor.
       
    90         */
       
    91         CHttpConnShutdownTimer( MShutdownObserver* aObserver );
       
    92 
       
    93         /**
       
    94         * Default Symbian 2nd phase constructor .
       
    95         */
       
    96         void ConstructL();
       
    97 
       
    98     public: // New functions
       
    99 
       
   100         /**
       
   101         * Starts the timer.
       
   102         * @param 
       
   103         * @return
       
   104         */
       
   105         void Start( TInt aTimeOut );
       
   106 
       
   107     private: // From CActive
       
   108 
       
   109         /**
       
   110         * Cancels the timer.
       
   111         * @param 
       
   112         * @return
       
   113         */
       
   114         void DoCancel();
       
   115 
       
   116         /**
       
   117         * Handles an active object’s request completion event.
       
   118         * @param 
       
   119         * @return
       
   120         */
       
   121         void RunL();
       
   122 
       
   123     private: // Data
       
   124 
       
   125         RTimer iTimer;
       
   126         MShutdownObserver* iObserver;   // owned
       
   127     };
       
   128 
       
   129 class MConnectionObserver
       
   130     {
       
   131     public:
       
   132 
       
   133         virtual void ConnectionStageChanged( TInt aStage ) = 0;
       
   134         virtual void ConnectionError( TInt aError ) = 0;
       
   135     };
       
   136 
       
   137 /**
       
   138 *  ?one_line_short_description.
       
   139 *  ?other_description_lines
       
   140 *
       
   141 *  @lib ?library
       
   142 *  @since Series 60 v2.8
       
   143 */
       
   144 NONSHARABLE_CLASS( CHttpConnStageNotifier ) : public CActive
       
   145     {
       
   146     public:  // Constructors and destructor
       
   147         
       
   148         /**
       
   149         * Two-phased constructor.
       
   150         */
       
   151         static CHttpConnStageNotifier* NewL( CHttpConnHandler* aConnHandler );
       
   152         
       
   153         /**
       
   154         * Destructor.
       
   155         */
       
   156         virtual ~CHttpConnStageNotifier();
       
   157 
       
   158     public: // New functions
       
   159         
       
   160         /**
       
   161         * Starts connection stage notification
       
   162         * @since Series 60 v2.8
       
   163         * @return none.
       
   164         */
       
   165         void Start();
       
   166 
       
   167     public: // Functions from base classes
       
   168 
       
   169         /**
       
   170         * methods from CActive
       
   171         */
       
   172 	    void DoCancel();
       
   173 	    void RunL();
       
   174         
       
   175     protected:  // New functions
       
   176         
       
   177     protected:  // Functions from base classes
       
   178         
       
   179     private:
       
   180 
       
   181         /**
       
   182         * C++ default constructor.
       
   183         */
       
   184         CHttpConnStageNotifier( CHttpConnHandler* aConnHandler );
       
   185 
       
   186         /**
       
   187         * By default Symbian 2nd phase constructor is private.
       
   188         */
       
   189         void ConstructL();
       
   190 
       
   191         // Prohibit copy constructor if not deriving from CBase.
       
   192         // CHttpConnStageNotifier( const CHttpConnStageNotifier& );
       
   193         // Prohibit assigment operator if not deriving from CBase.
       
   194         // CHttpConnStageNotifier& operator=( const CHttpConnStageNotifier& );
       
   195 
       
   196     public:     // Data
       
   197         // ?one_line_short_description_of_data
       
   198         //?data_declaration;
       
   199     
       
   200     protected:  // Data
       
   201 
       
   202         CHttpConnHandler* iConnHandler;     // pointer to CHttpConnHandler.
       
   203                                             // Not owned by this class!
       
   204         TNifProgressBuf iProgressBuf;
       
   205 
       
   206     private:    // Data
       
   207 
       
   208     public:     // Friend classes
       
   209     protected:  // Friend classes
       
   210     private:    // Friend classes
       
   211     };
       
   212 
       
   213 /**
       
   214 *  ?one_line_short_description.
       
   215 *  ?other_description_lines
       
   216 *
       
   217 *  @lib ?library
       
   218 *  @since Series 60 v2.8
       
   219 */
       
   220 NONSHARABLE_CLASS( CHttpConnHandler ) : public CActive,
       
   221                                         public MConnectionObserver,
       
   222                                         public MShutdownObserver
       
   223     {
       
   224     public:  // Constructors and destructor
       
   225         
       
   226         /**
       
   227         * Two-phased constructor.
       
   228         */
       
   229         static CHttpConnHandler* NewL( CHttpClientApp* aClientApp );
       
   230         
       
   231         /**
       
   232         * Destructor.
       
   233         */
       
   234         virtual ~CHttpConnHandler();
       
   235 
       
   236     public: // New functions
       
   237         
       
   238         /**
       
   239         * Starts asynchronous connect to the network.
       
   240         * @since Series 60 v2.8
       
   241         * @return none. Leaves on error.
       
   242         */
       
   243         void ConnectL();
       
   244 
       
   245         /**
       
   246         * Disconnects from the network. Counts how many download still
       
   247         * using this connection. If there is no more, starts disconnection 
       
   248         * timer.
       
   249         * @since Series 60 v2.8
       
   250         * @param aExit if ETrue disconnects at once
       
   251         * @return none.
       
   252         */
       
   253         void Disconnect( TBool aAtOnce = EFalse,
       
   254                          CHttpDownload* aDownload = NULL );
       
   255 
       
   256         /**
       
   257         * Returns associated IAP id.
       
   258         * @since Series 60 v2.8
       
   259         * @return IAPid used to create connection
       
   260         */
       
   261         TUint32 IapId() const;
       
   262 
       
   263         /**
       
   264         * Returns associated client application.
       
   265         * @since Series 60 v2.8
       
   266         * @return pointer to the client application. Ownership not passed.
       
   267         */
       
   268         CHttpClientApp* ClientApp() const;
       
   269 
       
   270         /**
       
   271         * Returns associated client application instance.
       
   272         * @since Series 60 v2.8
       
   273         * @return pointer to the client application instance. Ownership not passed.
       
   274         */
       
   275         CHttpClientAppInstance* ClientAppInst() const;
       
   276 
       
   277         /**
       
   278         * Returns the HTTP session.
       
   279         * @since Series 60 v2.8
       
   280         * @return HTTP session
       
   281         */
       
   282         RHTTPSession& Session();
       
   283 
       
   284         /**
       
   285         * Returns the RConnection.
       
   286         * @since Series 60 v2.8
       
   287         * @return reference to the RConnection
       
   288         */
       
   289         RConnection& Connection();
       
   290 
       
   291         /**
       
   292         * See EDlMgrConnectionName.
       
   293         * @since Series 60 v2.8
       
   294         * @return none. Leaves on failure.
       
   295         */
       
   296         HBufC* ConnectionNameL( TBool& aDelete );
       
   297 
       
   298         /**
       
   299         * See EDlMgrAPName.
       
   300         * @since Series 60 v2.8
       
   301         * @return none. Leaves on failure.
       
   302         */
       
   303         void APNameL( TPtrC16& aValue );
       
   304 
       
   305         /**
       
   306         * Returns the connection state.
       
   307         * @since Series 60 v2.8
       
   308         * @return ETrue if connected
       
   309         */
       
   310         TBool IsConnected();
       
   311 
       
   312         /**
       
   313         * Associates connection handler with the given client application
       
   314         * instance.
       
   315         * @since Series 60 v2.8
       
   316         * @param aClientInst client instance to use this connection handler
       
   317         * @return none.
       
   318         */
       
   319         void SetClientAppInst( CHttpClientAppInstance* aClientInst );
       
   320 
       
   321         /**
       
   322         * Sets IAP id to be used to create connection.
       
   323         * Cannot be called after connection is created.
       
   324         * @since Series 60 v2.8
       
   325         * @param IAP id to be used to create connection.
       
   326         * @return none.
       
   327         */
       
   328         void SetIapId( TUint32 aIapId );
       
   329 
       
   330         /**
       
   331         * Set connection name to be used to clone an already exist connection
       
   332         * IAP id is ignored in this case.
       
   333         */
       
   334         void SetConnectionNameL( const TDesC& aConnName );
       
   335 
       
   336     public: // Functions from base classes
       
   337 
       
   338         /**
       
   339         * methods from CActive
       
   340         */
       
   341         void DoCancel();
       
   342         void RunL();
       
   343 
       
   344         /**
       
   345         * methods from CHttpConnStageNotifier
       
   346         */
       
   347         void ConnectionStageChanged( TInt aStage );
       
   348         void ConnectionError( TInt aError );
       
   349 
       
   350         /**
       
   351         * methods from MShutdownObserver
       
   352         */
       
   353         void ShutDown( TBool aFromDestructor = EFalse );
       
   354         
       
   355     protected:  // New functions
       
   356         
       
   357         /**
       
   358         * Initializes HTTP session.
       
   359         * @since Series 60 v2.8
       
   360         * @return none. Leaves on error.
       
   361         */
       
   362         void InitSessionL();
       
   363 
       
   364         /**
       
   365         * Sets connection info in HTTP session.
       
   366         * @since Series 60 v2.8
       
   367         * @return none. Leaves on error.
       
   368         */
       
   369         void SetConnectionInfoL();
       
   370 
       
   371         /**
       
   372         * Called if connection is successfully created.
       
   373         * @since Series 60 v2.8
       
   374         * @return none.
       
   375         */
       
   376         void Connected();
       
   377 
       
   378         /**
       
   379         * Returns the number of downloads using this connection handler.
       
   380         * @since Series 60 v2.8
       
   381         * @return number of downloads using this connection handler
       
   382         */
       
   383         TInt Referencies();
       
   384         
       
   385         /**
       
   386         * Updates iIapId after connection made.
       
   387         * @since Series 60 v3.0
       
   388         * @return None.
       
   389         */
       
   390         void UpdateIapId();
       
   391 
       
   392     protected:  // Functions from base classes
       
   393         
       
   394     private:
       
   395 
       
   396         /**
       
   397         * C++ default constructor.
       
   398         */
       
   399         CHttpConnHandler( CHttpClientApp* aClientApp );
       
   400 
       
   401         /**
       
   402         * By default Symbian 2nd phase constructor is private.
       
   403         */
       
   404         void ConstructL();
       
   405 
       
   406     public:     // Data
       
   407         // ?one_line_short_description_of_data
       
   408         //?data_declaration;
       
   409     
       
   410     protected:  // Data
       
   411         // ?one_line_short_description_of_data
       
   412         //?data_declaration;
       
   413         RHTTPSession    iHttpSession;
       
   414         RConnection     iConnection;
       
   415         TCommDbConnPref iPref;
       
   416         TUint32         iIapId;             // See EDlMgrIap
       
   417         CHttpClientAppInstance* iClientInst;// Associated client app instance. not owned
       
   418         CHttpClientApp* iClientApp;         // This is needed because instance can be
       
   419                                             // closed while associated conn handler 
       
   420                                             // stays active. not owned
       
   421         CHttpConnStageNotifier* iConnNotif; // Connection stage notifier. owner
       
   422         CHttpConnShutdownTimer* iShutDown;  // Shutdown timer after last reference is closed.
       
   423                                             // owned
       
   424 
       
   425         TInt    iConnStage;
       
   426         HBufC*  iConnName;                  // owned
       
   427 
       
   428     private:    // Data
       
   429 
       
   430         TBool iNewConnection;
       
   431         
       
   432         // Reserved pointer for future extension
       
   433         //TAny* iReserved;
       
   434 
       
   435     public:     // Friend classes
       
   436         //?friend_class_declaration;
       
   437     protected:  // Friend classes
       
   438         //?friend_class_declaration;
       
   439     private:    // Friend classes
       
   440         //?friend_class_declaration;
       
   441 
       
   442     };
       
   443 
       
   444 #endif      // HTTPCONNHANDLER_H   
       
   445             
       
   446 // End of File