multimediacommsengine/tsrc/testdriver/testclient/net/src/CTcIAPManager.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.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 *
       
    14 * Description:  Implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include <commdb.h>
       
    19 
       
    20 #include "CTcIAPManager.h"
       
    21 
       
    22 EXPORT_C CTcIAPManager* CTcIAPManager::NewL()
       
    23 	{
       
    24 	CTcIAPManager* self = new( ELeave ) CTcIAPManager();
       
    25 
       
    26 	CleanupStack::PushL( self );
       
    27 	self->ConstructL();
       
    28 	CleanupStack::Pop();
       
    29 
       
    30 	return self;
       
    31 	}
       
    32 
       
    33 EXPORT_C CTcIAPManager::~CTcIAPManager()
       
    34 	{
       
    35 	}
       
    36 
       
    37 CTcIAPManager::CTcIAPManager()
       
    38 	: iEntries( 1 )
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CTcIAPManager::ConstructL()
       
    43 	{
       
    44 	// Open Comms DB
       
    45 	CCommsDatabase* commsDb = CCommsDatabase::NewL();
       
    46 	CleanupStack::PushL( commsDb );
       
    47 
       
    48 	// Get the IAP table
       
    49 	CCommsDbTableView* ispTable = commsDb->OpenTableLC( TPtrC( IAP ) );
       
    50 
       
    51 	// Loop through IAP entries
       
    52 	TInt res = ispTable->GotoFirstRecord();
       
    53 	while( res == KErrNone )
       
    54 		{
       
    55 		// Fetch Name and Id for each entry and store then into an array
       
    56 		TEntry iapEntry;
       
    57 		TBuf< KCommsDbSvrMaxColumnNameLength > tmpName;
       
    58 		ispTable->ReadUintL( TPtrC( COMMDB_ID ), iapEntry.iId );
       
    59 		ispTable->ReadTextL( TPtrC( COMMDB_NAME ), tmpName );
       
    60 		iapEntry.iName.Copy( tmpName );	// unicode to narrow conversion
       
    61 		iEntries.AppendL( iapEntry );
       
    62 
       
    63 		// Get next record in table
       
    64 		res = ispTable->GotoNextRecord();
       
    65 		}
       
    66 
       
    67 	CleanupStack::PopAndDestroy( 2 );	// ispTable, commsDb
       
    68 	}
       
    69 
       
    70 TInt CTcIAPManager::MdcaCount() const
       
    71 	{
       
    72 	return Count();
       
    73 	}
       
    74 
       
    75 TPtrC8 CTcIAPManager::MdcaPoint( TInt aIndex ) const
       
    76 	{
       
    77 	return TPtrC8( Name( aIndex ) );
       
    78 	}
       
    79 
       
    80 EXPORT_C TInt CTcIAPManager::Count() const
       
    81 	{
       
    82 	return iEntries.Count();
       
    83 	}
       
    84 
       
    85 EXPORT_C TUint32 CTcIAPManager::Id( TInt aIndex ) const
       
    86 	{
       
    87 	return iEntries[ aIndex ].iId;
       
    88 	}
       
    89 
       
    90 EXPORT_C const TDesC8& CTcIAPManager::Name( TInt aIndex ) const
       
    91 	{
       
    92 	return iEntries[ aIndex ].iName;
       
    93 	}
       
    94 
       
    95 EXPORT_C const TDesC8& CTcIAPManager::NameForIdL( TUint32 aId ) const
       
    96 	{
       
    97 	TInt count = iEntries.Count();
       
    98 	for( TInt i = 0; i < count; i++ )
       
    99 		{
       
   100 		const TEntry& entry = iEntries[ i ];
       
   101 		if( entry.iId == aId )
       
   102 			{
       
   103 			return entry.iName;
       
   104 			}
       
   105 		}
       
   106 
       
   107 	User::Leave( KErrNotFound );
       
   108 	return KNullDesC8;	// keep compiler happy
       
   109 	}
       
   110 
       
   111 EXPORT_C TUint32 CTcIAPManager::IdForNameL( const TDesC8& aName ) const
       
   112 	{
       
   113 	TInt count = iEntries.Count();
       
   114 	for( TInt i = 0; i < count; i++ )
       
   115 		{
       
   116 		const TEntry& entry = iEntries[ i ];
       
   117 		if( entry.iName.CompareF( aName ) == 0 )
       
   118 			{
       
   119 			return entry.iId;
       
   120 			}
       
   121 		}
       
   122 
       
   123 	User::Leave( KErrNotFound );
       
   124 	return 0;	// keep compiler happy
       
   125 	}