Join Now
Quality Rating:
  • Currently 4.5 / 5
(4.5 / 5 - 2 votes cast)
Expertise Level:
  • Currently 4.5 / 5
(4.5 / 5 - 2 votes cast)

This page was last modified 21:31, 6 March 2008.

Reading internet access points from the device

From Forum Nokia Wiki

Contents

Access point (IAP) selection dialog

you need to add this to your header file

class TIapData
{
public:
	TBuf<128> iName;
	TUint32 iIap;
 
};
TInt SelectIAPL()
{
	CArrayFixFlat<TIapData>* iEApList=new (ELeave) CArrayFixFlat<TIapData>(2) ;
	TInt stack=0;
	// Make listitems. and PUSH it
	CAknSinglePopupMenuStyleListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox;
	CleanupStack::PushL(list);stack++; 
 
	// Create popup list and PUSH it.
	CAknPopupList* popupList = CAknPopupList::NewL(list,
		R_AVKON_SOFTKEYS_OK_CANCEL, AknPopupLayouts::EMenuWindow);
	CleanupStack::PushL(popupList);stack++; 
 
	CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat(5);
	CleanupStack::PushL(items);stack++; 
	// initialize listbox.
	list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
	list->CreateScrollBarFrameL(ETrue);
	list->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
		CEikScrollBarFrame::EAuto);
 
 
	TBuf<52> iapfromtable;
	TInt err = KErrNone;
 
	CCommsDatabase* iCommsDB=CCommsDatabase::NewL(EDatabaseTypeIAP);
	CleanupStack::PushL(iCommsDB);stack++; 
#ifdef __SERIES60_3X__
	CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(
		ECommDbBearerGPRS|ECommDbBearerWLAN|ECommDbBearerVirtual,
		ECommDbConnectionDirectionOutgoing); 
#else
	CCommsDbTableView* gprsTable = iCommsDB->OpenIAPTableViewMatchingBearerSetLC(
		ECommDbBearerGPRS|ECommDbBearerVirtual,
		ECommDbConnectionDirectionOutgoing); 
#endif
	User::LeaveIfError(gprsTable->GotoFirstRecord());
	TInt i=0;
	TUint32 id;
	TIapData eap;	
 
	TInt cur =0; //current value
	do
	{
		gprsTable->ReadTextL(TPtrC(COMMDB_NAME), iapfromtable);
		gprsTable->ReadUintL(TPtrC(COMMDB_ID), id);
		items->AppendL(iapfromtable);
		eap.iIap = id;
		eap.iName.Copy(iapfromtable);
		iEApList->AppendL(eap);
 
		err = gprsTable->GotoNextRecord();
		i++;
	}
	while (err == KErrNone);
	CleanupStack::PopAndDestroy(2); stack--; 
 
	// Set listitems.
	CTextListBoxModel* model = list->Model();
	model->SetItemTextArray(items);
	model->SetOwnershipType(ELbmOwnsItemArray);
	CleanupStack::Pop();    
 
	popupList->SetTitleL(_L("IAP"));
	list->SetListBoxObserver(popupList);
	TInt popupOk = popupList->ExecuteLD();
	CleanupStack::Pop();    
	TInt iap=0;
	if (popupOk)
	{	
		TInt index = list->CurrentItemIndex();
		iap=(*iEApList)[index].iIap;
 
	}
	CleanupStack::PopAndDestroy();  
	iEApList->Reset();
	delete iEApList;
	return iap;
}

Reading all access points from the device

The following code reads all access points from the device disregarding their type. This is preferred unless there is some grave reason why you would force the user to select e.g. from GPRS connections.


TFileName iapName;
TUint32 iapID;
TInt err; 
 
// open the IAP communications database
CCommsDatabase* commDB = CCommsDatabase::NewL();
CleanupStack::PushL(commDB);
 
// Open the IAP table
CCommsDbTableView* view = commDB->OpenTableLC(TPtrC(IAP));
 
// Point to the first entry
if (view->GotoFirstRecord() == KErrNone)
{
	do
	{
		view->ReadTextL(TPtrC(COMMDB_NAME), iapName);
		view->ReadUintL(TPtrC(COMMDB_ID), iapID);
 
		// Store name and ID to where you want to
	} while (err = view->GotoNextRecord(), err == KErrNone);
}
 
CleanupStack::PopAndDestroy(); // view
CleanupStack::PopAndDestroy(); // commDB


Reading GPRS/CSD internet access points from the device

Following code sample shows how to retrieve all set GPRS or CSD internet access point from the device.


CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDb);
 
CCommsDbTableView* commView = commDb->OpenIAPTableViewMatchingBearerSetLC(
  ECommDbBearerCSD|ECommDbBearerGPRS, ECommDbConnectionDirectionOutgoing);
 
TFileName TmpName;	
 
if (commView->GotoFirstRecord() == KErrNone)
{
	do
	{
		TmpName.Zero();
		commView->ReadTextL(TPtrC(COMMDB_NAME),TmpName);
		
		// Add TmpName to CDesCArray for example
		// it has the IAP's human readable name
		
		TUint32 IapNum;
		commView->ReadUintL(TPtrC(COMMDB_ID),IapNum);
		
		// Add IapNum into other array, 
		// it has the ID for the accesspoint used with connection
		
	}while (commView->GotoNextRecord() == KErrNone);
}
 
CleanupStack::PopAndDestroy(2);//commView,commDb


With the code the TmpName variable will held the internet access point name you could show to user for selection, and the IapNum variable holds the internet access point identifier you could then use with the RConnection when making a silent connection. Note that when making a silent connection you also need to call the SetDialogPreference()-function with ECommDbDialogPrefDoNotPrompt for the connection preferences (TCommDbConnPref).

Retrieving Proxy Server Name from IAP

The code below shows how to retrieve proxy server name and the port number from a certain IAP.


//
// The tableView variable here is the instance of CCommsDbTableView
// Normally you call CCommsDatabase::OpenTableLC() to get the instance of
// CCommsDbTableView.
// (See also the other examples above.)
//
 
// Firstly, we need to get the IAPService and IAPServiceType 
// of our IAP in order to find out the proxy information.
TUint32 iapService;
HBufC* iapServiceType;
tableView->ReadUintL(TPtrC(IAP_SERVICE), iapService);
iapServiceType = tableView->ReadLongTextLC(TPtrC(IAP_SERVICE_TYPE));
        
// Check whether this IAP uses proxy or not.
TBool isProxyEnabled = EFalse;
CCommsDbTableView* proxyTableView = commsDb->OpenViewOnProxyRecordLC(
        iapService, *iapServiceType);
if (KErrNone == proxyTableView->GotoFirstRecord())
    {
    proxyTableView->ReadBoolL(TPtrC(PROXY_USE_PROXY_SERVER), isProxyEnabled);
 
    // If proxy is enabled then do something.
    if (isProxyEnabled)
        {
        proxyServerName = proxyTableView->ReadLongTextLC(TPtrC(PROXY_SERVER_NAME));
        proxyTableView->ReadUintL(TPtrC(PROXY_PORT_NUMBER), proxyPortNumber);
	
        // Do whatever you want with proxyServerName and proxyPortNumber.
        	
        CleanupStack::PopAndDestroy(proxyServerName);
        }
    }
Related Discussions
Thread Thread Starter Forum Replies Last Post
Install a sis file on a N80 phone kaiten-sushi General Symbian C++ 20 2007-02-06 12:24
Local PC -> Device TCP/IP Communication borquist General Symbian C++ 6 2004-02-04 17:28
Nokia 6101 Locked 2 TMobile Midlet can't access internet... Jason Glass Mobile Java Networking & Messaging & Security 45 2007-11-14 02:19
How to activate an access point ahe Symbian Networking & Messaging 1 2006-12-06 14:03
关于网络状态求助 chocolate Symbian 5 2007-09-27 04:46
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX