ncdengine/engine/transport/src/catalogshttpsessionimpl.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "catalogshttpconfig.h"
       
    20 #include "catalogshttpsessionimpl.h"
       
    21 #include "catalogstransporttypes.h"
       
    22 #include "catalogshttpdownloadmanagerimpl.h"
       
    23 #include "catalogshttpoperation.h"
       
    24 #include "catalogshttptransactionmanagerimpl.h"
       
    25 #include "catalogsdebug.h"
       
    26 #include "catalogstransportimpl.h"
       
    27 #include "catalogshttpconnectionmanager.h"
       
    28 #include "catalogsconnectioneventsink.h"
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // Creator
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CCatalogsHttpSession* CCatalogsHttpSession::NewL( 
       
    37     TInt32 aSessionId, 
       
    38     CCatalogsTransport& aOwner, 
       
    39     MCatalogsHttpSessionManager& aSessionManager,
       
    40     TBool aCleanupSession )
       
    41     {
       
    42     DLTRACEIN( ( "" ) );
       
    43     CCatalogsHttpSession* self = new ( ELeave ) CCatalogsHttpSession(
       
    44         aSessionId, aOwner, aSessionManager );
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL( aSessionManager, aCleanupSession );
       
    47     CleanupStack::Pop( self );
       
    48     DLTRACEOUT( ( "self: %X", self ) );
       
    49     return self;
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Destructor
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 CCatalogsHttpSession::~CCatalogsHttpSession()
       
    58     {
       
    59     DLTRACEIN( ( "" ) );
       
    60     // disconnect network connection if no clients use it
       
    61     TRAP_IGNORE( iSessionManager.DisconnectL() );
       
    62     delete iDownloadMgr;
       
    63     delete iTransactionMgr;
       
    64     delete iConnectionMgr;
       
    65     delete iConnectionEventSink;
       
    66     
       
    67     if ( iOwner ) 
       
    68         {        
       
    69         iOwner->RemoveSession( this );
       
    70         }
       
    71     
       
    72     DLTRACEOUT( ( "" ) );
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Add a reference
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TInt CCatalogsHttpSession::AddRef()
       
    81     {
       
    82     iRefCount++;
       
    83     return iRefCount;
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // Release a reference
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 TInt CCatalogsHttpSession::Release()
       
    92     {
       
    93     iRefCount--;
       
    94     if ( !iRefCount ) 
       
    95         {
       
    96         delete this;
       
    97         return 0;
       
    98         }
       
    99     return iRefCount;
       
   100     }
       
   101         
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Reference count
       
   105 // ---------------------------------------------------------------------------
       
   106 //        
       
   107 TInt CCatalogsHttpSession::RefCount() const
       
   108     {
       
   109     return iRefCount;
       
   110     }
       
   111 
       
   112 
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // Session id getter
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 TInt32 CCatalogsHttpSession::SessionId() const
       
   119     {
       
   120     return iSessionId;
       
   121     }
       
   122         
       
   123         
       
   124 // ---------------------------------------------------------------------------
       
   125 // Session type getter
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt CCatalogsHttpSession::SessionType() const
       
   129     {
       
   130     return KCatalogsTransportHttpInterface;
       
   131     }
       
   132 
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // Download creator
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 MCatalogsHttpOperation* CCatalogsHttpSession::CreateDownloadL( 
       
   139     const TDesC16& aUrl, TBool aStart, MCatalogsHttpObserver* aObserver)
       
   140     {        
       
   141     return iDownloadMgr->CreateDownloadL( aUrl, aStart, aObserver );    
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Download creator
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 MCatalogsHttpOperation* CCatalogsHttpSession::CreateDownloadL( 
       
   149     const TDesC8& aUrl, TBool aStart, MCatalogsHttpObserver* aObserver)
       
   150     {        
       
   151     return iDownloadMgr->CreateDownloadL( aUrl, aStart, aObserver );    
       
   152     }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // Transaction creator
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 MCatalogsHttpOperation* CCatalogsHttpSession::CreateTransactionL( 
       
   160     const TDesC16& aUrl, MCatalogsHttpObserver* aObserver )
       
   161     {
       
   162     return iTransactionMgr->CreateTransactionL( aUrl, aObserver );
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Transaction creator
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 MCatalogsHttpOperation* CCatalogsHttpSession::CreateTransactionL( 
       
   171     const TDesC8& aUrl, MCatalogsHttpObserver* aObserver )
       
   172     {
       
   173     return iTransactionMgr->CreateTransactionL( aUrl, aObserver );
       
   174     }
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // Download transaction creator
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 MCatalogsHttpOperation* CCatalogsHttpSession::CreateDlTransactionL( 
       
   182     const TDesC8& aUrl, MCatalogsHttpObserver& aObserver,
       
   183     const CCatalogsHttpConfig& aConfig )
       
   184     {
       
   185     return iTransactionMgr->CreateDlTransactionL( aUrl, aObserver, aConfig );
       
   186     }
       
   187 
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Download getter
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 MCatalogsHttpOperation* CCatalogsHttpSession::Download( 
       
   194     const TCatalogsTransportOperationId& aId ) const
       
   195     {
       
   196     return iDownloadMgr->Download( aId );
       
   197     }
       
   198 
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // Transaction getter
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 MCatalogsHttpOperation* CCatalogsHttpSession::Transaction( 
       
   205     const TCatalogsTransportOperationId& aId ) const
       
   206     {    
       
   207     return iTransactionMgr->Transaction( aId );
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // Download array getter
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 const RCatalogsHttpOperationArray& 
       
   216     CCatalogsHttpSession::CurrentDownloads() const
       
   217     {
       
   218     return iDownloadMgr->CurrentDownloads();
       
   219     }
       
   220         
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // Restored downloads getter
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 const RCatalogsHttpOperationArray&
       
   227     CCatalogsHttpSession::RestoredDownloads() const
       
   228     {
       
   229     return iDownloadMgr->RestoredDownloads();
       
   230     }
       
   231         
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // Moves a restored download to current downloads
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 TInt CCatalogsHttpSession::MoveRestoredDlToCurrentDls( 
       
   238     MCatalogsHttpOperation& aDownload )
       
   239     {
       
   240     return iDownloadMgr->MoveRestoredDlToCurrentDls( aDownload );
       
   241     }
       
   242     
       
   243 // ---------------------------------------------------------------------------
       
   244 // Transaction array getter
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 const RCatalogsHttpOperationArray& 
       
   248     CCatalogsHttpSession::CurrentTransactions() const
       
   249     {
       
   250     return iTransactionMgr->CurrentTransactions();
       
   251     }
       
   252 
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Cancel all operations
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 void CCatalogsHttpSession::CancelAllOperations()
       
   259     {
       
   260     CancelAllDownloads();
       
   261     CancelAllTransactions();    
       
   262     }
       
   263 
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // Cancel all operations
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CCatalogsHttpSession::NotifyCancelAllOperations()
       
   271     {
       
   272     iSessionManager.SetResumeMode( EFalse );
       
   273     iTransactionMgr->NotifyCancelAll();
       
   274     iDownloadMgr->NotifyCancelAll();    
       
   275     iSessionManager.SetResumeMode( ETrue );
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // Cancel all downloads
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CCatalogsHttpSession::CancelAllDownloads()
       
   283     {
       
   284     // Disable operation resuming during cancel so that ops are not
       
   285     // unnecessarily resumed
       
   286     iSessionManager.SetResumeMode( EFalse );
       
   287     iDownloadMgr->CancelAll();    
       
   288     iSessionManager.SetResumeMode( ETrue );
       
   289     }
       
   290 
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // Cancel all transactions
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 void CCatalogsHttpSession::CancelAllTransactions()
       
   297     {
       
   298     // Disable operation resuming during cancel so that ops are not
       
   299     // unnecessarily resumed
       
   300     iSessionManager.SetResumeMode( EFalse );
       
   301     iTransactionMgr->CancelAll();
       
   302     iSessionManager.SetResumeMode( ETrue );
       
   303     }
       
   304 
       
   305 
       
   306 // ---------------------------------------------------------------------------
       
   307 // Deletes restored downloads
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 void CCatalogsHttpSession::DeleteRestoredDownloads()
       
   311     {
       
   312     iDownloadMgr->DeleteRestoredDownloads();
       
   313     }
       
   314     
       
   315 // ---------------------------------------------------------------------------
       
   316 // Transaction configuration getter
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 MCatalogsHttpConfig& 
       
   320     CCatalogsHttpSession::DefaultTransactionConfig() const
       
   321     {    
       
   322     return iTransactionMgr->DefaultConfig();
       
   323     }
       
   324 
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // Download configuration getter
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 MCatalogsHttpConfig& CCatalogsHttpSession::DefaultDownloadConfig() const
       
   331     {
       
   332     return iDownloadMgr->DefaultConfig();
       
   333     }
       
   334   
       
   335         
       
   336 // ---------------------------------------------------------------------------
       
   337 // Set default accesspoint for downloads and transactions
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CCatalogsHttpSession::SetDefaultConnectionMethod( 
       
   341     const TCatalogsConnectionMethod& aMethod )
       
   342     {
       
   343     iDownloadMgr->DefaultConfig().SetConnectionMethod( aMethod );
       
   344     iTransactionMgr->DefaultConfig().SetConnectionMethod( aMethod );
       
   345 
       
   346     iConnectionMgr->SetDefaultConnectionMethod( aMethod );
       
   347     }
       
   348 // ---------------------------------------------------------------------------
       
   349 // SetOwner
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CCatalogsHttpSession::SetOwner( CCatalogsTransport* aOwner )
       
   353     {
       
   354     iOwner = aOwner;
       
   355     }
       
   356     
       
   357     
       
   358 // ---------------------------------------------------------------------------
       
   359 // Connection manager getter
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 CCatalogsHttpConnectionManager& CCatalogsHttpSession::ConnectionManager()
       
   363     {
       
   364     DASSERT( iConnectionMgr );
       
   365     return *iConnectionMgr;
       
   366     }
       
   367 
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // Session options setter
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 void CCatalogsHttpSession::SetOptions( TUint32 aOptions )
       
   374     {
       
   375     DLTRACEIN(("aOptions: %d", aOptions));
       
   376     iDownloadMgr->DefaultConfig().SetOptions( aOptions );
       
   377     }
       
   378 
       
   379 // ---------------------------------------------------------------------------
       
   380 // Constructor
       
   381 // ---------------------------------------------------------------------------
       
   382 //
       
   383 CCatalogsHttpSession::CCatalogsHttpSession( TInt32 aSessionId, 
       
   384     CCatalogsTransport& aOwner, 
       
   385     MCatalogsHttpSessionManager& aSessionManager ) : 
       
   386     iOwner( &aOwner ), 
       
   387     iSessionManager( aSessionManager ),
       
   388     iSessionId( aSessionId ),
       
   389     iRefCount( 1 )
       
   390     {
       
   391     }
       
   392     
       
   393     
       
   394 // ---------------------------------------------------------------------------
       
   395 // 2nd phase constructor
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void CCatalogsHttpSession::ConstructL( MCatalogsHttpSessionManager& aManager,
       
   399     TBool aCleanupSession )
       
   400     {
       
   401     DLTRACEIN(("this=%X",this));    
       
   402     iConnectionMgr = CCatalogsHttpConnectionManager::NewL( *this );
       
   403     
       
   404     iTransactionMgr = CCatalogsHttpTransactionManager::NewL( 
       
   405         aManager, 
       
   406         *this, 
       
   407         *iConnectionMgr, 
       
   408         iSessionId );
       
   409     DLINFO(("transaction mgr ok"));
       
   410     
       
   411     iDownloadMgr = CCatalogsHttpDownloadManager::NewL( 
       
   412         aManager, 
       
   413         *this,
       
   414         iSessionId,
       
   415         *iTransactionMgr, 
       
   416         *iConnectionMgr, 
       
   417         aCleanupSession );
       
   418     
       
   419     // This uid must be the client side process SID. We assume that
       
   420     // the session id is the same as client side SID.
       
   421     TUid uid = TUid::Uid( iSessionId );
       
   422     iConnectionEventSink = CCatalogsConnectionEventSink::NewL( uid );
       
   423     DLTRACEOUT((""));
       
   424     }
       
   425 
       
   426 
       
   427 void CCatalogsHttpSession::ReportConnectionStatus( TBool aActive )
       
   428     {
       
   429     DLTRACEIN((""));
       
   430     iConnectionEventSink->ReportConnectionStatus( aActive );
       
   431     }