author | ivan.fildichev@opencode.com |
Fri, 15 Oct 2010 11:27:58 +0300 | |
branch | opencode |
changeset 78 | d4cfc65049ba |
parent 32 | 58332560b319 |
permissions | -rw-r--r-- |
24 | 1 |
// Copyright (c) 2002-2010 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 |
// Implements the active object that controls the Read() requests. |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
*/ |
|
21 |
||
22 |
#include "Receiver.h" |
|
23 |
#include "Constants.h" |
|
24 |
#include <es_ini.h> |
|
25 |
||
26 |
const TUint KBufferIncreaseStep=500; |
|
27 |
const TUint K64k=65535; |
|
28 |
||
29 |
CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize) |
|
30 |
/** |
|
31 |
* Constructor. Performs standard active object initialisation. |
|
32 |
* |
|
33 |
* @param aObserver Reference to the observer of this state machine |
|
34 |
* @param aTheLogger The logging object |
|
35 |
*/ |
|
36 |
: CActive(EPriorityHigh), |
|
37 |
iObserver(aObserver), |
|
38 |
iTheLogger(aTheLogger), |
|
39 |
iMaxPacketSize(aMaxPacketSize) |
|
40 |
{ |
|
41 |
CActiveScheduler::Add(this); |
|
42 |
} |
|
43 |
||
44 |
CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TUint aMaxPacketSize) |
|
45 |
/** |
|
46 |
* Two-phase constructor. Creates a new CBcaIoController object, performs |
|
47 |
* second-phase construction, then returns it. |
|
48 |
* |
|
49 |
* @param aObserver The observer, to which events will be reported |
|
50 |
* @param aTheLogger The logging object |
|
51 |
* @return A newly constructed CBcaIoController object |
|
52 |
*/ |
|
53 |
{ |
|
54 |
CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSize); |
|
55 |
CleanupStack::PushL(self); |
|
56 |
self->ConstructL(); |
|
57 |
CleanupStack::Pop(self); |
|
58 |
return self; |
|
59 |
} |
|
60 |
||
61 |
void CReceiver::ConstructL() |
|
62 |
/** |
|
63 |
* Second-phase constructor. Creates all the state objects it owns. |
|
64 |
*/ |
|
65 |
{ |
|
66 |
_LOG_L1C1(_L8("CReceiver::ConstructL")); |
|
67 |
iData.CreateL(iMaxPacketSize); |
|
68 |
} |
|
69 |
||
70 |
CReceiver::~CReceiver() |
|
71 |
/** |
|
72 |
* Destructor. |
|
73 |
*/ |
|
74 |
{ |
|
75 |
iData.Close(); |
|
76 |
Cancel(); |
|
77 |
} |
|
78 |
||
79 |
void CReceiver::RunL() |
|
80 |
/** |
|
81 |
* Method called when read request completes. This will only be once the BCA has a full IP |
|
82 |
* packet in its buffer. |
|
83 |
*/ |
|
84 |
{ |
|
85 |
_LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int()); |
|
86 |
||
87 |
if (iStatus != KErrNone) |
|
88 |
{ |
|
89 |
if (iStatus == KErrNoMemory) |
|
90 |
{ |
|
91 |
_LOG_L2C1( |
|
92 |
_L8("WARNING! CReceiver: Read failed with KErrNoMemory. Increase buffer.")); |
|
93 |
// Read operation failed!! Nif will re-issue the read request. Increase buffer. |
|
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 |
} |
|
113 |
} |
|
114 |
else |
|
115 |
{ |
|
116 |
_LOG_L2C1(_L8("WARNING! CReceiver: Read failed")); |
|
117 |
iObserver.Stop(iStatus.Int()); |
|
118 |
} |
|
119 |
return; |
|
120 |
} |
|
121 |
else |
|
122 |
{ |
|
123 |
_LOG_L1C1(_L8("CReceiver: Data Packet Received")); |
|
124 |
||
125 |
iRMBufPacket.CreateL(iData); |
|
126 |
||
127 |
// Immediately execute new read request. |
|
128 |
(iObserver.Bca())->Read(iStatus, iData); |
|
129 |
||
130 |
SetActive(); |
|
131 |
||
132 |
iRMBufPacket.Pack(); |
|
133 |
||
134 |
#ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
135 |
TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket); |
|
136 |
#else |
|
137 |
TUint16 protocolCode = 0; |
|
138 |
#endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
139 |
||
140 |
// Process the packet |
|
141 |
iObserver.GetObserver().Process(iRMBufPacket, protocolCode); |
|
142 |
iRMBufPacket.Free(); |
|
143 |
} |
|
144 |
} |
|
145 |
||
32
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
146 |
TInt CReceiver::RunError(TInt aError) |
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
147 |
{ |
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
148 |
_LOG_L2C1(_L8("WARNING! CReceiver::RunError Read failed")); |
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
149 |
iObserver.Stop(aError); |
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
150 |
return KErrNone; |
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
151 |
} |
58332560b319
Bring opencode branch up-to-date with latest cellularsrv changes
Oscar Gonzalez <oscar.1.gonzalez@nokia.com>
parents:
24
diff
changeset
|
152 |
|
24 | 153 |
void CReceiver::DoCancel() |
154 |
/** |
|
155 |
* Cancel active request |
|
156 |
*/ |
|
157 |
{ |
|
158 |
_LOG_L1C1(_L8("CReceiver::DoCancel")); |
|
159 |
||
160 |
(iObserver.Bca())->CancelRead(); |
|
161 |
} |
|
162 |
||
163 |
void CReceiver::StartListening() |
|
164 |
/** |
|
165 |
* This method issues a Read request. This is the API used to receive |
|
166 |
* packets from BCA. |
|
167 |
*/ |
|
168 |
{ |
|
169 |
_LOG_L1C1(_L8("CReceiver::StartListening")); |
|
170 |
||
171 |
// The BCA will complete this read once it has a full IP packet in its buffer. |
|
172 |
(iObserver.Bca())->Read(iStatus, iData); |
|
173 |
||
174 |
SetActive(); |
|
175 |
} |