upnp/upnpstack/dlnawebserver/inc/upnpretrywrite.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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_CUPNPRETRYWRITE_H
       
    20 #define C_CUPNPRETRYWRITE_H
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <in_sock.h>
       
    26 
       
    27 
       
    28 static const TInt KWriteErrorsMax = 5;
       
    29 static const TInt KWaitWithSocketWrite = 1000000;
       
    30 
       
    31 
       
    32 // CLASS DECLARATION
       
    33 /**
       
    34 * An interface for retry write
       
    35 *
       
    36 *  @since Series60 3.1
       
    37 */
       
    38 class MUpnpRetryWriteObserver
       
    39 {
       
    40 	public:
       
    41 
       
    42         /**
       
    43         * RetryWriteSucceed
       
    44         * A callback function for succeed writing.
       
    45         * @since Series60 3.1
       
    46         */
       
    47 		virtual void RetryWriteSucceed() = 0;
       
    48 
       
    49         /**
       
    50         * RetryWriteFailL
       
    51         * A callback function for failed writing.
       
    52         * @since Series60 3.1
       
    53 		* @param aError Error code
       
    54         */
       
    55 		virtual void RetryWriteFailL( TInt aError ) = 0;
       
    56 };
       
    57 
       
    58 
       
    59 NONSHARABLE_CLASS (CUpnpRetryWrite) : CActive
       
    60 {
       
    61 	public:
       
    62 		
       
    63 	    /**
       
    64 	    * Constructor function.
       
    65 	    * @since Series60 3.1
       
    66 	    * @return A new CUpnpRetryWrite instance.
       
    67 	    **/
       
    68 		static CUpnpRetryWrite* NewL( CUpnpTcpSession&, RSocket&, MUpnpRetryWriteObserver*, TThreadPriority );
       
    69 
       
    70         /**
       
    71         * Destructor.
       
    72         */
       
    73 		~CUpnpRetryWrite();
       
    74 
       
    75         /**
       
    76         * IssueWriteRetry
       
    77         * Starts retry procedure
       
    78         * @since Series60 3.1
       
    79         */
       
    80 		void IssueWriteRetry();
       
    81 		
       
    82         /**
       
    83         * IsStarted
       
    84         * Checks if the retrying procedure is started
       
    85         * @since Series60 3.1
       
    86         * @return ETrue when retrying procedure is started, else return EFalse
       
    87         */
       
    88 		TBool IsStarted();
       
    89 		
       
    90 	private:
       
    91         /**
       
    92         * Constructor
       
    93         */
       
    94 		CUpnpRetryWrite(CUpnpTcpSession&, RSocket&, MUpnpRetryWriteObserver*, TThreadPriority );
       
    95 
       
    96         /**
       
    97         * ConstructL
       
    98         */
       
    99 		void ConstructL();
       
   100 	
       
   101         /**
       
   102         * WriteToSocket
       
   103         * Starts writing null descriptor to the socket
       
   104         * @since Series60 3.1
       
   105         */
       
   106 		void WriteToSocket();
       
   107 
       
   108         /**
       
   109         * PassErrorToObserverL
       
   110         * Retruns the error code to the observer
       
   111         * @since Series60 3.1
       
   112 		* @param aError Returned error code
       
   113         */
       
   114 		void PassErrorToObserverL( TInt aError );
       
   115 	
       
   116         /**
       
   117         * RunL
       
   118         * Active object state machine.
       
   119         * @since Series60 2.0
       
   120         */
       
   121 		void RunL();
       
   122 
       
   123         /**
       
   124         * DoCancel
       
   125         * Cancel outstanding request(s) and reset the iActive flag.
       
   126         * @since Series60 2.0
       
   127         */
       
   128 		void DoCancel();
       
   129 
       
   130         /**
       
   131         * RunError
       
   132         * RunError in case RunL leaves.
       
   133         * @since Series60 2.0
       
   134         */
       
   135 		TInt RunError( TInt aError );
       
   136 			
       
   137 	
       
   138         /**
       
   139         * TInternalState
       
   140         * Internal states.
       
   141         * @since Series60 3.1
       
   142         */
       
   143     enum TInternalState
       
   144         {
       
   145         EUnknown,
       
   146         EWaiting,
       
   147         EWriting
       
   148         };
       
   149 	
       
   150 	private:
       
   151 
       
   152 	    /**
       
   153 	    * Reference to session that owns the writer.
       
   154 	    * Session is request writing and is notified when it's finished or
       
   155 	    * errors occure, not owned.
       
   156 	    */
       
   157 		CUpnpTcpSession& iSession;
       
   158 
       
   159 	    /**
       
   160 	    * Socket used for writing data, not owned.
       
   161 	    */
       
   162 		RSocket& iSocket;
       
   163 	
       
   164 	    /**
       
   165 	    * Interface observer object.
       
   166 	    */
       
   167 		MUpnpRetryWriteObserver* iObserver;
       
   168 
       
   169 	    /**
       
   170 	    * Internal state variable.
       
   171 	    */
       
   172 		TInternalState iInternalState;
       
   173 	
       
   174 	    /**
       
   175 	    * Internal timer.
       
   176 	    */
       
   177 		RTimer iWriteTimer;
       
   178 
       
   179 	    /**
       
   180 	    * Errors coumter.
       
   181 	    */
       
   182 		TInt iWriteErrorsCount;
       
   183 		
       
   184 };
       
   185 
       
   186 
       
   187 
       
   188 #endif
       
   189