applayerpluginsandutils/httpprotocolplugins/WspProtocolHandler/CWspAliasAddresses.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2001-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 "CWspAliasAddresses.h"
       
    17 
       
    18 #include "CAliasAddress.h"
       
    19 
       
    20 CWspAliasAddresses* CWspAliasAddresses::NewL()
       
    21 	{
       
    22 	return new (ELeave) CWspAliasAddresses();
       
    23 	}
       
    24 
       
    25 CWspAliasAddresses::~CWspAliasAddresses()
       
    26 	{
       
    27 	iAddresses.ResetAndDestroy();
       
    28 	}
       
    29 
       
    30 CWspAliasAddresses::CWspAliasAddresses()
       
    31 : CBase(), iIndex(KErrNotFound)
       
    32 	{
       
    33 	}
       
    34 
       
    35 TInt CWspAliasAddresses::Start() const
       
    36 	{
       
    37 	// Have any addresses been added?
       
    38 	if( iAddresses.Count() != 0 )
       
    39 		{
       
    40 		// There are addresses in array - set index to start
       
    41 		iIndex = 0;
       
    42 		}
       
    43 	// iIndex now is the error (return) value
       
    44 	return iIndex;
       
    45 	}
       
    46 
       
    47 TInt CWspAliasAddresses::GetNext(TWspBearer& aBearer, TUint16& aPort, TPtrC8& aAddress) const
       
    48 	{
       
    49 	// Check to see if array can be accessed
       
    50 	TInt error = KErrNone;
       
    51 	if( iIndex == KErrNotFound )
       
    52 		{
       
    53 		// Array is empty or have indexed to end of array
       
    54 		error = KErrNotFound;
       
    55 		}
       
    56 	else
       
    57 		{
       
    58 		// Have still got an address to access - get values
       
    59 		const CAliasAddress& address = *iAddresses[iIndex];
       
    60 		aBearer	= address.GetBearer();
       
    61 		aPort	= address.GetPort();
       
    62 		aAddress.Set(address.GetAddress());
       
    63 
       
    64 		// Increment index and check to see reached the end of the array
       
    65 		++iIndex;
       
    66 		if( iIndex == iAddresses.Count() )
       
    67 			{
       
    68 			iIndex = KErrNotFound;
       
    69 			}
       
    70 		}
       
    71 	return error;
       
    72 	}
       
    73 
       
    74 void CWspAliasAddresses::Reset()
       
    75 	{
       
    76 	// Reset the array and index
       
    77 	iAddresses.ResetAndDestroy();
       
    78 	iIndex = KErrNotFound;
       
    79 	}
       
    80 
       
    81 void CWspAliasAddresses::AddAddressL(TWspBearer aBearer, TUint16 aPort, const TDesC8& aAddress)
       
    82 	{
       
    83 	// Create address object
       
    84 	CAliasAddress* address = CAliasAddress::NewL(aBearer, aPort, aAddress);
       
    85 	CleanupStack::PushL(address);
       
    86 
       
    87 	// Append to array
       
    88 	User::LeaveIfError(iAddresses.Append(address));
       
    89 	CleanupStack::Pop(address);
       
    90 	}
       
    91