0
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
1
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
0
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
1
|
14 |
* Description:
|
0
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#define TRACE_PREFIX "WSOCK: Interface: "
|
|
20 |
#include "wsock.h"
|
|
21 |
#include "WinsockInterface.h"
|
|
22 |
#include "WinsockProtocolFamily.h"
|
1
|
23 |
#include <es_enum_partner.h>
|
0
|
24 |
|
|
25 |
const TInt KWinsockSubConnectionId = 1;
|
|
26 |
const TConnectionType EWinsockConnectionType = EConnectionEthernet;
|
|
27 |
#define super CNifIfLink
|
|
28 |
|
|
29 |
// CWinsockInterface::CallbackQueueEntry
|
|
30 |
class CWinsockInterface::CallbackQueueEntry
|
|
31 |
{
|
|
32 |
private:
|
|
33 |
CWinsockInterface* iInterface;
|
|
34 |
CallbackMethod iMethod;
|
|
35 |
TInt iParam1;
|
|
36 |
TInt iParam2;
|
|
37 |
public:
|
|
38 |
TSglQueLink iLink;
|
|
39 |
CallbackQueueEntry(CWinsockInterface* aInterface, CallbackMethod aMethod,
|
|
40 |
TInt aParam1, TInt aParam2) : iInterface(aInterface),
|
|
41 |
iMethod(aMethod), iParam1(aParam1), iParam2(aParam2) {}
|
|
42 |
void Invoke() { (iInterface->*iMethod)(iParam1, iParam2); }
|
|
43 |
};
|
|
44 |
|
|
45 |
// CWinsockInterface
|
|
46 |
CWinsockInterface::CWinsockInterface(CNifIfFactory* aFactory,
|
|
47 |
MNifIfNotify* aNotify) :
|
|
48 |
super(*aFactory),
|
|
49 |
iSignature(KWinsockInterfaceSignature),
|
|
50 |
iCallbackQueue(_FOFF(CallbackQueueEntry,iLink)),
|
|
51 |
iCallback(TCallBack(AsyncCallbackProc,this),CActive::EPriorityStandard)
|
|
52 |
{
|
|
53 |
iNotify = aNotify;
|
|
54 |
iTimeStarted.HomeTime();
|
|
55 |
TRACE1("created [%08X]",this);
|
|
56 |
}
|
|
57 |
|
|
58 |
CWinsockInterface::~CWinsockInterface()
|
|
59 |
{
|
|
60 |
CancelOutstandingCallbacks();
|
|
61 |
TRACE1("destroyed [%08X]",this);
|
|
62 |
}
|
|
63 |
|
|
64 |
TInt CWinsockInterface::Signature() const
|
|
65 |
{
|
|
66 |
return KWinsockInterfaceSignature;
|
|
67 |
}
|
|
68 |
|
|
69 |
TInt CWinsockInterface::AsyncCallbackProc(TAny* aPtr)
|
|
70 |
{
|
|
71 |
CWinsockInterface* self = (CWinsockInterface*)aPtr;
|
|
72 |
self->HandleAsyncCallback();
|
|
73 |
return KErrNone;
|
|
74 |
}
|
|
75 |
|
|
76 |
void CWinsockInterface::HandleAsyncCallback()
|
|
77 |
{
|
|
78 |
// Invoke the first callback in the queue
|
|
79 |
if (!iCallbackQueue.IsEmpty()) {
|
|
80 |
CallbackQueueEntry* entry = iCallbackQueue.First();
|
|
81 |
iCallbackQueue.Remove(*entry);
|
|
82 |
entry->Invoke();
|
|
83 |
delete entry;
|
|
84 |
|
|
85 |
// Schedule the next one
|
|
86 |
if (!iCallbackQueue.IsEmpty()) {
|
|
87 |
iCallback.CallBack();
|
|
88 |
}
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
void CWinsockInterface::ScheduleAsyncCallback(CallbackMethod aMethod,
|
|
93 |
TInt aP1, TInt aP2)
|
|
94 |
{
|
|
95 |
CallbackQueueEntry* entry = new CallbackQueueEntry(this,aMethod,aP1,aP2);
|
|
96 |
if (entry) {
|
|
97 |
iCallbackQueue.AddLast(*entry);
|
|
98 |
iCallback.Cancel();
|
|
99 |
iCallback.CallBack();
|
|
100 |
}
|
|
101 |
}
|
|
102 |
|
|
103 |
void CWinsockInterface::CancelOutstandingCallbacks()
|
|
104 |
{
|
|
105 |
iCallback.Cancel();
|
|
106 |
while (!iCallbackQueue.IsEmpty()) {
|
|
107 |
CallbackQueueEntry* entry = iCallbackQueue.First();
|
|
108 |
iCallbackQueue.Remove(*entry);
|
|
109 |
delete entry;
|
|
110 |
}
|
|
111 |
}
|
|
112 |
|
|
113 |
void CWinsockInterface::NotifyLinkLayerUp(TInt, TInt)
|
|
114 |
{
|
|
115 |
ScheduleAsyncCallback(NotifySubConnectionOpened);
|
|
116 |
TRACE("firing LinkLayerUp event");
|
|
117 |
iNotify->LinkLayerUp();
|
|
118 |
}
|
|
119 |
|
|
120 |
void CWinsockInterface::NotifyLinkLayerOpen(TInt, TInt)
|
|
121 |
{
|
|
122 |
TRACE("firing LinkLayerOpen event");
|
|
123 |
iNotify->IfProgress(KLinkLayerOpen, KErrNone);
|
|
124 |
}
|
|
125 |
|
|
126 |
// Sends a subconnection opened event for the entire connection
|
|
127 |
void CWinsockInterface::NotifySubConnectionOpened(TInt, TInt)
|
|
128 |
{
|
|
129 |
ScheduleAsyncCallback(NotifyLinkLayerOpen);
|
|
130 |
|
|
131 |
TRACE("firing TSubConnectionOpenedEvent");
|
|
132 |
TSubConnectionOpenedEvent event;
|
|
133 |
event.iSubConnectionUniqueId = KNifEntireConnectionSubConnectionId;
|
|
134 |
TPckg<TSubConnectionOpenedEvent> eventPtr(event);
|
|
135 |
iNotify->NifEvent(ESubConnectionEvent, ESubConnectionOpened, eventPtr);
|
|
136 |
}
|
|
137 |
|
|
138 |
// Sends a subconnection Closed event for the entire connection
|
|
139 |
void CWinsockInterface::NotifySubConnectionClosed(TInt aReason, TInt)
|
|
140 |
{
|
|
141 |
ScheduleAsyncCallback(NotifyLinkLayerClosed, aReason);
|
|
142 |
|
|
143 |
TRACE("firing TSubConnectionClosedEvent");
|
|
144 |
TSubConnectionClosedEvent event;
|
|
145 |
event.iSubConnectionUniqueId = KNifEntireConnectionSubConnectionId;
|
|
146 |
event.iTotalUplinkDataVolume = iBytesReceived;
|
|
147 |
event.iTotalDownlinkDataVolume = iBytesSent;
|
|
148 |
event.iTimeClosed.UniversalTime();
|
|
149 |
TPckg<TSubConnectionClosedEvent> eventPtr(event);
|
|
150 |
iNotify->NifEvent(ESubConnectionEvent, ESubConnectionClosed, eventPtr);
|
|
151 |
}
|
|
152 |
|
|
153 |
void CWinsockInterface::NotifyLinkLayerDown(TInt aReason, TInt aAction)
|
|
154 |
{
|
|
155 |
ScheduleAsyncCallback(NotifySubConnectionClosed, aReason);
|
|
156 |
TRACE("firing LinkLayerDown event");
|
|
157 |
iNotify->LinkLayerDown(aReason, (MNifIfNotify::TAction)aAction);
|
|
158 |
}
|
|
159 |
|
|
160 |
void CWinsockInterface::NotifyLinkLayerClosed(TInt aReason, TInt)
|
|
161 |
{
|
|
162 |
TRACE("firing LinkLayerClosed event");
|
|
163 |
iNotify->IfProgress(KLinkLayerClosed, aReason);
|
|
164 |
}
|
|
165 |
|
|
166 |
void CWinsockInterface::DataSent(TUint aBytes)
|
|
167 |
{
|
|
168 |
// Handle rollover?
|
|
169 |
iBytesSent += aBytes;
|
|
170 |
if (iBytesSentGranularity)
|
|
171 |
{
|
|
172 |
TUint delta = iBytesSent - iBytesSentMark;
|
|
173 |
if (delta >= iBytesSentGranularity)
|
|
174 |
{
|
|
175 |
int chunks = delta/iBytesSentGranularity;
|
|
176 |
iBytesSentMark += chunks*iBytesSentGranularity;
|
|
177 |
iNotify->NotifyDataSent(KWinsockSubConnectionId,
|
|
178 |
delta*iBytesSentGranularity);
|
|
179 |
}
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
void CWinsockInterface::DataReceived(TUint aBytes)
|
|
184 |
{
|
|
185 |
// Handle rollover?
|
|
186 |
iBytesReceived += aBytes;
|
|
187 |
if (iBytesReceivedGranularity)
|
|
188 |
{
|
|
189 |
TUint delta = iBytesReceived - iBytesReceivedMark;
|
|
190 |
if (delta >= iBytesReceivedGranularity)
|
|
191 |
{
|
|
192 |
int chunks = delta/iBytesReceivedGranularity;
|
|
193 |
iBytesReceivedMark += chunks*iBytesReceivedGranularity;
|
|
194 |
iNotify->NotifyDataReceived(KWinsockSubConnectionId,
|
|
195 |
delta*iBytesReceivedGranularity);
|
|
196 |
}
|
|
197 |
}
|
|
198 |
}
|
|
199 |
|
|
200 |
// CNifIfBase
|
|
201 |
void CWinsockInterface::Info(TNifIfInfo& aInfo) const
|
|
202 |
{
|
|
203 |
aInfo.iName = KWinsockInterface;
|
|
204 |
aInfo.iVersion = TVersion(1,0,0);
|
|
205 |
aInfo.iFlags = KNifIfIsBase | KNifIfIsLink | KNifIfUsesNotify | KNifIfCreatedByFactory;
|
|
206 |
aInfo.iProtocolSupported = 0;
|
|
207 |
for (TInt i=0; i<CWinsockProtocolFamily::ProtocolCount(); i++)
|
|
208 |
{
|
|
209 |
const TServerProtocolDesc* p = CWinsockProtocolFamily::ProtocolDesc(i);
|
|
210 |
aInfo.iProtocolSupported |= p->iProtocol;
|
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
TInt CWinsockInterface::Send(RMBufChain& /*aPdu*/, TAny* /*aSource*/)
|
|
215 |
{
|
|
216 |
TRACE("Send()");
|
|
217 |
return KErrNotSupported;
|
|
218 |
}
|
|
219 |
|
|
220 |
TInt CWinsockInterface::Notification(TAgentToNifEventType DEBUG_ONLY(aEvent),
|
|
221 |
TAny* /*aInfo*/)
|
|
222 |
{
|
|
223 |
TRACE1("Notification(%d)",aEvent);
|
|
224 |
return KErrNotSupported;
|
|
225 |
}
|
|
226 |
|
|
227 |
// CNifIfLink
|
|
228 |
TInt CWinsockInterface::Start()
|
|
229 |
{
|
|
230 |
TRACE("Start()");
|
|
231 |
ScheduleAsyncCallback(NotifyLinkLayerUp);
|
|
232 |
return KErrNone;
|
|
233 |
}
|
|
234 |
|
|
235 |
void CWinsockInterface::Stop(TInt aReason, MNifIfNotify::TAction aAction)
|
|
236 |
{
|
|
237 |
TRACE2("Stop(%d,%d)",aReason, aAction);
|
|
238 |
CancelOutstandingCallbacks();
|
|
239 |
ScheduleAsyncCallback(NotifyLinkLayerDown, aReason, aAction);
|
|
240 |
}
|
|
241 |
|
|
242 |
CNifIfBase* CWinsockInterface::GetBinderL(const TDesC& DEBUG_ONLY(aName))
|
|
243 |
{
|
|
244 |
TRACE1("GetBinderL(%S)",&aName);
|
|
245 |
return this;
|
|
246 |
}
|
|
247 |
|
|
248 |
TInt CWinsockInterface::Control(TUint aLevel,TUint aName,TDes8& aOption,
|
|
249 |
TAny* aSource)
|
|
250 |
{
|
|
251 |
TRACE3("Control(%d,%08X), %d bytes",aLevel,aName,aOption.Length());
|
|
252 |
switch (aLevel)
|
|
253 |
{
|
1
|
254 |
/* case KCOLInterface:
|
0
|
255 |
switch (aName)
|
|
256 |
{
|
|
257 |
case KCOGetNifEMIPtr:
|
|
258 |
default:
|
|
259 |
{
|
|
260 |
MNifIfExtendedManagementInterface** that =
|
|
261 |
(MNifIfExtendedManagementInterface**)aOption.Ptr();
|
|
262 |
if (aOption.Length() == sizeof(*that))
|
|
263 |
{
|
|
264 |
MNifIfExtendedManagementInterface* This = this;
|
|
265 |
TRACE1("MNifIfExtendedManagementInterface = %08X",This);
|
|
266 |
*that = This;
|
|
267 |
return KErrNone;
|
|
268 |
}
|
|
269 |
else
|
|
270 |
{
|
|
271 |
return KErrArgument;
|
|
272 |
}
|
|
273 |
}
|
|
274 |
break;
|
|
275 |
}
|
|
276 |
break;
|
1
|
277 |
*/
|
0
|
278 |
case KCOLAgent:
|
|
279 |
switch (aName)
|
|
280 |
{
|
|
281 |
case KCOGetAgentEMIPtr:
|
|
282 |
{
|
|
283 |
MNifAgentExtendedManagementInterface** that =
|
|
284 |
(MNifAgentExtendedManagementInterface**)aOption.Ptr();
|
|
285 |
if (aOption.Length() == sizeof(*that))
|
|
286 |
{
|
|
287 |
MNifAgentExtendedManagementInterface* This = this;
|
|
288 |
TRACE1("MNifAgentExtendedManagementInterface = %08X",This);
|
|
289 |
*that = This;
|
|
290 |
return KErrNone;
|
|
291 |
}
|
|
292 |
else
|
|
293 |
{
|
|
294 |
return KErrArgument;
|
|
295 |
}
|
|
296 |
}
|
|
297 |
default:
|
|
298 |
break;
|
|
299 |
}
|
|
300 |
break;
|
|
301 |
|
|
302 |
default:
|
|
303 |
break;
|
|
304 |
}
|
|
305 |
return super::Control(aLevel, aName, aOption, aSource);
|
|
306 |
}
|
|
307 |
|
|
308 |
// MNifIfExtendedManagementInterface
|
|
309 |
TInt CWinsockInterface::Stop(TSubConnectionUniqueId aId,
|
|
310 |
TInt DEBUG_ONLY(aReason))
|
|
311 |
{
|
|
312 |
TRACE2("Stop(%d,%d)", aId, aReason);
|
|
313 |
switch (aId)
|
|
314 |
{
|
|
315 |
case KNifEntireConnectionSubConnectionId:
|
|
316 |
case KWinsockSubConnectionId:
|
|
317 |
return KErrNone;
|
|
318 |
default:
|
|
319 |
return KErrNotFound;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
TInt CWinsockInterface::GetDataTransferred(TSubConnectionUniqueId aId,
|
|
324 |
TUint& aSentBytes,
|
|
325 |
TUint& aReceivedBytes)
|
|
326 |
{
|
|
327 |
TRACE1("GetDataTransferred(%d)", aId);
|
|
328 |
switch (aId)
|
|
329 |
{
|
|
330 |
case KNifEntireConnectionSubConnectionId:
|
|
331 |
case KWinsockSubConnectionId:
|
|
332 |
aSentBytes = iBytesSent;
|
|
333 |
aReceivedBytes = iBytesReceived;
|
|
334 |
return KErrNone;
|
|
335 |
default:
|
|
336 |
return KErrNotFound;
|
|
337 |
}
|
|
338 |
}
|
|
339 |
|
|
340 |
TInt CWinsockInterface::SetDataSentNotificationGranularity(TSubConnectionUniqueId aId,
|
|
341 |
TUint aGranularity)
|
|
342 |
{
|
|
343 |
TRACE2("SetDataSentNotificationGranularity(%d,%d)", aId, aGranularity);
|
|
344 |
switch (aId)
|
|
345 |
{
|
|
346 |
case KNifEntireConnectionSubConnectionId:
|
|
347 |
case KWinsockSubConnectionId:
|
|
348 |
iBytesSentGranularity = aGranularity;
|
|
349 |
return KErrNone;
|
|
350 |
default:
|
|
351 |
return KErrNotFound;
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
TInt CWinsockInterface::CancelDataSentNotification(TSubConnectionUniqueId aId)
|
|
356 |
{
|
|
357 |
TRACE1("CancelDataSentNotification(%d)", aId);
|
|
358 |
switch (aId)
|
|
359 |
{
|
|
360 |
case KNifEntireConnectionSubConnectionId:
|
|
361 |
case KWinsockSubConnectionId:
|
|
362 |
iBytesSentGranularity = 0;
|
|
363 |
return KErrNone;
|
|
364 |
default:
|
|
365 |
return KErrNotFound;
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
TInt CWinsockInterface::SetDataReceivedNotificationGranularity(TSubConnectionUniqueId aId,
|
|
370 |
TUint aGranularity)
|
|
371 |
{
|
|
372 |
TRACE2("SetDataReceivedNotificationGranularity(%d,%d)", aId, aGranularity);
|
|
373 |
switch (aId)
|
|
374 |
{
|
|
375 |
case KNifEntireConnectionSubConnectionId:
|
|
376 |
case KWinsockSubConnectionId:
|
|
377 |
iBytesReceivedGranularity = aGranularity;
|
|
378 |
return KErrNone;
|
|
379 |
default:
|
|
380 |
return KErrNotFound;
|
|
381 |
}
|
|
382 |
}
|
|
383 |
|
|
384 |
TInt CWinsockInterface::CancelDataReceivedNotification(TSubConnectionUniqueId aId)
|
|
385 |
{
|
|
386 |
TRACE1("CancelDataReceivedNotification(%d)", aId);
|
|
387 |
switch (aId)
|
|
388 |
{
|
|
389 |
case KNifEntireConnectionSubConnectionId:
|
|
390 |
case KWinsockSubConnectionId:
|
|
391 |
iBytesReceivedGranularity = 0;
|
|
392 |
return KErrNone;
|
|
393 |
default:
|
|
394 |
return KErrNotFound;
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
// MNifAgentExtendedManagementInterface
|
|
399 |
TInt CWinsockInterface::GetInterfaceType(TConnectionType& aConnectionType)
|
|
400 |
{
|
|
401 |
aConnectionType = EWinsockConnectionType;
|
|
402 |
return KErrNone;
|
|
403 |
}
|
|
404 |
|
|
405 |
TInt CWinsockInterface::EnumerateSubConnections(TUint& aCount)
|
|
406 |
{
|
|
407 |
aCount = 1;
|
|
408 |
return KErrNone;
|
|
409 |
}
|
|
410 |
|
|
411 |
TInt CWinsockInterface::GetSubConnectionInfo(TUint aIndex,
|
|
412 |
TDes8& aInfo)
|
|
413 |
{
|
|
414 |
if (aInfo.Length() != sizeof(TSubConnectionInfo))
|
|
415 |
{
|
|
416 |
return KErrArgument;
|
|
417 |
}
|
|
418 |
|
|
419 |
TSubConnectionInfo* info = (TSubConnectionInfo*)aInfo.Ptr();
|
|
420 |
switch (aIndex)
|
|
421 |
{
|
|
422 |
case KNifEntireConnectionSubConnectionId:
|
|
423 |
case KWinsockSubConnectionId:
|
|
424 |
info->iConnectionType = EWinsockConnectionType;
|
|
425 |
info->iSubConnectionUniqueId = aIndex;
|
|
426 |
info->iTimeStarted = iTimeStarted;
|
|
427 |
return KErrNone;
|
|
428 |
default:
|
|
429 |
return KErrNotFound;
|
|
430 |
}
|
|
431 |
}
|
|
432 |
|
|
433 |
TInt CWinsockInterface::GetSubConnectionInfo(TDes8& aInfo)
|
|
434 |
{
|
|
435 |
if (aInfo.Length() != sizeof(TSubConnectionInfo))
|
|
436 |
{
|
|
437 |
return KErrArgument;
|
|
438 |
}
|
|
439 |
|
|
440 |
TSubConnectionInfo* info = (TSubConnectionInfo*)aInfo.Ptr();
|
|
441 |
return GetSubConnectionInfo(info->iSubConnectionUniqueId, aInfo);
|
|
442 |
}
|