|
1 // Copyright (c) 1997-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 // IrLAN data send/receive active objects |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 */ |
|
21 |
|
22 #include <nifman.h> |
|
23 #include <nifvar.h> |
|
24 #include <nifutl.h> |
|
25 #include <es_mbuf.h> |
|
26 #include "PKTDRV.H" |
|
27 #include "IRLAN.H" |
|
28 #include "IRLANUTL.H" |
|
29 #include "IRLANBUF.H" |
|
30 #include "INTSOCK.H" |
|
31 |
|
32 //#define __TRACEWIN__ |
|
33 #ifdef __TRACEWIN__ |
|
34 #include <log.h> |
|
35 #else |
|
36 #define LOG(a) |
|
37 #endif |
|
38 |
|
39 //############################ IrLAN Sender ############################ |
|
40 |
|
41 /** |
|
42 Constructor. |
|
43 */ |
|
44 CIrlanSender::CIrlanSender() : CActive(EIrlanSenderPriority) |
|
45 { |
|
46 __DECLARE_NAME(_S("CIrlanSender")); |
|
47 } |
|
48 |
|
49 /** |
|
50 Destructor. |
|
51 */ |
|
52 CIrlanSender::~CIrlanSender() |
|
53 { |
|
54 #ifdef __TRACEWIN__ |
|
55 LOG(Log::Printf(_L("IRLAN ~CIrlanSender\r\n"))); |
|
56 #endif |
|
57 } |
|
58 |
|
59 /** |
|
60 Create a new CIrlanSender object. |
|
61 @param aParent A pointer to CIrlanControlEngine object. |
|
62 @param aSock A pointer to CInternalSocket object. |
|
63 @return A pointer to CIrlanSender class. |
|
64 */ |
|
65 CIrlanSender* CIrlanSender::NewL(CIrlanControlEngine* aParent,CInternalSocket* aSock) |
|
66 { |
|
67 #ifdef __TRACEWIN__ |
|
68 LOG(Log::Printf(_L("IRLAN CIrlanSender::NewL\r\n"))); |
|
69 #endif |
|
70 CIrlanSender *sd=new (ELeave) CIrlanSender; |
|
71 CleanupStack::PushL(sd); |
|
72 sd->InitL(aParent,aSock); |
|
73 CActiveScheduler::Add(sd); |
|
74 CleanupStack::Pop(); |
|
75 return sd; |
|
76 } |
|
77 |
|
78 /** |
|
79 Add the newly created object to an object container |
|
80 @param aParent A pointer to CIrlanControlEngine object. |
|
81 @param aSock A pointer to CInternalSocket object. |
|
82 */ |
|
83 void CIrlanSender::InitL(CIrlanControlEngine* aParent,CInternalSocket* aSock) |
|
84 { |
|
85 iParent=aParent; |
|
86 iDataSock=aSock; |
|
87 } |
|
88 |
|
89 /** |
|
90 Waits to read the data from the Queue. |
|
91 @param aPdu A reference to the packet to be sent (really an RMBufPkt) |
|
92 */ |
|
93 void CIrlanSender::QueueSend(RMBufChain& aPdu) |
|
94 { |
|
95 if (iDataSock->Write(aPdu,NULL,iStatus,0)!=static_cast<TUint>(KErrNone)) |
|
96 IrlanUtil::Panic(EIrlanDataWrite); |
|
97 SetActive(); |
|
98 } |
|
99 |
|
100 /** |
|
101 Initiate sending for tha data. |
|
102 */ |
|
103 void CIrlanSender::KickSender() |
|
104 { |
|
105 if (IsActive()) |
|
106 return; |
|
107 else |
|
108 SeeIfPacketToSend(); |
|
109 } |
|
110 |
|
111 /** |
|
112 Check in Queue whether the packet to send. |
|
113 */ |
|
114 void CIrlanSender::SeeIfPacketToSend() |
|
115 { |
|
116 RMBufChain pkt; |
|
117 if (iParent->iDataSendQ.Remove(pkt)) |
|
118 { |
|
119 QueueSend(pkt); |
|
120 pkt.Free(); |
|
121 } |
|
122 } |
|
123 |
|
124 /** |
|
125 Handles an active object’s request completion event. |
|
126 */ |
|
127 void CIrlanSender::RunL() |
|
128 { |
|
129 TInt ret=iStatus.Int(); |
|
130 if (ret!=KErrNone) |
|
131 { |
|
132 #ifdef __TRACEWIN__ |
|
133 LOG(Log::Printf(_L("IRLAN Data send failed with err=%d\r\n"),ret)); |
|
134 #endif |
|
135 iParent->HandleErrorL(); |
|
136 return; |
|
137 } |
|
138 SeeIfPacketToSend(); |
|
139 } |
|
140 |
|
141 /** |
|
142 cancellation of an outstanding request. |
|
143 */ |
|
144 void CIrlanSender::DoCancel() |
|
145 { |
|
146 iDataSock->CancelSend(); |
|
147 } |
|
148 |
|
149 //############################ IrLAN Receiver ############################ |
|
150 |
|
151 /** |
|
152 Constructor. |
|
153 */ |
|
154 CIrlanReceiver::CIrlanReceiver() : CActive(EIrlanReceiverPriority) |
|
155 { |
|
156 __DECLARE_NAME(_S("CIrlanReceiver")); |
|
157 } |
|
158 |
|
159 /** |
|
160 Destructor. |
|
161 */ |
|
162 CIrlanReceiver::~CIrlanReceiver() |
|
163 { |
|
164 DoCancel(); |
|
165 } |
|
166 |
|
167 /** |
|
168 Create a new CIrlanReceiver object. |
|
169 @param aParent A pointer to CIrlanControlEngine object. |
|
170 @param aSock A pointer to CInternalSocket object. |
|
171 @return A pointer to CIrlanReceiver class. |
|
172 */ |
|
173 CIrlanReceiver* CIrlanReceiver::NewL(CIrlanControlEngine* aParent,CInternalSocket* aSock) |
|
174 { |
|
175 #ifdef __TRACEWIN__ |
|
176 LOG(Log::Printf(_L("IRLAN CIrlanReceiver::NewL\r\n"))); |
|
177 #endif |
|
178 CIrlanReceiver *rv=new (ELeave) CIrlanReceiver; |
|
179 CleanupStack::PushL(rv); |
|
180 rv->InitL(aParent,aSock); |
|
181 CActiveScheduler::Add(rv); |
|
182 CleanupStack::Pop(); |
|
183 return rv; |
|
184 } |
|
185 |
|
186 /** |
|
187 Add the newly created object to an object container |
|
188 |
|
189 @param aParent A pointer to CIrlanControlEngine object. |
|
190 @param aSock A pointer to CInternalSocket object. |
|
191 */ |
|
192 void CIrlanReceiver::InitL(CIrlanControlEngine* aParent,CInternalSocket* aSock) |
|
193 { |
|
194 iParent=aParent; |
|
195 iDataSock=aSock; |
|
196 } |
|
197 |
|
198 /** |
|
199 Waits to read the data from the Queue. |
|
200 */ |
|
201 void CIrlanReceiver::QueueRead() |
|
202 { |
|
203 #ifdef __TRACEWIN__ |
|
204 LOG(Log::Printf(_L("IRLAN QUEUEING WAIT FOR DATA\r\n"))); |
|
205 #endif |
|
206 |
|
207 iParent->iRecvBufPtr.SetLength(iParent->iRecvBufLength); |
|
208 TInt ret; |
|
209 ret = iDataSock->Recv(iParent->iRecvBufPtr,NULL,iStatus,0); |
|
210 if (ret!=KErrNone) |
|
211 {// what do we do here - panic? |
|
212 IrlanUtil::Panic(EIrlanDataRead); |
|
213 } |
|
214 SetActive(); |
|
215 } |
|
216 |
|
217 /** |
|
218 Handles an active object’s request completion event. |
|
219 */ |
|
220 void CIrlanReceiver::RunL() |
|
221 { |
|
222 TInt ret=iStatus.Int(); |
|
223 if (ret!=KErrNone) |
|
224 { |
|
225 #ifdef __TRACEWIN__ |
|
226 LOG(Log::Printf(_L("IRLAN Data receive failed with err=%d\r\n"),ret)); |
|
227 #endif |
|
228 iParent->HandleErrorL(); |
|
229 return; |
|
230 } |
|
231 iParent->ProcessReceivedPacketL(); |
|
232 QueueRead(); |
|
233 } |
|
234 |
|
235 /** |
|
236 cancellation of an outstanding request. |
|
237 */ |
|
238 void CIrlanReceiver::DoCancel() |
|
239 { |
|
240 iDataSock->CancelRecv(); |
|
241 } |