📄 iapconnect_v20engine.cpp
字号:
//
// Cancels ongoing requests
// ---------------------------------------------------------------------------
//
void CIAPConnect_v20Engine::DoCancel()
{
// Nothing to do here
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::TerminateConnectionL()
//
// This function should not be used in normal situation, since it terminates
// the active connection, even if there are other application using
// the connection. Calling the RConnection::Close() closes the connection.
// ---------------------------------------------------------------------------
//
void CIAPConnect_v20Engine::TerminateConnectionL()
{
if (iProgressNotifier->GetState() == EIAPConnectStateConnected)
{
// Show confirmation dialog first
if (ShowQueryDialogL())
{
// RConnection::Stop() terminates connection by stopping whole
// network interface even if there are other clients using
// the connection. It is not recommended to use it unless it is
// really meaningful.
User::LeaveIfError(iConnect.Stop());
}
}
else
{
PrintNoteL(KTextNotConnected);
}
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::GetConnectionInfoL()
//
// This function collects information about active connections
// ---------------------------------------------------------------------------
//
void CIAPConnect_v20Engine::GetConnectionInfoL(TDes8& aInfoBuf)
{
TUint connCount = 0;
// Count active connections
iConnect.EnumerateConnections(connCount);
if (connCount)
{
aInfoBuf.Append(KTextConnectionInfoHeader);
for(TUint i = 1; i <= connCount; i++)
{
aInfoBuf.AppendFormat(KTextConnectionInfoTitle, i);
TPckgBuf<TConnectionInfo> connInfo;
// Get connection info
User::LeaveIfError(iConnect.GetConnectionInfo(i, connInfo));
aInfoBuf.AppendFormat(KTextConnectionInfoIds,
connInfo().iIapId, connInfo().iNetId);
// Get info about clients using this connection
TConnectionEnumArg args;
args.iIndex = i;
TConnEnumArgBuf enumBuf(args);
TConnectionGetClientInfoArg clientInfoArg;
clientInfoArg.iIndex = 1;
TConnGetClientInfoArgBuf clientInfoBuf(clientInfoArg);
TConnectionClientInfo clientInfo;
// Query number of clients using the connection
User::LeaveIfError(iConnect.Control
(KCOLConnection, KCoEnumerateConnectionClients, enumBuf));
aInfoBuf.AppendFormat(KTextConnectionInfoClients,
enumBuf().iCount);
for(TUint j = 1; j <= enumBuf().iCount; j++)
{
clientInfoBuf().iIndex = j;
// Get client info
User::LeaveIfError(iConnect.Control(
KCOLConnection, KCoGetConnectionClientInfo, clientInfoBuf));
clientInfo = clientInfoBuf().iClientInfo;
aInfoBuf.AppendFormat(KTextConnectionInfoProcessId,
clientInfo.iProcessId);
}
}
}
else
{
aInfoBuf.Append(KTextConnectionInfoNoConnections);
}
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::IsConnected(TUint32& aIap)
//
// This function checks if there is an active connection.
// ---------------------------------------------------------------------------
//
TBool CIAPConnect_v20Engine::IsConnected(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;
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::ShowQueryDialogL()
//
// This function shows a query dialog to make sure that user wants to terminate
// the active connection.
// ---------------------------------------------------------------------------
//
TInt CIAPConnect_v20Engine::ShowQueryDialogL() const
{
CAknQueryDialog* dlg = new(ELeave) CAknQueryDialog(CAknQueryDialog::ENoTone);
return dlg->ExecuteLD(R_IAPCONNECT_V20_TERMINATION_QUERY_DIALOG);
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::SetConnectionPreferences(TUint aBearer,
// TBool aDialog,
// TUint32 aIapId)
//
// This function sets connection preferences.
// ---------------------------------------------------------------------------
//
void CIAPConnect_v20Engine::SetConnectionPreferences(
TUint aBearer,
TBool aDialog,
TUint32 aIapId)
{
iPref.SetDirection(ECommDbConnectionDirectionOutgoing);
if (aDialog)
{
iPref.SetDialogPreference(ECommDbDialogPrefPrompt);
}
else
{
iPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
}
iPref.SetIapId(aIapId);
iPref.SetBearerSet(aBearer);
iPref.SetDirection(ECommDbConnectionDirectionOutgoing);
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::SelectAccessPointL(TUint32& aSelectedIap)
//
// This function launch an access point selection list
// ---------------------------------------------------------------------------
//
void CIAPConnect_v20Engine::SelectAccessPointL(TUint32& aIap)
{
// Create Ap Settings Handler. See SDK Help for parameters.
CApSettingsHandler* settingsHandler = CApSettingsHandler::NewLC(
ETrue,
EApSettingsSelListIsListPane,
EApSettingsSelMenuSelectNormal,
KEApIspTypeAll,
EApBearerTypeAll,
KEApSortNameAscending);
TUint32 originallyFocused(0);
TUint32 aSelectedIap(0);
// Show the dialog
settingsHandler->RunSettingsL(originallyFocused, aSelectedIap);
// Original value 0 is not valid IAP id, so failed if 0 after RunSettingsL().
if (aSelectedIap)
{
CCommsDatabase* db = CCommsDatabase::NewL();
CleanupStack::PushL(db);
CApUtils* apUtils = CApUtils::NewLC(*db);
// Convert IAP id to CommsDb id
aIap = apUtils->IapIdFromWapIdL(aSelectedIap);
CleanupStack::PopAndDestroy(2);
}
else
{
aIap = 0;
}
CleanupStack::PopAndDestroy();
}
// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::GetState()
//
// Queries the connection state from the progress notifier
// ---------------------------------------------------------------------------
//
TInt CIAPConnect_v20Engine::GetState() const
{
return iProgressNotifier->GetState();
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -