|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file SHIMDATATRANSFER.CPP |
|
18 */ |
|
19 |
|
20 #include "shimnifmansconn.h" |
|
21 #include "shimdatatransfer.h" |
|
22 #include "es_prot.h" //CConnectionProvdBase alias NIFMAN |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 CConnDataTransferShim::CConnDataTransferShim(CNifManSubConnectionShim& aSubConnectionProviderShim) : |
|
28 iSubConnectionProviderShim(aSubConnectionProviderShim) |
|
29 { |
|
30 } |
|
31 |
|
32 CConnDataTransferShim::~CConnDataTransferShim() |
|
33 { |
|
34 iUplinkGranularities.Close(); |
|
35 iDownlinkGranularities.Close(); |
|
36 } |
|
37 |
|
38 |
|
39 TInt CConnDataTransferShim::DoDataTransferred(TUint& aUplinkVolume, TUint& aDownlinkVolume) |
|
40 { |
|
41 // Find out the amount of data transferred from the connection provider |
|
42 TInt ret = iSubConnectionProviderShim.Provider().DataTransferred(iSubConnectionProviderShim.Id(), aUplinkVolume, aDownlinkVolume); |
|
43 |
|
44 // Let the subinterface know in case any subconnections have outstanding data notification requests that might be completed by this |
|
45 NotifyDataTransferred(aUplinkVolume, aDownlinkVolume); |
|
46 |
|
47 // And return the results to the connection |
|
48 return(ret); |
|
49 } |
|
50 |
|
51 TInt CConnDataTransferShim::DoDataTransferredCancel() |
|
52 { |
|
53 // do nothing |
|
54 return KErrNone; |
|
55 } |
|
56 |
|
57 TInt CConnDataTransferShim::DoDataSentNotificationRequest(TUint aRequestedGranularity, TUint aRequestedNotificationVolume) |
|
58 { |
|
59 TInt requiredGranularity; |
|
60 |
|
61 if(aRequestedGranularity == 0) // absolute mode |
|
62 { |
|
63 // Start by finding out how much data has been sent, then calculate granularity |
|
64 TUint uplinkDataVolume; |
|
65 TUint dummyDataVolume; |
|
66 |
|
67 DoDataTransferred( uplinkDataVolume, dummyDataVolume); |
|
68 |
|
69 requiredGranularity = aRequestedNotificationVolume - uplinkDataVolume; |
|
70 if(requiredGranularity < 0) // we've already achieved this so notify immediately |
|
71 { |
|
72 // possible optimisation: pass reference to caller in here and |
|
73 // only notify them if this condition is met |
|
74 // essentially we don't know what the granularity was here |
|
75 for(TInt i=0; i < iClients.Count(); i++) |
|
76 { |
|
77 iClients[i]->NotifyDataSent(uplinkDataVolume, 0); |
|
78 } |
|
79 } |
|
80 } |
|
81 else // relative mode |
|
82 { |
|
83 requiredGranularity = aRequestedGranularity; |
|
84 } |
|
85 |
|
86 return CalculateNewUplinkGranularity(requiredGranularity); |
|
87 } |
|
88 |
|
89 TInt CConnDataTransferShim::DoDataSentNotificationCancel() |
|
90 { |
|
91 // Do nothing. Not worth trying to adjust granularity array. |
|
92 return KErrNone; |
|
93 } |
|
94 |
|
95 TInt CConnDataTransferShim::DoDataReceivedNotificationRequest(TUint aRequestedGranularity, TUint aRequestedNotificationVolume) |
|
96 { |
|
97 TInt requiredGranularity; |
|
98 |
|
99 if(aRequestedGranularity == 0) // absolute mode |
|
100 { |
|
101 // Start by finding out how much data has been sent, then calculate granularity |
|
102 TUint dummyDataVolume; |
|
103 TUint downlinkDataVolume; |
|
104 |
|
105 DoDataTransferred( dummyDataVolume, downlinkDataVolume); |
|
106 |
|
107 requiredGranularity = aRequestedNotificationVolume - downlinkDataVolume; |
|
108 if(requiredGranularity < 0) // we've already achieved this so notify immediately |
|
109 { |
|
110 // possible optimisation: pass reference to caller in here |
|
111 // and only notify them if this condition is met |
|
112 // essentially we don't know what the granularity was here |
|
113 for(TInt i=0; i < iClients.Count(); i++) |
|
114 { |
|
115 iClients[i]->NotifyDataReceived(downlinkDataVolume, 0); |
|
116 } |
|
117 } |
|
118 } |
|
119 else // relative mode |
|
120 { |
|
121 requiredGranularity = aRequestedGranularity; |
|
122 } |
|
123 |
|
124 return CalculateNewDownlinkGranularity(requiredGranularity); |
|
125 } |
|
126 |
|
127 TInt CConnDataTransferShim::DoDataReceivedNotificationCancel() |
|
128 { |
|
129 // Do nothing. Not worth trying to adjust granularity array. |
|
130 return KErrNone; |
|
131 } |
|
132 |
|
133 TInt CConnDataTransferShim::NotifyDataTransferred(TUint aUplinkVolume, TUint aDownlinkVolume) |
|
134 /** |
|
135 Called as a side-effect of someone calling DataTransferredRequest(), to allow any absolute volume notifications that may be outstanding to be completed if the required amount of data has been sent/received |
|
136 |
|
137 @param aUplinkVolume The total volume of data sent on this subconnection |
|
138 @param aDownlinkVolume The total volume of data received on this subconnection |
|
139 @return KErrNone, or one of the system-wide error codes |
|
140 */ |
|
141 { |
|
142 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: New data transferred notification (uplink: %d, downlink: %d)"), |
|
143 iSubConnectionProviderShim.Id(), aUplinkVolume, aDownlinkVolume)); |
|
144 |
|
145 for(TInt i=0; i < iClients.Count(); i++) |
|
146 { |
|
147 iClients[i]->NotifyDataTransferred(aUplinkVolume, aDownlinkVolume); |
|
148 } |
|
149 |
|
150 return KErrNone; |
|
151 } |
|
152 |
|
153 TInt CConnDataTransferShim::NotifyDataSent(TUint aUplinkVolume) |
|
154 /** |
|
155 Notification from connection provider via CInterface that the requested granularity for data sent has been met or exceeded |
|
156 |
|
157 @note The granularity system is not perfect, as it may be the case that we get notifications for more than "granularity" quantity of data. |
|
158 @param aUplinkVolume The total volume of data sent so far on this subconnection |
|
159 @return KErrNone, or one of the system-wide error codes |
|
160 */ |
|
161 { |
|
162 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: New data sent notification (uplink: %d)"), |
|
163 iSubConnectionProviderShim.Id(), aUplinkVolume)); |
|
164 |
|
165 // Pass notification up to all subconnections, including the current granularity setting in case they are in relative notification mode |
|
166 for(TInt i=0; i < iClients.Count(); i++) |
|
167 { |
|
168 iClients[i]->NotifyDataSent(aUplinkVolume, iCurrentUplinkGranularity); |
|
169 } |
|
170 |
|
171 // Set the new granularity required of the interface |
|
172 return SetNextUplinkGranularity(); |
|
173 } |
|
174 |
|
175 TInt CConnDataTransferShim::NotifyDataReceived(TUint aDownlinkVolume) |
|
176 /** |
|
177 Notification from connection provider via CInterface that the requested granularity for data received has been met or exceeded |
|
178 |
|
179 @param aDownlinkVolume The total volume of data received so far on this subconnection |
|
180 @return KErrNone, or one of the system-wide error codes |
|
181 */ |
|
182 { |
|
183 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: New data received notification (downlink: %d)"), iSubConnectionProviderShim.Id(), aDownlinkVolume)); |
|
184 |
|
185 // Pass notification up to all subconnections, including the current granularity setting in case they are in relative notification mode |
|
186 for(TInt i=0; i < iClients.Count(); i++) |
|
187 { |
|
188 iClients[i]->NotifyDataReceived(aDownlinkVolume, iCurrentDownlinkGranularity); |
|
189 } |
|
190 |
|
191 // Set the new granularity required of the interface |
|
192 return SetNextDownlinkGranularity(); |
|
193 } |
|
194 |
|
195 TInt CConnDataTransferShim::CalculateNewUplinkGranularity(TUint aRequestedGranularity) |
|
196 /** |
|
197 Calculate the required granularity to satisfy client requests |
|
198 This function calculates the delta between client requests and stores it in an array. |
|
199 |
|
200 @param aRequestedGranularity The new requested granularity |
|
201 @return KErrNone if successful, otherwise one of the system-wide error codes |
|
202 @todo Quantise requests to granularity of 1K |
|
203 */ |
|
204 { |
|
205 TInt ret = KErrNone; |
|
206 TInt requestedGranularity = static_cast<TInt>(aRequestedGranularity); |
|
207 |
|
208 //@todo In the future, this method could be rewritten to expand the maximum |
|
209 //granularity from 2GB to 4GB. Probably not necessary... |
|
210 if(requestedGranularity < 0) // check that the cast didn't produce an invalid result |
|
211 { |
|
212 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: ERROR - calculating new uplink granularity - overflow when casting integer"), |
|
213 iSubConnectionProviderShim.Id())); |
|
214 return(KErrOverflow); |
|
215 } |
|
216 |
|
217 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: Calculating new uplink granularity..."), |
|
218 iSubConnectionProviderShim.Id())); |
|
219 |
|
220 TUint newGranularity = 0; |
|
221 |
|
222 ret = CalculateNewGranularity(requestedGranularity, iCurrentUplinkGranularity, iUplinkGranularities, newGranularity); |
|
223 if (ret == KErrNone && newGranularity) |
|
224 { |
|
225 ret = SetUplinkGranularity(newGranularity); |
|
226 } |
|
227 return(ret); |
|
228 } |
|
229 |
|
230 TInt CConnDataTransferShim::CalculateNewDownlinkGranularity(TUint aRequestedGranularity) |
|
231 /** |
|
232 Calculate the required granularity to satisfy client requests |
|
233 This function calculates the delta between client requests and stores it in an array. |
|
234 |
|
235 @param aRequestedGranularity The new requested granularity |
|
236 @return KErrNone if successful, otherwise one of the system-wide error codes |
|
237 @todo Quantise requests to granularity of 1K |
|
238 */ |
|
239 { |
|
240 TInt ret; |
|
241 TInt requestedGranularity = static_cast<TInt>(aRequestedGranularity); |
|
242 |
|
243 //@todo In the future, this method could be rewritten to expand the maximum |
|
244 // granularity from 2GB to 4GB. Probably not necessary... |
|
245 if(requestedGranularity < 0) // check that the cast didn't produce an invalid result |
|
246 { |
|
247 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: ERROR - calculating new downlink granularity - overflow when casting integer"), |
|
248 iSubConnectionProviderShim.Id())); |
|
249 return(KErrOverflow); |
|
250 } |
|
251 |
|
252 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("ESock: CConnDataTransferShim[id: %d]: Calculating new downlink granularity..."), |
|
253 iSubConnectionProviderShim.Id())); |
|
254 |
|
255 TUint newGranularity = 0; |
|
256 |
|
257 ret = CalculateNewGranularity(requestedGranularity, iCurrentDownlinkGranularity, iDownlinkGranularities, newGranularity); |
|
258 if (ret == KErrNone && newGranularity) |
|
259 { |
|
260 ret = SetDownlinkGranularity(newGranularity); |
|
261 } |
|
262 return(ret); |
|
263 } |
|
264 |
|
265 TInt CConnDataTransferShim::CalculateNewGranularity(TInt aRequestedGranularity, TUint aCurrentGranularity, RArray<TUint>& aGranularities, TUint& aNewCurrentGranularity) |
|
266 /** |
|
267 Given a new granularity, calculate new values for the Current granularity and granularity array. |
|
268 |
|
269 Helper function used for processing new uplink and downlink granularities. |
|
270 |
|
271 @param aRequestedGranularity new granularity (in). |
|
272 @param aCurrentGranularity current granularity in the lower provider (in). |
|
273 @param aGranularities ordered array of delta granularities which will become the current granularity |
|
274 after the latter has expired (in/out). |
|
275 @param aNewCurrentGranularity new value of current granularity to be set in lower provider (out). |
|
276 @return KErrNone or a system wide error code. |
|
277 */ |
|
278 { |
|
279 TInt ret = KErrNone; |
|
280 TInt i = 0; |
|
281 TInt count = aGranularities.Count(); // granularities in the array |
|
282 |
|
283 // The reason we have the three way if statement below is because we have to deal with |
|
284 // the fact that there is a "current" granularity (set in the lower provider), and |
|
285 // an array of delta granularities which will become the current granularity in turn: |
|
286 // |
|
287 // +---+ +---+---+---+ |
|
288 // | | | | | |... |
|
289 // +---+ +---+---+---+ |
|
290 // 0 1 2 |
|
291 // Current Array |
|
292 // |
|
293 // The complexity comes when a new granularity needs to be notionally inserted either before the |
|
294 // current granularity or between the current granularity and the first entry in the array. |
|
295 |
|
296 if (count == 0 && aCurrentGranularity == 0) |
|
297 { |
|
298 // Empty granularity array and no current granularity. |
|
299 // |
|
300 // - set current granularity to the requested granularity (no entries needed in array) |
|
301 aNewCurrentGranularity = aRequestedGranularity; |
|
302 } |
|
303 else |
|
304 if (aRequestedGranularity < aCurrentGranularity) |
|
305 { |
|
306 // Requested granularity is less than current granularity. The requested granularity |
|
307 // needs to be notionally inserted before the current granularity. |
|
308 |
|
309 // add a new entry into the beginning of the array that contains the delta between the requested |
|
310 // granularity and current granularity. This new entry represents the "old" current granularity. |
|
311 ret = aGranularities.Insert(aCurrentGranularity - aRequestedGranularity, 0); |
|
312 if (ret == KErrNone) |
|
313 { |
|
314 // the requested granularity becomes the new current granularity |
|
315 aNewCurrentGranularity = aRequestedGranularity; |
|
316 } |
|
317 } |
|
318 else |
|
319 if (aRequestedGranularity > aCurrentGranularity) |
|
320 { |
|
321 // Requested granularity is greater than current granularity. The requested granularity |
|
322 // needs to be inserted into the array at the appropriate place. The current granularity |
|
323 // remains unchanged. |
|
324 |
|
325 // Take into account the current granularity by subtracting it from requested granularity |
|
326 aRequestedGranularity -= aCurrentGranularity; |
|
327 |
|
328 // Find correct insertion position. Each entry visited in the array will subtract from the |
|
329 // requested granularity, leaving the latter as being delta based. |
|
330 for(i=0; i < count ; i++) |
|
331 { |
|
332 aRequestedGranularity -= aGranularities[i]; |
|
333 if (aRequestedGranularity <= 0) |
|
334 { |
|
335 break; |
|
336 } |
|
337 } |
|
338 |
|
339 if (aRequestedGranularity < 0) |
|
340 { |
|
341 // Insertion position found within the array - held in "i". |
|
342 aRequestedGranularity += aGranularities[i]; |
|
343 ret = aGranularities.Insert(aRequestedGranularity, i); |
|
344 if (ret == KErrNone) |
|
345 { |
|
346 // Adjust the next granularity in the array by the Requested granularity |
|
347 // that we've just inserted. "i+1" because of the Insert() above. |
|
348 aGranularities[i+1] -= aRequestedGranularity; |
|
349 } |
|
350 } |
|
351 else |
|
352 if (aRequestedGranularity > 0) |
|
353 { |
|
354 // Reached end of the array while searching - insert requested granularity at the end. |
|
355 ret = aGranularities.Append(aRequestedGranularity); |
|
356 } |
|
357 // aRequestedGranularity == 0 is a no-op case (setting zero granularity). |
|
358 } |
|
359 // (aRequestedGranularity == iCurrentUplinkGranularity) is a no-op case (setting the same |
|
360 // granularity as current value). |
|
361 return (ret); |
|
362 } |
|
363 |
|
364 |
|
365 TInt CConnDataTransferShim::SetUplinkGranularity(TUint aRequestedGranularity) |
|
366 /** |
|
367 Set data sent notification granularity in lower provider. |
|
368 |
|
369 @param aRequestedGranularity granularity to set. If zero, cancel data sent notifications. |
|
370 @return KErrNone or a system wide error code. |
|
371 */ |
|
372 { |
|
373 iCurrentUplinkGranularity = aRequestedGranularity; |
|
374 if (iCurrentUplinkGranularity) |
|
375 { |
|
376 return iSubConnectionProviderShim.Provider().SetDataSentNotificationGranularity(iSubConnectionProviderShim.Id(), iCurrentUplinkGranularity); |
|
377 } |
|
378 else |
|
379 { |
|
380 return iSubConnectionProviderShim.Provider().DataSentNotificationCancel(iSubConnectionProviderShim.Id()); |
|
381 } |
|
382 } |
|
383 |
|
384 TInt CConnDataTransferShim::SetNextUplinkGranularity() |
|
385 /** |
|
386 Get the next uplink granularity from the array, and send it to the connection provider |
|
387 |
|
388 @return KErrNone if successful, otherwise one of the system-wide error codes |
|
389 */ |
|
390 { |
|
391 if(iUplinkGranularities.Count()) |
|
392 { |
|
393 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: setting new uplink granularity (%d)"), |
|
394 iSubConnectionProviderShim.Id(), iCurrentUplinkGranularity)); |
|
395 |
|
396 // Read the next granularity from the array |
|
397 TUint granularity = iUplinkGranularities[0]; |
|
398 |
|
399 // Remove the value read |
|
400 iUplinkGranularities.Remove(0); |
|
401 |
|
402 return SetUplinkGranularity(granularity); |
|
403 } |
|
404 else |
|
405 { |
|
406 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: cancelling data sent notifications - no values remaining in granularity array"), |
|
407 iSubConnectionProviderShim.Id())); |
|
408 |
|
409 return SetUplinkGranularity(0); // cancel notifications |
|
410 } |
|
411 } |
|
412 |
|
413 TInt CConnDataTransferShim::SetDownlinkGranularity(TUint aRequestedGranularity) |
|
414 /** |
|
415 Set data received notification granularity in lower provider. |
|
416 |
|
417 @param aRequestedGranularity granularity to set. If zero, cancel data received notifications. |
|
418 @return KErrNone or a system wide error code. |
|
419 */ |
|
420 { |
|
421 iCurrentDownlinkGranularity = aRequestedGranularity; |
|
422 if (iCurrentDownlinkGranularity) |
|
423 { |
|
424 return iSubConnectionProviderShim.Provider().SetDataReceivedNotificationGranularity(iSubConnectionProviderShim.Id(), iCurrentDownlinkGranularity); |
|
425 } |
|
426 else |
|
427 { |
|
428 return iSubConnectionProviderShim.Provider().DataReceivedNotificationCancel(iSubConnectionProviderShim.Id()); |
|
429 } |
|
430 } |
|
431 |
|
432 TInt CConnDataTransferShim::SetNextDownlinkGranularity() |
|
433 /** |
|
434 Get the next downlink granularity from the array, and send it to the connection provider |
|
435 |
|
436 @return KErrNone if successful, otherwise one of the system-wide error codes |
|
437 */ |
|
438 { |
|
439 if(iDownlinkGranularities.Count()) |
|
440 { |
|
441 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("CConnDataTransferShim[id: %d]: setting new downlink granularity (%d)"), |
|
442 iSubConnectionProviderShim.Id(), iCurrentDownlinkGranularity)); |
|
443 // Read the next granularity from the array |
|
444 TUint granularity = iDownlinkGranularities[0]; |
|
445 |
|
446 // Remove the value read |
|
447 iDownlinkGranularities.Remove(0); |
|
448 |
|
449 return SetDownlinkGranularity(granularity); |
|
450 } |
|
451 else |
|
452 { |
|
453 __CFLOG_VAR((KShimScprTag, KShimScprDataTag, _L8("ESock: CConnDataTransferShim[id: %d]: cancelling data received notifications - no values remaining in granularity array"), |
|
454 iSubConnectionProviderShim.Id())); |
|
455 |
|
456 return SetDownlinkGranularity(0); // cancel notifications |
|
457 } |
|
458 } |