|
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 the License "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: This Class provides the core functionality to Application Manager |
|
15 * SAPI |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <apgcli.h> |
|
23 |
|
24 #include "asynchrequestmanager.h" |
|
25 #include "launcherobserver.h" |
|
26 #include "appobserver.h" |
|
27 |
|
28 |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CCAsynchRequestManager ::NewLC |
|
32 // Returns the instance of CCAsynchRequestManager class. |
|
33 // ----------------------------------------------------------------------------- |
|
34 CAsynchRequestManager * CAsynchRequestManager ::NewL() |
|
35 { |
|
36 CAsynchRequestManager * self = new ( ELeave )CAsynchRequestManager (); |
|
37 return self; |
|
38 } |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CCAsynchRequestManager ::~CCAsynchRequestManager |
|
43 // Destructor |
|
44 // ----------------------------------------------------------------------------- |
|
45 |
|
46 CAsynchRequestManager ::~CAsynchRequestManager () |
|
47 { |
|
48 |
|
49 //Cancel All pending request |
|
50 |
|
51 TInt pos = iAsyncObjArray.Count() - 1; |
|
52 TAsyncRequestInfo obj; |
|
53 for ( ; pos >= 0; pos-- ) |
|
54 { |
|
55 obj = iAsyncObjArray[pos]; |
|
56 //No need to inform for this cancel |
|
57 //obj.iAsyncObj->SetAppObserver( NULL ); |
|
58 obj.iAsyncObj->Cancel(); |
|
59 delete obj.iAsyncObj; |
|
60 } |
|
61 iAsyncObjArray.Close(); |
|
62 |
|
63 } |
|
64 |
|
65 |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CCAsynchRequestManager ::Cancel |
|
69 // Cancel the pending asynchronous request |
|
70 // ----------------------------------------------------------------------------- |
|
71 TInt CAsynchRequestManager ::Cancel( TInt32 aTransactionID ) |
|
72 { |
|
73 |
|
74 TInt pos = iAsyncObjArray.Count() - 1; |
|
75 TAsyncRequestInfo obj; |
|
76 for ( ; pos >= 0; pos-- ) |
|
77 { |
|
78 obj = iAsyncObjArray[pos]; |
|
79 if( obj.iTransactionId == aTransactionID ) |
|
80 { |
|
81 obj.iAsyncObj->Cancel(); |
|
82 delete obj.iAsyncObj; |
|
83 return KErrNone; |
|
84 } |
|
85 } |
|
86 return KErrNotFound; |
|
87 |
|
88 } |
|
89 |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CCAsynchRequestManager ::RequestComplete |
|
93 // This is called by the observer when asynch request complete |
|
94 // ----------------------------------------------------------------------------- |
|
95 void CAsynchRequestManager ::RequestComplete( TInt32 aTransactionID ) |
|
96 |
|
97 { |
|
98 TInt pos = iAsyncObjArray.Count()-1; |
|
99 TAsyncRequestInfo obj; |
|
100 for ( ; pos >= 0; pos-- ) |
|
101 { |
|
102 obj = iAsyncObjArray[pos]; |
|
103 if( obj.iTransactionId == aTransactionID ) |
|
104 { |
|
105 iAsyncObjArray.Remove(pos); |
|
106 iAsyncObjArray.Compress(); |
|
107 return; |
|
108 } |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CCAsynchRequestManager ::AddObserever |
|
114 // AddObserever |
|
115 // ----------------------------------------------------------------------------- |
|
116 CLauncherObserver* CAsynchRequestManager ::AddObsereverLC( MAppObserver* aObserver, TInt32& aTransactionID, TThreadId& aThreadId ) |
|
117 |
|
118 { |
|
119 // Add the given observer in array and return the laucher observer |
|
120 // strutcure for binding the transaction ID and callback object |
|
121 |
|
122 TAsyncRequestInfo asyncRequestInfo; |
|
123 asyncRequestInfo.iTransactionId = aTransactionID; |
|
124 |
|
125 //observer for observering underlying classes |
|
126 CLauncherObserver* observer = CLauncherObserver::NewL( aObserver,aTransactionID, this); |
|
127 CleanupStack::PushL( observer ); |
|
128 |
|
129 observer->ActivateRequestL( aThreadId ); |
|
130 asyncRequestInfo.iAsyncObj = observer; |
|
131 |
|
132 User::LeaveIfError( iAsyncObjArray.Append( asyncRequestInfo ) ); |
|
133 |
|
134 return observer; |
|
135 } |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |