⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iapconnect_v20engine.cpp

📁 symbian中网络连接代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
* ============================================================================
*  Name     : CIAPConnect_v20Engine from IAPConnect_v20Engine.cpp
*  Part of  : IAPConnect_v20
*  Created  : 08.01.2004 by Forum Nokia
*  Implementation notes:
*       Engine class implementation
*  Version  : 1.0
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES

#include "IAPConnect_v20.hrh"
#include "IAPConnect_v20Engine.h"
#include "IAPConnect_v20ProgressNotifier.h"

#include <iapconnect_v20.rsg>

#include <eikenv.h>
#include <aknglobalnote.h> 

#include <nifman.h>

#include <TextResolver.h>
#include <aknquerydialog.h> 
#include <apsettingshandlerui.h> 
#include <aputils.h> 

// 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 is no active connection");
_LIT(KTextConnectionReleased,       "Application has released the connection");
_LIT(KTextErrorCodePrompt,          "\nError code: ");

_LIT8(KTextConnectionInfoHeader,    "--- Connections ---");
_LIT8(KTextConnectionInfoTitle,     "\nConnection %d:\n");
_LIT8(KTextConnectionInfoClients,   " Number of clients: %d\n");
_LIT8(KTextConnectionInfoIds,       " IapId: %d\n NetId: %d\n");
_LIT8(KTextConnectionInfoProcessId, "  Process id: %d\n");
_LIT8(KTextConnectionInfoNoConnections, "--- No connections ---\n");

// ========================== MEMBER FUNCTIONS ===============================

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::NewL(MIAPConnect_v20StateObserver* aObserver)
//
// Constructs CIAPConnect_v20Engine object
// ---------------------------------------------------------------------------
//
CIAPConnect_v20Engine* CIAPConnect_v20Engine::NewL(
    MIAPConnect_v20StateObserver* aObserver)
    {
    CIAPConnect_v20Engine* self = NewLC(aObserver);
    CleanupStack::Pop(self);
    return self;
    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::NewLC(MIAPConnect_v20StateObserver* aObserver)
//
// Constructs CIAPConnect_v20Engine object
// ---------------------------------------------------------------------------
//    
CIAPConnect_v20Engine* CIAPConnect_v20Engine::NewLC(
    MIAPConnect_v20StateObserver* aObserver)
    {
    CIAPConnect_v20Engine* self = new (ELeave) CIAPConnect_v20Engine(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::CIAPConnect_v20Engine(
//    MIAPConnect_v20StateObserver* aObserver)
//
// Constructor
// ---------------------------------------------------------------------------
//  
CIAPConnect_v20Engine::CIAPConnect_v20Engine(MIAPConnect_v20StateObserver* aObserver)
: CActive(CActive::EPriorityStandard),
  iObserver(aObserver)
    {
    SetConnectionPreferences(ECommDbBearerUnknown, ETrue);
    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::~CIAPConnect_v20Engine()
//
// Destructor
// ---------------------------------------------------------------------------
//  
CIAPConnect_v20Engine::~CIAPConnect_v20Engine()
    {
   	Cancel();

    delete iTextResolver;
	delete iProgressNotifier;

    iConnect.Close();
    iSocketServ.Close();

    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::ConstructL()
//
// Second phase constructor
// ---------------------------------------------------------------------------
//  
void CIAPConnect_v20Engine::ConstructL()
    {

   	iSocketServ.Connect();
    iConnect.Open(iSocketServ);

   	iTextResolver = CTextResolver::NewL();
    iProgressNotifier = CIAPConnect_v20ProgressNotifier::NewL(iObserver, iConnect);

	CActiveScheduler::Add(this);
   
    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::ConnectL()
//
// Start connecting to IAP. 
// ---------------------------------------------------------------------------
//  
void CIAPConnect_v20Engine::ConnectL()
	{

	if (!IsActive())
		{ 
        iConnect.Start(iPref, iStatus);
		SetActive();
        }
	else 
		{
		CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
		globalNote->ShowNoteL(EAknGlobalInformationNote, KTextNotReady); 
		CleanupStack::PopAndDestroy();
		}

	}

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::RunL()
//
// Handle request completion events
// ---------------------------------------------------------------------------
//  
void CIAPConnect_v20Engine::RunL()
	{
 
    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;
        // Use text resolver to resolve error text
        errorText = iTextResolver->ResolveError(statusCode);
        PrintErrorL(errorText, statusCode);
        break;
        }
        }

	}


// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::PrintErrorL(const TDesC& aErrorText, TInt aErrorCode)
//
// Shows error notification
// ---------------------------------------------------------------------------
//  
void CIAPConnect_v20Engine::PrintErrorL(
    const TDesC& aErrorText, 
    TInt aErrorCode) const
    {
    TBuf<KErrorResolverMaxTextLength+30> buf;
    
    buf.Append(aErrorText);
    buf.Append(KTextErrorCodePrompt);
    buf.AppendNum(aErrorCode);

	CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
	globalNote->ShowNoteL(EAknGlobalErrorNote, buf); 
	CleanupStack::PopAndDestroy();
    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::PrintNoteL(const TDesC& aNoteText)
//
// Shows information notification
// ---------------------------------------------------------------------------
//  
void CIAPConnect_v20Engine::PrintNoteL(const TDesC& aNoteText) const
    {
	CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
	globalNote->ShowNoteL(EAknGlobalInformationNote, aNoteText); 
    CleanupStack::PopAndDestroy();
    }

// ---------------------------------------------------------------------------
// CIAPConnect_v20Engine::DoCancel()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -