1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
2 // All rights reserved. |
2 // All rights reserved. |
3 // This component and the accompanying materials are made available |
3 // This component and the accompanying materials are made available |
4 // under the terms of "Eclipse Public License v1.0" |
4 // under the terms of "Eclipse Public License v1.0" |
5 // which accompanies this distribution, and is available |
5 // which accompanies this distribution, and is available |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
21 |
21 |
22 #include "Receiver.h" |
22 #include "Receiver.h" |
23 #include "Constants.h" |
23 #include "Constants.h" |
24 #include <es_ini.h> |
24 #include <es_ini.h> |
25 |
25 |
26 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise) |
26 const TUint KBufferIncreaseStep=500; |
|
27 const TUint K64k=65535; |
|
28 |
|
29 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize) |
27 /** |
30 /** |
28 * Constructor. Performs standard active object initialisation. |
31 * Constructor. Performs standard active object initialisation. |
29 * |
32 * |
30 * @param aObserver Reference to the observer of this state machine |
33 * @param aObserver Reference to the observer of this state machine |
31 * @param aTheLogger The logging object |
34 * @param aTheLogger The logging object |
32 */ |
35 */ |
33 : CActive(EPriorityHigh), |
36 : CActive(EPriorityHigh), |
34 iObserver(aObserver), |
37 iObserver(aObserver), |
35 iTheLogger(aTheLogger), |
38 iTheLogger(aTheLogger), |
36 iMaxPacketSise(aMaxPacketSise) |
39 iMaxPacketSize(aMaxPacketSize) |
37 { |
40 { |
38 CActiveScheduler::Add(this); |
41 CActiveScheduler::Add(this); |
39 } |
42 } |
40 |
43 |
41 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise) |
44 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize) |
42 /** |
45 /** |
43 * Two-phase constructor. Creates a new CBcaIoController object, performs |
46 * Two-phase constructor. Creates a new CBcaIoController object, performs |
44 * second-phase construction, then returns it. |
47 * second-phase construction, then returns it. |
45 * |
48 * |
46 * @param aObserver The observer, to which events will be reported |
49 * @param aObserver The observer, to which events will be reported |
47 * @param aTheLogger The logging object |
50 * @param aTheLogger The logging object |
48 * @return A newly constructed CBcaIoController object |
51 * @return A newly constructed CBcaIoController object |
49 */ |
52 */ |
50 { |
53 { |
51 CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSise); |
54 CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSize); |
52 CleanupStack::PushL(self); |
55 CleanupStack::PushL(self); |
53 self->ConstructL(); |
56 self->ConstructL(); |
54 CleanupStack::Pop(self); |
57 CleanupStack::Pop(self); |
55 return self; |
58 return self; |
56 } |
59 } |
79 * packet in its buffer. |
82 * packet in its buffer. |
80 */ |
83 */ |
81 { |
84 { |
82 _LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int()); |
85 _LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int()); |
83 |
86 |
84 if (iStatus!=KErrNone) |
87 if (iStatus != KErrNone) |
85 { |
88 { |
86 if(iStatus == KErrNoMemory) |
89 if (iStatus == KErrNoMemory) |
87 { |
90 { |
88 _LOG_L2C1( |
91 _LOG_L2C1( |
89 _L8("WARNING! CReceiver: Read failed with KErrNoMemory")); |
92 _L8("WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer.")); |
90 // Read operation failed!! Nif will re-issue the read request. |
93 // Read operation failed!! Nif will re-issue the read request. Increase buffer. |
91 StartListening(); |
94 if ((iMaxPacketSize + KBufferIncreaseStep) > K64k) |
|
95 { |
|
96 // In theory IP packet can't be bigger than 64k, so if we come here something is wrong so stop observer. |
|
97 iObserver.Stop(KErrNoMemory); |
|
98 } |
|
99 else |
|
100 { |
|
101 iMaxPacketSize += KBufferIncreaseStep; |
|
102 TInt err = iData.ReAlloc(iMaxPacketSize); |
|
103 if (KErrNoMemory == err) |
|
104 { |
|
105 iObserver.Stop(KErrNoMemory); |
|
106 } |
|
107 else |
|
108 { |
|
109 (iObserver.Bca())->Read(iStatus, iData); |
|
110 SetActive(); |
|
111 } |
|
112 } |
92 } |
113 } |
93 else |
114 else |
94 { |
115 { |
95 _LOG_L2C1(_L8("WARNING! CReceiver: Read failed")); |
116 _LOG_L2C1(_L8("WARNING! CReceiver: Read failed")); |
96 iObserver.Stop(iStatus.Int()); |
117 iObserver.Stop(iStatus.Int()); |
97 } |
118 } |
98 return; |
119 return; |
99 } |
120 } |
100 |
121 else |
101 _LOG_L1C1(_L8("CReceiver: Data Packet Received")); |
122 { |
102 |
123 _LOG_L1C1(_L8("CReceiver: Data Packet Received")); |
103 iRMBufPacket.CreateL(iData); |
124 |
104 iRMBufPacket.Pack(); |
125 iRMBufPacket.CreateL(iData); |
105 |
126 |
106 // Immediately execute new read request. |
127 // Immediately execute new read request. |
107 StartListening(); |
128 (iObserver.Bca())->Read(iStatus, iData); |
108 |
129 |
|
130 SetActive(); |
|
131 |
|
132 iRMBufPacket.Pack(); |
|
133 |
109 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
134 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
110 TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket); |
135 TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket); |
111 #else |
136 #else |
112 TUint16 protocolCode = 0; |
137 TUint16 protocolCode = 0; |
113 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
138 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
114 |
139 |
115 // Process the packet |
140 // Process the packet |
116 iObserver.GetObserver().Process(iRMBufPacket, protocolCode); |
141 iObserver.GetObserver().Process(iRMBufPacket, protocolCode); |
117 iRMBufPacket.Free(); |
142 iRMBufPacket.Free(); |
|
143 } |
118 } |
144 } |
119 |
145 |
120 void CReceiver::DoCancel() |
146 void CReceiver::DoCancel() |
121 /** |
147 /** |
122 * Cancel active request |
148 * Cancel active request |