upnpavcontroller/upnpavcontrollerserver/src/upnpfiletransfersessionbase.cpp
changeset 0 7f85d04be362
child 30 5ec426854821
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2007 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:      server impl. of session against media server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INTERNAL INCLUDES
       
    24 #include "upnpfiletransfersessionbase.h"
       
    25 #include "upnpavdeviceextended.h"
       
    26 #include "upnpavcontrollerserver.h"
       
    27 #include "upnpdevicerepository.h"
       
    28 #include "upnpfiletransferitem.h"
       
    29 
       
    30 _LIT( KComponentLogfile, "upnpavcontrollerserver.txt");
       
    31 #include "upnplog.h"
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // --------------------------------------------------------------------------
       
    36 // CUPnPFileTransferSessionBase::CUPnPFileTransferSessionBase
       
    37 // See upnpdownloadsession.h
       
    38 // --------------------------------------------------------------------------
       
    39 CUPnPFileTransferSessionBase::CUPnPFileTransferSessionBase(
       
    40     CUpnpAVControllerServer& aServer, TInt aSessionId ) :
       
    41     iServer( aServer ),
       
    42     iSessionId( aSessionId )
       
    43     {
       
    44     __LOG( "CUPnPFileTransferSessionBase::CUPnPFileTransferSessionBase" );
       
    45     }
       
    46 
       
    47 // --------------------------------------------------------------------------
       
    48 // CUPnPFileTransferSessionBase::~CUPnPFileTransferSessionBase
       
    49 // See upnpdownloadsession.h
       
    50 // --------------------------------------------------------------------------
       
    51 CUPnPFileTransferSessionBase::~CUPnPFileTransferSessionBase()
       
    52     {
       
    53     __LOG( "CUPnPFileTransferSessionBase::~CUPnPFileTransferSessionBase" );
       
    54     
       
    55     delete iDevice;
       
    56     iTransferItems.Close();
       
    57     iEventQueu.Close();
       
    58     if( iEventMsg )
       
    59         {
       
    60         iEventMsg->Complete( KErrCancel );
       
    61         delete iEventMsg;
       
    62         }
       
    63     
       
    64     __LOG( "CUPnPFileTransferSessionBase::~CUPnPFileTransferSessionBase \
       
    65 - end" );    
       
    66     }
       
    67 
       
    68 // --------------------------------------------------------------------------
       
    69 // CUPnPFileTransferSessionBase::ConstructL
       
    70 // See upnpdownloadsession.h
       
    71 // --------------------------------------------------------------------------
       
    72 void CUPnPFileTransferSessionBase::ConstructL( const TDesC8& aUuid )
       
    73     {
       
    74     __LOG( "CUPnPFileTransferSessionBase::ConstructL" );
       
    75     
       
    76     const RPointerArray<CUpnpAVDeviceExtended>& devList =
       
    77         iServer.DeviceRepository().DeviceList();
       
    78     TInt count = devList.Count();
       
    79     TInt i;
       
    80     for( i = 0; i < count; i++ )
       
    81         {
       
    82         if( devList[ i ]->Uuid() == aUuid )
       
    83             {
       
    84             iDevice = CUpnpAVDeviceExtended::NewL( *devList[ i ] );
       
    85             }             
       
    86         }
       
    87     if( !iDevice )
       
    88         {
       
    89         User::Leave( KErrNotFound );
       
    90         }        
       
    91     }
       
    92     
       
    93 // --------------------------------------------------------------------------
       
    94 // CUPnPFileTransferSessionBase::SessionId
       
    95 // See upnpdownloadsession.h
       
    96 // --------------------------------------------------------------------------
       
    97 TInt CUPnPFileTransferSessionBase::SessionId() const
       
    98     {
       
    99     __LOG( "CUPnPFileTransferSessionBase::SessionId" );
       
   100     
       
   101     return iSessionId;
       
   102     }
       
   103     
       
   104 // --------------------------------------------------------------------------
       
   105 // CUPnPFileTransferSessionBase::Uuid
       
   106 // See upnpdownloadsession.h
       
   107 // --------------------------------------------------------------------------
       
   108 const TDesC8& CUPnPFileTransferSessionBase::Uuid() const
       
   109     {
       
   110     __LOG( "CUPnPFileTransferSessionBase::Uuid" );
       
   111     
       
   112     return iDevice->Uuid();
       
   113     }
       
   114 
       
   115 // --------------------------------------------------------------------------
       
   116 // CUPnPFileTransferSessionBase::CheckIfKeyExists
       
   117 // See upnpdownloadsession.h
       
   118 // --------------------------------------------------------------------------
       
   119 TBool CUPnPFileTransferSessionBase::CheckIfKeyExists( TInt aKey )
       
   120     {
       
   121     __LOG( "CUPnPFileTransferSessionBase::CheckIfKeyExists" );
       
   122     
       
   123     TBool retVal = EFalse;
       
   124     TInt count = iTransferItems.Count();
       
   125     for( TInt i = 0; i < count; i++ )
       
   126         {
       
   127         if( iTransferItems[ i ].iKey == aKey )
       
   128             {
       
   129             retVal = ETrue;
       
   130             i = count;
       
   131             }
       
   132         }
       
   133     return retVal;    
       
   134     }
       
   135 
       
   136 // --------------------------------------------------------------------------
       
   137 // CUPnPFileTransferSessionBase::CheckIfKeyExists
       
   138 // See upnpdownloadsession.h
       
   139 // --------------------------------------------------------------------------
       
   140 TBool CUPnPFileTransferSessionBase::CheckIfKeyExists( TInt aKey,
       
   141     TInt& aIndex )
       
   142     {
       
   143     __LOG( "CUPnPFileTransferSessionBase::CheckIfKeyExists" );
       
   144     
       
   145     TBool retVal = EFalse;
       
   146     TInt count = iTransferItems.Count();
       
   147     for( aIndex = 0; aIndex < count; aIndex++ )
       
   148         {
       
   149         if( iTransferItems[ aIndex ].iKey == aKey )
       
   150             {
       
   151             retVal = ETrue;
       
   152             break;
       
   153             }
       
   154         }
       
   155     return retVal;    
       
   156     }
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 // CUPnPFileTransferSessionBase::FindItemByKey
       
   160 // See upnpdownloadsession.h
       
   161 // --------------------------------------------------------------------------
       
   162 TInt CUPnPFileTransferSessionBase::FindItemByKey( TUpnpFileTransferEvent&
       
   163     aItem, TInt aKey )
       
   164     {
       
   165     __LOG( "CUPnPFileTransferSessionBase::FindItemByKey" );
       
   166     
       
   167     TBool retVal = KErrNotFound;
       
   168     TInt count = iTransferItems.Count();
       
   169     for( TInt i = 0; i < count; i++ )
       
   170         {
       
   171         if( iTransferItems[ i ].iKey == aKey )
       
   172             {
       
   173             aItem = iTransferItems[ i ];
       
   174             retVal = KErrNone;
       
   175             i = count;
       
   176             }
       
   177         }
       
   178     return retVal;        
       
   179     }
       
   180 
       
   181 // --------------------------------------------------------------------------
       
   182 // CUPnPFileTransferSessionBase::FindItemByKey
       
   183 // See upnpdownloadsession.h
       
   184 // --------------------------------------------------------------------------
       
   185 TInt CUPnPFileTransferSessionBase::FindItemByKey( TUpnpFileTransferEvent&
       
   186     aItem, TInt aKey, TInt& aIndex )
       
   187     {
       
   188     __LOG( "CUPnPFileTransferSessionBase::FindItemByKey" );
       
   189     
       
   190     TBool retVal = KErrNotFound;
       
   191     TInt count = iTransferItems.Count();
       
   192     for( aIndex = 0; aIndex < count; aIndex++ )
       
   193         {
       
   194         if( iTransferItems[ aIndex ].iKey == aKey )
       
   195             {
       
   196             aItem = iTransferItems[ aIndex ];
       
   197             retVal = KErrNone;
       
   198             break;
       
   199             }
       
   200         }
       
   201     return retVal;
       
   202     }
       
   203 
       
   204 // --------------------------------------------------------------------------
       
   205 // CUPnPFileTransferSessionBase::ReadTransferItemFromMessageL
       
   206 // See upnpdownloadsession.h
       
   207 // --------------------------------------------------------------------------
       
   208 void CUPnPFileTransferSessionBase::ReadTransferItemFromMessageL(
       
   209     const RMessage2& aMessage, TInt aSlot, CUpnpFileTransferItem* aItem ) 
       
   210     {
       
   211     __LOG( "CUPnPFileTransferSessionBase::ReadTransferItemFromMessageL" );
       
   212     
       
   213     // create buffer
       
   214     TInt len = aMessage.GetDesMaxLength( aSlot );
       
   215     HBufC8* buf = HBufC8::NewLC( len );
       
   216     TPtr8 ptr( buf->Des() );
       
   217     User::LeaveIfError( aMessage.Read( aSlot, ptr ) );
       
   218     
       
   219     // read stream
       
   220     RDesReadStream stream( *buf );
       
   221     CleanupClosePushL( stream );
       
   222     
       
   223     // internalize object
       
   224     stream >> *aItem;
       
   225     
       
   226     // clean up
       
   227     CleanupStack::PopAndDestroy( &stream );
       
   228     CleanupStack::PopAndDestroy( buf );
       
   229     }    
       
   230 
       
   231 // --------------------------------------------------------------------------
       
   232 // CUPnPFileTransferSessionBase::Complete
       
   233 // See upnpdownloadsession.h
       
   234 // --------------------------------------------------------------------------
       
   235 void CUPnPFileTransferSessionBase::Complete(
       
   236     const TUpnpFileTransferEvent& aEvent )
       
   237     {
       
   238     __LOG( "CUPnPFileTransferSessionBase::Complete" );          
       
   239     
       
   240     if( iEventMsg )
       
   241         {
       
   242         __LOG( "Complete" );
       
   243         __LOG1( "iEvent = %d", aEvent.iEvent );
       
   244         __LOG1( "iKey = %d", aEvent.iKey );
       
   245         __LOG1( "iStatus = %d", aEvent.iStatus );        
       
   246         TPckg<TUpnpFileTransferEvent> resp1( aEvent );
       
   247         iEventMsg->Write( 1, resp1  ); // Write response using slot 1
       
   248         iEventMsg->Complete( KErrNone );
       
   249         delete iEventMsg; iEventMsg = NULL;
       
   250         }
       
   251     else
       
   252         {
       
   253         __LOG( "Complete - Add to queu" );
       
   254         __LOG1( "iEvent = %d", aEvent.iEvent );
       
   255         __LOG1( "iKey = %d", aEvent.iKey );
       
   256         __LOG1( "iStatus = %d", aEvent.iStatus );        
       
   257         iEventQueu.Append( aEvent );
       
   258         }
       
   259     }
       
   260     
       
   261 // End of file