📄 aoexampleengine.h
字号:
/*
* ==============================================================================
* Name : CAOExampleEngine from AOExampleEngine.h
* Part of : AOExample
* Created : 3.5.2004
* Description:
* Version :
* Copyright: Nokia
* ==============================================================================
*/
#ifndef AOEXAMPLEENGINE_H
#define AOEXAMPLEENGINE_H
#include <e32base.h>
#include <in_sock.h>
#include "Debug.h"
/**
* Instance of this class is used to fetch a document from a HTTP server.
* This is an example implementation that uses a socket connection to the
* server and fetches the document by using simple HTTP 1.0 request.
*
* The implementation is based on active object framework so the file
* fetching
*/
class CAOExampleEngine : public CActive
{
public:
enum TStates
{
ENotConnected,
ELookingUpIP,
EConnecting,
EWriting,
EReading,
};
/**
* Class implementing this observer interface is called by the
* engine when and events occurs and when the requested
* document is fetched.
*/
class MEngineObserver
{
public:
/**
* Called when the requested document is fetched.
* @param aContent content of the fetched document
*/
virtual void FileFetched(CBufBase* aContent)=0;
/**
* Called when the file fetching fails for some
* reason and is cancelled.
* @param aReason an explanation what went wrong.
*/
virtual void Cancelled(const TDesC& aReason)=0;
/**
* Called when the progress of document fetching
* goes to a next step.
*/
virtual void ToState(TStates aState)=0;
};
public: // methods
/**
* Factory method to be used to create an instance of engine
* object.
*/
static CAOExampleEngine* NewLC();
/**
* Constructor.
*/
CAOExampleEngine();
/**
* Two phase constructor.
*/
void ConstructL();
/**
* Destructor.
*/
CAOExampleEngine::~CAOExampleEngine();
/**
* Fetches a document from the HTTP server asynchronously.
* @param anURL an URL, for example:
* "http://www.myserver.com:81/docs/doc.html"
* @param aBuffer dynamic buffer where the document
* content is stored.
* @param anObserver is notified when the file download
* has completed or it has been cancelled.
*/
void FetchFileL( const TDesC& anURL,
CBufBase* aBuffer,
MEngineObserver* anObserver );
/**
* Helper function that parses server name, port and document
* part from http url string.
*/
static void ParseURLL( const TDesC& anURL,
MEngineObserver& anObserver,
TDes& aServerName,
TInt& aPort,
TDes& aDocument );
private: // methods
/**
* Checks the IP address of server. iServerName must be set
* before calling. This makes an asynchronous call and sets
* this active object to wait until address is resolved. RunL
* is then called.
*/
void ResolveIP();
/**
* Open socket connection to given address. This makes an
* asychronous call. RunL is called when request completes.
*/
void Connect(TInetAddr& aInetAddr);
/**
* Writes a HTTP request to the open socket. This is an
* asynchronous call. RunL is called when data is sent.
*/
void CAOExampleEngine::MakeHTTPRequest();
/**
* Writes a HTTP request to the open socket. This is an
* asynchronous call. RunL is called when data is sent.
* @param aContinue, whether or not to make a new read
* request to the server
*/
void ReadHTTPResponse(TBool aContinue);
/**
* Reset the state of this object to state like it would
* just have been constructed. Any outstanding request is
* cancelled.
*/
void Reset();
private: // from CActive
virtual void RunL();
virtual void DoCancel();
private: // attributes
TInt iState; // don't mess to CActive::iStatus
TBuf<64> iServerName;
TInt iPort;
TBuf<128> iDocument;
MEngineObserver* iObserver;
CBufBase* iOutputBuffer;
TBuf<512> iMsgBuf; // buffer for messages
TBuf8<256> iSocketBuf;
RSocketServ iSocketServ;
RSocket iSocket;
RHostResolver iHostResolver;
TNameEntry iNameEntry;
TSockXfrLength iStupid;
DEBUG
(
public:
/**
* Debug given string witn file logger.
*/
void Log(const TDesC& msg);
CFileLogger* iFileLogger;
);
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -