|
1 /* |
|
2 * Copyright (c) 2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mcsdef.h" |
|
19 #include "mcsmenu.h" |
|
20 #include "mcsmenufilter.h" |
|
21 |
|
22 #include "mcsrunningapps.h" |
|
23 #include "mcsservice.h" |
|
24 #include "mcsconstants.h" |
|
25 #include "mcsmenuopwatcher.h" |
|
26 #include "mcsoperationmanager.h" |
|
27 |
|
28 // --------------------------------------------------------------------------- |
|
29 // two-phased constructor |
|
30 // --------------------------------------------------------------------------- |
|
31 CMCSRunningApps* CMCSRunningApps::NewL( RMenu& aMCS, MMCSCallback* aCallback, |
|
32 RMcsOperationManager& aOperationManager ) |
|
33 { |
|
34 CMCSRunningApps* self = new (ELeave) CMCSRunningApps( aMCS, aCallback, |
|
35 aOperationManager ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // destructor |
|
44 // --------------------------------------------------------------------------- |
|
45 CMCSRunningApps::~CMCSRunningApps() |
|
46 { |
|
47 Cancel(); |
|
48 iUidArray.Close(); |
|
49 } |
|
50 |
|
51 // --------------------------------------------------------------------------- |
|
52 // default constructor |
|
53 // --------------------------------------------------------------------------- |
|
54 CMCSRunningApps::CMCSRunningApps( RMenu& aMCS, MMCSCallback* aCallback, |
|
55 RMcsOperationManager& aOperationManager ) : |
|
56 CActive( EPriorityStandard ), |
|
57 iMCS( aMCS ), |
|
58 iCallback( aCallback ), |
|
59 iOperationManager(aOperationManager) |
|
60 { |
|
61 } |
|
62 |
|
63 // --------------------------------------------------------------------------- |
|
64 // second phase constructor |
|
65 // --------------------------------------------------------------------------- |
|
66 void CMCSRunningApps::ConstructL( ) |
|
67 { |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Inherited from CActive class |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CMCSRunningApps::DoCancel() |
|
75 { |
|
76 TRAP_IGNORE( iCallback->NotifyResultL( KErrCancel, NULL )); |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------------------------- |
|
80 // Inherited from CActive class |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 void CMCSRunningApps::RunL() |
|
84 { |
|
85 TInt err = iStatus.Int(); |
|
86 |
|
87 if ( err == KErrNone ) |
|
88 { |
|
89 RunningAppsChangedL();//temporary |
|
90 } |
|
91 if(err != KErrNone) |
|
92 { |
|
93 NotifyRequestResult( err ); |
|
94 } |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CMCSRunningApps::RunError |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 TInt CMCSRunningApps::RunError(TInt aError) |
|
102 { |
|
103 NotifyRequestResult( aError ); |
|
104 if ( (aError != KErrDiskFull) && (aError != KErrNoMemory)) |
|
105 { |
|
106 aError = KErrNone; |
|
107 } |
|
108 return aError; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // Activates the asynchronous request |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CMCSRunningApps::ActivateRequest( TInt aReason ) |
|
116 { |
|
117 iStatus = KRequestPending; |
|
118 SetActive(); |
|
119 TRequestStatus* temp = &iStatus; |
|
120 User::RequestComplete( temp, aReason ); |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------------------------------------- |
|
124 // Notifies callback the result for asynchronous request. |
|
125 // -------------------------------------------------------------------------------------------------------- |
|
126 // |
|
127 void CMCSRunningApps::NotifyRequestResult( TInt aReason ) |
|
128 { |
|
129 iOperationManager.Remove( this );//remove it |
|
130 //from operation manager |
|
131 if ( iCallback ) |
|
132 { |
|
133 TRAP_IGNORE( iCallback->NotifyResultL( aReason, (TAny*)(&iUidArray))); |
|
134 // iCallback deletes itself. |
|
135 } |
|
136 delete this; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // ExecuteActionL - Async |
|
141 // --------------------------------------------------------------------------- |
|
142 void CMCSRunningApps::GetRunningApplicationL() |
|
143 { |
|
144 if( !iCallback ) |
|
145 { |
|
146 User::Leave( KErrArgument ); |
|
147 } |
|
148 CActiveScheduler::Add ( this ); |
|
149 ActivateRequest( KErrNone ); |
|
150 } |
|
151 |
|
152 // -------------------------------------------------------------------------------------------------------- |
|
153 // Notifies callback the result for asynchronous request. |
|
154 // -------------------------------------------------------------------------------------------------------- |
|
155 // |
|
156 void CMCSRunningApps::RunningAppsChangedL() |
|
157 { |
|
158 TRAPD(err, |
|
159 { |
|
160 RArray<TUid> uids; |
|
161 CleanupClosePushL( uids ); |
|
162 iMCS.GetRunningAppsL( uids ); |
|
163 for(TInt i =0; i<uids.Count(); i++) |
|
164 { |
|
165 iUidArray.AppendL( uids[i] ); |
|
166 } |
|
167 CleanupStack::PopAndDestroy( &uids ); |
|
168 }); |
|
169 NotifyRequestResult( err ); |
|
170 } |