×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Regular Contributor
    Join Date
    Jun 2004
    Posts
    135

    ExampleClientEngine ...

    Hello,

    Could you guys post the ExampleClientEngine .h and .cpp files from the HTTP client example , modified in order not to prompt the access point dialog box , and that displays a wait dialog box ? ( I've tried for Series 80 and I use the CCknCancelDialog class to diaplay the wait dialog box )


    Thanks.


    Or could you please modify mine?


    ///////////////////////////////////////////////////////////////////////////////////////
    // Example Client Engine Header file
    ///////////////////////////////////////////////////////////////////////////////////////

    /*
    * ============================================================================
    * Name : ExampleClientEngine.h
    * Part of : HTTP Example
    * Created : 11/14/2003 by Forum Nokia
    * Implementation notes:
    *
    *
    * Version : 1.0
    * Copyright: Nokia Corporation
    * ============================================================================
    */


    #ifndef __EXAMPLECLIENTENGINE_H__
    #define __EXAMPLECLIENTENGINE_H__

    #include <coecntrl.h>
    #include <http\mhttpdatasupplier.h>
    #include <http\mhttptransactioncallback.h>
    #include <http\mhttpauthenticationcallback.h>

    #include <http\mhttpsessioneventcallback.h>

    #include <ckncancl.h>

    /*
    * Forward declarations
    */
    class RHTTPSession;
    class RHTTPTransaction;

    /*
    * MClientObserver
    * CClientEngine passes events and responses body data with this interface.
    * An instance of this class must be provided for construction of CClientEngine.
    */
    class MClientObserver
    {
    public:
    /*
    * ClientEvent()
    *
    * Called when event occurs in CClientEngine.
    *
    * Params:
    * aEventDescription: A event in textual format, e.g.
    * "Transaction Successful"
    *
    * Returns:
    * -
    *
    */
    virtual void ClientEvent(const TDesC& aEventDescription) = 0;

    /*
    * ClientBodyReceived()
    *
    * Called when a part of the HTTP body is received.
    *
    * Params:
    * aBodyData: Part of the body data received. (e.g. part of
    * the received HTML page)
    *
    * Returns:
    * -
    *
    */
    virtual void ClientBodyReceived(const TDesC8& aBodyData) = 0;
    };

    /*
    * Provides simple interface to HTTP Client API.
    */
    class CClientEngine : public CBase,
    public MHTTPTransactionCallback,
    public MHTTPDataSupplier,
    public MHTTPAuthenticationCallback,
    public MCknCancellableOperation
    {
    public:
    /*
    * NewL()
    *
    * Create a CClientEngine object.
    *
    * Params:
    * iObserver:
    *
    * Returns:
    * A pointer to the created instance of CClientEngine
    *
    */
    static CClientEngine* NewL(MClientObserver& iObserver);

    /*
    * NewLC()
    *
    * Create a CClientEngine object.
    *
    * Params:
    * iObserver:
    *
    * Returns:
    * A pointer to the created instance of CClientEngine
    *
    */
    static CClientEngine* NewLC(MClientObserver& iObserver);

    /*
    * ~CClientEngine()
    *
    * Destroy the object
    *
    * Params:
    * -
    *
    * Returns:
    * -
    *
    */
    ~CClientEngine();

    /*
    * IssueHTTPGetL()
    *
    * Starts a new HTTP GET transaction.
    *
    * Params:
    * aUri: URI to get. (e.g. http://host.org")
    *
    * Returns:
    * -
    *
    */
    void IssueHTTPGetL(const TDesC8& aUri);

    /*
    * IssueHTTPPostL()
    *
    * Starts a new HTTP POST transaction.
    *
    * Params:
    * aUri: URI where to post the data (e.g. http://host.org")
    * aContentType: Content type of the body, e.g. "text/plain"
    * aBody: Body data for the transaction.
    *
    * Returns:
    * -
    *
    */
    void IssueHTTPPostL(const TDesC8& aUri,
    const TDesC8& aContentType,
    const TDesC8& aBody);

    /*
    * CancelTransaction()
    *
    * Closes currently running transaction and frees resources related to it.
    *
    * Params:
    * -
    *
    * Returns:
    * -
    *
    */
    void CancelTransaction();

    /*
    * IsRunning()
    *
    * Checks if the transaction is running.
    *
    * Params:
    * -
    *
    * Returns:
    * ETrue, if transaction is currently running.
    *
    */
    inline TBool IsRunning() { return iRunning; };

    private:
    /*
    * ConstructL()
    *
    * Perform the second phase construction of a CClientEngine object.
    *
    * Params:
    * -
    *
    * Returns:
    * -
    *
    */
    void ConstructL();

    /*
    * CClientEngine()
    *
    * Perform the first phase of two phase construction.
    *
    * Params:
    * iObserver:
    *
    * Returns:
    * -
    *
    */
    CClientEngine(MClientObserver& iObserver);

    /*
    * SetHeaderL()
    *
    * Sets header value of an HTTP request.
    *
    * Params:
    * aHeaders: Headers of the HTTP request
    * aHdrField: Enumerated HTTP header field, e.g. HTTP::EUserAgent
    * aHdrValue: New value for header field
    *
    * Returns:
    * -
    *
    */
    void SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField,
    const TDesC8& aHdrValue);

    /*
    * From MHTTPSessionEventCallback
    */
    private:
    /*
    * MHFRunL()
    *
    * Called by framework to notify about transaction events.
    *
    * Params:
    * aTransaction: Transaction, where the event occured.
    * aEvent: Occured event.
    *
    * Returns:
    * -
    *
    */
    void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);

    /*
    * MHFRunError()
    *
    * Called by framework when *leave* occurs in handling of transaction event.
    *
    * Params:
    * aError: The leave code that occured.
    * aTransaction: The transaction that was being processed when leave
    * occured.
    * aEvent: The event that was being processed when leave
    * occured.
    *
    * Returns:
    * KErrNone, if the error was handled. Otherwise the value of aError, or
    * some other error value. Returning error value causes causes
    * HTTP-CORE 6 panic.
    *
    */
    TInt MHFRunError( TInt aError,
    RHTTPTransaction aTransaction,
    const THTTPEvent& aEvent);

    /*
    * From MHTTPDataSupplier (needed for HTTP POST)
    */
    private:
    /*
    * ReleaseData()
    *
    * Called by framework to allow data supplier to release resources
    * related to previous data part.
    *
    * Params:
    * -
    *
    * Returns:
    * -
    *
    */
    void ReleaseData();

    /*
    * GetNextDataPart()
    *
    * Called when next data part is needed.
    *
    * Params:
    * aDataPart: Must be set to point to the next data part.
    *
    * Returns:
    * ETrue if the provided data part is the last one. If more data parts
    * are needed after the provided one, return EFalse.
    *
    */
    TBool GetNextDataPart(TPtrC8& aDataPart);

    /*
    * Reset()
    *
    * Called by framework to reset the data supplier to its initial state.
    *
    * Params:
    * -
    *
    * Returns:
    * KErrNone if successfull.
    *
    */
    TInt Reset();

    /*
    * OverallDataSize()
    *
    * Called by framework when it needs to know the size of the
    * body data.
    *
    * Params:
    * -
    *
    * Returns:
    * Size of the data, or KErrNotFound (or KErrNotSupported)
    * if the size of the data is not known.
    *
    */
    TInt OverallDataSize();

    /*
    * From MHTTPAuthenticationCallback (needed for HTTP authentication)
    */
    private:
    /*
    * GetCredentialsL()
    *
    * Called by framework when username and password for requested URI is
    * needed.
    *
    * Params:
    * aURI: The URI being requested (e.g. "http://host.org")
    * aRealm: The realm being requested (e.g. "user@host.org")
    * aAuthenticationType: Authentication type. (e.g. "Basic")
    * aUsername: Given user name.
    * aPassword: Given password.
    *
    * Returns:
    * A pointer to the created document
    *
    */
    TBool GetCredentialsL( const TUriC8& aURI,
    RString aRealm,
    RStringF aAuthenticationType,
    RString& aUsername,
    RString& aPassword);


    void CancelOperation();

    //void MHFSessionRunL(const THTTPSessionEvent& aEvent);
    //TInt MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent);

    private:
    RHTTPSession iSession;
    RHTTPTransaction iTransaction;

    MClientObserver& iObserver; // Used for passing body data and
    // events to UI.
    HBufC8* iPostData; // Data for HTTP POST
    TBool iRunning; // ETrue, if transaction running

    CCknCancelDialog* iCancelNote;

    RSocketServ socketServ;
    RConnection connection;

    };

    #endif // __EXAMPLECLIENTENGINE_H__

  2. #2
    Regular Contributor
    Join Date
    Jun 2004
    Posts
    135

    Re: ExampleClientEngine ...

    ///////////////////////////////////////////////////////////////////////////////////////
    // Example Client Engine cpp file
    ///////////////////////////////////////////////////////////////////////////////////////


    /*
    * ============================================================================
    * Name : ExampleClientEngine.cpp
    * Part of : HTTP Example
    * Created : 11/14/2003 by Forum Nokia
    * Implementation notes:
    *
    *
    * Version : 1.0
    * Copyright: Nokia Corporation
    * ============================================================================
    */

    #include <eikon.hrh>
    //#include <aknnotewrappers.h>
    #include <uri8.h>
    #include <http.h>
    #include <chttpformencoder.h>
    #include <HttpStringConstants.h>
    #include <http\RHTTPTransaction.h>
    #include <http\RHTTPSession.h>
    #include <http\RHTTPHeaders.h>
    //#include <network.rsg>

    #include "ExampleClient.pan"
    #include "ExampleClient.hrh"
    #include "ExampleClientEngine.h"
    #include <eikenv.h>

    #include <es_sock.h>
    #include <commdb.h>
    #include <cdbcols.h>
    #include "CommDbConnPref.h"


    // Used user agent for requests
    _LIT8(KUserAgent, "SimpleClient 1.0");

    // This client accepts all content types.
    // (change to e.g. "text/plain" for plain text only)
    _LIT8(KAccept, "*/*");


    // ----------------------------------------------------------------------------
    // CClientEngine::NewL()
    //
    // Creates instance of CClientEngine.
    // ----------------------------------------------------------------------------
    CClientEngine* CClientEngine::NewL(MClientObserver& aObserver)
    {
    CClientEngine* self = CClientEngine::NewLC(aObserver);
    CleanupStack::Pop(self);
    return self;
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::NewLC()
    //
    // Creates instance of CClientEngine.
    // ----------------------------------------------------------------------------
    CClientEngine* CClientEngine::NewLC(MClientObserver& aObserver)
    {
    CClientEngine* self = new (ELeave) CClientEngine(aObserver);
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::CClientEngine()
    //
    // First phase constructor.
    // ----------------------------------------------------------------------------
    CClientEngine::CClientEngine(MClientObserver& aObserver)
    : iObserver(aObserver),
    iPostData(NULL),
    iRunning(EFalse)
    {
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::~CClientEngine()
    //
    // Destructor.
    // ----------------------------------------------------------------------------
    CClientEngine::~CClientEngine()
    {
    iSession.Close();

    delete iPostData;
    iPostData = NULL;


    if(iCancelNote)
    {
    delete iCancelNote;
    iCancelNote = NULL;
    }
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::ConstructL()
    //
    // Second phase construction.
    // ----------------------------------------------------------------------------
    void CClientEngine::ConstructL()
    {
    // Open RHTTPSession with default protocol ("HTTP/TCP")
    TRAPD(err, iSession.OpenL());
    if(err != KErrNone)
    {
    // Most common error; no access point configured, and session creation
    // leaves with KErrNotFound.
    _LIT(KErrMsg,
    "Cannot create session. Is internet access point configured?");
    _LIT(KExitingApp, "Exiting app.");
    CEikonEnv::Static()->InfoWinL(KErrMsg, KExitingApp);
    User::Leave(err);
    }

    // Initialise the socket server session.
    //RSocketServ socketServ;
    User::LeaveIfError(socketServ.Connect());

    // Initialise the RConnection.
    //RConnection connection;
    User::LeaveIfError(connection.Open(socketServ));

    // open the IAP communications database
    CCommsDatabase* commDB = CCommsDatabase::NewL(EDatabaseTypeIAP);
    CleanupStack::PushL(commDB);

    // initialize a view
    CCommsDbConnectionPrefTableView* commDBView =
    commDB->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing);

    // go to the first record
    User::LeaveIfError(commDBView->GotoFirstRecord());

    // Declare a prefTableView Object.
    CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;

    // read the connection preferences
    commDBView->ReadConnectionPreferenceL(pref);
    TUint32 iapID = pref.iBearer.iIapId;

    // pop and destroy the IAP View
    CleanupStack::PopAndDestroy(commDBView);

    // pop and destroy the database object
    CleanupStack::PopAndDestroy(commDB);

    // Now we have the iap Id. Use it to connect for the connection.
    // Create a connection preference variable.
    TCommDbConnPref connectPref;

    // setup preferences
    connectPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    connectPref.SetDirection(ECommDbConnectionDirectionOutgoing);
    connectPref.SetBearerSet(ECommDbBearerGPRS);
    connectPref.SetIapId(iapID);

    // start a synchronous connection
    TInt errConnect = connection.Start(connectPref);

    //Then, associate the current socket server session and rconnection object
    //used above with the HttpSession which u will be using.

    //RStringPool strP = iSession.StringPool();
    //RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    //connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
    //TInt connPtr = REINTERPRET_CAST(TInt, &(connection));
    //connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );



    // Install this class as the callback for authentication requests. When
    // page requires authentication the framework calls GetCredentialsL to get
    // user name and password.
    InstallAuthenticationL(iSession);

    }

    void CClientEngine::CancelOperation()
    {
    CEikonEnv::Static()->InfoMsg(_L("cancel"));
    // if(iCancelNote)
    // iCancelNote->Release();
    CancelTransaction();
    }

    // ----------------------------------------------------------------------------
    // CClientEngine::SetHeaderL()
    //
    // Used to set header value to HTTP request
    // ----------------------------------------------------------------------------
    void CClientEngine::SetHeaderL(RHTTPHeaders aHeaders,
    TInt aHdrField,
    const TDesC8& aHdrValue)
    {
    if(iCancelNote)
    {
    delete iCancelNote;
    iCancelNote = NULL;
    }

    iCancelNote = CCknCancelDialog::NewL(&iCancelNote, this,_L("login"), _L("please wait...."));
    iCancelNote->RunDlgLD();

    RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
    CleanupClosePushL(valStr);
    THTTPHdrVal val(valStr);
    aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val);
    CleanupStack::PopAndDestroy(); // valStr
    }


    // ----------------------------------------------------------------------------
    // CClientEngine::IssueHTTPGetL()
    //
    // Start a new HTTP GET transaction.
    // ----------------------------------------------------------------------------
    void CClientEngine::IssueHTTPGetL(const TDesC8& aUri)
    {
    // Parse string to URI (as defined in RFC2396)
    TUriParser8 uri;
    uri.Parse(aUri);

    // Get request method string for HTTP GET
    RStringF method = iSession.StringPool().StringF(HTTP::EGET,
    RHTTPSession::GetTable());

    // Open transaction with previous method and parsed uri. This class will
    // receive transaction events in MHFRunL and MHFRunError.
    iTransaction = iSession.OpenTransactionL(uri, *this, method);

    // Set headers for request; user agent and accepted content type
    RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
    SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
    SetHeaderL(hdr, HTTP::EAccept, KAccept);


    RStringPool strP = iSession.StringPool();
    RHTTPConnectionInfo connInfo = iSession.ConnectionInfo();
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (socketServ.Handle()) );
    TInt connPtr = REINTERPRET_CAST(TInt, &(connection));
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );


    // Submit the transaction. After this the framework will give transaction
    // events via MHFRunL and MHFRunError.
    iTransaction.SubmitL();

    iRunning = ETrue;
    _LIT(KConnecting,"Connecting...");
    iObserver.ClientEvent(KConnecting);
    }

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    41

    Re: ExampleClientEngine ...

    Check out http://sw.nokia.com/id/b014acbe-4cbf...ample_v1_1.zip

    Especially the TaskManagerEngine.cpp. It uses the RConnection class to connect without prompting the access point. In CTaskManagerEngine::ConnectL() method, the HTTP connection is "attached" to the connected IAP like this:

    RStringPool strP = iHttpSession.StringPool();
    RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo();
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), THTTPHdrVal (iSockServ.Handle()) );
    TInt connPtr = reinterpret_cast<TInt>(&iConnection);
    connInfo.SetPropertyL ( strP.StringF(HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), THTTPHdrVal (connPtr) );

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×