📄 iapconnectengine.cpp
字号:
/*
* ============================================================================
* Name : CIAPConnectEngine from IAPConnectEngine.cpp
* Part of : Internet Access Points Example v2.0
* Created : 01.09.2006 by Forum Nokia
* Version : 2.0
* Copyright: Forum Nokia
* ============================================================================
*/
// INCLUDE FILES
#include "IAPConnect.hrh"
#include "IAPConnectEngine.h"
#include "IAPConnectProgressNotifier.h"
#include "IAPConnect.pan"
#include <iapconnect.rsg>
#include <nifman.h> // KConnDisableTimers
#include <eikenv.h>
#include <aknglobalnote.h>
#include <es_enum.h>
#include <TextResolver.h>
#include <aknquerydialog.h>
#include <apsettingshandlerui.h>
#include <txtetext.h> // CEditableText
// Some of the operations in this class's GetConnectionInfoL() method
// require NetworkControl capability in S60 3rd Edition. If you have
// this capability set, uncomment the following line:
// #define __S60_3X_NET_CTRL__
// CONSTANTS
_LIT(KTextConnectionCreated, "Connection created");
_LIT(KTextConnectionExists, "Connection exists");
_LIT(KTextGeneralError, "General error");
_LIT(KTextConnectionCancelled, "Connection cancelled");
_LIT(KTextNotReady, "Active request already ongoing");
_LIT(KTextAlreadyReleased, "Connection is already released");
_LIT(KTextNotConnected, "There are no active connections");
_LIT(KTextConnectionReleased, "Application has released the connection");
_LIT(KTextErrorCodePrompt, "\nError code: ");
_LIT(KTextConnectionInfoHeader, "--- Connections ---");
_LIT(KTextConnectionInfoTitle, "Connection %d:");
_LIT(KTextConnectionInfoClients, " - Number of clients: %d");
_LIT(KTextConnectionInfoIapId, " - IapId: %d");
_LIT(KTextConnectionInfoNetId, " - NetId: %d");
_LIT(KTextConnectionInfoProcessId, " * Process id: %d");
_LIT(KTextConnectionInfoNoConnections, "--- No connections ---");
_LIT(KIapAndId, "IAP\\Id");
_LIT(KNullIp, "0.0.0.0");
_LIT(KIpLit, "ip");
_LIT(KIapCreated, "New IAP created");
const TInt KMaxInfoBufferLength = 1024;
const TInt KResolverMaxErrorMsgLength = 256;
const TInt KMaxErrorMsgLength = 286;
const TInt KNameLength = 32;
const TInt KMaxWapBearerLength = 64;
// ========================== MEMBER FUNCTIONS =============================
// -------------------------------------------------------------------------
// CIAPConnectEngine::NewL(MIAPConnectStateObserver* aObserver,
// MIAPConnectDemoEngineObserver* aDemoEngineObserver)
//
// Constructs CIAPConnectEngine object
// -------------------------------------------------------------------------
//
CIAPConnectEngine* CIAPConnectEngine::NewL(
MIAPConnectStateObserver* aObserver,
MIAPConnectDemoEngineObserver* aDemoEngineObserver)
{
CIAPConnectEngine* self = NewLC(aObserver, aDemoEngineObserver);
CleanupStack::Pop(self);
return self;
}
// -------------------------------------------------------------------------
// CIAPConnectEngine::NewLC(MIAPConnectStateObserver* aObserver,
// MIAPConnectDemoEngineObserver* aDemoEngineObserver)
//
// Constructs CIAPConnectEngine object
// -------------------------------------------------------------------------
//
CIAPConnectEngine* CIAPConnectEngine::NewLC(
MIAPConnectStateObserver* aObserver,
MIAPConnectDemoEngineObserver* aDemoEngineObserver)
{
CIAPConnectEngine* self = new (ELeave) CIAPConnectEngine(aObserver);
CleanupStack::PushL(self);
self->ConstructL(aDemoEngineObserver);
return self;
}
// -------------------------------------------------------------------------
// CIAPConnectEngine::CIAPConnectEngine(
// MIAPConnectStateObserver* aObserver,
// MIAPConnectDemoEngineObserver* aDemoEngineObserver)
//
// Constructor
// -------------------------------------------------------------------------
//
CIAPConnectEngine::CIAPConnectEngine(
MIAPConnectStateObserver* aObserver)
: CActive(CActive::EPriorityStandard), iRunningDemo(EFalse),
iObserver(aObserver)
{
SetConnectionPreferences(ECommDbBearerUnknown, ETrue);
}
// -------------------------------------------------------------------------
// CIAPConnectEngine::~CIAPConnectEngine()
//
// Destructor
// -------------------------------------------------------------------------
//
CIAPConnectEngine::~CIAPConnectEngine()
{
Cancel();
if (iTextResolver)
{
delete iTextResolver;
iTextResolver = NULL;
}
if (iProgressNotifier)
{
delete iProgressNotifier;
iProgressNotifier = NULL;
}
if (iDemoEngine)
{
delete iDemoEngine;
iDemoEngine = NULL;
}
iConnect.Close();
iSocketServ.Close();
}
// -------------------------------------------------------------------------
// CIAPConnectEngine::ConstructL(
// MIAPConnectDemoEngineObserver* aDemoEngineObserver)
//
// Second phase constructor
// -------------------------------------------------------------------------
//
void CIAPConnectEngine::ConstructL(
MIAPConnectDemoEngineObserver* aDemoEngineObserver)
{
User::LeaveIfError(iSocketServ.Connect());
User::LeaveIfError(iConnect.Open(iSocketServ));
iTextResolver = CTextResolver::NewL();
iProgressNotifier = CIAPConnectProgressNotifier::NewL(iObserver, iConnect);
iDemoEngine = CIAPConnectDemoEngine::NewL(
aDemoEngineObserver, iConnect, iSocketServ);
CActiveScheduler::Add(this);
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::ConnectL()
//
// Start connecting to IAP.
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::ConnectL()
{
if (iProgressNotifier->GetState() == EIAPConnectStateConnected)
{
return; // Already connected, do nothing
}
/*
In S60 3rd Edition, enabling/disabling the inactivity timer will require
the NetworkControl capability, which is only accessed via Symbian
partner.
*/
// Disable inactivity timer, otherwise inactive connection is closed
// within few seconds if there are no activity (e.g sockets)
#if !defined(__SERIES60_3X__) || defined(__S60_3X_NET_CTRL__)
iConnect.SetOpt(KCOLProvider, KConnDisableTimers, ETrue);
#endif
if (!IsActive())
{
iConnect.Start(iPref, iStatus);
SetActive();
}
else
{
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalInformationNote, KTextNotReady);
CleanupStack::PopAndDestroy(globalNote);
}
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::RunL()
//
// Handle request completion events
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::RunL()
{
if (!iRunningDemo)
{
TInt statusCode = iStatus.Int();
switch (statusCode)
{
case KErrNone: // Connection created succesfully
{
PrintNoteL(KTextConnectionCreated);
break;
}
case KErrNotFound: // Connection failed
{
PrintNoteL(KTextGeneralError);
break;
}
case KErrCancel: // Connection attempt cancelled
{
PrintNoteL(KTextConnectionCancelled);
break;
}
case KErrAlreadyExists: // Connection already exists
{
PrintNoteL(KTextConnectionExists);
break;
}
default:
{
// TBuf<KErrorResolverMaxTextLength> errorText; Don't use that
// constant, it is deprecated/removed in 3.0
TBuf<KResolverMaxErrorMsgLength> errorText;
// Use text resolver to resolve error text
#ifdef __SERIES60_3X__
errorText = iTextResolver->ResolveErrorString(statusCode);
#else
errorText = iTextResolver->
ResolveErrorUnlimited(statusCode);
#endif
PrintErrorL(errorText, statusCode);
break;
}
}
}
else // We are running the demo at the moment
{
// Nothing to do
}
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::PrintErrorL(const TDesC& aErrorText, TInt aErrorCode)
//
// Shows error notification
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::PrintErrorL(const TDesC& aErrorText, TInt aErrorCode)
{
TBuf<KMaxErrorMsgLength> buf;
buf.Append(aErrorText);
buf.Append(KTextErrorCodePrompt);
buf.AppendNum(aErrorCode);
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalErrorNote, buf);
CleanupStack::PopAndDestroy(globalNote);
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::PrintNoteL(const TDesC& aNoteText)
//
// Shows information notification
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::PrintNoteL(const TDesC& aNoteText)
{
CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
globalNote->ShowNoteL(EAknGlobalInformationNote, aNoteText);
CleanupStack::PopAndDestroy(globalNote);
}
// ---------------------------------------------------------------------------
// CIAPConnectEngine::DoCancel()
//
// Cancels ongoing requests
// ---------------------------------------------------------------------------
//
void CIAPConnectEngine::DoCancel()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -