upnpframework/upnpfiletransferengine/src/upnpfiletransferengine.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Implementation of the CUpnpFileTransferEngine class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 // System
       
    21 #include <badesca.h>                            // CDesC8ArrayFlat
       
    22 
       
    23 // upnp stack api
       
    24 #include <upnpcontainer.h>                      // CUpnpContainer
       
    25 
       
    26 // upnpframework / avcontroller api
       
    27 #include "upnpavbrowsingsession.h"              // MUPnPAVSessionBase
       
    28 
       
    29 // upnpfiletransferengine internal
       
    30 #include "upnpfiletransferengine.h"             // CUpnpFileTransferEngine
       
    31 #include "upnpfiletransferhandler.h"            // CUpnpFileTransferHandler
       
    32 #include "upnpdownloadhandler.h"                // CUpnpDownloadHandler
       
    33 #include "upnpuploadhandler.h"                  // CUpnpUploadHandler
       
    34 
       
    35 
       
    36 _LIT( KComponentLogfile, "filetransferengine.txt");
       
    37 #include "upnplog.h"
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 // CUpnpFileTransferEngine::NewL
       
    41 // NewL.
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 EXPORT_C CUpnpFileTransferEngine* CUpnpFileTransferEngine::NewL(
       
    45                             MUPnPAVBrowsingSession* aBrowsingSession )
       
    46     {
       
    47     __LOG( "[UpnpFileTransferEngine] CUpnpFileTransferEngine: NewL" );
       
    48 
       
    49     // Check that the browsing session is valid and has target device set.
       
    50     if( !aBrowsingSession )
       
    51         {
       
    52         User::Leave( KErrArgument );
       
    53         }
       
    54 
       
    55     CUpnpFileTransferEngine* self = NULL;
       
    56     self = new (ELeave) CUpnpFileTransferEngine;
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aBrowsingSession );
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // Constuctor
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 CUpnpFileTransferEngine::CUpnpFileTransferEngine()
       
    68     {
       
    69     __LOG( "[UpnpFileTransferEngine] Constructor" );
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // Destructor
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 CUpnpFileTransferEngine::~CUpnpFileTransferEngine()
       
    77     {
       
    78     __LOG( "[UpnpFileTransferEngine] Destructor" );
       
    79 
       
    80     // Delete the file transfer handler.
       
    81     delete iFileTransferHandler;
       
    82     delete iUploadHandler;
       
    83 
       
    84     }
       
    85 
       
    86 // --------------------------------------------------------------------------
       
    87 // CUpnpFileTransferEngine::ConstructL
       
    88 // Second phase constructor
       
    89 // --------------------------------------------------------------------------
       
    90 //
       
    91 void CUpnpFileTransferEngine::ConstructL(
       
    92                                 MUPnPAVBrowsingSession* aBrowsingSession )
       
    93     {
       
    94     __LOG( "[UpnpFileTransferEngine] ConstructL" );
       
    95 
       
    96     // Check the parameter first
       
    97     if( !aBrowsingSession)
       
    98         {
       
    99         User::Leave( KErrArgument );
       
   100         }
       
   101 
       
   102     iBrowsingSession = aBrowsingSession; // not owned
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CUpnpFileTransferEngine::CopyToHandsetL
       
   107 // Copies items (whose object ids are provided) from a remote Upnp Media
       
   108 // Server to the handset.
       
   109 // --------------------------------------------------------------------------
       
   110 //
       
   111 EXPORT_C TInt CUpnpFileTransferEngine::CopyToHandsetL(
       
   112                                         CDesC8ArrayFlat* aObjectIds )
       
   113     {
       
   114     __LOG( "[UpnpFileTransferEngine] CopyToHandsetL" );
       
   115 
       
   116     // Create the download handler
       
   117     CUpnpDownloadHandler* downloadHandler =
       
   118                             CUpnpDownloadHandler::NewL( iBrowsingSession );
       
   119     CleanupStack::PushL( downloadHandler );
       
   120 
       
   121     // Do the download
       
   122     downloadHandler->DownloadItemsL( aObjectIds );
       
   123     
       
   124     TInt fileNumber = downloadHandler->GetNumCopiedFiles();
       
   125     // Clean up
       
   126     CleanupStack::PopAndDestroy( downloadHandler );
       
   127     downloadHandler = NULL;
       
   128     return fileNumber;
       
   129     }
       
   130 
       
   131 // --------------------------------------------------------------------------
       
   132 // CUpnpFileTransferEngine::CopyLocalFilesToRemoteServerL
       
   133 // Copies local files to a remote media server.
       
   134 // --------------------------------------------------------------------------
       
   135 //
       
   136 EXPORT_C void CUpnpFileTransferEngine::CopyLocalFilesToRemoteServerL(
       
   137                                 RPointerArray<TDesC16>* aFilePaths )
       
   138     {
       
   139     __LOG( "[UpnpFileTransferEngine] CopyLocalItemsToRemoteServerL" );
       
   140 
       
   141     // Create the download handler
       
   142     if( !iUploadHandler )
       
   143         {
       
   144         iUploadHandler = CUpnpUploadHandler::NewL( iBrowsingSession );    
       
   145         }
       
   146     
       
   147     iUploadHandler->UploadItemsL( aFilePaths, EUpnpCopy );
       
   148     }
       
   149 
       
   150 // --------------------------------------------------------------------------
       
   151 // CUpnpFileTransferEngine::MoveLocalFilesToRemoteServerL
       
   152 // Moves local files to a remote media server.
       
   153 // --------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CUpnpFileTransferEngine::MoveLocalFilesToRemoteServerL(
       
   156                                 RPointerArray<TDesC16>* aFilePaths )
       
   157     {
       
   158     __LOG( "[UpnpFileTransferEngine] MoveLocalFilesToRemoteServerL" );
       
   159 
       
   160     // Create the download handler
       
   161     if( !iUploadHandler )
       
   162         {
       
   163         iUploadHandler = CUpnpUploadHandler::NewL( iBrowsingSession );    
       
   164         }
       
   165     
       
   166     iUploadHandler->UploadItemsL( aFilePaths, EUpnpMove );
       
   167     }
       
   168 
       
   169 // --------------------------------------------------------------------------
       
   170 // CUpnpFileTransferEngine::CopyLocalPlaylistToRemoteServerL
       
   171 // Copies a playlist from the local handset to a remote Upnp Media Server.
       
   172 // Deprecated!
       
   173 // --------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void CUpnpFileTransferEngine::CopyLocalPlaylistToRemoteServerL(
       
   176                                 const TDesC& aPlaylistName,
       
   177                                 RPointerArray<TDesC16>* aFilePaths )
       
   178     {
       
   179     __LOG( "[UpnpFileTransferEngine] \
       
   180 CopyLocalPlaylistToRemoteServerL" );
       
   181 
       
   182     // Create the download handler
       
   183     if( !iUploadHandler )
       
   184         {
       
   185         iUploadHandler = CUpnpUploadHandler::NewL( iBrowsingSession );    
       
   186         }
       
   187     
       
   188     iUploadHandler->UploadPlayListL( aPlaylistName, aFilePaths, EUpnpCopy );
       
   189     }
       
   190 
       
   191 // --------------------------------------------------------------------------
       
   192 // CUpnpFileTransferEngine::CopyRemoteItemsToHandsetL
       
   193 // Copies items from a remote Upnp Media Server to default location.
       
   194 // --------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C void CUpnpFileTransferEngine::CopyRemoteItemsToHandsetL(
       
   197                             RPointerArray<CUpnpItem>& aItems )
       
   198     {
       
   199     __LOG( "[UpnpFileTransferEngine] CopyRemoteItemsToHandsetL" );
       
   200 
       
   201     // Create the file transfer handler, if not yet created
       
   202     if( !iFileTransferHandler )
       
   203         {
       
   204         iFileTransferHandler = CUpnpFileTransferHandler::NewL(
       
   205                                                     iBrowsingSession );
       
   206         }
       
   207 
       
   208     // Forward the method call with the correct transfer mode
       
   209     iFileTransferHandler->TransferRemoteItemsToHandsetL(
       
   210                                 EUpnpCopyRemoteItemsToDefaultLocation,
       
   211                                 aItems );
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CUpnpFileTransferEngine::CopyRemoteContainerToHandsetL
       
   216 // Copies a container from a remote Upnp Media Server to the default (setting
       
   217 // set in the Home Network Application) location.
       
   218 // --------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C void CUpnpFileTransferEngine::CopyRemoteContainerToHandsetL(
       
   221                             CUpnpContainer* aContainer )
       
   222     {
       
   223     __LOG( "[UpnpFileTransferEngine] CopyRemoteContainerToHandsetL" );
       
   224 
       
   225     // Create the file transfer handler, if not yet created
       
   226     if( !iFileTransferHandler )
       
   227         {
       
   228         iFileTransferHandler = CUpnpFileTransferHandler::NewL(
       
   229                                                     iBrowsingSession );
       
   230         }
       
   231 
       
   232     // Forward the method call with the correct transfer mode
       
   233     iFileTransferHandler->TransferRemoteContainerToHandsetL(
       
   234                             EUpnpCopyRemoteContainerToDefaultLocation,
       
   235                             aContainer );
       
   236     }
       
   237 
       
   238 // --------------------------------------------------------------------------
       
   239 // CUpnpFileTransferEngine::CopyRemotePlaylistToHandsetL
       
   240 // Copies a playlist from a remote Upnp Media Server to the default (setting
       
   241 // set in the Home Network Application) location.
       
   242 // --------------------------------------------------------------------------
       
   243 //
       
   244 EXPORT_C void CUpnpFileTransferEngine::CopyRemotePlaylistToHandsetL(
       
   245                             CUpnpContainer* aContainer )
       
   246     {
       
   247     __LOG( "[UpnpFileTransferEngine] CopyRemotePlaylistToHandsetL" );
       
   248 
       
   249     // Create the file transfer handler, if not yet created
       
   250     if( !iFileTransferHandler )
       
   251         {
       
   252         iFileTransferHandler = CUpnpFileTransferHandler::NewL(
       
   253                                                     iBrowsingSession );
       
   254         }
       
   255 
       
   256     // Forward the method call with the correct transfer mode
       
   257     iFileTransferHandler->TransferRemoteContainerToHandsetL(
       
   258                             EUpnpCopyRemotePlaylistToDefaultLocation,
       
   259                             aContainer );
       
   260     }
       
   261 
       
   262  
       
   263 // --------------------------------------------------------------------------
       
   264 // CUpnpFileTransferEngine::ItemCopiedFromContainer
       
   265 // returns a number of items copied from a container
       
   266 // --------------------------------------------------------------------------
       
   267 //
       
   268 EXPORT_C TInt CUpnpFileTransferEngine::ItemCopiedFromContainer()
       
   269     {
       
   270     TInt returnValue = KErrNotReady;
       
   271     if( iFileTransferHandler )
       
   272         {
       
   273         returnValue = iFileTransferHandler->ItemCopiedFromContainer();
       
   274         }
       
   275     return returnValue;
       
   276     }
       
   277 
       
   278 // End of file