networkingtestandutils/networkingunittest/dummynif/dummyniffactory.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-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 //
       
    15  
       
    16 #include <es_mbuf.h>
       
    17 #include "dummynif.h"
       
    18 #include "dummynifvar.h"
       
    19 
       
    20 /*
       
    21  * Factory functions...
       
    22  * Build this file with its factory when you want a normal dummy nif which will
       
    23  * echo back udp packets and respond to commands
       
    24  */
       
    25  
       
    26 EXPORT_C CNifFactory* NewInterfaceFactoryL()
       
    27 	{
       
    28 	return new(ELeave) CDummyIfFactory;
       
    29 	}
       
    30 
       
    31 void CDummyIfFactory::InstallL()
       
    32 	{
       
    33 	iDelayPipe.SetLengthL(KDelayQueueSize);
       
    34 	for(TInt prime = 0; prime < KDelaySlots; ++prime)
       
    35 		{
       
    36 		RMBuf* stopper = NULL;
       
    37 		User::LeaveIfError(iDelayPipe.Add(&stopper));
       
    38 		}
       
    39 	if(KDelaySlots > 0)
       
    40 		{
       
    41 		iNetDelayTimer = CPeriodic::NewL(50000);	// arbitrary stupid high priority, but we really need to run on our ticks & not get delayed until flow-offs & retransmits
       
    42 		iNetDelayTimer->Start(KDelayQuantum, KDelayQuantum, TCallBack(CDummyIfFactory::DripCallback, this));
       
    43 		TCallBack callBack(DripCallback, this);
       
    44 		}
       
    45 	}
       
    46 	
       
    47 void CDummyIfFactory::SetDripReceiver(TCallBack aReceiver)
       
    48 	{
       
    49 	iDripReceiver = aReceiver;
       
    50 	}
       
    51 
       
    52 TInt CDummyIfFactory::DripCallback(TAny* aSelf)
       
    53 	{
       
    54 	CDummyIfFactory* self = (CDummyIfFactory*) aSelf;
       
    55 	if(self->iDripReceiver.iPtr)
       
    56 		{
       
    57 		RMBuf* stopper = NULL;
       
    58 		self->iDelayPipe.Add(&stopper);	// keep the supply of backstops constant
       
    59 		self->iDripReceiver.CallBack();
       
    60 		}
       
    61 	return 0;
       
    62 	}
       
    63 
       
    64 RMBuf* CDummyIfFactory::GetDrip()
       
    65 	{
       
    66 	RMBuf* next = NULL;
       
    67 	iDelayPipe.Remove(&next);
       
    68 	return next;
       
    69 	}
       
    70 	
       
    71 void CDummyIfFactory::AddDrip(RMBuf* aDrip)
       
    72 	{
       
    73 	TInt err = iDelayPipe.Add(&aDrip);
       
    74 	__ASSERT_ALWAYS(err == 1, User::Panic(_L("DummyIfOver"), 0));
       
    75 	}
       
    76 	
       
    77 	
       
    78 	
       
    79 CDummyIfFactory::~CDummyIfFactory()
       
    80 	{
       
    81 	delete iNetDelayTimer;
       
    82 	}
       
    83 	
       
    84 
       
    85 CNifIfBase* CDummyIfFactory::NewInterfaceL(const TDesC& /*aName*/)
       
    86 	{	
       
    87 	CDummyIfLink* s = new(ELeave) CDummyIfLink(*this);
       
    88 	CleanupStack::PushL(s);
       
    89 	s->TimerConstructL(ESocketTimerPriority);
       
    90 	CleanupStack::Pop();
       
    91 	return s;
       
    92 	}
       
    93 
       
    94 TInt CDummyIfFactory::Info(TNifIfInfo& aInfo, TInt /*aIndex*/) const
       
    95 	{
       
    96 	CDummyIfLink::FillInInfo(aInfo, (TAny*)this);
       
    97 
       
    98 	return 1;
       
    99 	}