upnp/upnpstack/dlnawebserver/inc/upnptcpsessionwriter.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  CUpnpTcpSessionWriter is a class responsible for 
       
    15 *                   asynchronous writing to a socket owned by CUpnpTcpSession.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_UPNPTCPSESSIONWRITER_H
       
    22 #define C_UPNPTCPSESSIONWRITER_H
       
    23 
       
    24 
       
    25 #include <e32base.h>
       
    26 #include <in_sock.h>
       
    27 #include "upnpretrywrite.h"
       
    28 
       
    29 class CUpnpTcpSession;
       
    30 class CUpnpTcpWriteRequest;
       
    31 
       
    32     
       
    33 /**
       
    34  *  CUpnpTcpSessionWriter is responsible for asynchronous writing.
       
    35  *  Writer class is owned by CUpnpTcpSession which request asynchronous 
       
    36  *  writing from it and is notified by writer when the write request 
       
    37  *  is completed or an error occured.
       
    38  *  When writer receives data to send it checks if it can be sent to the socket
       
    39  *  right away and if session is not yet connected or writer already sends data
       
    40  *  then it queues incoming data. When writing to the socket ends, writer checks 
       
    41  *  if there is data in queue waiting for sending. If thereis then it issues writing it 
       
    42  *  until the queue is empty. After writing all data, the writer notifies session about
       
    43  *  completion of the writing taska and switches to waiting state until it receives 
       
    44  *  another write request.
       
    45  *  @lib DLNAWebServer.lib
       
    46  *  @since Series60 2.6
       
    47  */
       
    48 NONSHARABLE_CLASS (CUpnpTcpSessionWriter) : public CActive, MUpnpRetryWriteObserver
       
    49     {
       
    50 public:
       
    51 
       
    52     /**
       
    53     * CUpnpTcpSessionWriter factory method.
       
    54     * @since Series60 2.6
       
    55     * @param aSession session that runs and supervises reader.
       
    56     * @param aSocket socket from which data will be read.
       
    57     * @param aPriority priority with which the reader will be working.
       
    58     * @return ?description
       
    59     */
       
    60     static CUpnpTcpSessionWriter* NewL( CUpnpTcpSession& aSession,
       
    61                                         RSocket& aSocket, 
       
    62                                         TThreadPriority aPriority );
       
    63 
       
    64     /**
       
    65     * Virtual destructor.
       
    66     * @since Series60 2.6
       
    67     */   
       
    68     virtual ~CUpnpTcpSessionWriter();
       
    69 
       
    70 public: // New functions
       
    71     
       
    72     /**
       
    73     * Issues writing in asynchronous mode.
       
    74     * @since Series60 2.6
       
    75     * @param aData buffer with data to write.
       
    76     */
       
    77     void IssueWriteL( const TDesC8& aData );
       
    78     
       
    79     
       
    80     /**
       
    81     * Function used by CUpnpTcpSession that owns the writer
       
    82     * to notify if socket is connected and if writer can write data.
       
    83     * @since Series60 2.6
       
    84     * @param aConnected
       
    85     */
       
    86     void SessionConnected( TBool aConnected );
       
    87     
       
    88     /**
       
    89     * Returnes true if there are some write request queued and
       
    90     *   false if all data has been sent already.
       
    91     * @since Series60 2.6
       
    92     * @return true if there are some write request queued and
       
    93     *   false if all data has been sent already.
       
    94     */
       
    95     TBool HasWriteRequestsToSend();
       
    96     
       
    97     /**
       
    98     * Returns if retrying of writng occurs
       
    99     * @since series60 3.2
       
   100     * @return ETrue/EFalse
       
   101     */  
       
   102     TBool IsRetrying();
       
   103 
       
   104     /**
       
   105     * Returns if writer is writing some data at the moment.
       
   106     * @since series60 2.6
       
   107     * @return true if writer writes data at the moment.
       
   108     */  
       
   109     TBool IsWriting();
       
   110 
       
   111 protected: // Functions from base CActive
       
   112     
       
   113     /**
       
   114     * Cancels issued writing request.
       
   115     * Standard active object function
       
   116     * @since Series60 2.6
       
   117     */
       
   118     void DoCancel();
       
   119     
       
   120     /**
       
   121     * Function called when the write request is finished.
       
   122     * Standard active object function
       
   123     * @since Series60 2.6
       
   124     */
       
   125     void RunL();
       
   126     
       
   127     /**
       
   128     * Trap RunL leaves
       
   129     * Standard active object function
       
   130     * @since Series60 2.0
       
   131     */
       
   132     TInt RunError( TInt aError );
       
   133     
       
   134 private: // Constructors and destructors
       
   135     
       
   136     /**
       
   137     * CUpnpTcpSessionWriter constructor.
       
   138     * @since Series60 2.6
       
   139     * @param aSession session that runs and supervises reader.
       
   140     * @param aSocket socket from which data will be read.
       
   141     * @param aPriority priority with which the reader will be working.
       
   142     */
       
   143     CUpnpTcpSessionWriter( CUpnpTcpSession& aSession,
       
   144                            RSocket& aSocket,
       
   145                            TThreadPriority aPriority );
       
   146 
       
   147     /**
       
   148     * By default Symbian 2nd phase constructor is private.
       
   149     * @since Series60 2.6
       
   150     */
       
   151     void ConstructL();
       
   152 
       
   153 
       
   154 private: // New functions
       
   155 
       
   156     /**
       
   157     * Sends next queued write request if such exists.
       
   158     * @since Series60 2.6
       
   159     */
       
   160     void SendNextWriteRequestL();
       
   161     
       
   162 private: // from MUpnpRetryWriteObserver
       
   163 	
       
   164     /**
       
   165     * Called when retrying of writing was succesed.
       
   166     * @since Series60 3.2
       
   167     */
       
   168 	void RetryWriteSucceed();
       
   169 
       
   170     /**
       
   171     * Called when retrying of writing fail.
       
   172     * @since Series60 3.2
       
   173     */
       
   174 	void RetryWriteFailL( TInt aError );
       
   175 
       
   176 private: // Enumerations
       
   177 
       
   178     /**
       
   179     * TWriteState, records whether a write request is pending.
       
   180     *   - EnotConnected Socket is not yet connected so writer cannot write.
       
   181     *   - EWriting  A write request is pending with the socket server.
       
   182     *   - EWaiting  The idle state for this object. Socket is connected
       
   183     *               and the writer waits for write requests form session.
       
   184     *   - EDisconnected Session is already disconnected so don't write and don't 
       
   185     *               queue requests.
       
   186     */
       
   187     enum TWriterState
       
   188         {
       
   189         ENotConnected,
       
   190         EWriting,
       
   191         EWaiting,
       
   192         EDisconnected
       
   193         };
       
   194 
       
   195 private: 
       
   196     
       
   197     /**
       
   198     * Socket used for writing data, not owned.
       
   199     */
       
   200     RSocket& iSocket;
       
   201 
       
   202     /**
       
   203     * Reference to session that owns the writer.
       
   204     * Session is request writing and is notified when it's finished or
       
   205     * errors occure, not owned.
       
   206     */
       
   207     CUpnpTcpSession& iSession;
       
   208 
       
   209     /**
       
   210     * State of the writer.
       
   211     */
       
   212     TWriterState iState;
       
   213 
       
   214     /**
       
   215     * Buffer that is used to send data to session.
       
   216     * Own.
       
   217     */
       
   218     RBuf8 iSendBuffer;
       
   219 
       
   220     /**
       
   221     * List of write requests. If session is unable to send data to session,
       
   222     * it is put into write request list.
       
   223     * Own.
       
   224     */
       
   225     RPointerArray<CUpnpTcpWriteRequest> iWriteRequestList;
       
   226     
       
   227     /**
       
   228     * Initial priority of the active object.
       
   229     */
       
   230     TThreadPriority iInitialPriority;
       
   231     
       
   232     /**
       
   233     * Implementation of retrying write to the socket
       
   234     */
       
   235     CUpnpRetryWrite* iRetryWrite;
       
   236 
       
   237     };
       
   238 
       
   239 #endif // C_UPNPTCPSESSIONWRITER_H
       
   240 
       
   241 // End Of File