upnpframework/upnpcommand/src/upnpcopycommand.cpp
changeset 0 7f85d04be362
child 38 5360b7ddc251
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:  Source file for CUpnpCopyCommand class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <upnpcopycommand.h>            // CUpnpCopyCommand
       
    21 #include "upnpcommand.h"                // CUpnpCommand
       
    22 #include "upnpcommandmain.h"            // UpnpCommandMain::LoadL
       
    23 
       
    24 // --------------------------------------------------------------------------
       
    25 // CUpnpCopyCommand::NewL
       
    26 // Creates a new UpnpCommand for file copying purposes.
       
    27 // --------------------------------------------------------------------------
       
    28 //
       
    29 EXPORT_C CUpnpCopyCommand* CUpnpCopyCommand::NewL()
       
    30     {
       
    31     // Create new CUpnpCopyCommand instance
       
    32     CUpnpCopyCommand* self = new (ELeave) CUpnpCopyCommand();
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 // CUpnpCopyCommand::CUpnpCopyCommand
       
    41 // Constructor
       
    42 // --------------------------------------------------------------------------
       
    43 //
       
    44 CUpnpCopyCommand::CUpnpCopyCommand()
       
    45     {
       
    46     // No implementation
       
    47     }
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CUpnpCopyCommand::~CUpnpCopyCommand
       
    51 // Destructor
       
    52 // --------------------------------------------------------------------------
       
    53 //
       
    54 CUpnpCopyCommand::~CUpnpCopyCommand()
       
    55     {
       
    56     delete iCommand;
       
    57     iCommand = NULL;
       
    58     }
       
    59 
       
    60 // --------------------------------------------------------------------------
       
    61 // CUpnpCopyCommand::ConstructL
       
    62 // Second phase constructor
       
    63 // --------------------------------------------------------------------------
       
    64 //
       
    65 void CUpnpCopyCommand::ConstructL()
       
    66     {
       
    67     iCommand = UpnpCommandMain::LoadL( UpnpCommand::ECommandCopy );
       
    68     }
       
    69 
       
    70 // --------------------------------------------------------------------------
       
    71 // CUpnpCopyCommand::CopyFilesL
       
    72 // Copies the given list of files to a remote Upnp Media Server.
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 EXPORT_C void CUpnpCopyCommand::CopyFilesL( CDesCArrayFlat* aFiles )
       
    76     {
       
    77     TInt status = KErrNone;
       
    78 
       
    79     // Check param
       
    80     if( !aFiles ||
       
    81         aFiles->Count() <= 0 )
       
    82         {
       
    83         User::Leave( KErrArgument );
       
    84         }
       
    85 
       
    86     // Push the filenames into the file pipe
       
    87     for( TInt index=0; index<aFiles->Count(); index++ )
       
    88         {
       
    89         if( status == KErrNone )
       
    90             {
       
    91             TRAP( status,
       
    92                   iCommand->PushFileL( aFiles->MdcaPoint( index ) ) );
       
    93             }
       
    94         }
       
    95 
       
    96     // If all files were pushed ok
       
    97     if( status == KErrNone )
       
    98         {
       
    99         // Allocate Upnp Fw only for the duration of the command execution
       
   100         TRAP( status, iCommand->AllocateResourcesL() );
       
   101         if( status == KErrNone )
       
   102             {
       
   103             // Execute the command
       
   104             TRAP( status, iCommand->ExecuteL() );
       
   105 
       
   106             // Move the failed files back to client file array
       
   107             aFiles->Reset();
       
   108             for ( TInt i=0; i<iCommand->FileCount(); ++i )
       
   109                 {
       
   110                 TRAP_IGNORE( aFiles->AppendL( iCommand->File( i ) ) );
       
   111                 }
       
   112 
       
   113             // Release Upnp Fw
       
   114             iCommand->ReleaseResources();
       
   115             }
       
   116         }
       
   117 
       
   118     // Reset the file pipe
       
   119     iCommand->ResetFiles();
       
   120 
       
   121     // Reset parameters
       
   122     iCommand->ResetParameters();
       
   123 
       
   124     // Leave if operation failed
       
   125     if( status != KErrNone )
       
   126         {
       
   127         User::Leave( status );
       
   128         }
       
   129     }
       
   130 
       
   131 // --------------------------------------------------------------------------
       
   132 // CUpnpCopyCommand::CopyPlaylistL
       
   133 // Copies the given playlist (playlist name + filenames) to a remote Upnp
       
   134 // Media Server.
       
   135 // --------------------------------------------------------------------------
       
   136 //
       
   137 EXPORT_C void CUpnpCopyCommand::CopyPlaylistL( const TDesC& aPlaylistName,
       
   138                                                CDesCArrayFlat* aFiles )
       
   139     {
       
   140     // Check playlist name parameter, aFiles will be checked later
       
   141     if( aPlaylistName == KNullDesC )
       
   142         {
       
   143         User::Leave( KErrArgument );
       
   144         }
       
   145 
       
   146     // Set the playlist parameter
       
   147     iCommand->SetParameterL(
       
   148         UpnpCommand::EParamCollectionName, aPlaylistName );
       
   149 
       
   150     // Use CopyFilesL to do the copy (and to handle cleanup)
       
   151     CopyFilesL( aFiles );
       
   152     }
       
   153 
       
   154 // --------------------------------------------------------------------------
       
   155 // CUpnpCopyCommand::IsAvailable
       
   156 // Inline implementation of the IsAvailable method.
       
   157 // --------------------------------------------------------------------------
       
   158 //
       
   159 EXPORT_C TBool CUpnpCopyCommand::IsAvailableL()
       
   160     {
       
   161     // create a temporary plugin instance
       
   162     // then query command availability.
       
   163     TBool available = EFalse;
       
   164     TRAP_IGNORE(
       
   165         CUpnpCommand* temp = UpnpCommandMain::LoadL( UpnpCommand::ECommandCopy );
       
   166         CleanupStack::PushL( temp );
       
   167         available = temp->IsAvailableL();
       
   168         CleanupStack::PopAndDestroy( temp );
       
   169         );
       
   170     return available;
       
   171     }
       
   172 
       
   173 // End of File