networkcontrol/ipscpr/src/asyncwriter.cpp
branchRCL_3
changeset 22 8d540f55e491
parent 21 abbed5a4b42a
child 23 425d8f4f7fa5
equal deleted inserted replaced
21:abbed5a4b42a 22:8d540f55e491
     1 // Copyright (c) 2005-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 "asyncwriter.h"
       
    17 
       
    18 
       
    19 CAsyncWriter* CAsyncWriter::NewL(CQoSMsgWriter* aWriter)
       
    20 	{
       
    21 	CAsyncWriter* self = new (ELeave) CAsyncWriter(aWriter);
       
    22 	CleanupStack::PushL(self);
       
    23 	self->ConstructL();
       
    24 	CleanupStack::Pop(self);
       
    25 	return self;
       
    26 	}
       
    27 	
       
    28 CAsyncWriter::CAsyncWriter(CQoSMsgWriter* aWriter) :
       
    29 	CActive(EPriorityNormal),
       
    30 	iWriter(aWriter)
       
    31 	{
       
    32         iPendingMsg.SetOffset(_FOFF(CQoSMsg, iLink));
       
    33         }
       
    34 
       
    35 void CAsyncWriter::ConstructL()
       
    36 	{
       
    37 	CActiveScheduler::Add(this);
       
    38 	}
       
    39 
       
    40 void CAsyncWriter::Send(CQoSMsg* aMessage)
       
    41 	{
       
    42 	if (IsActive())
       
    43  		{
       
    44  		iPendingMsg.AddLast(*aMessage);
       
    45  		}
       
    46  	else
       
    47  		{
       
    48  		iWriter->Send(aMessage);
       
    49  		SetActive();
       
    50  		TRequestStatus* stat = &iStatus;
       
    51  		User::RequestComplete(stat,KErrNone);
       
    52  		}
       
    53 	}
       
    54 	
       
    55 void CAsyncWriter::RunL()
       
    56 	{
       
    57 	ASSERT(iWriter);
       
    58 	if (!iPendingMsg.IsEmpty())
       
    59  		{
       
    60  		CQoSMsg* msg = iPendingMsg.First();
       
    61  		iPendingMsg.Remove(*msg);
       
    62  		iWriter->Send(msg);
       
    63  		SetActive();
       
    64  		}
       
    65 	}
       
    66 	
       
    67 void CAsyncWriter::DoCancel()
       
    68 	{
       
    69 	//No code needed here becuase the request is completed immediately on activation
       
    70 	}