upnpavcontrolpoint/avcpengine/src/upnpuploadcommand.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /** @file
       
     2 * Copyright (c) 2005-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:  CUpnpUploadCommand
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpuploadcommand.h"
       
    20 
       
    21 #include "upnppathresolver.h"
       
    22 #include "upnppathelement.h"
       
    23 #include "upnpavcpmanager.h"
       
    24 #include "upnpavcontrolpoint.h"
       
    25 #include "upnphttpmessagefactory.h"
       
    26 
       
    27 #include "upnpavcpenginehelper.h"
       
    28 using namespace UpnpAVCPEngine;
       
    29 
       
    30 
       
    31 _LIT8(KBrowseFilter, "res,res@protocolInfo,res@importUri");
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CUpnpUploadCommand::NewL
       
    35 // Two-phased constructor.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 CUpnpUploadCommand* CUpnpUploadCommand::NewL(CUpnpAVCPManager& aAVCPManager, CUpnpAVCPEngineSession& aSession, const RMessage2& aMessage)
       
    39 	{
       
    40     CUpnpUploadCommand* self = new( ELeave ) CUpnpUploadCommand(aAVCPManager, aSession, aMessage);
       
    41     
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45 
       
    46     return self;   
       
    47 	}	
       
    48   
       
    49 // -----------------------------------------------------------------------------
       
    50 // CUpnpUploadCommand::ConstructL
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //    
       
    54 void CUpnpUploadCommand::ConstructL() 
       
    55 	{
       
    56 	CUpnpCommand::BaseConstructL();
       
    57 	} 
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CUpnpUploadCommand::CUpnpUploadCommand
       
    61 // C++ default constructor can NOT contain any code, that
       
    62 // might leave.
       
    63 // -----------------------------------------------------------------------------   
       
    64 //     
       
    65 CUpnpUploadCommand::CUpnpUploadCommand(CUpnpAVCPManager& aAVCPManager, 
       
    66                    CUpnpAVCPEngineSession& aSession, 
       
    67                    const RMessage2& aMessage):
       
    68                    CUpnpCommand( aAVCPManager,
       
    69                    		     aSession, 
       
    70                    		     aMessage)
       
    71 	{
       
    72 	}
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CUpnpUploadCommand::~CUpnpUploadCommand
       
    76 // desctructor
       
    77 // -----------------------------------------------------------------------------
       
    78 // 
       
    79 CUpnpUploadCommand::~CUpnpUploadCommand()
       
    80 	{
       
    81     delete iObjectId;
       
    82     delete iImportURI;   
       
    83     delete iSrcPath;
       
    84 	}
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CUpnpUploadCommand::SessionId
       
    88 // -----------------------------------------------------------------------------
       
    89 // 
       
    90 TInt CUpnpUploadCommand::SessionId() 
       
    91 	{
       
    92     return CUpnpCommand::SessionId();   
       
    93 	}
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CUpnpUploadCommand::RunError
       
    97 // -----------------------------------------------------------------------------
       
    98 // 
       
    99 void CUpnpUploadCommand::RunError(TInt aErrorCode) 
       
   100 	{
       
   101     return CUpnpCommand::RunError(aErrorCode);   
       
   102 	}
       
   103 	
       
   104 // -----------------------------------------------------------------------------
       
   105 // CUpnpUploadCommand::ExecuteL
       
   106 // -----------------------------------------------------------------------------
       
   107 // 
       
   108 void CUpnpUploadCommand::ExecuteL()
       
   109 	{
       
   110 	//ASSERT(iType == EPutFile);
       
   111     
       
   112     HBufC8* uuid = NULL;
       
   113     HBufC8* dstPath = NULL;
       
   114     HBufC* srcPath = NULL;
       
   115 
       
   116    	DEBUGSTRING(("Execute Upload command"));
       
   117     	            
       
   118     uuid = ReadDes8FromMessageLC(0); 
       
   119     DEBUGSTRING8(("  uuid: %S",uuid));       
       
   120 	srcPath = ReadDes16FromMessageLC(1);                     	
       
   121 	DEBUGSTRING16(("  srcPath: %S",srcPath));   			
       
   122 	dstPath = ReadDes8FromMessageLC(2); 
       
   123 	DEBUGSTRING8(("  dstPath: %S",dstPath));   		
       
   124 
       
   125     // convert to 8-bit representation 
       
   126     iSrcPath = HBufC8::NewL(srcPath->Length()); 
       
   127     iSrcPath->Des().Copy(*srcPath);
       
   128                       
       
   129     iPathResolver = &(iAVCPManager.PathResolverL(*uuid, &iSession));
       
   130     	 
       
   131     iPathResolver->ResolveIdL(*dstPath, *this);
       
   132     
       
   133     CleanupStack::PopAndDestroy(dstPath);          
       
   134     CleanupStack::PopAndDestroy(srcPath);          
       
   135 	CleanupStack::PopAndDestroy(uuid);          
       
   136 	}
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CCUploadCommand::SetResultL
       
   140 // -----------------------------------------------------------------------------
       
   141 // 
       
   142 void CUpnpUploadCommand::SetResultL(const RMessage2& /*aMessage*/) 
       
   143 	{
       
   144 	}
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // CUpnpUploadCommand::Interpret
       
   148 // -----------------------------------------------------------------------------
       
   149 // 
       
   150 void CUpnpUploadCommand::InterpretL(TInt aErrorCode, CUpnpAction* /*aAction*/) 
       
   151 	{
       
   152 	DEBUGSTRING(("Interpret action response %d", aErrorCode));	
       
   153    
       
   154     if (aErrorCode == EHttp200Ok)
       
   155     	{    	
       
   156     	if( iImportURI) 
       
   157     		{    	    	        
       
   158         	CUpnpHttpMessage* msg = RUpnpHttpMessageFactory::HttpPostL( *iImportURI );       
       
   159 	    	CleanupStack::PushL( msg );
       
   160 			msg->SetOutFilenameL( *iSrcPath );		    	    			
       
   161         	iAVCPManager.SendL(msg);  
       
   162         	iSessionId = msg->SessionId();
       
   163         	iAVCPManager.RegisterForHttp(*this);         
       
   164         
       
   165         	CleanupStack::PopAndDestroy( msg );              
       
   166     		}
       
   167     	else
       
   168     		{
       
   169     		iMessage.Complete(KErrPathNotFound); 
       
   170         	delete this;	
       
   171     		}
       
   172     	}
       
   173     else 
       
   174     	{
       
   175         iMessage.Complete(KErrAbort); 
       
   176         delete this;
       
   177     	}   
       
   178 	}
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CUpnpUploadCommand::Interpret
       
   182 // -----------------------------------------------------------------------------
       
   183 // 
       
   184 void CUpnpUploadCommand::InterpretL(TInt aErrorCode, CUpnpHttpMessage* /*aMessage*/) 
       
   185 	{
       
   186 	DEBUGSTRING(("HTTP Interpret %d", aErrorCode));	
       
   187     if (aErrorCode == KHttpPostStarted) 
       
   188     	{
       
   189       	// transfer pending   
       
   190       	return;
       
   191     	}
       
   192     iAVCPManager.UnregisterForHttp(*this); 
       
   193     if (aErrorCode == EHttp200Ok) 
       
   194     	{
       
   195     	iMessage.Complete(KErrNone);
       
   196     	delete this; 
       
   197     	}
       
   198     else  
       
   199     	{
       
   200        	iMessage.Complete(KErrNotFound);         
       
   201        	delete this;
       
   202     	}    
       
   203 	}
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CUpnpUploadCommand::ResolvedId
       
   207 // -----------------------------------------------------------------------------
       
   208 // 
       
   209 void CUpnpUploadCommand::ResolvedIdL(TInt aErrCode, CUpnpPathElement* aIdElement)
       
   210 	{
       
   211     
       
   212     if (aErrCode == KErrNone)  
       
   213     	{
       
   214         iObjectId = aIdElement->Id().AllocL();
       
   215         iImportURI = (aIdElement->ImportURI()!= KNullDesC8()) ? aIdElement->ImportURI().AllocL(): NULL;
       
   216             
       
   217         iSessionId = iAVCPManager.CdsBrowseActionL(iPathResolver->UUID(), *iObjectId, KBrowseMetadata, KBrowseFilter, 0, 0, KNullDesC8);    
       
   218       
       
   219         iAVCPManager.RegisterForAction(*this);        
       
   220     	}
       
   221     else 
       
   222     	{
       
   223         iMessage.Complete(KErrNotFound);
       
   224         delete this;
       
   225     	}
       
   226 	}