upnp/upnpstack/upnpconnmanager/inc/upnpconnmanagerengine.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:  CUpnpConnManagerEngine
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef C_CUPNPCONNMANAGERENGINE_H
       
    19 #define C_CUPNPCONNMANAGERENGINE_H
       
    20 
       
    21 // INCLUDES
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <es_sock.h>
       
    25 #include <commdbconnpref.h>
       
    26 
       
    27 #include "upnpnotifytimer.h"
       
    28 #include "upnpconninterfacewatcher.h"
       
    29 
       
    30 // FORWARD DECLARATIONS
       
    31 class CUpnpConnManagerSession;
       
    32 
       
    33 /**
       
    34  * Class used to wrap Symbian RConnection class.
       
    35  * Fixes performance problem when RConnection::Start() used symultanously by
       
    36  * two or more processes/threads.
       
    37  * @see CUpnpConnectionManagerProxy for more information.
       
    38  * @since S60 5.0
       
    39  */
       
    40 class CUpnpConnManagerEngine : public CBase, public MUpnpNotifyTimerObserver,
       
    41                                public MUpnpConnInterfaceWatcherObserver
       
    42     {
       
    43 public:
       
    44 
       
    45     /**
       
    46      * A two-phased constructor function
       
    47      * @param aIterator sessions iterator
       
    48      * @result A new instance of CUpnpConnManagerEngine
       
    49      */
       
    50     static CUpnpConnManagerEngine* NewL( TDblQueIter<CSession2>& aIterator );
       
    51 
       
    52     /**
       
    53      * Destructor function
       
    54      */
       
    55     virtual ~CUpnpConnManagerEngine();
       
    56 
       
    57 public:
       
    58 
       
    59     /**
       
    60      * After call of this method the caller is sure that
       
    61      * RConnection was started.
       
    62      * @param aAccessPoint id of current accessPoint on which RConnection was started
       
    63      * @return starting error
       
    64      */
       
    65     TInt EnsureStart( TInt& aAccessPoint );
       
    66 
       
    67     /**
       
    68      * @since Series60 5.0 HN
       
    69      * @return indicates whether RConnection is started.
       
    70      */
       
    71     TBool IsStarted();
       
    72 
       
    73     /**
       
    74      * @since Series60 5.0 HN
       
    75      * @return active iap
       
    76      */
       
    77     TInt ActiveIap();
       
    78     
       
    79     /**
       
    80      * Returns inet address
       
    81      * @since Series60 5.0 HN
       
    82      * @return local IP address
       
    83      */
       
    84     const TInetAddr& LocalAddress();
       
    85     
       
    86     /**
       
    87      * Checks if left any session which called EnsureStart(), 
       
    88      * when not then RConnection is closed
       
    89      * @since Series60 5.0 HN
       
    90      * @param Session wich call this function
       
    91      * @return None
       
    92      */
       
    93     void CheckAndCloseConnection( CUpnpConnManagerSession* aSession );
       
    94     
       
    95 private:
       
    96     /**
       
    97      * Default constructor.
       
    98      */
       
    99     CUpnpConnManagerEngine( TDblQueIter<CSession2>& aIterator );
       
   100 
       
   101     /**
       
   102      * 2nd phase constructor.
       
   103      */
       
   104     void ConstructL();
       
   105 
       
   106     /**
       
   107      * Opens and connects RConnection, subscribes for IP event notyfications 
       
   108      * (for address change) and Connection closed notyfication. In case of error
       
   109      * Leaves.
       
   110      * @since Series60 5.0 HN
       
   111      * @return None
       
   112      */
       
   113     void EnsureStartL();
       
   114 
       
   115     /**
       
   116      * Set state that one attempt to start the RConnection
       
   117      * @param aError error code of starting
       
   118      * @param aUSec microsecond for timeout
       
   119      */
       
   120     void SetStartAttemptStatus( TInt aError, TTimeIntervalMicroSeconds32 aUSec );
       
   121 
       
   122     /**
       
   123      * Reset state. One will be able to attempt to start RConnection again
       
   124      * @since Series60 5.0 HN
       
   125      * @return None
       
   126      */
       
   127     void ClearStartAttemptStatus();
       
   128     
       
   129     /**
       
   130      * Cancel all subscription to network event
       
   131      * @since Series60 5.0 HN
       
   132      * @return None
       
   133      */
       
   134     void CancelAllSubscription();
       
   135     
       
   136     /**
       
   137      * Notify all clients about wlan lost event
       
   138      * @since Series60 5.0 HN
       
   139      * @return None
       
   140      */                                 
       
   141     void NotifyAllAboutWlanLost();
       
   142             
       
   143     /**
       
   144      * Notify all clients about address change event
       
   145      * @since Series60 5.0 HN
       
   146      * @return None
       
   147      */                                 
       
   148     void NotifyAllAboutAddressChange( TInetAddr& aAddr );
       
   149 
       
   150     /**
       
   151      * Notify all clients about connection closed event
       
   152      * @since Series60 5.0 HN
       
   153      * @return None
       
   154      */                                 
       
   155     void NotifyAllAboutConnectionClosed();
       
   156 
       
   157     /**
       
   158      * Closes RConnection
       
   159      * @since Series60 5.0 HN
       
   160      * @return None
       
   161      */                                 
       
   162     void CloseConnection();
       
   163 
       
   164     /**
       
   165      * Gets Iap from central repository and sets iCommDbConnPref.
       
   166      * @since Series60 5.0 HN
       
   167      * @return None
       
   168      */                                 
       
   169     void SetupConnectionPreferencesL();
       
   170             
       
   171 private: // from MUpnpConnInterfaceWatcherObserver    
       
   172         
       
   173     /**
       
   174      * Marks connection interface as not vaild
       
   175      */
       
   176     void WlanNetworkLost();
       
   177 
       
   178     /**
       
   179      * Invoked when address changes
       
   180      * @param new address
       
   181      */
       
   182     void InterfaceAddressChange( TInetAddr& aAddr );
       
   183         
       
   184 private: // from MUpnpNotifyTimerObserver
       
   185 
       
   186     void TimerEventL( CUpnpNotifyTimer* aTimer );
       
   187 
       
   188 private:
       
   189     // Connection preferences
       
   190     TCommDbConnPref iCommDbConnPref;
       
   191 
       
   192     // Connection
       
   193     RConnection iConnection;
       
   194 
       
   195     // SocketServer
       
   196     RSocketServ iSocketServ;
       
   197 
       
   198     // have we tried to start the interface
       
   199     TInt iStartAttemptDone;
       
   200 
       
   201     // error code of starting
       
   202     TInt iCachedStartError;
       
   203 
       
   204     // hysteresis timer preventing double asking 
       
   205     // when first attempt fails e.g. when user cancels starting of IAP
       
   206     CUpnpNotifyTimer* iUnsuccesfulStartCacheTimer;
       
   207     
       
   208     // it is needed only for "always ask" case
       
   209     TInt iActiveIap;
       
   210 
       
   211     // connection interface watcher
       
   212     CUpnpConnInterfaceWatcher* iIfWatcher;
       
   213     
       
   214     // session iterator
       
   215     TDblQueIter<CSession2>& iSessionIter;
       
   216     
       
   217     };
       
   218 
       
   219 
       
   220 #endif // C_CUPNPCONNMANAGERENGINE_H