📄 iapconnectengine.cpp
字号:
// Nothing to do here
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::ReleaseL()
//
// Releases the connection by calling RConnection::DisableTimers(EFalse).
// After that the connection is closed if it's not used (e.g. by sockets).
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::ReleaseL()
{
// Check if there is an active connection
if (iProgressNotifier->GetState() == EIAPConnectStateConnected)
{
Cancel();
/*
In S60 3rd Edition, enabling/disabling the inactivity timer will require
the NetworkControl capability, which is only accessed via Symbian partner.
In S60 3rd Edition this method is called only if the NetworkControl
capability is set. Otherwise do nothing in S60 3rd Ed.
*/
#if !defined(__SERIES60_3X__) || defined(__S60_3X_NET_CTRL__)
// Enable the connection idle timer
iConnect.SetOpt(KCOLProvider, KConnDisableTimers, EFalse);
#endif
PrintNoteL(KTextConnectionReleased);
}
else
{
PrintNoteL(KTextNotConnected);
}
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::TerminateConnectionL()
//
// This function should not be used in normal situations, since it terminates
// the active connection, even if there are other application using
// the connection. Use the ReleaseL() function instead.
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::TerminateConnectionL()
{
// Check if there is an active connection
if (iProgressNotifier->GetState() == EIAPConnectStateConnected)
{
// Show confirmation dialog first
if (ShowQueryDialogL())
{
Cancel();
// RConnection::Stop() terminates connection by force even if
// there are other clients using the connection. Thus it is not
// recommended to use it unless it is really necessary
// This function call requires NetworkControl capability
// in S60 3rd Ed
#if !defined(__SERIES60_3X__) || defined(__S60_3X_NET_CTRL__)
iConnect.SetOpt(KCOLProvider, KConnDisableTimers, EFalse);
User::LeaveIfError(iConnect.Stop());
#else
// To overcome the constraint of Stop() in 3rd Ed if NetworkControl
// is not available:
if (iProgressNotifier)
{
delete iProgressNotifier;
iProgressNotifier = NULL;
}
iConnect.Close();
// reopen the connection
User::LeaveIfError(iConnect.Open(iSocketServ));
iProgressNotifier = CIAPConnectProgressNotifier::NewL(iObserver,
iConnect);
#endif
}
}
else
{
PrintNoteL(KTextNotConnected);
}
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::IsConnectedL(TUint32& aIap)
//
// This function checks if there is an active connection.
// ---------------------------------------------------------------------------
//
TBool CIAPConnectEngine::IsConnectedL(TUint32& aIap)
{
// Check if there is an active connection
TBool connected = EFalse;
TUint connectionCount;
//Enumerate currently active connections across all socket servers
User::LeaveIfError(iConnect.EnumerateConnections(connectionCount));
if (connectionCount)
{
TPckgBuf<TConnectionInfoV2> connectionInfo;
for (TUint i = 1; i <= connectionCount; ++i)
{
iConnect.GetConnectionInfo(i, connectionInfo);
if (connectionInfo().iIapId == aIap)
{
connected = ETrue;
break;
}
}
}
return connected;
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::GetState()
//
// Queries the connection state from the progress notifier
// ---------------------------------------------------------------------------
//
TInt CIAPConnectEngine::GetState() const
{
return iProgressNotifier->GetState();
}
/* Not used, just for demonstration purposes...
TInt CIAPConnectEngine::ReadTableL()
{
CCommsDatabase* commsDb;
commsDb = CCommsDatabase::NewL();
CleanupStack::PushL(commsDb);
TBuf<32> aux;
CCommsDbTableView* lanBearer = commsDb->OpenTableLC(TPtrC(LAN_BEARER));
TUint32 timeoutVal1, timeoutVal2, timeoutVal3;
TInt result = lanBearer->GotoFirstRecord();
while (result == KErrNone)
{
lanBearer->ReadUintL(TPtrC(LAST_SOCKET_ACTIVITY_TIMEOUT), timeoutVal1);
aux.Format(_L("Socket act. timeout = %d"), timeoutVal1);
PrintNoteL(aux);
lanBearer->ReadUintL(TPtrC(LAST_SESSION_CLOSED_TIMEOUT), timeoutVal2);
aux.Zero();
aux.Format(_L("\r\nSession closed timeout = %d"), timeoutVal2);
PrintNoteL(aux);
lanBearer->ReadUintL(TPtrC(LAST_SOCKET_CLOSED_TIMEOUT), timeoutVal3);
aux.Zero();
aux.Format(_L("\r\nSocket closed timeout = %d"), timeoutVal3);
PrintNoteL(aux);
result = lanBearer->GotoNextRecord();
}
CleanupStack::PopAndDestroy(2);
return 0;
}
*/
// ---------------------------------------------------------------------------
// CIAPConnectEngine::CreateNewIapL(...)
//
// This function creates a new IAP record and insert it into the Comms
// database.
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::CreateNewIapL(const TDesC& aIapName)
{
CCommsDatabase* commsDb;
commsDb = CCommsDatabase::NewL();
CleanupStack::PushL(commsDb);
TBufC<KNameLength> commsdb_name_val(aIapName);
TUint32 network_id;
commsDb->BeginTransaction();
/* Step 1 */
// creating a new network record
CCommsDbTableView* network = commsDb->OpenTableLC(TPtrC(NETWORK));
network->InsertRecord(network_id);
network->WriteTextL(TPtrC(COMMDB_NAME), commsdb_name_val);
network->PutRecordChanges();
CleanupStack::PopAndDestroy(network);
/* Step 2 */
// creating a new outgoing gprs record
TUint32 og_gprs_id;
// See implementations in the CreateNewOgGprsL function
CreateNewOgGprsL(*commsDb, commsdb_name_val, og_gprs_id);
/* Step 3 */
// creating a new wap accesspoint record
TUint32 ap_id;
// See implementations in the CreateNewAccessPointL function
CreateNewAccessPointL(*commsDb, commsdb_name_val, ap_id);
/* Step 4 */
// creating a new IAP record
CCommsDbTableView* iap = commsDb->OpenTableLC(TPtrC(IAP));
TUint32 iap_id;
iap->InsertRecord(iap_id);
iap->WriteTextL(TPtrC(COMMDB_NAME), commsdb_name_val);
iap->WriteUintL(TPtrC(IAP_SERVICE), og_gprs_id);
iap->WriteTextL(TPtrC(IAP_SERVICE_TYPE), TPtrC(OUTGOING_GPRS));
iap->WriteTextL(TPtrC(IAP_BEARER_TYPE), TPtrC(MODEM_BEARER));
// In real application, don't hard-code. Should check from the modem bearer
iap->WriteUintL( TPtrC(IAP_BEARER), 3);
iap->WriteUintL( TPtrC(IAP_NETWORK), network_id);
iap->WriteUintL( TPtrC(IAP_NETWORK_WEIGHTING), 0 );
iap->WriteUintL( TPtrC(IAP_LOCATION), 2);
iap->PutRecordChanges();
CleanupStack::PopAndDestroy(iap);
/* Step 5 */
// creating a new wap bearer
CCommsDbTableView* wap_bearer = commsDb->OpenTableLC(TPtrC(WAP_IP_BEARER));
TUint32 wb_id;
wap_bearer->InsertRecord(wb_id);
wap_bearer->WriteUintL(TPtrC(WAP_ACCESS_POINT_ID), ap_id);
_LIT(wap_gw_address, "0.0.0.0");
wap_bearer->WriteTextL(TPtrC(WAP_GATEWAY_ADDRESS), wap_gw_address);
wap_bearer->WriteUintL( TPtrC(WAP_IAP), iap_id);
wap_bearer->WriteUintL( TPtrC(WAP_WSP_OPTION),
EWapWspOptionConnectionOriented);
wap_bearer->WriteBoolL( TPtrC(WAP_SECURITY), EFalse);
wap_bearer->WriteUintL( TPtrC(WAP_PROXY_PORT), 0 );
wap_bearer->PutRecordChanges();
CleanupStack::PopAndDestroy(wap_bearer);
// Finish
User::LeaveIfError(commsDb->CommitTransaction());
CleanupStack::PopAndDestroy(commsDb);
PrintNoteL(KIapCreated); // Show a success note to the user
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::CreateNewOgGprsL(...)
//
// This function creates a new outgoing GPRS record.
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::CreateNewOgGprsL(CCommsDatabase& aCommsDb,
const TDesC& aCommsdb_name_val, TUint32& aOgGprsId)
{
CCommsDbTableView* commsOgGprs =
aCommsDb.OpenTableLC(TPtrC(OUTGOING_GPRS));
commsOgGprs->InsertRecord(aOgGprsId);
commsOgGprs->WriteTextL(TPtrC(COMMDB_NAME), aCommsdb_name_val);
_LIT(apn_val, "dummy test");
commsOgGprs->WriteLongTextL(TPtrC(GPRS_APN), apn_val);
commsOgGprs->WriteUintL( TPtrC(GPRS_PDP_TYPE), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_PRECEDENCE), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_DELAY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_RELIABILITY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_PEAK_THROUGHPUT), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_REQ_MEAN_THROUGHPUT), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_PRECEDENCE), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_DELAY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_RELIABILITY), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_PEAK_THROUGHPUT), 0);
commsOgGprs->WriteUintL( TPtrC(GPRS_MIN_MEAN_THROUGHPUT), 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -