author | Shabe Razvi <shaber@symbian.org> |
Thu, 04 Nov 2010 17:22:05 +0000 | |
changeset 4 | b3b823debf08 |
parent 1 | ac50fd48361b |
permissions | -rw-r--r-- |
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; |
|
4
b3b823debf08
Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented.
Shabe Razvi <shaber@symbian.org>
parents:
1
diff
changeset
|
177 |
// |
b3b823debf08
Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented.
Shabe Razvi <shaber@symbian.org>
parents:
1
diff
changeset
|
178 |
// Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented. |
b3b823debf08
Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented.
Shabe Razvi <shaber@symbian.org>
parents:
1
diff
changeset
|
179 |
// |
b3b823debf08
Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented.
Shabe Razvi <shaber@symbian.org>
parents:
1
diff
changeset
|
180 |
// iNotify->NotifyDataSent(KWinsockSubConnectionId, |
b3b823debf08
Workaround for Bug 3917 - CWinsockInterface::DataSent calls NotifyDataSent which is not implemented.
Shabe Razvi <shaber@symbian.org>
parents:
1
diff
changeset
|
181 |
// delta*iBytesSentGranularity); |
0 | 182 |
} |
183 |
} |
|
184 |
} |
|
185 |
||
186 |
void CWinsockInterface::DataReceived(TUint aBytes) |
|
187 |
{ |
|
188 |
// Handle rollover? |
|
189 |
iBytesReceived += aBytes; |
|
190 |
if (iBytesReceivedGranularity) |
|
191 |
{ |
|
192 |
TUint delta = iBytesReceived - iBytesReceivedMark; |
|
193 |
if (delta >= iBytesReceivedGranularity) |
|
194 |
{ |
|
195 |
int chunks = delta/iBytesReceivedGranularity; |
|
196 |
iBytesReceivedMark += chunks*iBytesReceivedGranularity; |
|
197 |
iNotify->NotifyDataReceived(KWinsockSubConnectionId, |
|
198 |
delta*iBytesReceivedGranularity); |
|
199 |
} |
|
200 |
} |
|
201 |
} |
|
202 |
||
203 |
// CNifIfBase |
|
204 |
void CWinsockInterface::Info(TNifIfInfo& aInfo) const |
|
205 |
{ |
|
206 |
aInfo.iName = KWinsockInterface; |
|
207 |
aInfo.iVersion = TVersion(1,0,0); |
|
208 |
aInfo.iFlags = KNifIfIsBase | KNifIfIsLink | KNifIfUsesNotify | KNifIfCreatedByFactory; |
|
209 |
aInfo.iProtocolSupported = 0; |
|
210 |
for (TInt i=0; i<CWinsockProtocolFamily::ProtocolCount(); i++) |
|
211 |
{ |
|
212 |
const TServerProtocolDesc* p = CWinsockProtocolFamily::ProtocolDesc(i); |
|
213 |
aInfo.iProtocolSupported |= p->iProtocol; |
|
214 |
} |
|
215 |
} |
|
216 |
||
217 |
TInt CWinsockInterface::Send(RMBufChain& /*aPdu*/, TAny* /*aSource*/) |
|
218 |
{ |
|
219 |
TRACE("Send()"); |
|
220 |
return KErrNotSupported; |
|
221 |
} |
|
222 |
||
223 |
TInt CWinsockInterface::Notification(TAgentToNifEventType DEBUG_ONLY(aEvent), |
|
224 |
TAny* /*aInfo*/) |
|
225 |
{ |
|
226 |
TRACE1("Notification(%d)",aEvent); |
|
227 |
return KErrNotSupported; |
|
228 |
} |
|
229 |
||
230 |
// CNifIfLink |
|
231 |
TInt CWinsockInterface::Start() |
|
232 |
{ |
|
233 |
TRACE("Start()"); |
|
234 |
ScheduleAsyncCallback(NotifyLinkLayerUp); |
|
235 |
return KErrNone; |
|
236 |
} |
|
237 |
||
238 |
void CWinsockInterface::Stop(TInt aReason, MNifIfNotify::TAction aAction) |
|
239 |
{ |
|
240 |
TRACE2("Stop(%d,%d)",aReason, aAction); |
|
241 |
CancelOutstandingCallbacks(); |
|
242 |
ScheduleAsyncCallback(NotifyLinkLayerDown, aReason, aAction); |
|
243 |
} |
|
244 |
||
245 |
CNifIfBase* CWinsockInterface::GetBinderL(const TDesC& DEBUG_ONLY(aName)) |
|
246 |
{ |
|
247 |
TRACE1("GetBinderL(%S)",&aName); |
|
248 |
return this; |
|
249 |
} |
|
250 |
||
251 |
TInt CWinsockInterface::Control(TUint aLevel,TUint aName,TDes8& aOption, |
|
252 |
TAny* aSource) |
|
253 |
{ |
|
254 |
TRACE3("Control(%d,%08X), %d bytes",aLevel,aName,aOption.Length()); |
|
255 |
switch (aLevel) |
|
256 |
{ |
|
1 | 257 |
/* case KCOLInterface: |
0 | 258 |
switch (aName) |
259 |
{ |
|
260 |
case KCOGetNifEMIPtr: |
|
261 |
default: |
|
262 |
{ |
|
263 |
MNifIfExtendedManagementInterface** that = |
|
264 |
(MNifIfExtendedManagementInterface**)aOption.Ptr(); |
|
265 |
if (aOption.Length() == sizeof(*that)) |
|
266 |
{ |
|
267 |
MNifIfExtendedManagementInterface* This = this; |
|
268 |
TRACE1("MNifIfExtendedManagementInterface = %08X",This); |
|
269 |
*that = This; |
|
270 |
return KErrNone; |
|
271 |
} |
|
272 |
else |
|
273 |
{ |
|
274 |
return KErrArgument; |
|
275 |
} |
|
276 |
} |
|
277 |
break; |
|
278 |
} |
|
279 |
break; |
|
1 | 280 |
*/ |
0 | 281 |
case KCOLAgent: |
282 |
switch (aName) |
|
283 |
{ |
|
284 |
case KCOGetAgentEMIPtr: |
|
285 |
{ |
|
286 |
MNifAgentExtendedManagementInterface** that = |
|
287 |
(MNifAgentExtendedManagementInterface**)aOption.Ptr(); |
|
288 |
if (aOption.Length() == sizeof(*that)) |
|
289 |
{ |
|
290 |
MNifAgentExtendedManagementInterface* This = this; |
|
291 |
TRACE1("MNifAgentExtendedManagementInterface = %08X",This); |
|
292 |
*that = This; |
|
293 |
return KErrNone; |
|
294 |
} |
|
295 |
else |
|
296 |
{ |
|
297 |
return KErrArgument; |
|
298 |
} |
|
299 |
} |
|
300 |
default: |
|
301 |
break; |
|
302 |
} |
|
303 |
break; |
|
304 |
||
305 |
default: |
|
306 |
break; |
|
307 |
} |
|
308 |
return super::Control(aLevel, aName, aOption, aSource); |
|
309 |
} |
|
310 |
||
311 |
// MNifIfExtendedManagementInterface |
|
312 |
TInt CWinsockInterface::Stop(TSubConnectionUniqueId aId, |
|
313 |
TInt DEBUG_ONLY(aReason)) |
|
314 |
{ |
|
315 |
TRACE2("Stop(%d,%d)", aId, aReason); |
|
316 |
switch (aId) |
|
317 |
{ |
|
318 |
case KNifEntireConnectionSubConnectionId: |
|
319 |
case KWinsockSubConnectionId: |
|
320 |
return KErrNone; |
|
321 |
default: |
|
322 |
return KErrNotFound; |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
TInt CWinsockInterface::GetDataTransferred(TSubConnectionUniqueId aId, |
|
327 |
TUint& aSentBytes, |
|
328 |
TUint& aReceivedBytes) |
|
329 |
{ |
|
330 |
TRACE1("GetDataTransferred(%d)", aId); |
|
331 |
switch (aId) |
|
332 |
{ |
|
333 |
case KNifEntireConnectionSubConnectionId: |
|
334 |
case KWinsockSubConnectionId: |
|
335 |
aSentBytes = iBytesSent; |
|
336 |
aReceivedBytes = iBytesReceived; |
|
337 |
return KErrNone; |
|
338 |
default: |
|
339 |
return KErrNotFound; |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
TInt CWinsockInterface::SetDataSentNotificationGranularity(TSubConnectionUniqueId aId, |
|
344 |
TUint aGranularity) |
|
345 |
{ |
|
346 |
TRACE2("SetDataSentNotificationGranularity(%d,%d)", aId, aGranularity); |
|
347 |
switch (aId) |
|
348 |
{ |
|
349 |
case KNifEntireConnectionSubConnectionId: |
|
350 |
case KWinsockSubConnectionId: |
|
351 |
iBytesSentGranularity = aGranularity; |
|
352 |
return KErrNone; |
|
353 |
default: |
|
354 |
return KErrNotFound; |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
TInt CWinsockInterface::CancelDataSentNotification(TSubConnectionUniqueId aId) |
|
359 |
{ |
|
360 |
TRACE1("CancelDataSentNotification(%d)", aId); |
|
361 |
switch (aId) |
|
362 |
{ |
|
363 |
case KNifEntireConnectionSubConnectionId: |
|
364 |
case KWinsockSubConnectionId: |
|
365 |
iBytesSentGranularity = 0; |
|
366 |
return KErrNone; |
|
367 |
default: |
|
368 |
return KErrNotFound; |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
TInt CWinsockInterface::SetDataReceivedNotificationGranularity(TSubConnectionUniqueId aId, |
|
373 |
TUint aGranularity) |
|
374 |
{ |
|
375 |
TRACE2("SetDataReceivedNotificationGranularity(%d,%d)", aId, aGranularity); |
|
376 |
switch (aId) |
|
377 |
{ |
|
378 |
case KNifEntireConnectionSubConnectionId: |
|
379 |
case KWinsockSubConnectionId: |
|
380 |
iBytesReceivedGranularity = aGranularity; |
|
381 |
return KErrNone; |
|
382 |
default: |
|
383 |
return KErrNotFound; |
|
384 |
} |
|
385 |
} |
|
386 |
||
387 |
TInt CWinsockInterface::CancelDataReceivedNotification(TSubConnectionUniqueId aId) |
|
388 |
{ |
|
389 |
TRACE1("CancelDataReceivedNotification(%d)", aId); |
|
390 |
switch (aId) |
|
391 |
{ |
|
392 |
case KNifEntireConnectionSubConnectionId: |
|
393 |
case KWinsockSubConnectionId: |
|
394 |
iBytesReceivedGranularity = 0; |
|
395 |
return KErrNone; |
|
396 |
default: |
|
397 |
return KErrNotFound; |
|
398 |
} |
|
399 |
} |
|
400 |
||
401 |
// MNifAgentExtendedManagementInterface |
|
402 |
TInt CWinsockInterface::GetInterfaceType(TConnectionType& aConnectionType) |
|
403 |
{ |
|
404 |
aConnectionType = EWinsockConnectionType; |
|
405 |
return KErrNone; |
|
406 |
} |
|
407 |
||
408 |
TInt CWinsockInterface::EnumerateSubConnections(TUint& aCount) |
|
409 |
{ |
|
410 |
aCount = 1; |
|
411 |
return KErrNone; |
|
412 |
} |
|
413 |
||
414 |
TInt CWinsockInterface::GetSubConnectionInfo(TUint aIndex, |
|
415 |
TDes8& aInfo) |
|
416 |
{ |
|
417 |
if (aInfo.Length() != sizeof(TSubConnectionInfo)) |
|
418 |
{ |
|
419 |
return KErrArgument; |
|
420 |
} |
|
421 |
||
422 |
TSubConnectionInfo* info = (TSubConnectionInfo*)aInfo.Ptr(); |
|
423 |
switch (aIndex) |
|
424 |
{ |
|
425 |
case KNifEntireConnectionSubConnectionId: |
|
426 |
case KWinsockSubConnectionId: |
|
427 |
info->iConnectionType = EWinsockConnectionType; |
|
428 |
info->iSubConnectionUniqueId = aIndex; |
|
429 |
info->iTimeStarted = iTimeStarted; |
|
430 |
return KErrNone; |
|
431 |
default: |
|
432 |
return KErrNotFound; |
|
433 |
} |
|
434 |
} |
|
435 |
||
436 |
TInt CWinsockInterface::GetSubConnectionInfo(TDes8& aInfo) |
|
437 |
{ |
|
438 |
if (aInfo.Length() != sizeof(TSubConnectionInfo)) |
|
439 |
{ |
|
440 |
return KErrArgument; |
|
441 |
} |
|
442 |
||
443 |
TSubConnectionInfo* info = (TSubConnectionInfo*)aInfo.Ptr(); |
|
444 |
return GetSubConnectionInfo(info->iSubConnectionUniqueId, aInfo); |
|
445 |
} |