|
1 // Copyright (c) 2006-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 #include "refBnepPacketNotifier.h" |
|
17 |
|
18 EXPORT_C MBnepPacketNotifierBase* CRefBnepPacketNotifier::NewL() |
|
19 { |
|
20 MBnepPacketNotifierBase* self = new(ELeave) CRefBnepPacketNotifier; |
|
21 return self; |
|
22 } |
|
23 |
|
24 |
|
25 |
|
26 CRefBnepPacketNotifier::CRefBnepPacketNotifier():iCounter(8) // 8 is the current maximum number of PAN connections, so is a good number to set the granularity to. |
|
27 { |
|
28 } |
|
29 |
|
30 CRefBnepPacketNotifier::~CRefBnepPacketNotifier() |
|
31 { |
|
32 iCounter.Close(); |
|
33 } |
|
34 |
|
35 void CRefBnepPacketNotifier::MbpnSetLinkControl(MPanLinkControlBase& aPanLinkControl) |
|
36 { |
|
37 iPanLinkControl=(MPanLinkControl*) aPanLinkControl.MplcbGetInterface(KUidPanLinkControlV1); |
|
38 } |
|
39 |
|
40 void CRefBnepPacketNotifier::MbpnBnepDataTransferred(const TArray<TBnepBytesTransferred> & aBnepBytesTransferred) |
|
41 { |
|
42 for (TInt dev=0;dev<aBnepBytesTransferred.Count();dev++) // Cycle through array passed to function |
|
43 { |
|
44 for (TInt index=0;index<iCounter.Count();index++) // Cycle through our array |
|
45 { |
|
46 TBTDevAddr & curAddr = iCounter[index].iAddr; |
|
47 if (curAddr == aBnepBytesTransferred[dev].iBTDevAddr) // If the device addresses are the same |
|
48 { |
|
49 iCounter[index].iByteCount+=aBnepBytesTransferred[dev].iBytesSent + aBnepBytesTransferred[dev].iBytesReceived; // Increment byte counter |
|
50 iCounter[index].iTickCount++; // Increment counter |
|
51 if (iCounter[index].iTickCount == KTicksToSniff) // If it's time to decide whether to sniff/active |
|
52 { |
|
53 iCounter[index].iTickCount=0; // Reset counter |
|
54 if (iPanLinkControl) |
|
55 { |
|
56 |
|
57 if (iCounter[index].iByteCount < KMaxBytesToSniff ) |
|
58 { |
|
59 |
|
60 iPanLinkControl->MplcRequestSniff(curAddr); // Sniff if under KMaxBytesToSniff |
|
61 |
|
62 } |
|
63 else |
|
64 { |
|
65 iPanLinkControl->MplcRequestActive(curAddr); // Otherwise active |
|
66 } |
|
67 iCounter[index].iByteCount=0; // Reset byte count |
|
68 } |
|
69 } |
|
70 if (aBnepBytesTransferred[dev].iBytesSent + aBnepBytesTransferred[dev].iBytesReceived > KMinBytesToUnSniff && iPanLinkControl) |
|
71 { |
|
72 iPanLinkControl->MplcRequestActive(curAddr); // If data in one tick is enough, bring out of sniff |
|
73 } |
|
74 } |
|
75 } |
|
76 } |
|
77 } |
|
78 |
|
79 void CRefBnepPacketNotifier::MbpnDeviceAdded(const TBTDevAddr& aAddr) |
|
80 { |
|
81 TByteCount devByteCount; |
|
82 devByteCount.iByteCount=0; |
|
83 devByteCount.iTickCount=0; |
|
84 devByteCount.iAddr=aAddr; |
|
85 iCounter.Append(devByteCount); |
|
86 } |
|
87 |
|
88 void CRefBnepPacketNotifier::MbpnDeviceRemoved(const TBTDevAddr& aAddr) |
|
89 { |
|
90 for (TUint dataIndex=0; dataIndex < iCounter.Count(); ++dataIndex) |
|
91 { |
|
92 if (iCounter[dataIndex].iAddr==aAddr) |
|
93 { |
|
94 iCounter.Remove(dataIndex); |
|
95 } |
|
96 } |
|
97 |
|
98 } |
|
99 |
|
100 MBnepPacketNotifier* CRefBnepPacketNotifier::Interface() |
|
101 { |
|
102 return this; |
|
103 } |
|
104 |
|
105 TAny* CRefBnepPacketNotifier::MbpnbGetInterface(const TUid & aInterface) |
|
106 { |
|
107 if (aInterface==KUidBnepPacketNotifierV1) |
|
108 { |
|
109 return Interface(); |
|
110 } |
|
111 return NULL; |
|
112 } |
|
113 |
|
114 void CRefBnepPacketNotifier::MbpnbRelease() |
|
115 { |
|
116 delete this; |
|
117 } |