|
1 // Copyright (c) 2002-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 // 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 CReceiver::CReceiver(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise) |
|
27 /** |
|
28 * Constructor. Performs standard active object initialisation. |
|
29 * |
|
30 * @param aObserver Reference to the observer of this state machine |
|
31 * @param aTheLogger The logging object |
|
32 */ |
|
33 : CActive(EPriorityHigh), |
|
34 iObserver(aObserver), |
|
35 iTheLogger(aTheLogger), |
|
36 iMaxPacketSise(aMaxPacketSise) |
|
37 { |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 CReceiver* CReceiver::NewL(CBcaIoController& aObserver, CBttLogger* aTheLogger, TInt aMaxPacketSise) |
|
42 /** |
|
43 * Two-phase constructor. Creates a new CBcaIoController object, performs |
|
44 * second-phase construction, then returns it. |
|
45 * |
|
46 * @param aObserver The observer, to which events will be reported |
|
47 * @param aTheLogger The logging object |
|
48 * @return A newly constructed CBcaIoController object |
|
49 */ |
|
50 { |
|
51 CReceiver* self = new (ELeave) CReceiver(aObserver, aTheLogger, aMaxPacketSise); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 void CReceiver::ConstructL() |
|
59 /** |
|
60 * Second-phase constructor. Creates all the state objects it owns. |
|
61 */ |
|
62 { |
|
63 _LOG_L1C1(_L8("CReceiver::ConstructL")); |
|
64 iData.CreateL(iMaxPacketSise); |
|
65 } |
|
66 |
|
67 CReceiver::~CReceiver() |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 { |
|
72 iData.Close(); |
|
73 Cancel(); |
|
74 } |
|
75 |
|
76 void CReceiver::RunL() |
|
77 /** |
|
78 * Method called when read request completes. This will only be once the BCA has a full IP |
|
79 * packet in its buffer. |
|
80 */ |
|
81 { |
|
82 _LOG_L1C2(_L8("CReceiver::RunL [iStatus=%d]"), iStatus.Int()); |
|
83 |
|
84 if (iStatus!=KErrNone) |
|
85 { |
|
86 if(iStatus == KErrNoMemory) |
|
87 { |
|
88 _LOG_L2C1( |
|
89 _L8("WARNING! CReceiver: Read failed with KErrNoMemory")); |
|
90 // Read operation failed!! Nif will re-issue the read request. |
|
91 StartListening(); |
|
92 } |
|
93 else |
|
94 { |
|
95 _LOG_L2C1(_L8("WARNING! CReceiver: Read failed")); |
|
96 iObserver.Stop(iStatus.Int()); |
|
97 } |
|
98 return; |
|
99 } |
|
100 |
|
101 _LOG_L1C1(_L8("CReceiver: Data Packet Received")); |
|
102 |
|
103 iRMBufPacket.CreateL(iData); |
|
104 iRMBufPacket.Pack(); |
|
105 |
|
106 // Immediately execute new read request. |
|
107 StartListening(); |
|
108 |
|
109 #ifdef RAWIP_HEADER_APPENDED_TO_PACKETS |
|
110 TUint16 protocolCode = iObserver.RemoveHeader(iRMBufPacket); |
|
111 #else |
|
112 TUint16 protocolCode = 0; |
|
113 #endif // RAWIP_HEADER_APPENDED_TO_PACKETS |
|
114 |
|
115 // Process the packet |
|
116 iObserver.GetObserver().Process(iRMBufPacket, protocolCode); |
|
117 iRMBufPacket.Free(); |
|
118 } |
|
119 |
|
120 void CReceiver::DoCancel() |
|
121 /** |
|
122 * Cancel active request |
|
123 */ |
|
124 { |
|
125 _LOG_L1C1(_L8("CReceiver::DoCancel")); |
|
126 |
|
127 (iObserver.Bca())->CancelRead(); |
|
128 } |
|
129 |
|
130 void CReceiver::StartListening() |
|
131 /** |
|
132 * This method issues a Read request. This is the API used to receive |
|
133 * packets from BCA. |
|
134 */ |
|
135 { |
|
136 _LOG_L1C1(_L8("CReceiver::StartListening")); |
|
137 |
|
138 // The BCA will complete this read once it has a full IP packet in its buffer. |
|
139 (iObserver.Bca())->Read(iStatus, iData); |
|
140 |
|
141 SetActive(); |
|
142 } |