IMPSengine/enginc/ImpsDataChannelAPI.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2005 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:  This file defines an interface for sending and receiving data
       
    15 *               from transport module. In other words a transport module must
       
    16 *               provide the methods defined below and call the observer methods
       
    17 *               for incoming data.
       
    18 *
       
    19 *
       
    20 */
       
    21 
       
    22 #ifndef WV_DATACHANNEL_API_H
       
    23 #define WV_DATACHANNEL_API_H
       
    24 
       
    25 // CLASS DECLARATIONS
       
    26 
       
    27 /**
       
    28 * MImpsDataReceiver
       
    29 *
       
    30 * Abstract interface for handling responses from data channel module.
       
    31 * Server implements this class and gives a pointer to the data channel.
       
    32 * Data channel module calls the method when it has received data.
       
    33 */
       
    34 
       
    35 class MImpsDataReceiver
       
    36     {
       
    37 
       
    38     public: // New functions
       
    39 
       
    40         /**
       
    41         * Callback for transport request response
       
    42         * This handles the responses to the SendL() method from MImpsSender
       
    43         *
       
    44         * NOTE: It is very important to bear in mind that the memory
       
    45         *       area which the fourth parameter points to, MUST be
       
    46         *       deallocated by the object that implements this abstract
       
    47         *       interface! After the IMPS Data Channel component has
       
    48         *       called this method, it is no longer responsible for
       
    49         *       maintenance (including deallocation) of this chunk of
       
    50         *       heap. Failure to free the memory area will result in
       
    51         *       a serious memory leak and, consequently, a crash.
       
    52         *       Also note that in many error cases, including a request
       
    53         *       timing out, the pointer will be NULL as there is no data
       
    54         *       to relay.
       
    55         *
       
    56         * @param TInt Operation-id given in SendL() method
       
    57         * @param TInt Internal error code, KErrNone if successful
       
    58         * @param TInt HTTP status code, 200 if successful
       
    59         * @param HBufC8* Pointer to the raw eight-bit CSP data;
       
    60         *                must be deleted by the implementing class
       
    61         *                after its contents are no longer needed
       
    62         */
       
    63         virtual void TransportResponse( const TInt aId,
       
    64                                         const TInt aError,
       
    65                                         const TInt aHttpStatus,
       
    66                                         HBufC8* aCspMessage ) = 0;
       
    67     };
       
    68 
       
    69 /**
       
    70 * MImpsSender
       
    71 *
       
    72 * Abstract interface for sending messages to the data channel.
       
    73 * The data channel module implements this class.
       
    74 */
       
    75 
       
    76 //The bearer connection manager used by MImpsSender instances
       
    77 class MMsgConnManager;
       
    78 
       
    79 class MImpsSender
       
    80     {
       
    81 
       
    82     public: // New functions
       
    83 
       
    84         /**
       
    85          * Opens a session to the HTTP Stack.
       
    86          *    - If already opened then error code is returned ( KErrAlreadyExists )
       
    87          *    - Leaves with KImpsErrorBearerSuspended if GPRS is suspended
       
    88          *    - KErrOutOfMemory if new objects cannot be allocated
       
    89          *    (- some other system-wide error code returned by the HTTP framework)
       
    90          *
       
    91          * This is a synchronous method: after a call to this method, the client
       
    92          * application can assume the data channel to be open - provided the
       
    93          * method call did not leave.
       
    94          *
       
    95          * @param aSAP WV SAP.
       
    96          *        The address has a format:
       
    97          *        hostport [ "/" hpath [ "?" search ]]
       
    98          *        Refer to RFC1738
       
    99          * @return void
       
   100          */
       
   101         virtual void OpenL( const TDesC& aSAP ) = 0;
       
   102 
       
   103         /**
       
   104         * Closes the session to HTTP Stack
       
   105         * @return Status code of the performed operation.
       
   106         */
       
   107         virtual void Close() = 0;
       
   108 
       
   109         /**
       
   110         * Send a request.
       
   111         * When this method returns the data is saved and aMessage
       
   112         * parameter can be re-used.
       
   113         * If the state of the bearer connection is other than
       
   114         * EImpsBearerActive, leaves with an error immediately:
       
   115         *   * EImpsBearerLost state - KImpsErrorBearerNotReady
       
   116         *   * EImpsBearerSuspended state - KImpsErrorBearerSuspended
       
   117         * The function may also leave with KImpsErrorSessionNotOpen
       
   118         * in case OpenL() has not been called prior to the call of this method.
       
   119         *
       
   120         * A response is received through MImpsReceiver.
       
   121         * The third parameter, aExpiryTime is optional. The function
       
   122         * first checks whether the value is something other than 0. If
       
   123         * it is, a timer gets instantiated and activated, and expires
       
   124         * according to the value passed in the parameter. The
       
   125         * value should be presented in seconds.
       
   126         *
       
   127         * @param aId operation-id to identify the request.
       
   128         * @param aMessage data to be sent
       
   129         * @param aExpiryTime expiry time of the request in seconds
       
   130         */
       
   131         virtual void SendL( const TInt aId,
       
   132                             const TDesC8& aMessage,
       
   133                             const TInt aExpiryTime = 0 ) = 0;
       
   134 
       
   135         /**
       
   136         * Destructor. A simple wrapper to the C++ destructor.
       
   137         *
       
   138         * NOTE that HTTP Stack uses the connection and socket
       
   139         * server instances owned by MImpsConnectionManager,
       
   140         * so one should be very careful NOT to Destroy() the
       
   141         * ConnMan instance before an instance of this interface.
       
   142         * At deletion time HTTP Stack might have outstanding socket
       
   143         * reads and/or writes, the cancelling of which will surely
       
   144         * fail in case the socket session on which the sockets were
       
   145         * initially opened has been prematurely closed.
       
   146         */
       
   147         virtual void Destroy() = 0;
       
   148 
       
   149         /**
       
   150         * Cancel all pending transactions.
       
   151         * After this request it is guaranteed that observer methods
       
   152         * are not called until new requests have been made.
       
   153         */
       
   154         virtual void CancelAll() = 0;
       
   155 
       
   156         /**
       
   157         * Cancel a named transaction.
       
   158         */
       
   159         virtual void CancelTransaction( const TInt aTID ) = 0;
       
   160 
       
   161         /**
       
   162         * Return the number of requests to which
       
   163         * a response has not yet been received.
       
   164         */
       
   165         virtual TInt PendingRequests() const = 0;
       
   166 
       
   167     };
       
   168 
       
   169 /**
       
   170 * Creates a new sender object
       
   171 * @param RFs& aSession Reference to an opened file session
       
   172 * @param TDesC8& aMimeType MIME type of the messages to be sent
       
   173 * @param MImpsReceiver* aReceiver Pointer to the receiving object
       
   174 * @return MImpsSender
       
   175 */
       
   176 IMPORT_C MImpsSender* NewImpsSenderL( MImpsDataReceiver& aReceiver,
       
   177                                       MMsgConnManager& aConnManager,
       
   178                                       const TDesC8& aMimeType );
       
   179 
       
   180 #endif      // ?INCLUDE_H   
       
   181 
       
   182 // End of File