ncdengine/engine/transport/src/catalogstransportimpl.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 "catalogstransportimpl.h"
       
    20 
       
    21 #include "catalogstransporttypes.h"
       
    22 #include "catalogssmssessionimpl.h"
       
    23 #include "catalogshttpsessionimpl.h"
       
    24 #include "catalogshttpsessionmanagerimpl.h"
       
    25 
       
    26 #include "catalogsdebug.h"
       
    27 
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // NewL
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CCatalogsTransport* CCatalogsTransport::NewL( CDocumentHandler& aDocHandler )
       
    36     {
       
    37     CCatalogsTransport* self = new( ELeave ) CCatalogsTransport();
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL( aDocHandler );
       
    40     CleanupStack::Pop( self );
       
    41     return self;    
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Destructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CCatalogsTransport::~CCatalogsTransport()
       
    50     {
       
    51     iRemovingAll = ETrue;
       
    52     
       
    53     DLTRACEIN(( KNullDesC() ));
       
    54     // Release SMS sessions if the clients haven't done it yet
       
    55     for ( TInt i = 0; i < iSmsSessions.Count(); ++i )
       
    56         {
       
    57         while ( iSmsSessions[i]->Release() )
       
    58             {
       
    59             }
       
    60         }
       
    61 
       
    62 
       
    63     DLTRACE( ( _L("Releasing HTTP sessions") ) );
       
    64     // Release HTTP sessions if the clients haven't done it yet
       
    65     for ( TInt i = 0; i < iHttpSessions.Count(); ++i )
       
    66         {
       
    67         /*
       
    68         while ( iHttpSessions[i]->Release() ) 
       
    69             {
       
    70             }
       
    71             */
       
    72         // Ensure sessions don't try to access Transport anymore
       
    73         static_cast<CCatalogsHttpSession*>(iHttpSessions[i])->SetOwner( NULL );
       
    74         }    
       
    75     DLTRACE( ( _L("HTTP sessions released") ) );
       
    76     
       
    77     // Should the sessions be deleted?
       
    78     iSmsSessions.Close();
       
    79     iHttpSessions.Close();
       
    80     //delete iHttpSessionManager;
       
    81     if ( iHttpSessionManager ) 
       
    82         {        
       
    83         iHttpSessionManager->Release();
       
    84         }
       
    85     DLTRACEOUT(( KNullDesC() ));
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Queries an interface from Transport
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 MCatalogsTransportSession* CCatalogsTransport::QueryInterfaceL( 
       
    94     TInt32 aSessionId, 
       
    95     TInt aInterfaceId,
       
    96     TBool aCleanupSession )
       
    97     {
       
    98     DLTRACEIN(("this=%X,session=%d,interface=%d",this, aSessionId,aInterfaceId));
       
    99     MCatalogsTransportSession* interface = NULL;
       
   100 	
       
   101     // Instantiate the correct interface
       
   102     switch( aInterfaceId ) 
       
   103         {
       
   104         case KCatalogsTransportSmsInterface: 
       
   105             {
       
   106             // Check if the interface has been already instantiated with 
       
   107             // the same session id
       
   108             interface = FindSession( aSessionId, iSmsSessions );
       
   109 			
       
   110             if ( !interface ) 
       
   111                 {			    
       
   112                 interface = CCatalogsSmsSession::NewL( aSessionId, *this );
       
   113     			
       
   114                 TInt err = iSmsSessions.Append( interface );			
       
   115                 if ( err != KErrNone ) 
       
   116                     {
       
   117                     interface->Release();
       
   118                     User::Leave( err );
       
   119                     }    			
       
   120                 }
       
   121             else 
       
   122                 {
       
   123                 // Increase reference count 
       
   124                 interface->AddRef();
       
   125                 }
       
   126             break;
       
   127             }
       
   128 		
       
   129 		
       
   130         case KCatalogsTransportHttpInterface:
       
   131             {
       
   132             // Check if the interface has been already instantiated with 
       
   133             // the same session id
       
   134             interface = FindSession( aSessionId, iHttpSessions );
       
   135 			
       
   136             if( !interface ) 
       
   137                 {			    
       
   138                 interface = CCatalogsHttpSession::NewL( 
       
   139                     aSessionId, 
       
   140                     *this, 
       
   141                     *iHttpSessionManager,
       
   142                     aCleanupSession );
       
   143     			
       
   144                 TInt err = iHttpSessions.Append( interface );
       
   145                 if ( err != KErrNone )
       
   146                     {
       
   147                     interface->Release();
       
   148                     User::Leave( err );
       
   149                     }    			
       
   150                 }
       
   151             else
       
   152                 {
       
   153                 interface->AddRef();
       
   154                 }
       
   155             break;
       
   156             }
       
   157 			
       
   158 			
       
   159         default: 
       
   160             {
       
   161             // Invalid interface ID
       
   162             User::Leave( KErrArgument );
       
   163             }
       
   164         }
       
   165 
       
   166     DLTRACEOUT((""));
       
   167     return interface;
       
   168     }
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Searches for the session
       
   173 // ---------------------------------------------------------------------------
       
   174 //		
       
   175 MCatalogsTransportSession* CCatalogsTransport::FindSession( 
       
   176     TInt32 aSessionId, RCatalogsSessionArray& aSessions ) const
       
   177     {
       
   178     for( TInt i = 0; i < aSessions.Count(); ++i )
       
   179         {
       
   180         if( aSessions[i]->SessionId() == aSessionId ) 
       
   181             {
       
   182             return aSessions[i];
       
   183             }
       
   184         }
       
   185     return NULL;
       
   186     }
       
   187 
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Removes the session from Transport
       
   191 // ---------------------------------------------------------------------------
       
   192 //			
       
   193 void CCatalogsTransport::RemoveSession( MCatalogsTransportSession* aSession )
       
   194     {
       
   195     DLTRACEIN( ( "aSession: %x", reinterpret_cast<TInt>( aSession ) ) );
       
   196     
       
   197     if( iRemovingAll ) 
       
   198         {
       
   199         return;
       
   200         }
       
   201         
       
   202     DASSERT( aSession );
       
   203     RCatalogsSessionArray* sessions = NULL;
       
   204     
       
   205     // Choose the correct array according to the session type
       
   206     switch( aSession->SessionType() )
       
   207         {
       
   208         case KCatalogsTransportSmsInterface:  
       
   209             {
       
   210             sessions = &iSmsSessions;
       
   211             break;
       
   212             }
       
   213 
       
   214         case KCatalogsTransportHttpInterface:  
       
   215             {
       
   216             sessions = &iHttpSessions;
       
   217             break;
       
   218             }
       
   219         
       
   220         default:
       
   221             {
       
   222             DASSERT( 0 );
       
   223             }
       
   224         }
       
   225             
       
   226     TInt index = sessions->Find( aSession );
       
   227 
       
   228     // There must not be a situation where a session is not found from
       
   229     // Transport
       
   230     //DASSERT( index != KErrNotFound );
       
   231 
       
   232     if ( index != KErrNotFound )
       
   233         {        
       
   234         // Remove the session
       
   235         sessions->Remove( index );
       
   236         }
       
   237     else
       
   238         {
       
   239         DLERROR(("Session was not found"));
       
   240         }
       
   241     }
       
   242     
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // 2nd phase constructor
       
   246 // ---------------------------------------------------------------------------
       
   247 //			
       
   248 void CCatalogsTransport::ConstructL( CDocumentHandler& aDocHandler )
       
   249     {
       
   250     DLTRACEIN( ( "" ) );
       
   251     iHttpSessionManager = CCatalogsHttpSessionManager::NewL( aDocHandler );
       
   252     DLTRACEOUT( ( "" ) );
       
   253     }