upnp/upnpstack/upnputils/inc/upnptimeoutelement.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:  Declares virtual MUpnpTimeoutElementParent callback class
       
    15 *                and the implemented active object class CUpnpTimeoutElement
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef C_CUPNPTIMEOUTELEMENT_H
       
    21 #define C_CUPNPTIMEOUTELEMENT_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <e32base.h>
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CUpnpTimeoutElement;
       
    29 
       
    30 // CLASS DECLARATION
       
    31 
       
    32 /**
       
    33 *  @brief A virtual parent class.
       
    34 *
       
    35 *  This interface class is used to receive the timeout callbacks from timeout
       
    36 *  elements.
       
    37 *
       
    38 *  @since Series60 2.0
       
    39 */
       
    40 
       
    41 class MUpnpTimeoutElementParent 
       
    42     {
       
    43     public:
       
    44 
       
    45     /**
       
    46     * A virtual function to be implemented in derived classes.
       
    47     * For example, the implementation might contain deletion of the timeout element.
       
    48     * @since Series60 2.0
       
    49     * @param anElement This pointer contains the element whose timeout has ran out. 
       
    50     * @return None
       
    51     */
       
    52 	virtual void TimeoutExpiredL( CUpnpTimeoutElement* anElement ) = 0;
       
    53     };
       
    54 
       
    55 /**
       
    56 *  @brief An element with timeout
       
    57 *
       
    58 *  This is a virtual base class containing a timeout functionality. This class
       
    59 *  is used by following steps:
       
    60 *
       
    61 *  1. Inherit your class from CUpnpTimeoutElement; 
       
    62 *
       
    63 *  2. In the constructor of the derived class, call also the constructor of 
       
    64 *  CUpnpTimeoutElement. This means you have to have an element library class which
       
    65 *  is derived from the class MUpnpTimeoutElementParent. This element library has to
       
    66 *  be passed to the constructor of CUpnpTimeoutElement.
       
    67 *
       
    68 *  3. Call the SetTimeout function to set the timeout of the element
       
    69 *
       
    70 *  4. If the timeout should be renewed after a timeout, call SetRenew to set the
       
    71 *  member variable iRenew. That variable can be used later to decide the destiny
       
    72 *  of an element.
       
    73 *
       
    74 *  @since Series60 2.0
       
    75 */
       
    76 class CUpnpTimeoutElement : public CActive
       
    77     {
       
    78     private:
       
    79         static const TUint32 KMicroInSec = 1000000;
       
    80         static const TInt KTime = 1800;
       
    81     
       
    82     protected: // Constructors and destructors
       
    83 
       
    84         /**
       
    85         * Constructor function; call from the constructor of a derived class.
       
    86         * @since Series60 2.0
       
    87         * @param aParent A class implementing the parent interface 
       
    88         * MUpnpTimeoutElementParent, in practice the library class
       
    89         */
       
    90     IMPORT_C CUpnpTimeoutElement( MUpnpTimeoutElementParent& aParent );
       
    91       
       
    92         /**
       
    93         * Base class constructor function
       
    94         * @since Series60 2.0
       
    95         */
       
    96     IMPORT_C void BaseConstructL();
       
    97    
       
    98     public:
       
    99  
       
   100     	/**
       
   101 	    * Destructor function; called automatically from the destructor of a 
       
   102         * derived class
       
   103 	    **/
       
   104 	IMPORT_C virtual ~CUpnpTimeoutElement();
       
   105 
       
   106         /**
       
   107     	* This function sets the timeout of the element. The TimeoutExpired()
       
   108         * function of the parent of this element is called after the timeout
       
   109         * @since Series60 2.0
       
   110         * @param aSeconds
       
   111         */
       
   112 	IMPORT_C void SetTimeout( TInt aSeconds );
       
   113 
       
   114     public: // From CActive
       
   115 
       
   116         /**
       
   117     	* Standard callback function of CActive-derived functions
       
   118         * @since Series60 2.0
       
   119         * @return None
       
   120         */
       
   121 	IMPORT_C void RunL();
       
   122 
       
   123         /**
       
   124     	* Standard callback function of CActive-derived functions
       
   125         * @since Series60 2.0
       
   126         * @return None
       
   127         */
       
   128 	IMPORT_C void DoCancel();
       
   129 
       
   130         /**
       
   131     	* Standard callback function of CActive-derived functions
       
   132         * @since Series60 2.0
       
   133         * @return None
       
   134         */
       
   135     IMPORT_C TInt RunError( TInt aError );
       
   136 
       
   137     public: // New Functions
       
   138 
       
   139 	    // Enumeration for different timeouts:
       
   140 	    enum TState {
       
   141 		    EAlive,
       
   142 		    EDead,
       
   143 		    ELongTime
       
   144 	    };
       
   145 
       
   146 	    // Enumeration for different timeouts:
       
   147 	    enum TRenew { 
       
   148 		    // This value is for timeouts that should be renewed after the timeout
       
   149 		    ERenew, 
       
   150 		    // This value is for timeouts that declare the closing of 
       
   151 			// an external (device) element; 
       
   152 		    EOnce,
       
   153 			// This value is for timeouts that declare the closing of an element;
       
   154 			// timeout not renewed anymore.
       
   155 			ERemove
       
   156 	    };
       
   157 
       
   158         /**
       
   159     	* Returns the current renew setting
       
   160         * @since Series60 2.0
       
   161         * @return Returns the current renew setting
       
   162         */
       
   163 	IMPORT_C TRenew& Renew();
       
   164 
       
   165         /**
       
   166     	* ets the renew setting of this element
       
   167         * @since Series60 2.0
       
   168         * @param aRenew The new renew setting
       
   169         */
       
   170 	IMPORT_C void SetRenew( TRenew aRenew );
       
   171 
       
   172     private: 
       
   173 
       
   174 	    TRenew iRenew;
       
   175 	    TState iState;
       
   176 	    RTimer iTimer;
       
   177 	    MUpnpTimeoutElementParent& iParent;
       
   178 	    TInt iSeconds;
       
   179     };
       
   180 
       
   181 #endif	// C_CUPNPTIMEOUTELEMENT_H
       
   182 
       
   183 // End of File