|
1 /* |
|
2 * Copyright (c) 2007-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: A composite command that runs subcommands parallel. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CParallelCompositeCmd.h" |
|
22 |
|
23 #include <VPbkDebug.h> |
|
24 #include "VPbkSimStoreImplError.h" |
|
25 #include "MVPbkSimCommandObserver.h" |
|
26 |
|
27 namespace VPbkSimStoreImpl { |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CParallelCompositeCmd::CParallelCompositeCmd |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CParallelCompositeCmd::CParallelCompositeCmd( |
|
38 TTerminationPolicy aTerminationPolicy ) |
|
39 : iTerminationPolicy( aTerminationPolicy ) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CParallelCompositeCmd::NewL |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CParallelCompositeCmd* CParallelCompositeCmd::NewL( |
|
48 TTerminationPolicy aTerminationPolicy ) |
|
49 { |
|
50 return new( ELeave ) CParallelCompositeCmd( aTerminationPolicy ); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CParallelCompositeCmd::NewLC |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CParallelCompositeCmd* CParallelCompositeCmd::NewLC( |
|
58 TTerminationPolicy aTerminationPolicy ) |
|
59 { |
|
60 CParallelCompositeCmd* self = |
|
61 new( ELeave ) CParallelCompositeCmd( aTerminationPolicy ); |
|
62 CleanupStack::PushL( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // Destructor |
|
67 CParallelCompositeCmd::~CParallelCompositeCmd() |
|
68 { |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CParallelCompositeCmd::Execute |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CParallelCompositeCmd::Execute() |
|
76 { |
|
77 __ASSERT_DEBUG( SubCommands().Count() > 0, |
|
78 Panic( EPreCondCParallelCompositeCmdExecute ) ); |
|
79 |
|
80 // Execute all subcommands parallel |
|
81 TArray<MVPbkSimCommand*> subCommands = SubCommands(); |
|
82 const TInt count = subCommands.Count(); |
|
83 if ( count > 0 ) |
|
84 { |
|
85 for ( TInt i = 0; i < count; ++i ) |
|
86 { |
|
87 subCommands[i]->Execute(); |
|
88 } |
|
89 } |
|
90 else |
|
91 { |
|
92 SendCommandDone(); |
|
93 } |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CParallelCompositeCmd::CommandDone |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CParallelCompositeCmd::CommandDone( MVPbkSimCommand& /*aCommand*/ ) |
|
101 { |
|
102 ++iTerminatedCommands; |
|
103 if ( iTerminationPolicy == EFirstSubCommandDone ) |
|
104 { |
|
105 // Cancel all other subcommands |
|
106 CancelCmd(); |
|
107 SendCommandDone(); |
|
108 } |
|
109 else if ( iTerminatedCommands == SubCommands().Count() ) |
|
110 { |
|
111 SendCommandDone(); |
|
112 } |
|
113 } |
|
114 } // namespace VPbkSimStoreImpl |
|
115 // End of File |