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

📄 response.cpp

📁 symbian http/post引擎 xml引擎 支持IAP设置
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CResponse from Response.cpp
*  Part of  : TaskManager
*  Created  : 03/13/2005 by Forum Nokia
*  Version  : 1.2
*  Copyright: Nokia Corporation
* ============================================================================
*/

// INCLUDE FILES
#include "Response.h"
#include "TaskManager.pan"

// CONSTANTS
_LIT(KError, "#Error:");
_LIT(KOkMessage, "#OK");
_LIT(KTab, "\t");
_LIT(KSeparator, "#");

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

// constructor
CResponse::CResponse()
	{
	}
	
// destructor	
CResponse::~CResponse()
	{
	iIds.Close();
	
	if(iDescriptions)
		{
		delete iDescriptions;
		iDescriptions=NULL;
		}
	
	if(iReceivedData)
		{
		delete iReceivedData;
		iReceivedData=NULL;
		}
	
	if(iXmlHandler)
		{
		delete iXmlHandler;
		iXmlHandler=NULL;
		}
	}

// ----------------------------------------------------
// CResponse::NewL()
// Two-phased constructor.
// ----------------------------------------------------
//	
CResponse* CResponse::NewL()
	{
	CResponse* self = CResponse::NewLC();
	CleanupStack::Pop(self);
	return self;
	}

// ----------------------------------------------------
// CResponse::NewLC()
// Two-phased constructor.
// ----------------------------------------------------
//	
CResponse* CResponse::NewLC()
	{
	CResponse* self = new (ELeave) CResponse;
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

// ----------------------------------------------------
// CResponse::ConstructL()
// Symbian OS default constructor can leave.
// ----------------------------------------------------
//	
void CResponse::ConstructL()
	{
	iDescriptions = new (ELeave) CDesCArrayFlat(1);
//    iXmlHandler = CXmlHandler::NewL( *this );
    }

// ----------------------------------------------------
// CResponse::InputDataL()
// This functions constructs a response object from the 
// data received from the server. E.g. if aData contains 
// tasks, tasks are parsed to arrays, where they can be 
// easily fetched. 
// ----------------------------------------------------
//	
void CResponse::InputDataL(const TDesC8& aData)
	{
	if(iReceivedData)
		{
		delete iReceivedData;
		iReceivedData=NULL;
		}
	
	iReceivedData=HBufC8::NewL(aData.Length());
    TPtr8 bufferPtr( iReceivedData->Des() );
        
    // Convert tag name from TDesC8 to TDesC16.
    bufferPtr.Copy( aData );
	
	// error occurred in the server side (i.e. the aData begins #Error: ).
/*	if (KError() == aData.Left(7))
		{
		// remove the #-character.
		iError = aData.Mid(1);
		return;
		}
	
	// response for completing task.
	if (aData.Find(KOkMessage) != KErrNotFound)
		{
		iResponseType = ETaskComplete;
		return;
		}
		
	TLex lex(aData);
	TTaskReadStatus status = EStart;
	
	// Tasks are in form: #id#description#id#description#
	while (!lex.Eos())
		{
		if (lex.Peek() == TChar(KSeparator()[0]))
			{
			switch (status)
				{
				// first #-character found
				case EStart:
					{
					status = EReadId;
					break;
					}
				// read the id of the tasks.
				case EReadId:
					{
					status = EReadTask;
					TInt id;
					TLex tmp(lex.MarkedToken());
					User::LeaveIfError(tmp.Val(id));
					User::LeaveIfError(iIds.Append(id));
					break;
					}
				// read the description of the task.
				case EReadTask:
					{
					status = EReadId;
					TPtrC task = lex.MarkedToken();
					iDescriptions->AppendL(task);
					break;
					}
				}
			lex.Inc();
			lex.Mark();
			}
		else
			{
			lex.Inc();	
			}
		}	*/
	}

// ----------------------------------------------------
// CResponse::HasError()
// Returns whether errors occurred in the server side 
// or not.
// ----------------------------------------------------
//	
TBool CResponse::HasError() const
	{
	TBool retval = EFalse;
	if (iError.Length() > 0)
		{
		retval = ETrue;
		}
	return retval;
	}

// ----------------------------------------------------
// CResponse::Error()
// Returns the error description. 
// ----------------------------------------------------
//	
TBuf<KMaxError> CResponse::Error() const
	{
	return iError;
	}

// ----------------------------------------------------
// CResponse::TaskCount()
// Returns the amount of tasks received from the server. 
// ----------------------------------------------------
//	
TInt CResponse::TaskCount() const
	{
	return iIds.Count();
	}

// ----------------------------------------------------
// CResponse::TaskDescription()
// Returns a task description. 
// ----------------------------------------------------
//	
TBuf<KMaxTaskLength> CResponse::TaskDescription(const TInt& aIndex) const
	{
	if (aIndex >= iDescriptions->Count() || 0 > aIndex)
		{
		Panic(ETaskManagerInvalidTaskIndex);
		}
		
	return (*iDescriptions)[aIndex];
	}

// ----------------------------------------------------
// CResponse::TaskId()
// Returns a task id. 
// ----------------------------------------------------
//	
TInt CResponse::TaskId(const TInt& aIndex) const
	{
	if (aIndex >= iDescriptions->Count() || 0 > aIndex)
		{
		Panic(ETaskManagerInvalidTaskIndex);
		}

	return iIds[aIndex];
	}

// ----------------------------------------------------
// CResponse::ResponseType()
// Returns the type of this response. 
// ----------------------------------------------------
//	
CResponse::TResponseType CResponse::ResponseType() const
	{
	return iResponseType;
	}
void CResponse::OnParseCompleted( TInt aError )
	{
	
	}
// End of file

⌨️ 快捷键说明

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