|
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 <upnpmovecommand.h> // CUpnpMoveCommand |
|
21 #include "upnpcommand.h" // CUpnpCommand |
|
22 #include "upnpcommandmain.h" // UpnpCommandMain::LoadL |
|
23 |
|
24 // -------------------------------------------------------------------------- |
|
25 // CUpnpMoveCommand::NewL |
|
26 // Creates a new UpnpCommand for file moving purposes. |
|
27 // -------------------------------------------------------------------------- |
|
28 // |
|
29 EXPORT_C CUpnpMoveCommand* CUpnpMoveCommand::NewL() |
|
30 { |
|
31 // Create new CUpnpMoveCommand instance |
|
32 CUpnpMoveCommand* self = new (ELeave) CUpnpMoveCommand(); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // -------------------------------------------------------------------------- |
|
40 // CUpnpMoveCommand::CUpnpMoveCommand |
|
41 // Constructor |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 CUpnpMoveCommand::CUpnpMoveCommand() |
|
45 { |
|
46 // No implementation |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CUpnpMoveCommand::~CUpnpMoveCommand |
|
51 // Destructor |
|
52 // -------------------------------------------------------------------------- |
|
53 // |
|
54 CUpnpMoveCommand::~CUpnpMoveCommand() |
|
55 { |
|
56 delete iCommand; |
|
57 iCommand = NULL; |
|
58 } |
|
59 |
|
60 // -------------------------------------------------------------------------- |
|
61 // CUpnpMoveCommand::ConstructL |
|
62 // Second phase constructor |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 void CUpnpMoveCommand::ConstructL() |
|
66 { |
|
67 iCommand = UpnpCommandMain::LoadL( UpnpCommand::ECommandMove ); |
|
68 } |
|
69 |
|
70 // -------------------------------------------------------------------------- |
|
71 // CUpnpMoveCommand::MoveFilesL |
|
72 // Moves the given list of files to a remote Upnp Media Server. |
|
73 // -------------------------------------------------------------------------- |
|
74 // |
|
75 EXPORT_C void CUpnpMoveCommand::MoveFilesL( CDesCArrayFlat* aFiles ) |
|
76 { |
|
77 TInt status = KErrNone; |
|
78 |
|
79 // Check params |
|
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 // CUpnpMoveCommand::IsAvailableL |
|
133 // Inline implementation of the IsAvailable method. |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C TBool CUpnpMoveCommand::IsAvailableL() |
|
137 { |
|
138 // create a temporary plugin instance |
|
139 // then query command availability. |
|
140 TBool available = EFalse; |
|
141 TRAP_IGNORE( |
|
142 CUpnpCommand* temp = UpnpCommandMain::LoadL( UpnpCommand::ECommandMove ); |
|
143 CleanupStack::PushL( temp ); |
|
144 available = temp->IsAvailableL(); |
|
145 CleanupStack::PopAndDestroy( temp ); |
|
146 ); |
|
147 return available; |
|
148 } |
|
149 |
|
150 // End of File |