×
Namespaces

Variants
Actions
(Difference between revisions)

Creating, deleting, editing, and listing WLAN access points using Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search
pavarang (Talk | contribs)
(Pavarang -)
ashraf fawzy (Talk | contribs)
(Ashraf fawzy -)
Line 30: Line 30:
  
 
== Description ==
 
== Description ==
Sometimes S60 3rd-party applications may want to provide the functionality for managing access points through their UI. It is possible for applications to programmatically create, edit, and delete access points.<br>To create, delete, edit, and list WLAN APs, the following headers/libraries are used:<br><nowiki>#</nowiki>include <nowiki><</nowiki>commdb.h<nowiki>></nowiki> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// link against commdb.lib<br><nowiki>#</nowiki>include <nowiki><</nowiki>apselect.h<nowiki>></nowiki> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// link against apengine.lib<br><nowiki>#</nowiki>include <nowiki><</nowiki>aplistitem.h<nowiki>></nowiki><br><nowiki>#</nowiki>include <nowiki><</nowiki>apdatahandler.h<nowiki>></nowiki><br><nowiki>#</nowiki>include <nowiki><</nowiki>apaccesspointitem.h<nowiki>></nowiki><br><nowiki>#</nowiki>include <nowiki><</nowiki>aputils.h<nowiki>></nowiki><br>A short example for each type of operation:<br><br>'''Creating an access point:'''<br>CApAccessPointItem *wlan = CApAccessPointItem::NewLC();<br>wlan-<nowiki>></nowiki>SetNamesL(_L("NewAP"));<br>wlan-<nowiki>></nowiki>SetBearerTypeL(EApBearerTypeWLAN);<br>wlan-<nowiki>></nowiki>WriteTextL(EApWlanNetworkName, _L("WlanAP"));<br>// Store it into the CommsDb<br>CCommsDatabase *commDb = CCommsDatabase::NewL();<br>CleanupStack::PushL(commDb);<br>CApDataHandler *handler = CApDataHandler::NewLC(*commDb);<br>TUint32 newApId = handler-<nowiki>></nowiki>CreateFromDataL(*wlan);<br>CleanupStack::PopAndDestroy(3); // handler, commDb, wlan<br><br>'''Removing an access point:'''<br>handler-<nowiki>></nowiki>RemoveAPL(myUid); // myUid: ID of an AP to remove<br><br>'''Editing an access point:'''<br>handler-<nowiki>></nowiki>AccessPointDataL(myUid, *wlan);<br>// myUid: ID of an AP to edit<br>TInt err;<br>err = wlan-<nowiki>></nowiki>WriteTextL(EApWlanNetworkName, _L("NewName"));<br>// EApWlanNetworkName is the column to edit.<br>// Other columns are listed in ApAccessPointItem.h<br>TBool nameChanged;<br>handler-<nowiki>></nowiki>UpdateAccessPointDataL(*iaccessPoint, nameChanged);<br><br>'''Getting the UID of the access points:'''<br>The UIDs of access points can be retrieved as follows:<br>CCommsDatabase* commDb =<br>&nbsp;&nbsp;&nbsp;&nbsp;CCommsDatabase::NewL(EDatabaseTypeIAP);<br>CleanupStack::PushL(commDb);<br>CApSelect* select = CApSelect::NewLC(<br>&nbsp;&nbsp;&nbsp;&nbsp;*commDb,<br>&nbsp;&nbsp;&nbsp;&nbsp;KEApIspTypeAll,<br>&nbsp;&nbsp;&nbsp;&nbsp;EApBearerTypeWLAN, // use EApBearerTypeAll for all types<br>&nbsp;&nbsp;&nbsp;&nbsp;KEApSortUidAscending);<br>TBuf<nowiki><</nowiki>256<nowiki>></nowiki> accessPoints;<br>_LIT(KAPInfoTxtFormat, "<nowiki>[</nowiki>%d<nowiki>]</nowiki>%S ");<br>TBool ok = select-<nowiki>></nowiki>MoveToFirst();<br>for(TInt i = 0; ok && (i <nowiki><</nowiki> select-<nowiki>></nowiki>Count()); i<nowiki>++</nowiki>)<br>&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>{</nowiki><br>&nbsp;&nbsp;&nbsp;&nbsp;accessPoints.AppendFormat(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;KAPInfoTxtFormat,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select-<nowiki>></nowiki>Uid(),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&select-<nowiki>></nowiki>Name());<br>&nbsp;&nbsp;&nbsp;&nbsp;ok = select-<nowiki>></nowiki>MoveNext(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;<nowiki>}</nowiki><br>CleanupStack::PopAndDestroy(2); // select, commDb<br>// accessPoints descriptor now contains WLAN AP IDs <nowiki>+</nowiki> names
+
Sometimes S60 3rd-party applications may want to provide the functionality for managing access points through their UI. It is possible for applications to programmatically create, edit, and delete access points.  
 +
To create, delete, edit, and list WLAN APs, the following headers / libraries are used:
 +
 
 +
==MMP File==
 +
This snippet requires the following libraries:
 +
<code>
 +
LIBRARY commdb.lib
 +
LIBRARY apengine.lib
 +
</code>
 +
 
 +
== Headers==
 +
 
 +
<code cpp>
 +
#include <commdb.h> // link against  
 +
#include <apselect.h> // link against apengine.lib
 +
#include <aplistitem.h>
 +
#include <apdatahandler.h>
 +
#include <apaccesspointitem.h>
 +
#include <aputils.h>
 +
</code>
 +
 
 +
==A short example for each type of operation:==
 +
 
 +
'''Creating an access point:'''
 +
<code cpp>
 +
CApAccessPointItem *wlan = CApAccessPointItem::NewLC();
 +
wlan->SetNamesL(_L("NewAP"));
 +
wlan->SetBearerTypeL(EApBearerTypeWLAN);
 +
wlan->WriteTextL(EApWlanNetworkName, _L("WlanAP"));
 +
 
 +
// Store it into the CommsDb
 +
 
 +
CCommsDatabase *commDb = CCommsDatabase::NewL();
 +
CleanupStack::PushL(commDb);
 +
 
 +
CApDataHandler *handler = CApDataHandler::NewLC(*commDb);
 +
TUint32 newApId = handler->CreateFromDataL(*wlan);
 +
CleanupStack::PopAndDestroy(3); // handler, commDb, wlan
 +
</code>
 +
 
 +
 
 +
'''Removing an access point:'''
 +
<code cpp>
 +
handler->RemoveAPL(myUid); // myUid: ID of an AP to remove
 +
</code>
 +
 
 +
'''Editing an access point:'''
 +
<code cpp>
 +
handler->AccessPointDataL(myUid, *wlan); // myUid: ID of an AP to edit
 +
TInt err;
 +
err = wlan->WriteTextL(EApWlanNetworkName, _L("NewName"));
 +
// EApWlanNetworkName is the column to edit.
 +
// Other columns are listed in ApAccessPointItem.h
 +
TBool nameChanged;
 +
handler->UpdateAccessPointDataL(*iaccessPoint, nameChanged);
 +
</code>
 +
 
 +
 
 +
'''Getting the UID of the access points:'''
 +
<code cpp>
 +
// The UIDs of access points can be retrieved as follows:  
 +
 
 +
CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);  
 +
CleanupStack::PushL(commDb);  
 +
CApSelect* select = CApSelect::NewLC(*commDb, KEApIspTypeAll, EApBearerTypeWLAN, /* use EApBearerTypeAll for all types */KEApSortUidAscending);  
 +
TBuf<256> accessPoints; _LIT(KAPInfoTxtFormat, "[%d]%S ");
 +
 
 +
TBool ok = select->MoveToFirst();
 +
for(TInt i = 0; ok && (i < select->Count()); i++)
 +
    {
 +
accessPoints.AppendFormat(
 +
        KAPInfoTxtFormat,
 +
        select->Uid(),
 +
        &select->Name());
 +
ok = select->MoveNext();      
 +
    }
 +
CleanupStack::PopAndDestroy(2); // select, commDb
 +
// accessPoints descriptor now contains WLAN AP IDs + names
 +
</code>

Revision as of 05:04, 9 September 2012

Article Metadata
Compatibility
Platform(s): S60 3rd Edition
S60 3rd Edition (initial release)
Article
Created: User:Technical writer 2 (21 Sep 2006)
Last edited: ashraf fawzy (09 Sep 2012)

Contents

Overview

Creating, deleting, editing, and listing WLAN access points

Description

Sometimes S60 3rd-party applications may want to provide the functionality for managing access points through their UI. It is possible for applications to programmatically create, edit, and delete access points. To create, delete, edit, and list WLAN APs, the following headers / libraries are used:

MMP File

This snippet requires the following libraries:

LIBRARY commdb.lib
LIBRARY apengine.lib

Headers

#include <commdb.h>  // link against 
#include <apselect.h> // link against apengine.lib
#include <aplistitem.h>
#include <apdatahandler.h>
#include <apaccesspointitem.h>
#include <aputils.h>

A short example for each type of operation:

Creating an access point:

CApAccessPointItem *wlan = CApAccessPointItem::NewLC();
wlan->SetNamesL(_L("NewAP"));
wlan->SetBearerTypeL(EApBearerTypeWLAN);
wlan->WriteTextL(EApWlanNetworkName, _L("WlanAP"));
 
// Store it into the CommsDb
 
CCommsDatabase *commDb = CCommsDatabase::NewL();
CleanupStack::PushL(commDb);
 
CApDataHandler *handler = CApDataHandler::NewLC(*commDb);
TUint32 newApId = handler->CreateFromDataL(*wlan);
CleanupStack::PopAndDestroy(3); // handler, commDb, wlan


Removing an access point:

handler->RemoveAPL(myUid); // myUid: ID of an AP to remove

Editing an access point:

handler->AccessPointDataL(myUid, *wlan); // myUid: ID of an AP to edit
TInt err;
err = wlan->WriteTextL(EApWlanNetworkName, _L("NewName"));
// EApWlanNetworkName is the column to edit.
// Other columns are listed in ApAccessPointItem.h
TBool nameChanged;
handler->UpdateAccessPointDataL(*iaccessPoint, nameChanged);


Getting the UID of the access points:

// The UIDs of access points can be retrieved as follows: 
 
CCommsDatabase* commDb = CCommsDatabase::NewL(EDatabaseTypeIAP);
CleanupStack::PushL(commDb);
CApSelect* select = CApSelect::NewLC(*commDb, KEApIspTypeAll, EApBearerTypeWLAN, /* use EApBearerTypeAll for all types */KEApSortUidAscending);
TBuf<256> accessPoints; _LIT(KAPInfoTxtFormat, "[%d]%S ");
 
TBool ok = select->MoveToFirst();
for(TInt i = 0; ok && (i < select->Count()); i++)
{
accessPoints.AppendFormat(
KAPInfoTxtFormat,
select->Uid(),
&select->Name());
ok = select->MoveNext();
}
CleanupStack::PopAndDestroy(2); // select, commDb
// accessPoints descriptor now contains WLAN AP IDs + names
79 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×