📄 iapconnectengine.cpp
字号:
/*
* ============================================================================
* Name : CIAPConnectEngine from IAPConnectEngine.cpp
* Part of : IAPConnect
* Created : 24.04.2003
* Implementation notes:
* Engine class
* Version : 1.0
* Copyright:
* ============================================================================
*/
// INCLUDE FILES
#include <eikenv.h>
#include <aknglobalnote.h>
#include <Intconninit.h>
#include <nifman.h>
#include <connectprog.h>
#include <TextResolver.h>
#include <aknquerydialog.h>
#include <Sabber.rsg>
#include "Sabber.hrh"
#include "IAPConnectEngine.h"
#include "IAPConnectWaitDialog.h"
// CONSTANTS
/*
_LIT(KTextConnectionCreated, "Connection created");
_LIT(KTextConnectionExists, "Connection exists");
_LIT(KTextConnectionPref1Created, "Connection preference 1 created");
_LIT(KTextConnectionPref1Exists, "Connection preference 1 exists");
_LIT(KTextConnectionPref2Created, "Connection preference 2 created");
_LIT(KTextConnectionPref2Exists, "Connection preference 2 exists");
_LIT(KTextAlreadyReleased, "Connection is already released");
_LIT(KTextNotConnected, "There is no active connection");
_LIT(KTextConnectionReleased, "Application has released the connection");
*/
_LIT(KTextErrorCodePrompt, "\nError code: ");
_LIT(KTextWrongValueInPrefs, "Wrong value in connection preferences");
_LIT(KTextNotReady, "Active request already ongoing");
const TUint32 KBearerSetUnknown = 1000;
// ========================== MEMBER FUNCTIONS ===============================
// ---------------------------------------------------------------------------
// CIAPConnectEngine::NewL(CIAPConnectContainer* aAppContainer)
//
// Constructs CIAPConnectEngine object
// ---------------------------------------------------------------------------
//
CIAPConnectEngine* CIAPConnectEngine::NewL( MIAPConnectStateObserver* aAppContainer )
{
CIAPConnectEngine* self = NewLC(aAppContainer);
CleanupStack::Pop(self);
return self;
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::NewLC(CIAPConnectContainer* aAppContainer)
//
// Constructs CIAPConnectEngine object
// ---------------------------------------------------------------------------
//
CIAPConnectEngine* CIAPConnectEngine::NewLC(MIAPConnectStateObserver* aObserver)
{
CIAPConnectEngine* self = new (ELeave) CIAPConnectEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::CIAPConnectEngine(CIAPConnectContainer* aAppContainer)
//
// Constructor
// ---------------------------------------------------------------------------
//
CIAPConnectEngine::CIAPConnectEngine(MIAPConnectStateObserver* aObserver)
: CActive(CActive::EPriorityStandard),
iState(EIAPConnectStateNotConnected),
iNifTimerState(ETimerEnabled),
iObserver(aObserver)
{
SetConnectionPreferences(ECommDbBearerUnknown, EFalse);
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::~CIAPConnectEngine()
//
// Destructor
// ---------------------------------------------------------------------------
//
CIAPConnectEngine::~CIAPConnectEngine()
{
Cancel();
iNif.DisableTimers(EFalse);
iNif.Close();
//if ( EIAPConnectStateConnected == iState )
// iConect->TerminateActiveConnection();
delete iConnect;
delete iWaitDialog;
delete iTextResolver;
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::ConstructL()
//
// Second phase constructor
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::ConstructL()
{
iConnect = CIntConnectionInitiator::NewL();
iWaitDialog = CIAPConnectWaitDialog::NewL(this);
iTextResolver = CTextResolver::NewL();
CActiveScheduler::Add(this);
iNif.Open();
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::ConnectL(TBool aRetry)
//
// Start connecting to IAP. aRetry parameter indicates if it is retry.
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::ConnectL(TBool aRetry)
{
// Make connection permanent even if there are no activity (e.g sockets).
// Otherwise inactive connection is closed within few seconds.
iNif.DisableTimers(ETrue);
iNifTimerState = ETimerDisabled;
if (aRetry)
{
iState = EIAPConnectStateRetry;
}
else
{
iState = EIAPConnectStateConnecting;
}
iObserver->IAPStateChangedL(iState);
if (!IsActive())
{
if (aRetry)
{
// Do not show dialog if it is retry
iPref.iDialogPref = ECommDbDialogPrefDoNotPrompt;
}
iWaitDialog->ShowDialogL(EIAPConnectStateConnecting);
iStatus = KRequestPending;
if ( iPref.iBearer.iIapId == 0 ) {
iPref.iDialogPref = ECommDbDialogPrefPrompt;
iConnect->ConnectL( iPref, iStatus );
} else
iConnect->ConnectL( iPref, iStatus );
SetActive();
}
else
{
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalInformationNote, KTextNotReady);
CleanupStack::PopAndDestroy();
}
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::RunL()
//
// Handles request completion events
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::RunL()
{
iWaitDialog->DismissDialogL();
TInt statusCode = iStatus.Int();
if (iState == EIAPConnectStateConnecting || iState == EIAPConnectStateRetry)
{
switch (statusCode)
{
case KErrCancel:
iState = EIAPConnectStateNotConnected;
break;
case KConnectionCreated:
//PrintNoteL(TPtrC(KTextConnectionCreated));
{
iConnect->GetActiveIap( iIapId );
//SYS_TRACE2( 0, "create iap:", iIapId );
}
iState = EIAPConnectStateConnected;
break;
case KConnectionExists:
//PrintNoteL(TPtrC(KTextConnectionExists));
iState = EIAPConnectStateConnected;
break;
case KConnectionPref1Created:
{
iConnect->GetActiveIap( iIapId );
//SYS_TRACE2( 0, "create iap:", iIapId );
}
//PrintNoteL(TPtrC(KTextConnectionPref1Created));
iState = EIAPConnectStateConnected;
break;
case KConnectionPref1Exists:
//PrintNoteL(TPtrC(KTextConnectionPref1Exists));
iState = EIAPConnectStateConnected;
break;
case KConnectionPref2Created:
//PrintNoteL(TPtrC(KTextConnectionPref2Created));
iState = EIAPConnectStateConnected;
break;
case KConnectionPref2Exists:
//PrintNoteL(TPtrC(KTextConnectionPref2Exists));
iState = EIAPConnectStateConnected;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -