chxavaccesspointdb.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:6k
源码类别:
Symbian
开发平台:
Visual C++
- /************************************************************************
- * chxavaccesspointdb.cpp
- * ----------------------
- *
- * Synopsis:
- * Access point utility routines implementation.
- *
- *
- * Target:
- * Symbian OS
- *
- *
- * (c) 1995-2003 RealNetworks, Inc. Patents pending. All rights reserved.
- *
- ************************************************************************/
- // Symbian includes...
- #include <aputils.h>
- // Helix includes...
- #include "hxslist.h"
- #include "hxstring.h"
- // Includes from this project...
- #include "chxavaccesspointdb.h"
- #include "chxavstringutils.h"
- #include "chxavcleanupstack.h"
- /*
- * CHXAvAccessPointDB
- * ------------------
- * Ctor
- *
- */
- CHXAvAccessPointDB::CHXAvAccessPointDB() : m_accessPoints(NULL), m_isOpen(FALSE)
- {
- }
- void CHXAvAccessPointDB::ConstructL()
- {
- m_accessPoints = new (ELeave) CHXSimpleList;
- OpenDBL();
- }
- /*
- * ~CHXAvAccessPointDB
- * -------------------
- * Dtor...close db if still open.
- *
- */
- CHXAvAccessPointDB::~CHXAvAccessPointDB()
- {
- ClearAccessPointsList();
- if (m_accessPoints != NULL) delete m_accessPoints;
- if (m_isOpen) CloseDB();
- }
- /*
- * OpenDB
- * ------
- * Open the access point database and prepare for transactions.
- * False returned if unsuccessful.
- *
- */
- bool
- CHXAvAccessPointDB::OpenDBL()
- {
- if (m_isOpen) return true;
- bool ret = FALSE;
- m_spDatabase = CCommsDatabase::NewL(EDatabaseTypeIAP);
- m_isOpen = TRUE;
- return ret;
- }
- /*
- * CloseDB
- * ------
- * Clean up a little.
- *
- */
- void
- CHXAvAccessPointDB::CloseDB()
- {
- m_isOpen = FALSE;
- }
- /*
- * GetIapIDFromNameL
- * -----------------
- * Copy out the id that corresponds to the given name.
- *
- */
- TUint32
- CHXAvAccessPointDB::GetIapIDFromNameL(const CHXString& name)
- {
- GetAllAccessPointsL();
- // Go through the list...
- LISTPOSITION pos = m_accessPoints->GetHeadPosition();
- while (pos != NULL)
- {
- AccessPointInfoPtr info = (AccessPointInfoPtr)(m_accessPoints->GetNext(pos));
- if (info != NULL)
- {
- if (info->name.CompareNoCase(name) == 0)
- {
- return info->id;
- }
- }
- }
- return 0;
- }
- /*
- * GetAllAccessPointsL
- * ------------------
- * Populates the accesspoint list with the current set of access points.
- *
- */
- void
- CHXAvAccessPointDB::GetAllAccessPointsL()
- {
- ClearAccessPointsList();
- // Open a view on the access point table...
- m_spTable = m_spDatabase->OpenTableLC(TPtrC(IAP));
- CleanupStack::Pop();
- CApUtils* pUtils = CApUtils::NewLC(*m_spDatabase);
- AUTO_POP_DEL(pUtils);
- // Now that we have a table view...we will navigate it...
- TInt err = m_spTable->GotoFirstRecord();
- while (err == KErrNone)
- {
- // Get the Id of this record...
- TUint32 id = 0;
- m_spTable->ReadUintL(TPtrC(COMMDB_ID), id);
- // Get the nave of this record...
- HBufC *name = NULL;
- name = m_spTable->ReadLongTextLC(TPtrC(COMMDB_NAME));
- AUTO_POP_DEL(name);
- CHXString nameStr = CHXAvStringUtils::DescToString(name->Des());
- // Get the service id...
- TUint32 iapService = 0;
- m_spTable->ReadUintL(TPtrC(IAP_SERVICE), iapService);
- // Save these values in the list...
- AccessPointInfoPtr info = new (ELeave) AccessPointInfo;
- info->id = id;
- info->service = iapService;
- info->name = nameStr;
- TBool exists = pUtils->IAPExistsL(id);
- if (exists)
- info->wapId = pUtils->WapIdFromIapIdL(id);
- m_accessPoints->AddTail((void *)info);
- // Advance to the next record...
- err = m_spTable->GotoNextRecord();
- }
- }
- /*
- * GetAPInfo
- * ---------
- * Return true if internet AP exists
- *
- */
- bool
- CHXAvAccessPointDB::IsValidL(TUint32 iapId)
- {
- CApUtils* pUtils = CApUtils::NewLC(*m_spDatabase);
- AUTO_POP_DEL(pUtils);
- return pUtils->IAPExistsL(iapId);
- }
- /*
- * GetAPInfo
- * ---------
- * Returns the info struct of the record by it's id.
- *
- */
- AccessPointInfoPtr
- CHXAvAccessPointDB::GetAPInfo(TUint32 iapId)
- {
- LISTPOSITION pos = m_accessPoints->GetHeadPosition();
- while (pos != NULL)
- {
- AccessPointInfoPtr info = (AccessPointInfoPtr)(m_accessPoints->GetNext(pos));
- if (info->id == iapId)
- return info;
- }
- return NULL;
- }
- /*
- * ClearAccessPointsList
- * ---------------------
- * Clear the list.
- *
- */
- void
- CHXAvAccessPointDB::ClearAccessPointsList()
- {
- LISTPOSITION pos = NULL;
- pos = m_accessPoints->GetHeadPosition();
- while (pos != NULL)
- {
- AccessPointInfoPtr info = (AccessPointInfoPtr)(m_accessPoints->GetNext(pos));
- delete info;
- }
- m_accessPoints->RemoveAll();
- }
- /*
- * AllocAccessPointNameL
- * ---------------------
- * Get the name given the access point id.
- *
- */
- HBufC*
- CHXAvAccessPointDB::AllocAccessPointNameL(TUint32 iapId)
- {
- CApUtils* pUtils = CApUtils::NewLC(*m_spDatabase);
- AUTO_POP_DEL(pUtils);
- // AccessPointInfoPtr info = GetAPInfo(iapId);
- // HX_ASSERT(info != NULL);
- HBufC* pbuff = HBufC::NewL(KModifiableTextLength);
- AUTO_PUSH_POP(pbuff);
- TPtr ptr = pbuff->Des();
- TRAPD(err, pUtils->NameL(GetWapIdFromAPIdL(iapId), ptr));
- return pbuff;
- }
- /*
- * SupportsInternetAccessL
- * ------------------
- * Return true if given wap ap id supports IP connections
- *
- */
- bool
- CHXAvAccessPointDB::SupportsInternetAccessL(TUint32 wapApId)
- {
- HX_ASSERT(wapApId);
- bool bSupportsInternet = false;
- if(wapApId != 0)
- {
- CApUtils* pUtils = CApUtils::NewLC(*m_spDatabase);
- AUTO_POP_DEL(pUtils);
- TCommsDbIspType ispType;
- pUtils->ISPTypeL(wapApId, ispType);
- bSupportsInternet = (EIspTypeInternetOnly == ispType || EIspTypeInternetAndWAP == ispType);
- }
- return bSupportsInternet;
- }
- TUint32 CHXAvAccessPointDB::GetAPIdFromWapIdL(TUint32 wapApId)
- {
- TUint32 iapId = 0;
- if(wapApId != 0)
- {
- CApUtils* pUtils = CApUtils::NewLC(*m_spDatabase);
- AUTO_POP_DEL(pUtils);
- iapId = pUtils->IapIdFromWapIdL(wapApId);
- }
- return iapId;
- }
- TUint32 CHXAvAccessPointDB::GetWapIdFromAPIdL(TUint32 iapId)
- {
- TUint32 wapApId = 0;
- if(iapId != 0)
- {
- CApUtils* pUtils = CApUtils::NewLC(*m_spDatabase);
- AUTO_POP_DEL(pUtils);
- wapApId = pUtils->WapIdFromIapIdL(iapId);
- }
- return wapApId;
- }