upnpavcontroller/upnpavcontrollerserver/src/upnpuploadsession.cpp
branchnew development branch with rendering state machine and other goodies
changeset 38 5360b7ddc251
parent 32 3785f754ee62
equal deleted inserted replaced
32:3785f754ee62 38:5360b7ddc251
    13 *
    13 *
    14 * Description:      server impl. of session against media server
    14 * Description:      server impl. of session against media server
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 // INCLUDE FILES
    18 // INCLUDE FILES
    24 // System
    19 // System
    25 #include <mmf/common/mmfcontrollerpluginresolver.h>
    20 #include <mmf/common/mmfcontrollerpluginresolver.h>
    26 
    21 
    27 // upnp stack api
    22 // upnp stack api
       
    23 #include <upnpstring.h>
       
    24 
       
    25 // dlnasrv / mediaserver api
    28 #include <upnpitem.h>
    26 #include <upnpitem.h>
    29 #include <upnpattribute.h>
    27 #include <upnpattribute.h>
    30 #include <upnpstring.h>
       
    31 #include <upnpdlnaprotocolinfo.h>
    28 #include <upnpdlnaprotocolinfo.h>
    32 #include <upnpavcontrolpoint.h>
    29 
    33 
    30 // dlnasrv / avcontroller helper api
    34 // upnpframework / avcontroller helper api
       
    35 #include "upnpconstantdefs.h" // for upnp-specific stuff
    31 #include "upnpconstantdefs.h" // for upnp-specific stuff
    36 #include "upnpitemutility.h" // FindElementByNameL, GetResElements
    32 #include "upnpitemutility.h" // FindElementByNameL, GetResElements
    37 
    33 
    38 // upnpframework / xmlparser api
    34 // dlnasrv / xmlparser api
    39 #include "upnpxmlparser.h"
    35 #include "upnpxmlparser.h"
    40 
    36 
    41 // upnpframework / internal api's
    37 // dlnasrv / internal api's
    42 #include "upnpcdsreselementutility.h"
    38 #include "upnpcdsreselementutility.h"
    43 #include "httpuploader.h"
    39 #include "httpuploader.h"
    44 #include "upnpmetadatafetcher.h"
    40 #include "upnpmetadatafetcher.h"
    45 #include "upnpcommonutils.h"
    41 #include "upnpcommonutils.h"
    46 
    42 
    47 // INTERNAL INCLUDES
    43 // dlnasrv / avcontroller internal api's
    48 #include "upnpuploadsession.h"
    44 #include "upnpuploadsession.h"
    49 #include "upnpfiletransferitem.h"
    45 #include "upnpfiletransferitem.h"
    50 #include "upnpavcontrollerserver.h"
    46 #include "upnpavcontrollerserver.h"
    51 #include "upnpfiletransferitem.h"
    47 #include "upnpfiletransferitem.h"
    52 #include "upnpavdeviceextended.h"
    48 #include "upnpavdeviceextended.h"
    53 #include "upnpavdispatcher.h"
    49 #include "upnpavdispatcher.h"
    54 #include "upnpaverrorhandler.h"
    50 #include "upnpaverrorhandler.h"
       
    51 #include "upnpavcpstrings.h"
    55 #include "upnpresourcehelper.h"
    52 #include "upnpresourcehelper.h"
       
    53 #include "upnpavcontrolpoint.h"
       
    54 
       
    55 using namespace UpnpAVCPStrings;
    56 
    56 
    57 _LIT( KComponentLogfile, "upnpavcontrollerserver.txt");
    57 _LIT( KComponentLogfile, "upnpavcontrollerserver.txt");
    58 #include "upnplog.h"
    58 #include "upnplog.h"
    59 
    59 
    60 // CONSTANTS
    60 // CONSTANTS
   118     
   118     
   119     CUPnPFileTransferSessionBase::ConstructL( aUuid );
   119     CUPnPFileTransferSessionBase::ConstructL( aUuid );
   120 
   120 
   121     iUploader = CHttpUploader::NewL( *this, (TUint32)iServer.IAP(),
   121     iUploader = CHttpUploader::NewL( *this, (TUint32)iServer.IAP(),
   122         KBufferSize, KParallerTransfers );
   122         KBufferSize, KParallerTransfers );
       
   123     
       
   124     // Gets related ControlPoint device (CUpnpDevice).
       
   125     // It is needed for CUpnpAVControlPoint.
       
   126     iCpDevice = iServer.ControlPoint().Device( aUuid );
       
   127     if ( !iCpDevice ) 
       
   128         {
       
   129         User::Leave( KErrNotFound );
       
   130         }
       
   131     
       
   132     }
       
   133 
       
   134 // --------------------------------------------------------------------------
       
   135 // CUPnPUploadSession::ActionResponseL
       
   136 // From MUpnpAVControlPointObserver
       
   137 // --------------------------------------------------------------------------
       
   138 void CUPnPUploadSession::ActionResponseL( CUpnpAction* aAction )
       
   139     {
       
   140     if (aAction->Name().Compare(KCreateObject) == 0)
       
   141         {
       
   142         __ASSERT( iIPSessionId == aAction->SessionId(),
       
   143             __FILE__, __LINE__ );
       
   144         CdsCreateObjectResponse(
       
   145             aAction->Error(),
       
   146             aAction->ArgumentValue(KObjectID), 
       
   147             aAction->ArgumentValue(KResult)
       
   148             );
       
   149         }
       
   150     }
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // CUPnPUploadSession::ActionResponseL
       
   154 // From MUpnpAVControlPointObserver
       
   155 // --------------------------------------------------------------------------
       
   156 void CUPnPUploadSession::StateUpdatedL( CUpnpService* /*aService*/ )
       
   157     {
       
   158     // No implementation required
       
   159     }
       
   160 
       
   161 // --------------------------------------------------------------------------
       
   162 // CUPnPUploadSession::ActionResponseL
       
   163 // From MUpnpAVControlPointObserver
       
   164 // --------------------------------------------------------------------------
       
   165 void CUPnPUploadSession::HttpResponseL( CUpnpHttpMessage* /*aMessage*/ )
       
   166     {
       
   167     // No implementation required
       
   168     }
       
   169 
       
   170 // --------------------------------------------------------------------------
       
   171 // CUPnPUploadSession::ActionResponseL
       
   172 // From MUpnpAVControlPointObserver
       
   173 // --------------------------------------------------------------------------
       
   174 void CUPnPUploadSession::DeviceDiscoveredL( CUpnpDevice* /*aDevice*/ )
       
   175     {
       
   176     // No implementation required
       
   177     }
       
   178 
       
   179 // --------------------------------------------------------------------------
       
   180 // CUPnPUploadSession::ActionResponseL
       
   181 // From MUpnpAVControlPointObserver
       
   182 // --------------------------------------------------------------------------
       
   183 void CUPnPUploadSession::DeviceDisappearedL( CUpnpDevice* /*aDevice*/ )
       
   184     {
       
   185     // No implementation required
   123     }
   186     }
   124 
   187 
   125 // --------------------------------------------------------------------------
   188 // --------------------------------------------------------------------------
   126 // CUPnPDownloadSession::TransferProgress
   189 // CUPnPDownloadSession::TransferProgress
   127 // See upnpdownloadsession.h
   190 // See upnpdownloadsession.h
   235 
   298 
   236             if( iResources[ i ]->ItemId() )
   299             if( iResources[ i ]->ItemId() )
   237                 {
   300                 {
   238                 // Send destroyobject
   301                 // Send destroyobject
   239                 __LOG( "CancelAllUploadsL - sending destroyobject" );
   302                 __LOG( "CancelAllUploadsL - sending destroyobject" );
   240                 TRAP_IGNORE( iServer.ControlPoint().CdsDestroyObjectActionL(
   303                 TRAP_IGNORE( DestroyObjectL( *iResources[ i ]->ItemId() ) );
   241                     iDevice->Uuid(), *iResources[ i ]->ItemId() ) );  
       
   242                 }
   304                 }
   243             }
   305             }
   244         iResources.ResetAndDestroy();    
   306         iResources.ResetAndDestroy();    
   245         iTransferItems.Reset();
   307         iTransferItems.Reset();
   246         }      
   308         }      
   249 // --------------------------------------------------------------------------
   311 // --------------------------------------------------------------------------
   250 // CUPnPUploadSession::CdsCreateObjectResponse
   312 // CUPnPUploadSession::CdsCreateObjectResponse
   251 // See upnpbrowsingsession.h
   313 // See upnpbrowsingsession.h
   252 // --------------------------------------------------------------------------
   314 // --------------------------------------------------------------------------
   253 void CUPnPUploadSession::CdsCreateObjectResponse(
   315 void CUPnPUploadSession::CdsCreateObjectResponse(
   254     const TDesC8& /*aUuid*/,
       
   255     TInt aSessionId,
       
   256     TInt aErr,
   316     TInt aErr,
   257     const TDesC8& /*aContainerID*/, 
       
   258     const TDesC8& /*aElements*/, 
       
   259     const TDesC8& aObjectID, 
   317     const TDesC8& aObjectID, 
   260     const TDesC8& aResult )
   318     const TDesC8& aResult )
   261     {
   319     {
   262     __LOG1( "CUPnPUploadSession::CdsCreateObjectResponse: %d" , aErr );
   320     __LOG1( "CUPnPUploadSession::CdsCreateObjectResponse: %d" , aErr );
   263     
   321 
   264     __ASSERTD( iIPSessionId == aSessionId, __FILE__, __LINE__ );
       
   265     
       
   266     __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, 
   322     __ASSERTD( iTransferItems.Count() == iResources.Count(), __FILE__, 
   267                __LINE__ );
   323                __LINE__ );
   268     
   324     
   269     iServer.Dispatcher().UnRegister( iIPSessionId );
   325     iServer.Dispatcher().UnRegister( iIPSessionId );
   270     iIPSessionId = KErrNotFound;
   326     iIPSessionId = KErrNotFound;
   376     
   432     
   377     iTransferItems.Append( transferItem );
   433     iTransferItems.Append( transferItem );
   378     
   434     
   379     CUPnPResourceHelper* helper = CUPnPResourceHelper::NewL();
   435     CUPnPResourceHelper* helper = CUPnPResourceHelper::NewL();
   380     CleanupStack::Pop( tmpUpnpItem );
   436     CleanupStack::Pop( tmpUpnpItem );
       
   437     CleanupStack::PushL( helper );
   381     helper->SetItem( tmpUpnpItem ); // Transfer ownership
   438     helper->SetItem( tmpUpnpItem ); // Transfer ownership
   382     iResources.AppendL( helper );
   439     if( iResources.Append( helper )!= KErrNone  )
       
   440         {
       
   441         CleanupStack::PopAndDestroy( helper );
       
   442         }
       
   443     CleanupStack::Pop( helper );
   383     
   444     
   384     iUploader->MoveToTransferQueueL( (TAny*)transferItem.iKey );
   445     iUploader->MoveToTransferQueueL( (TAny*)transferItem.iKey );
   385     
   446     
   386     CleanupStack::PopAndDestroy( tmpTransferItem );
   447     CleanupStack::PopAndDestroy( tmpTransferItem );
   387     
   448     
   410         aMessage.Complete( KErrNone );
   471         aMessage.Complete( KErrNone );
   411         iTransferItems.Remove( index );
   472         iTransferItems.Remove( index );
   412         if( iResources[ index ]->ItemId() )
   473         if( iResources[ index ]->ItemId() )
   413             {
   474             {
   414             // Send destroyobject
   475             // Send destroyobject
   415             iServer.ControlPoint().CdsDestroyObjectActionL( iDevice->Uuid(),
   476             DestroyObjectL( *iResources[ index ]->ItemId() );
   416                 *iResources[ index ]->ItemId() );
       
   417             }
   477             }
   418         delete iResources[index ];
   478         delete iResources[index ];
   419         iResources.Remove( index );   
   479         iResources.Remove( index );   
   420         }
   480         }
   421     else
   481     else
   444 
   504 
   445         if( iResources[ i ]->ItemId() )
   505         if( iResources[ i ]->ItemId() )
   446             {
   506             {
   447             // Send destroyobject
   507             // Send destroyobject
   448             __LOG( "CancelAllUploadsL - sending destroyobject" );
   508             __LOG( "CancelAllUploadsL - sending destroyobject" );
   449             iServer.ControlPoint().CdsDestroyObjectActionL( iDevice->Uuid(),
   509             DestroyObjectL( *iResources[ i ]->ItemId() );
   450                 *iResources[ i ]->ItemId() );  
       
   451             }
   510             }
   452         }
   511         }
   453     iResources.ResetAndDestroy();
   512     iResources.ResetAndDestroy();
   454     iTransferItems.Reset();
   513     iTransferItems.Reset();
   455     iEventQueu.Reset();
   514     iEventQueu.Reset();
   620         User::Leave( KErrCorrupt );
   679         User::Leave( KErrCorrupt );
   621         }
   680         }
   622     
   681     
   623     HBufC8* xmlDoc = CUPnPXMLParser::XmlForCreateObjectLC(
   682     HBufC8* xmlDoc = CUPnPXMLParser::XmlForCreateObjectLC(
   624         *tmpUpnpItem );
   683         *tmpUpnpItem );
   625     
   684 
   626     iIPSessionId = iServer.ControlPoint().CdsCreateObjectActionL(
   685     iIPSessionId = CreateObjectL( KContainerIdAny, *xmlDoc );
   627         iDevice->Uuid(), KContainerIdAny, *xmlDoc );
   686 
   628 
   687     // Register
   629     if( iIPSessionId > 0 )
   688     iServer.Dispatcher().RegisterL( iIPSessionId, *this );
   630         {
       
   631         // Register
       
   632         iServer.Dispatcher().RegisterL( iIPSessionId, *this );
       
   633         }
       
   634     else
       
   635         {
       
   636         User::Leave( iIPSessionId );
       
   637         }                             
       
   638     
   689     
   639     CleanupStack::PopAndDestroy( xmlDoc );
   690     CleanupStack::PopAndDestroy( xmlDoc );
   640     
   691     
   641     iWait.Start();
   692     iWait.Start();
   642     
   693     
   672             }
   723             }
   673         else
   724         else
   674             {
   725             {
   675             // Background is not available for some reason.
   726             // Background is not available for some reason.
   676             // Check if media specific transfer mode is available
   727             // Check if media specific transfer mode is available
   677             if( UPnPCommonUtils::IsImageSupported( tmpInfo->ProtocolInfoL() ) )
   728             if( UPnPCommonUtils::IsImageSupported( 
       
   729                     tmpInfo->ProtocolInfoL() ) )
   678                 {
   730                 {
   679                 // Uploading image, alternative for background is interactive
   731                 // Uploading image, alternative for background is interactive
   680                 if( tmpInfo->DlnaFlag( UpnpDlnaProtocolInfo::TM_I_FLAG ) )
   732                 if( tmpInfo->DlnaFlag( UpnpDlnaProtocolInfo::TM_I_FLAG ) )
   681                     {
   733                     {
   682                     __LOG( "ReadyForTransferL - Use interactive mode" );
   734                     __LOG( "ReadyForTransferL - Use interactive mode" );
   933     {
   985     {
   934     __LOG( "ProtocolInfoToUPnPL::DoSchedulerStoppedCallBack" );
   986     __LOG( "ProtocolInfoToUPnPL::DoSchedulerStoppedCallBack" );
   935     iSchedulerStopped = ETrue;
   987     iSchedulerStopped = ETrue;
   936     }
   988     }
   937 
   989 
       
   990 //---------------------------------------------------------------------------
       
   991 // CUPnPUploadSession::CreateObjectL()
       
   992 //---------------------------------------------------------------------------
       
   993 //
       
   994 int CUPnPUploadSession::CreateObjectL( const TDesC8& aContainerId,
       
   995     const TDesC8& aElements )
       
   996     {
       
   997     CUpnpAction* action = iServer.ControlPoint().CreateActionLC( 
       
   998             iCpDevice, KContentDirectory, KCreateObject );
       
   999     
       
  1000     action->SetArgumentL( KContainerID, aContainerId );
       
  1001     action->SetArgumentL( KElements, aElements );
       
  1002 
       
  1003     iServer.ControlPoint().SendL( action );
       
  1004     CleanupStack::Pop( action );
       
  1005     if (action->SessionId() < 0)
       
  1006         {
       
  1007         User::Leave( action->SessionId() );    
       
  1008         }
       
  1009     return action->SessionId();
       
  1010     }
       
  1011 
       
  1012 //---------------------------------------------------------------------------
       
  1013 // CUPnPUploadSession::DestroyObjectL()
       
  1014 //---------------------------------------------------------------------------
       
  1015 //
       
  1016 int CUPnPUploadSession::DestroyObjectL( const TDesC8& aObjectId )
       
  1017     {
       
  1018     CUpnpAction* action = iServer.ControlPoint().CreateActionLC( 
       
  1019             iCpDevice, KContentDirectory, KDestroyObject );
       
  1020     
       
  1021     action->SetArgumentL( KObjectID, aObjectId );
       
  1022 
       
  1023     iServer.ControlPoint().SendL( action );
       
  1024     CleanupStack::Pop( action );
       
  1025     if (action->SessionId() < 0)
       
  1026         {
       
  1027         User::Leave( action->SessionId() );    
       
  1028         }
       
  1029     return action->SessionId();
       
  1030     }
       
  1031 
   938 // End of file
  1032 // End of file