|
1 /* |
|
2 * Copyright (c) 2006-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: Active Object for asynchronous scan request. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "wlmscanrequest.h" |
|
20 #include "am_debug.h" |
|
21 |
|
22 // ======== MEMBER FUNCTIONS ======== |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // --------------------------------------------------------------------------- |
|
26 // |
|
27 CWlmScanRequest* CWlmScanRequest::NewL( |
|
28 RWLMServer& aClient ) |
|
29 { |
|
30 DEBUG( "CWlmScanRequest::NewL()" ); |
|
31 |
|
32 CWlmScanRequest* self = new CWlmScanRequest( |
|
33 aClient ); |
|
34 CleanupStack::PushL( self ); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop( self ); |
|
37 |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 CWlmScanRequest::~CWlmScanRequest() |
|
45 { |
|
46 DEBUG( "CWlmScanRequest::~CWlmScanRequest()" ); |
|
47 |
|
48 iScanList = NULL; |
|
49 iClientStatus = NULL; |
|
50 iCacheLifetime = NULL; |
|
51 iMaxDelay = NULL; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 TInt CWlmScanRequest::IssueRequest( |
|
58 ScanList& aScanList, |
|
59 const TDesC8& aSsid, |
|
60 TInt& aCacheLifetime, |
|
61 TUint& aMaxDelay, |
|
62 TRequestStatus* aStatus ) |
|
63 { |
|
64 DEBUG( "CWlmScanRequest::IssueRequest()" ); |
|
65 |
|
66 iScanList = &aScanList; |
|
67 iScanList->ClearAll(); |
|
68 if ( !iScanList->SetCurrentMaxSize( KWlmScanListMaxSize ) ) |
|
69 { |
|
70 DEBUG( "CWlmScanRequest::IssueRequest() - unable to set scan list size" ); |
|
71 |
|
72 if ( !aStatus ) |
|
73 { |
|
74 return KErrNoMemory; |
|
75 } |
|
76 |
|
77 User::RequestComplete( aStatus, KErrNoMemory ); |
|
78 |
|
79 return KErrNone; |
|
80 } |
|
81 |
|
82 iScanListPtr.Set( iScanList->Data(), 0, KWlmScanListMaxSize ); |
|
83 |
|
84 iDynamicScanListBuf().count = 0; |
|
85 iDynamicScanListBuf().size = 0; |
|
86 |
|
87 iSsidBuf().ssidLength = aSsid.Length(); |
|
88 Mem::Copy( |
|
89 &iSsidBuf().ssid[0], |
|
90 aSsid.Ptr(), |
|
91 aSsid.Length() ); |
|
92 |
|
93 iCacheLifetime = &aCacheLifetime; |
|
94 iMaxDelay = &aMaxDelay; |
|
95 |
|
96 iScanSchedulingBuf().cacheLifetime = aCacheLifetime; |
|
97 iScanSchedulingBuf().maxDelay = aMaxDelay; |
|
98 |
|
99 TIpcArgs params( &iScanListPtr, &iSsidBuf, &iDynamicScanListBuf, &iScanSchedulingBuf ); |
|
100 |
|
101 if ( !aStatus ) |
|
102 { |
|
103 TInt ret = iClient.SendReceive( EGetScanResults, params ); |
|
104 if ( ret != KErrNone ) |
|
105 { |
|
106 DEBUG1( "CWlmScanRequest::IssueRequest() - EGetScanResults failed (%d)", |
|
107 ret ); |
|
108 |
|
109 return ret; |
|
110 } |
|
111 aCacheLifetime = iScanSchedulingBuf().cacheLifetime; |
|
112 aMaxDelay = iScanSchedulingBuf().maxDelay; |
|
113 |
|
114 return UpdateResults(); |
|
115 } |
|
116 else |
|
117 { |
|
118 iClientStatus = aStatus; |
|
119 *iClientStatus = KRequestPending; |
|
120 iClient.SendReceive( EGetScanResults, params, iStatus ); |
|
121 SetActive(); |
|
122 } |
|
123 |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TRequestStatus* CWlmScanRequest::ClientStatus() |
|
131 { |
|
132 return iClientStatus; |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 void CWlmScanRequest::RunL() |
|
139 { |
|
140 DEBUG( "CWlmScanRequest::RunL()" ); |
|
141 |
|
142 *iCacheLifetime = iScanSchedulingBuf().cacheLifetime; |
|
143 *iMaxDelay = iScanSchedulingBuf().maxDelay; |
|
144 |
|
145 TInt ret = iStatus.Int(); |
|
146 if ( ret == KErrNone ) |
|
147 { |
|
148 ret = UpdateResults(); |
|
149 } |
|
150 else |
|
151 { |
|
152 DEBUG1( "CWlmScanRequest::RunL() - EGetScanResults failed (%d)", |
|
153 ret ); |
|
154 } |
|
155 |
|
156 User::RequestComplete( iClientStatus, ret ); |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 TInt CWlmScanRequest::RunError( |
|
163 TInt /* aError */ ) |
|
164 { |
|
165 // Ignore the error. |
|
166 return KErrNone; |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CWlmScanRequest::DoCancel() |
|
173 { |
|
174 DEBUG( "CWlmScanRequest::DoCancel()" ); |
|
175 |
|
176 *iCacheLifetime = iScanSchedulingBuf().cacheLifetime; |
|
177 *iMaxDelay = iScanSchedulingBuf().maxDelay; |
|
178 |
|
179 // Send the command |
|
180 iClient.SendReceive( ECancelGetScanResults ); |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 CWlmScanRequest::CWlmScanRequest( |
|
187 RWLMServer& aClient ) : |
|
188 CActive( CActive::EPriorityStandard ), |
|
189 iClient( aClient ), |
|
190 iScanList( NULL ), |
|
191 iScanListPtr( NULL, 0 ), |
|
192 iCacheLifetime( NULL ), |
|
193 iMaxDelay( NULL ), |
|
194 iClientStatus( NULL ) |
|
195 { |
|
196 DEBUG( "CWlmScanRequest::CWlmScanRequest()" ); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 void CWlmScanRequest::ConstructL() |
|
203 { |
|
204 DEBUG( "CWlmScanRequest::ConstructL()" ); |
|
205 |
|
206 CActiveScheduler::Add( this ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 TInt CWlmScanRequest::UpdateResults() |
|
213 { |
|
214 DEBUG( "CWlmScanRequest::UpdateResults()" ); |
|
215 |
|
216 DEBUG1( "CWlmScanRequest::UpdateResults() - scan list count is %u", |
|
217 iDynamicScanListBuf().count ); |
|
218 DEBUG1( "CWlmScanRequest::UpdateResults() - scan list size is %u", |
|
219 iDynamicScanListBuf().size ); |
|
220 |
|
221 iScanList->Update( iDynamicScanListBuf().count, iDynamicScanListBuf().size ); |
|
222 iScanList->Compress(); |
|
223 |
|
224 return KErrNone; |
|
225 } |