upnp/upnpstack/serviceframework/inc/upnphttpmessagesender.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies  this distribution, and is available 
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declares the CUpnpHttpMessageSender class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __UPNPHTTPMESSAGESENDER_H__
       
    20 #define __UPNPHTTPMESSAGESENDER_H__
       
    21 
       
    22 #include <http.h>
       
    23 #include <upnpnotifytimer.h>
       
    24 
       
    25 class MUpnpHttpMessageSenderOwner;
       
    26 class CUpnpHttpTransaction;
       
    27 
       
    28 /**
       
    29  *  Class that manage sending process of a single transaction (
       
    30  *  request http message and response http message).
       
    31  *
       
    32  */
       
    33 NONSHARABLE_CLASS( CUpnpHttpMessageSender ) : public CBase,
       
    34                                               public MHTTPTransactionCallback,
       
    35                                               public MHTTPDataSupplier,
       
    36                                               public MUpnpNotifyTimerObserver
       
    37     {
       
    38 public:
       
    39     /**
       
    40      * Two-phased constructor. Create a CUpnpHttpMessageSender object.
       
    41      * @param aUpnpTransaction unsent upnp transaction object
       
    42      * @param aSession opened http session that will be used to send the message
       
    43      * @param aOwner object that should be notified when sender finish its job
       
    44      *                  and issue destruction of this (sender) object
       
    45      * @return A pointer to the created instance of CUpnpHttpMessageSender
       
    46      */
       
    47     static CUpnpHttpMessageSender* NewL( CUpnpHttpTransaction& aUpnpTransaction,
       
    48                                          RHTTPSession aSession,
       
    49                                          MUpnpHttpMessageSenderOwner& aOwner
       
    50                                          );
       
    51 
       
    52     /**
       
    53      * Two-phased constructor. Create a CUpnpHttpMessageSender object.
       
    54      * @param aUpnpTransaction unsent upnp transaction object
       
    55      * @param aSession opened http session that will be used to send the message
       
    56      * @param aOwner object that should be notified when sender finish its job
       
    57      *                  and issue destruction of this (sender) object
       
    58      * @return A pointer to the created instance of CUpnpHttpMessageSender
       
    59      */
       
    60     static CUpnpHttpMessageSender* NewLC( CUpnpHttpTransaction& aUpnpTransaction,
       
    61                                           RHTTPSession aSession,
       
    62                                           MUpnpHttpMessageSenderOwner& aOwner
       
    63                                           );
       
    64 
       
    65     /**
       
    66      * Destructor.
       
    67      */
       
    68     ~CUpnpHttpMessageSender();
       
    69 
       
    70     /**
       
    71      * Start a new HTTP transaction maintained by the object. It will start
       
    72      * asynchronous sending of request message.
       
    73      */
       
    74     void StartTransactionL();
       
    75 
       
    76     /**
       
    77      * Returns upnp transaction object that is maintained by the object.
       
    78      * @return upnp transaction object that is maintained by the object
       
    79      */
       
    80     CUpnpHttpTransaction& UpnpTransaction();
       
    81     
       
    82     
       
    83     void CancelTransaction();
       
    84 
       
    85 private:    //from MHTTPTransactionCallback
       
    86     /**
       
    87      * Called by framework to notify about transaction events.
       
    88      * @param aTransaction: Transaction, where the event occured.
       
    89      * @param aEvent:       Occured event.
       
    90      */
       
    91     virtual void MHFRunL( RHTTPTransaction aTransaction, const THTTPEvent& aEvent );
       
    92 
       
    93     /**
       
    94      * Called by framework when *leave* occurs in handling of transaction event.
       
    95      * @param aError:       The leave code that occured.
       
    96      * @param aTransaction: The transaction that was being processed when leave occured.
       
    97      * @param aEvent:       The event that was being processed when leave occured.
       
    98      * @return KErrNone,    if the error was handled. Otherwise the value of aError, or
       
    99      *                      some other error value. Returning error value causes causes
       
   100      *                      HTTP-CORE 6 panic.
       
   101      */
       
   102     virtual TInt MHFRunError( TInt aError,
       
   103             RHTTPTransaction aTransaction,
       
   104             const THTTPEvent& aEvent );
       
   105 
       
   106 private:    //from MHTTPDataSupplier
       
   107     /*
       
   108      * Methods from MHTTPDataSupplier are used to supply body of request from
       
   109      * our UpnpMessage to Symian RHTTPRequest
       
   110      */
       
   111     virtual TBool GetNextDataPart( TPtrC8& aDataChunk );
       
   112 
       
   113     virtual void ReleaseData();
       
   114 
       
   115     virtual TInt OverallDataSize();
       
   116 
       
   117     virtual TInt Reset();
       
   118 
       
   119 private:    //from MNotifyTimerObserver
       
   120     /**
       
   121      * From MNotifyTimerObserver Function which indicate that message is timeout.
       
   122      * @since Series ?XX ?SeriesXX_version
       
   123      * @param aTimer Timer.
       
   124      */
       
   125     virtual void TimerEventL( CUpnpNotifyTimer* aTimer );
       
   126 
       
   127 private:
       
   128     /**
       
   129      * Constructor
       
   130      * @param aUpnpTransaction unsent upnp transaction object
       
   131      * @param aSession opened http session that will be used to send the message
       
   132      * @param aOwner object that should be notified when sender finish its job
       
   133      *                  and issue destruction of this (sender) object
       
   134      */
       
   135     CUpnpHttpMessageSender( CUpnpHttpTransaction& aUpnpTransaction,
       
   136                             RHTTPSession aSession,
       
   137                             MUpnpHttpMessageSenderOwner& aOwner
       
   138                             );
       
   139                                                         
       
   140     /**
       
   141      * Second phase constructor
       
   142      */
       
   143     void ConstructL();
       
   144 
       
   145     /**
       
   146      * Opens RHTTPTransaction with request method and uri, subscribe
       
   147      * for transaction's events
       
   148      */
       
   149     void PrepareRequestTransactionL();
       
   150 
       
   151     /**
       
   152      * Sets http headers from UpnpHttpTransaction to RHTTPTransaction
       
   153      */
       
   154     void PrepareRequestHeadersL();
       
   155 
       
   156     /**
       
   157      * Copies http headers from RHTTPTransaction to UpnpHttpTransaction
       
   158      */
       
   159     void CopyResponseHeadersL();
       
   160 
       
   161     /**
       
   162      * Sets http message body from UpnpHttpTransaction to RHTTPTransaction
       
   163      */
       
   164     void PrepareRequestBody();
       
   165 
       
   166     /**
       
   167      * Starts timer of request sending with TcpTimeout value.
       
   168      */
       
   169     void StartRequestTimer();
       
   170 
       
   171     /**
       
   172      * Called when transaction succeeded.
       
   173      * Closes RHTTPTransaction, and forward result message to observer.
       
   174      */
       
   175     void TransactionSucceeded();
       
   176 
       
   177     /**
       
   178      * Do NOT use this method directly, but via TransactionFailed
       
   179      */
       
   180     void DoTransactionFailedL( TInt aStatus, TInt aError );
       
   181     
       
   182     /**
       
   183      * Do NOT use this method directly, but via TransactionSucceded
       
   184      */
       
   185     void DoTransactionSucceededL();
       
   186     
       
   187     /**
       
   188      * Called in case of every fail of transaction.
       
   189      * Closes RHTTPTransaction, creates error message (408 timeout), and forward it
       
   190      * to observer.
       
   191      */
       
   192     void TransactionFailed( TInt aStatus, TInt aError = 0 );
       
   193 
       
   194     /**
       
   195      * Called when transaction got another part of body data.
       
   196      * Data is concatenated to iBody and when the last part of body is received
       
   197      * request message is created witin transaction.
       
   198      */
       
   199     void GotResponseBodyDataL( MHTTPDataSupplier& aResponseBodySupplier );
       
   200 
       
   201     /**
       
   202      * Helper method that allocate descriptor object with destination uri of message
       
   203      * passed as a parameter.
       
   204      */
       
   205     static HBufC8* DestinationUriL( CUpnpHttpMessage* aMessage );
       
   206 
       
   207 private:
       
   208     /**
       
   209      * Represents UPnP transaction
       
   210      */
       
   211     CUpnpHttpTransaction& iUpnpTransaction;
       
   212 
       
   213     /**
       
   214      * Timer of transaction
       
   215      */
       
   216     CUpnpNotifyTimer* iTimer;
       
   217 
       
   218     /**
       
   219      * Represents HTTP Transaction used to realize UPnP transaction
       
   220      */
       
   221     RHTTPTransaction iTransaction;
       
   222 
       
   223     /**
       
   224      * Error number to be sent if transaction failed
       
   225      */    
       
   226     TInt iCurrentErrorNumber;
       
   227     
       
   228     /**
       
   229      * Represents HTTP Session object
       
   230      */
       
   231     RHTTPSession iSession;
       
   232 
       
   233     /**
       
   234      * Body of received message
       
   235      */
       
   236     HBufC8* iBody;
       
   237 
       
   238     /*
       
   239      * Owner of an instance.
       
   240      */
       
   241     MUpnpHttpMessageSenderOwner& iOwner;
       
   242 
       
   243     };
       
   244 
       
   245 #endif /*__UPNPHTTPMESSAGESENDER_H__*/
       
   246 
       
   247 //  End of File
       
   248