24
|
1 |
// Copyright (c) 2004-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 |
// C32 Baseband Channel Adaptor(BCA) Factory APIs implementation.
|
|
15 |
// This file contains all the API implementations of C32BcaFactory for Symbian OS.
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
/**
|
|
20 |
@file
|
|
21 |
@internalComponent
|
|
22 |
*/
|
|
23 |
#include "MBca2Impl.h"
|
|
24 |
#include <networking/bca.h>
|
|
25 |
#include <comms-infras/commsbuf.h>
|
|
26 |
#include "C32BcaFactory.h"
|
|
27 |
|
|
28 |
using namespace BasebandChannelAdaptation;
|
|
29 |
using namespace BasebandChannelAdaptation::C32Bca;
|
|
30 |
using namespace BasebandChannelAdaptation2;
|
|
31 |
using namespace BasebandChannelAdaptation2::C32BcaShim;
|
|
32 |
|
|
33 |
MBca2* MBca2FactoryImpl::NewBcaL()
|
|
34 |
{
|
|
35 |
MBca2Impl* instance = new(ELeave) MBca2Impl;
|
|
36 |
CleanupStack::PushL(instance);
|
|
37 |
instance->ConstructL();
|
|
38 |
CleanupStack::Pop(instance);
|
|
39 |
return instance;
|
|
40 |
}
|
|
41 |
|
|
42 |
void MBca2FactoryImpl::Release()
|
|
43 |
{
|
|
44 |
delete this;
|
|
45 |
}
|
|
46 |
|
|
47 |
MBca2Impl::MBca2Impl() : iControl(NULL),
|
|
48 |
iBcaParams(NULL),
|
|
49 |
iLowerDataSender(NULL),
|
|
50 |
iReceiver(NULL),
|
|
51 |
iMBca(NULL),
|
|
52 |
iC32BcaFactory(NULL),
|
|
53 |
iRecvBlocked(EFalse)
|
|
54 |
{
|
|
55 |
|
|
56 |
}
|
|
57 |
|
|
58 |
MBca2Impl::~MBca2Impl()
|
|
59 |
{
|
|
60 |
iReceiver->Cancel();
|
|
61 |
delete iReceiver;
|
|
62 |
delete iLowerDataSender;
|
|
63 |
iMBca->Release();
|
|
64 |
iC32BcaFactory->Release();
|
|
65 |
}
|
|
66 |
|
|
67 |
void MBca2Impl::ConstructL()
|
|
68 |
{
|
|
69 |
iC32BcaFactory = new(ELeave) CC32BcaFactory;
|
|
70 |
iMBca = iC32BcaFactory->NewBcaL();
|
|
71 |
iLowerDataSender = MLowerDataSenderImpl::NewL(iMBca);
|
|
72 |
iReceiver = new (ELeave) CReceiver(iMBca);
|
|
73 |
}
|
|
74 |
|
|
75 |
TInt MBca2Impl::Open(MUpperControl& aControl,
|
|
76 |
MUpperDataReceiver& aData,
|
|
77 |
const TBcaParams& aBcaParams)
|
|
78 |
{
|
|
79 |
iControl = &aControl;
|
|
80 |
iLowerDataSender->SetControl(&aControl);
|
|
81 |
iReceiver->SetParams(&aData,&aBcaParams);
|
|
82 |
iBcaParams = &aBcaParams;
|
|
83 |
return KErrNone;
|
|
84 |
}
|
|
85 |
|
|
86 |
void MBca2Impl::Start()
|
|
87 |
{
|
|
88 |
TRequestStatus status;
|
|
89 |
iMBca->Open(status,iBcaParams->iChannelId);
|
|
90 |
User::WaitForRequest(status);
|
|
91 |
TInt ret = status.Int();
|
|
92 |
|
|
93 |
if (ret != KErrNone && ret != KErrAlreadyExists )
|
|
94 |
{
|
|
95 |
TRequestStatus shutdownStatus;
|
|
96 |
iMBca->Shutdown(shutdownStatus);
|
|
97 |
User::WaitForRequest(shutdownStatus);
|
|
98 |
}
|
|
99 |
else
|
|
100 |
{
|
|
101 |
iControl->StartSending();
|
|
102 |
iReceiver->StartListening();
|
|
103 |
}
|
|
104 |
return;
|
|
105 |
}
|
|
106 |
|
|
107 |
MLowerDataSender& MBca2Impl::GetSender()
|
|
108 |
{
|
|
109 |
return *iLowerDataSender;
|
|
110 |
}
|
|
111 |
|
|
112 |
void MBca2Impl::Close()
|
|
113 |
{
|
|
114 |
iMBca->Close();
|
|
115 |
}
|
|
116 |
|
|
117 |
void MBca2Impl::Release()
|
|
118 |
{
|
|
119 |
delete this;
|
|
120 |
}
|
|
121 |
|
|
122 |
void MBca2Impl::SetFlowControl(TBlockOption aOption)
|
|
123 |
{
|
|
124 |
if(aOption == EBlockFlow)
|
|
125 |
{
|
|
126 |
iRecvBlocked = ETrue;
|
|
127 |
iReceiver->Cancel();
|
|
128 |
}
|
|
129 |
else if(aOption == EUnblockFlow)
|
|
130 |
{
|
|
131 |
if( iRecvBlocked)
|
|
132 |
{
|
|
133 |
iReceiver->StartListening();
|
|
134 |
}
|
|
135 |
else
|
|
136 |
{
|
|
137 |
iRecvBlocked = EFalse;
|
|
138 |
}
|
|
139 |
}
|
|
140 |
}
|
|
141 |
|
|
142 |
void MBca2Impl::Control(TRequestStatus& aStatus,
|
|
143 |
TUint aOptLevel,
|
|
144 |
TUint aOptName,
|
|
145 |
TDes8& aOpt)
|
|
146 |
{
|
|
147 |
iMBca->Ioctl(aStatus,aOptLevel,aOptName,aOpt);
|
|
148 |
}
|
|
149 |
|
|
150 |
void MBca2Impl::CancelControl()
|
|
151 |
{
|
|
152 |
iMBca->CancelIoctl();
|
|
153 |
}
|
|
154 |
|
|
155 |
MLowerDataSenderImpl* MLowerDataSenderImpl::NewL(BasebandChannelAdaptation::MBca* aMBca)
|
|
156 |
{
|
|
157 |
MLowerDataSenderImpl* instance = new (ELeave) MLowerDataSenderImpl;
|
|
158 |
CleanupStack::PushL(instance);
|
|
159 |
instance->ConstructL(aMBca);
|
|
160 |
CleanupStack::Pop(instance);
|
|
161 |
return instance;
|
|
162 |
}
|
|
163 |
|
|
164 |
MLowerDataSenderImpl::MLowerDataSenderImpl() : iSender(NULL), iControl(NULL), iSendBlocked(EFalse)
|
|
165 |
{
|
|
166 |
|
|
167 |
}
|
|
168 |
|
|
169 |
void MLowerDataSenderImpl::ConstructL(BasebandChannelAdaptation::MBca* aMBca)
|
|
170 |
{
|
|
171 |
iSender = new (ELeave) CSender(aMBca);
|
|
172 |
}
|
|
173 |
|
|
174 |
MLowerDataSenderImpl::~MLowerDataSenderImpl()
|
|
175 |
{
|
|
176 |
iSender->Cancel();
|
|
177 |
delete iSender;
|
|
178 |
}
|
|
179 |
|
|
180 |
void MLowerDataSenderImpl::SetControl(MUpperControl* aControl)
|
|
181 |
{
|
|
182 |
iControl = aControl;
|
|
183 |
}
|
|
184 |
|
|
185 |
MLowerDataSender::TSendResult MLowerDataSenderImpl::Send(RCommsBufChain& aCommsBufChain)
|
|
186 |
{
|
|
187 |
TRequestStatus status;
|
|
188 |
TInt retSend = iSender->Send(status, aCommsBufChain);
|
|
189 |
if(retSend == -1)
|
|
190 |
{
|
|
191 |
iSendBlocked = ETrue;
|
|
192 |
return ESendBlocked;
|
|
193 |
}
|
|
194 |
User::WaitForRequest(status);
|
|
195 |
TInt ret = status.Int();
|
|
196 |
if(ret == KErrNone)
|
|
197 |
{
|
|
198 |
if(iSendBlocked)
|
|
199 |
{
|
|
200 |
iControl->StartSending();
|
|
201 |
iSendBlocked = EFalse;
|
|
202 |
}
|
|
203 |
return ESendAccepted;
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{
|
|
207 |
iControl->Error(ret);
|
|
208 |
return ESendBlocked;
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
CReceiver::CReceiver(BasebandChannelAdaptation::MBca* aMBca) : CActive(EPriorityNormal), iMBca(aMBca)
|
|
213 |
{
|
|
214 |
CActiveScheduler::Add(this);
|
|
215 |
}
|
|
216 |
|
|
217 |
CReceiver::~CReceiver()
|
|
218 |
{
|
|
219 |
|
|
220 |
}
|
|
221 |
|
|
222 |
void CReceiver::SetParams(MUpperDataReceiver* aDataReceiver, const MBca2::TBcaParams* aBcaParams)
|
|
223 |
{
|
|
224 |
iDataReceiver = aDataReceiver;
|
|
225 |
iBcaParams = aBcaParams;
|
|
226 |
}
|
|
227 |
|
|
228 |
void CReceiver::RunL()
|
|
229 |
{
|
|
230 |
TCommsBufAllocator allocator = const_cast<RCommsBufPond&>(iBcaParams->iCommsBufPond).Allocator();
|
|
231 |
iBufChain.Alloc(iData.Length(),allocator);
|
|
232 |
iBufChain.Write(iData);
|
|
233 |
iDataReceiver->Process(iBufChain);
|
|
234 |
StartListening();
|
|
235 |
}
|
|
236 |
|
|
237 |
void CReceiver::DoCancel()
|
|
238 |
{
|
|
239 |
iMBca->CancelRead();
|
|
240 |
}
|
|
241 |
|
|
242 |
void CReceiver::StartListening()
|
|
243 |
{
|
|
244 |
// call read on MBca
|
|
245 |
iData.SetMax();
|
|
246 |
iMBca->Read(iStatus,iData);
|
|
247 |
SetActive();
|
|
248 |
}
|
|
249 |
|
|
250 |
CSender::CSender(BasebandChannelAdaptation::MBca* aMBca) : CActive(EPriorityNormal), iMBca(aMBca)
|
|
251 |
{
|
|
252 |
CActiveScheduler::Add(this);
|
|
253 |
}
|
|
254 |
CSender::~CSender()
|
|
255 |
{
|
|
256 |
|
|
257 |
}
|
|
258 |
|
|
259 |
void CSender::RunL()
|
|
260 |
{
|
|
261 |
User::RequestComplete(iSendRequest, iStatus.Int());
|
|
262 |
}
|
|
263 |
|
|
264 |
void CSender::DoCancel()
|
|
265 |
{
|
|
266 |
iMBca->CancelWrite();
|
|
267 |
}
|
|
268 |
|
|
269 |
TInt CSender::Send(TRequestStatus& aStatus,RCommsBufChain& aPdu)
|
|
270 |
{
|
|
271 |
if(iStatus == KRequestPending)
|
|
272 |
{
|
|
273 |
return -1;
|
|
274 |
}
|
|
275 |
else
|
|
276 |
{
|
|
277 |
aStatus = KRequestPending;
|
|
278 |
iSendRequest = &aStatus;
|
|
279 |
TBuf8<KMaxIPPacketAndHeader> buffer;
|
|
280 |
if(aPdu.Length() > KMaxIPPacketAndHeader)
|
|
281 |
{
|
|
282 |
// discard packet and return
|
|
283 |
aPdu.Free();
|
|
284 |
User::RequestComplete(iSendRequest, KErrNone);
|
|
285 |
return 0;
|
|
286 |
}
|
|
287 |
buffer.SetLength(aPdu.Length());
|
|
288 |
aPdu.Read(buffer);
|
|
289 |
aPdu.Free();
|
|
290 |
SendBuffer(buffer);
|
|
291 |
return 0;
|
|
292 |
}
|
|
293 |
|
|
294 |
}
|
|
295 |
void CSender::SendBuffer(const TDesC8& aBuffer)
|
|
296 |
{
|
|
297 |
iMBca->Write(iStatus,aBuffer);
|
|
298 |
SetActive();
|
|
299 |
}
|
|
300 |
|