17 |
17 |
18 /** |
18 /** |
19 @file |
19 @file |
20 */ |
20 */ |
21 |
21 |
|
22 |
|
23 #include "OstTraceDefinitions.h" |
|
24 #ifdef OST_TRACE_COMPILER_IN_USE |
|
25 #include "ReceiverTraces.h" |
|
26 #endif |
|
27 |
22 #include "Receiver.h" |
28 #include "Receiver.h" |
23 #include "Constants.h" |
29 #include "Constants.h" |
24 #include <es_ini.h> |
30 #include <es_ini.h> |
25 |
31 |
26 const TUint KBufferIncreaseStep=500; |
32 const TUint KBufferIncreaseStep=500; |
27 const TUint K64k=65535; |
33 const TUint K64k=65535; |
28 |
34 |
29 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize) |
35 CReceiver::CReceiver(CBcaIoController& aObserver, TUint aMaxPacketSize) |
30 /** |
36 /** |
31 * Constructor. Performs standard active object initialisation. |
37 * Constructor. Performs standard active object initialisation. |
32 * |
38 * |
33 * @param aObserver Reference to the observer of this state machine |
39 * @param aObserver Reference to the observer of this state machine |
34 * @param aTheLogger The logging object |
|
35 */ |
40 */ |
36 : CActive(EPriorityHigh), |
41 : CActive(EPriorityHigh), |
37 iObserver(aObserver), |
42 iObserver(aObserver), |
38 iTheLogger(aTheLogger), |
|
39 iMaxPacketSize(aMaxPacketSize) |
43 iMaxPacketSize(aMaxPacketSize) |
40 { |
44 { |
41 CActiveScheduler::Add(this); |
45 CActiveScheduler::Add(this); |
42 } |
46 } |
43 |
47 |
44 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize) |
48 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, TUint aMaxPacketSize) |
45 /** |
49 /** |
46 * Two-phase constructor. Creates a new CBcaIoController object, performs |
50 * Two-phase constructor. Creates a new CBcaIoController object, performs |
47 * second-phase construction, then returns it. |
51 * second-phase construction, then returns it. |
48 * |
52 * |
49 * @param aObserver The observer, to which events will be reported |
53 * @param aObserver The observer, to which events will be reported |
50 * @param aTheLogger The logging object |
|
51 * @return A newly constructed CBcaIoController object |
54 * @return A newly constructed CBcaIoController object |
52 */ |
55 */ |
53 { |
56 { |
54 CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSize); |
57 CReceiver* self = new (ELeave) CReceiver(aObserver, aMaxPacketSize); |
55 CleanupStack::PushL(self); |
58 CleanupStack::PushL(self); |
56 self->ConstructL(); |
59 self->ConstructL(); |
57 CleanupStack::Pop(self); |
60 CleanupStack::Pop(self); |
58 return self; |
61 return self; |
59 } |
62 } |
61 void CReceiver::ConstructL() |
64 void CReceiver::ConstructL() |
62 /** |
65 /** |
63 * Second-phase constructor. Creates all the state objects it owns. |
66 * Second-phase constructor. Creates all the state objects it owns. |
64 */ |
67 */ |
65 { |
68 { |
66 _LOG_L1C1(_L8("CReceiver::ConstructL")); |
69 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_CONSTRUCTL_1, "CReceiver::ConstructL"); |
67 iData.CreateL(iMaxPacketSize); |
70 iData.CreateL(iMaxPacketSize); |
68 } |
71 } |
69 |
72 |
70 CReceiver::~CReceiver() |
73 CReceiver::~CReceiver() |
71 /** |
74 /** |
83 /** |
86 /** |
84 * Method called when read request completes. This will only be once the BCA has a full IP |
87 * Method called when read request completes. This will only be once the BCA has a full IP |
85 * packet in its buffer. |
88 * packet in its buffer. |
86 */ |
89 */ |
87 { |
90 { |
88 _LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int()); |
91 OstTraceDef1(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_1, "CReceiver::RunL [iStatus=%d]", iStatus.Int()); |
89 |
92 |
90 if (iStatus != KErrNone) |
93 if (iStatus != KErrNone) |
91 { |
94 { |
92 if (iStatus == KErrNoMemory) |
95 if (iStatus == KErrNoMemory) |
93 { |
96 { |
94 _LOG_L2C1( |
97 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_2, "WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer."); |
95 _L8("WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer.")); |
98 // Read operation failed!! Nif will re-issue the read request. Increase buffer. |
96 // Read operation failed!! Nif will re-issue the read request. Increase buffer. |
|
97 if ((iMaxPacketSize + KBufferIncreaseStep) > K64k) |
99 if ((iMaxPacketSize + KBufferIncreaseStep) > K64k) |
98 { |
100 { |
99 // In theory IP packet can't be bigger than 64k, so if we come here something is wrong so stop observer. |
101 // In theory IP packet can't be bigger than 64k, so if we come here something is wrong so stop observer. |
100 iObserver.Stop(KErrNoMemory); |
102 iObserver.Stop(KErrNoMemory); |
101 } |
103 } |
114 } |
116 } |
115 } |
117 } |
116 } |
118 } |
117 else |
119 else |
118 { |
120 { |
119 _LOG_L2C1(_L8("WARNING! CReceiver: Read failed")); |
121 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_3, "WARNING! CReceiver: Read failed"); |
120 iObserver.Stop(iStatus.Int()); |
122 iObserver.Stop(iStatus.Int()); |
121 } |
123 } |
122 return; |
124 return; |
123 } |
125 } |
124 else |
126 else |
125 { |
127 { |
126 _LOG_L1C1(_L8("CReceiver: Data Packet Received")); |
128 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNL_4, "CReceiver: Data Packet Received"); |
127 |
129 |
128 iRMBufPacket.CreateL(iData); |
130 iRMBufPacket.CreateL(iData); |
129 |
131 |
130 // Immediately execute new read request. |
132 // Immediately execute new read request. |
131 (iObserver.Bca())->Read(iStatus, iData); |
133 (iObserver.Bca())->Read(iStatus, iData); |
132 |
134 |
133 SetActive(); |
135 SetActive(); |
134 |
136 |
135 iRMBufPacket.Pack(); |
137 iRMBufPacket.Pack(); |
136 |
138 |
137 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
139 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
138 TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket); |
140 TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket); |
139 #else |
141 #else |
140 TUint16 protocolCode = 0; |
142 TUint16 protocolCode = 0; |
141 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
143 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
146 } |
148 } |
147 } |
149 } |
148 |
150 |
149 TInt CReceiver::RunError(TInt aError) |
151 TInt CReceiver::RunError(TInt aError) |
150 { |
152 { |
151 _LOG_L2C1(_L8("WARNING! CReceiver::RunError Read failed")); |
153 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_RUNERROR_1, "WARNING! CReceiver::RunError Read failed"); |
152 iObserver.Stop(aError); |
154 iObserver.Stop(aError); |
153 return KErrNone; |
155 return KErrNone; |
154 } |
156 } |
155 |
157 |
156 void CReceiver::DoCancel() |
158 void CReceiver::DoCancel() |
157 /** |
159 /** |
158 * Cancel active request |
160 * Cancel active request |
159 */ |
161 */ |
160 { |
162 { |
161 _LOG_L1C1(_L8("CReceiver::DoCancel")); |
163 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_DOCANCEL_1, "CReceiver::DoCancel"); |
162 |
164 |
163 (iObserver.Bca())->CancelRead(); |
165 (iObserver.Bca())->CancelRead(); |
164 } |
166 } |
165 |
167 |
166 void CReceiver::StartListening() |
168 void CReceiver::StartListening() |
167 /** |
169 /** |
168 * This method issues a Read request. This is the API used to receive |
170 * This method issues a Read request. This is the API used to receive |
169 * packets from BCA. |
171 * packets from BCA. |
170 */ |
172 */ |
171 { |
173 { |
172 _LOG_L1C1(_L8("CReceiver::StartListening")); |
174 OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CRECEIVER_STARTLISTENING_1, "CReceiver::StartListening"); |
173 |
175 |
174 // The BCA will complete this read once it has a full IP packet in its buffer. |
176 // The BCA will complete this read once it has a full IP packet in its buffer. |
175 (iObserver.Bca())->Read(iStatus, iData); |
177 (iObserver.Bca())->Read(iStatus, iData); |
176 |
178 |
177 SetActive(); |
179 SetActive(); |