browserutilities/feedsengine/FeedsServer/UrlHandler/src/ServerHttpConnection.cpp
changeset 0 dd21522fd290
child 25 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2005 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:  A class that fetches resources via HTTP 1.1.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aputils.h> 
       
    20 #include <InternetConnectionManager.h>
       
    21 
       
    22 #include "ServerHttpConnection.h"
       
    23 #include "Logger.h"
       
    24 
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CServerHttpConnection::NewL
       
    28 //
       
    29 // Two-phased constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CServerHttpConnection* CServerHttpConnection::NewL( TUint32 iDefaultAccessPoint )
       
    33     {
       
    34     CServerHttpConnection* self = new (ELeave) CServerHttpConnection( iDefaultAccessPoint );
       
    35     
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop();
       
    39 
       
    40     return self;
       
    41     }
       
    42 
       
    43         
       
    44 // -----------------------------------------------------------------------------
       
    45 // CServerHttpConnection::CServerHttpConnection
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CServerHttpConnection::CServerHttpConnection( TUint32 aDefaultAccessPoint ):
       
    51         iLeakTracker( CLeakTracker::EHttpConnection ),
       
    52         iDefaultAccessPoint( aDefaultAccessPoint )
       
    53     {
       
    54     }
       
    55         
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CServerHttpConnection::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void CServerHttpConnection::ConstructL()
       
    63     {
       
    64     BaseConstructL();
       
    65 
       
    66     // Create the connection mgr.
       
    67     iConMgr = CInternetConnectionManager::NewL(ETrue);
       
    68     }        
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // CServerHttpConnection::~CServerHttpConnection
       
    73 // Deconstructor.
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 CServerHttpConnection::~CServerHttpConnection()
       
    77     {
       
    78     // close http session
       
    79     iSession.Close();
       
    80 
       
    81     // delete ConnectionManager
       
    82     Disconnect();
       
    83     delete iConMgr;
       
    84     }
       
    85 
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CServerHttpConnection::CreateConnection
       
    89 // 
       
    90 // It propagates the connection callback to the browser client.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TInt CServerHttpConnection::CreateConnection(TInt* aConnectionPtr, TInt* aSockSvrHandle, 
       
    94         TBool* aNewConn, TApBearerType* aBearerType)
       
    95     {
       
    96     TInt  err = KErrNone;
       
    97 
       
    98     // If need be establish the connection.
       
    99     if(!IsConnected())
       
   100         {
       
   101         // Set the default access point.
       
   102         iConMgr->SetRequestedAP( iDefaultAccessPoint );
       
   103             
       
   104         // Open a connection.
       
   105         TRAP(err, err = iConMgr->StartConnectionL(ETrue));                
       
   106         if (err != KErrNone)
       
   107             {
       
   108             // Notify the HttpHandler that the establishing the access point failed
       
   109             if (iObserver != NULL)
       
   110                 {
       
   111                 iObserver->ConnectionFailed(err);
       
   112                 }
       
   113                 
       
   114             return err;
       
   115             }
       
   116 
       
   117         *aNewConn = ETrue;
       
   118 
       
   119         if (iObserver != NULL)
       
   120             {
       
   121             iObserver->ConnectionAvailable();
       
   122             }
       
   123         }
       
   124         
       
   125     // Otherwise the connection is valid.
       
   126     else
       
   127         {
       
   128         *aNewConn = EFalse;
       
   129         }
       
   130 
       
   131     // Set the connection, server handler, and bearer type.
       
   132     *aConnectionPtr = (TInt) &iConMgr->Connection();
       
   133     *aSockSvrHandle = (TInt) iConMgr->SocketServer().Handle();
       
   134 
       
   135     TRAP(err, *aBearerType = iConMgr->CurrentBearerTypeL());
       
   136     if (err != KErrNone)
       
   137         {
       
   138         // Notify the HttpHandler that the establishing the access point failed
       
   139         if (iObserver != NULL)
       
   140             {
       
   141             iObserver->ConnectionFailed(err);
       
   142             }
       
   143                 
       
   144         return err;
       
   145         }
       
   146     
       
   147     return KErrNone;
       
   148     }
       
   149 
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CServerHttpConnection::IsConnected
       
   153 //
       
   154 // Returns whether or not the connection is active.
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool CServerHttpConnection::IsConnected()
       
   158     {
       
   159     return iConMgr->Connected();
       
   160     }
       
   161     
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CServerHttpConnection::Disconnect
       
   165 //
       
   166 // Closes the connection.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CServerHttpConnection::Disconnect()
       
   170     {
       
   171     if (IsConnected())
       
   172         {
       
   173         iConMgr->Disconnect();
       
   174         }
       
   175     }
       
   176 
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // CServerHttpConnection::SetAccessPointL
       
   180 // 
       
   181 // Set the new access point.
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 void CServerHttpConnection::SetAccessPointL( TUint32 aAccessPoint )
       
   185     {
       
   186     iDefaultAccessPoint = aAccessPoint;
       
   187     }