|
1 /* |
|
2 * Copyright (c) 2006-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: DUN USB configuration accessor and listener |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "DunUsbConfig.h" |
|
20 #include "DunDebug.h" |
|
21 |
|
22 const TUint KDunUsbSupportedConfigVersion = 1; |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // Two-phased constructor. |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CDunUsbConfig* CDunUsbConfig::NewL( MDunServerCallback* aServer, |
|
29 MDunUsbConfig* aCallback, |
|
30 TUint8 aProtocol ) |
|
31 { |
|
32 CDunUsbConfig* self = new (ELeave) CDunUsbConfig( aServer, |
|
33 aCallback, |
|
34 aProtocol ); |
|
35 CleanupStack::PushL( self ); |
|
36 self->ConstructL(); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // Destructor. |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CDunUsbConfig::~CDunUsbConfig() |
|
46 { |
|
47 FTRACE(FPrint( _L("CDunUsbConfig::~CDunUsbConfig()" ))); |
|
48 ResetData(); |
|
49 FTRACE(FPrint( _L("CDunUsbConfig::~CDunUsbConfig() complete" ))); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Resets data to initial values |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 void CDunUsbConfig::ResetData() |
|
57 { |
|
58 // APIs affecting this: |
|
59 // IssueRequest() |
|
60 Stop(); |
|
61 // NewL() |
|
62 iAcmProperty.Close(); |
|
63 // Internal |
|
64 Initialize(); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // Compares initialized protocol number to configuration by index |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 TInt CDunUsbConfig::GetConfigValidityByIndex( TInt aIndex, TBool& aValidity ) |
|
72 { |
|
73 FTRACE(FPrint( _L("CDunUsbConfig::GetConfigValidityByIndex()" ))); |
|
74 if ( iConfigState != EUsbConfigStateIdle ) |
|
75 { |
|
76 FTRACE(FPrint( _L("CDunUsbConfig::GetConfigValidityByIndex() (not ready) complete" ))); |
|
77 return KErrNotReady; |
|
78 } |
|
79 if ( !iConfigExist ) |
|
80 { |
|
81 TInt retTemp = GetConfiguration( iConfig ); |
|
82 if ( retTemp != KErrNone ) |
|
83 { |
|
84 FTRACE(FPrint( _L("CDunUsbConfig::GetConfigValidityByIndex() (get failed) complete" ))); |
|
85 return retTemp; |
|
86 } |
|
87 } |
|
88 if ( aIndex < 0 || |
|
89 aIndex >= iConfig.iAcmCount || |
|
90 aIndex >= TPublishedAcmConfigs::KAcmMaxFunctions ) |
|
91 { |
|
92 FTRACE(FPrint( _L("CDunUsbConfig::GetConfigValidityByIndex() (not found) complete" ))); |
|
93 return KErrNotFound; |
|
94 } |
|
95 if ( iConfig.iAcmConfig[aIndex].iProtocol == iProtocol ) |
|
96 { |
|
97 aValidity = ETrue; |
|
98 } |
|
99 else |
|
100 { |
|
101 aValidity = EFalse; |
|
102 } |
|
103 FTRACE(FPrint( _L("CDunUsbConfig::GetConfigValidityByIndex() complete (%d/%d)" ), aIndex, aValidity)); |
|
104 return KErrNone; |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Starts listening for ACM configuration changes |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 TInt CDunUsbConfig::IssueRequest() |
|
112 { |
|
113 FTRACE(FPrint( _L("CDunUsbConfig::IssueRequest()" ))); |
|
114 if ( iConfigState != EUsbConfigStateIdle ) |
|
115 { |
|
116 FTRACE(FPrint( _L("CDunUsbConfig::IssueRequest() (not ready) complete" ))); |
|
117 return KErrNotReady; |
|
118 } |
|
119 iStatus = KRequestPending; |
|
120 iAcmProperty.Subscribe( iStatus ); |
|
121 SetActive(); |
|
122 iConfigState = EUsbConfigStateWaiting; |
|
123 FTRACE(FPrint( _L("CDunUsbConfig::IssueRequest() complete" ))); |
|
124 return KErrNone; |
|
125 } |
|
126 |
|
127 // --------------------------------------------------------------------------- |
|
128 // Stops listening for ACM configuration changes |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 TInt CDunUsbConfig::Stop() |
|
132 { |
|
133 FTRACE(FPrint( _L("CDunUsbConfig::Stop()" ))); |
|
134 if ( iConfigState != EUsbConfigStateWaiting ) |
|
135 { |
|
136 FTRACE(FPrint( _L("CDunUsbConfig::Stop() (not ready) complete" ))); |
|
137 return KErrNotReady; |
|
138 } |
|
139 iAcmProperty.Cancel(); |
|
140 Cancel(); |
|
141 iConfigState = EUsbConfigStateIdle; |
|
142 FTRACE(FPrint( _L("CDunUsbConfig::Stop() complete" ))); |
|
143 return KErrNone; |
|
144 } |
|
145 |
|
146 // --------------------------------------------------------------------------- |
|
147 // CDunUsbConfig::CDunUsbConfig |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 CDunUsbConfig::CDunUsbConfig( MDunServerCallback* aServer, |
|
151 MDunUsbConfig* aCallback, |
|
152 TUint8 aProtocol ) : |
|
153 CActive( EPriorityStandard ), |
|
154 iServer( aServer ), |
|
155 iCallback( aCallback ), |
|
156 iProtocol( aProtocol ) |
|
157 { |
|
158 Initialize(); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // CDunUsbConfig::ConstructL |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CDunUsbConfig::ConstructL() |
|
166 { |
|
167 FTRACE(FPrint( _L("CDunUsbConfig::ConstructL()" ))); |
|
168 if ( !iServer || !iCallback ) |
|
169 { |
|
170 User::Leave( KErrGeneral ); |
|
171 } |
|
172 User::LeaveIfError( iAcmProperty.Attach(KUidSystemCategory,KAcmKey) ); |
|
173 CActiveScheduler::Add( this ); |
|
174 FTRACE(FPrint( _L("CDunUsbConfig::ConstructL() complete" ))); |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------------------------- |
|
178 // Initializes this class |
|
179 // --------------------------------------------------------------------------- |
|
180 // |
|
181 void CDunUsbConfig::Initialize() |
|
182 { |
|
183 // Don't initialize iCallback here (it is set through NewL) |
|
184 // Don't initialize iProtocol here (it is set through NewL) |
|
185 iConfigState = EUsbConfigStateIdle; |
|
186 iConfig.iAcmConfigVersion = 0; |
|
187 iConfig.iAcmCount = 0; |
|
188 iConfigExist = EFalse; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // Gets current ACM configuration |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 TInt CDunUsbConfig::GetConfiguration( TPublishedAcmConfigs& aConfig ) |
|
196 { |
|
197 FTRACE(FPrint( _L("CDunUsbConfig::GetConfiguration()" ))); |
|
198 TPckgBuf<TPublishedAcmConfigs> configBuf; |
|
199 TInt retTemp = iAcmProperty.Get( configBuf ); |
|
200 if ( retTemp != KErrNone ) |
|
201 { |
|
202 FTRACE(FPrint( _L("CDunUsbConfig::GetConfiguration() (ERROR) complete" ))); |
|
203 return retTemp; |
|
204 } |
|
205 aConfig = configBuf(); |
|
206 // Check that version is that which we currently support |
|
207 if ( aConfig.iAcmConfigVersion != KDunUsbSupportedConfigVersion ) |
|
208 { |
|
209 FTRACE(FPrint( _L("CDunUsbConfig::GetConfiguration() (not supported) complete" ))); |
|
210 return KErrNotSupported; |
|
211 } |
|
212 // Check that count is within bounds |
|
213 if ( aConfig.iAcmCount > TPublishedAcmConfigs::KAcmMaxFunctions ) |
|
214 { |
|
215 FTRACE(FPrint( _L("CDunUsbConfig::GetConfiguration() (overflow) complete" ))); |
|
216 return KErrOverflow; |
|
217 } |
|
218 iConfigExist = ETrue; |
|
219 FTRACE(FPrint( _L("CDunUsbConfig::GetConfiguration() complete" ))); |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------------------------- |
|
224 // From class CActive. |
|
225 // Gets called when ACM configuration changes |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 void CDunUsbConfig::RunL() |
|
229 { |
|
230 FTRACE(FPrint( _L("CDunUsbConfig::RunL()" ))); |
|
231 iConfigState = EUsbConfigStateIdle; |
|
232 |
|
233 TPublishedAcmConfigs newConfig; |
|
234 TInt retTemp = GetConfiguration( newConfig ); |
|
235 if ( retTemp != KErrNone ) |
|
236 { |
|
237 FTRACE(FPrint( _L("CDunUsbConfig::RunL() (ERROR) complete (%d)" ), retTemp)); |
|
238 iServer->NotifyPluginCloseRequest( KDunUsbPluginUid, ETrue ); |
|
239 return; |
|
240 } |
|
241 // Change that is same is not possible so check that first |
|
242 if ( newConfig.iAcmCount == iConfig.iAcmCount ) |
|
243 { |
|
244 FTRACE(FPrint( _L("CDunUsbConfig::RunL() (no change) complete" ))); |
|
245 iServer->NotifyPluginCloseRequest( KDunUsbPluginUid, ETrue ); |
|
246 return; |
|
247 } |
|
248 |
|
249 // Now we have the changed configuration so find out are there added or |
|
250 // removed USB ACMs |
|
251 |
|
252 TInt i; |
|
253 if ( newConfig.iAcmCount > iConfig.iAcmCount ) // addition |
|
254 { |
|
255 // Addition is always done to end of ACM queue by N entry addition |
|
256 // Scan through new array and report change if necessary |
|
257 for ( i=iConfig.iAcmCount; i<newConfig.iAcmCount; i++ ) |
|
258 { |
|
259 if ( newConfig.iAcmConfig[i].iProtocol == iProtocol ) |
|
260 { |
|
261 iCallback->NotifyConfigAddition( i ); |
|
262 } |
|
263 } |
|
264 } |
|
265 else // removal ( newConfig.iAcmCount < iConfig.iAcmCount ) |
|
266 { |
|
267 // Removal is always done to end of ACM queue by N entry removal |
|
268 // Scan through old array and report change if necessary |
|
269 for ( i=newConfig.iAcmCount; i<iConfig.iAcmCount; i++ ) |
|
270 { |
|
271 if ( iConfig.iAcmConfig[i].iProtocol == iProtocol ) |
|
272 { |
|
273 iCallback->NotifyConfigRemoval( i ); |
|
274 } |
|
275 } |
|
276 } |
|
277 |
|
278 // Update config and restart listening |
|
279 iConfig = newConfig; |
|
280 IssueRequest(); |
|
281 |
|
282 FTRACE(FPrint( _L("CDunUsbConfig::RunL() complete" ))); |
|
283 } |
|
284 |
|
285 // --------------------------------------------------------------------------- |
|
286 // From class CActive. |
|
287 // Gets called on cancel |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 void CDunUsbConfig::DoCancel() |
|
291 { |
|
292 } |