wlanutilities/wlansniffer/engine/server/inc/wsfwlanbearerconnectionmonitor.h
branchRCL_3
changeset 25 f28ada11abbf
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Class header for CWsfWlanBearerConnectionMonitor
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef C_WSFWLANBEARERCONNECTIONMONITOR_H
       
    21 #define C_WSFWLANBEARERCONNECTIONMONITOR_H
       
    22 
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <rconnmon.h>
       
    27 #include <es_sock.h>
       
    28 #include <cmdefconnvalues.h>
       
    29 #include <cmmanagerext.h>
       
    30 
       
    31 //  INTERNAL INCLUDES
       
    32 #include "wsfwlaninfo.h"
       
    33 #include "wsfwlanconnectiondetailsprovider.h"
       
    34 
       
    35 
       
    36 //  FORWARD DECLARATIONS
       
    37 class MWsfWlanMonitorObserver;
       
    38 class MWsfServerCloserAdapter;
       
    39 class CWsfIct;
       
    40 
       
    41 
       
    42 //  CLASS DEFINITION
       
    43 /**
       
    44  * Class to monitor and control all WLAN bearer related events and actions
       
    45  *
       
    46  * @since S60 5.0
       
    47  * @lib wsfserver.exe
       
    48  */
       
    49 NONSHARABLE_CLASS( CWsfWlanBearerConnectionMonitor ): public CActive, 
       
    50                                      public MConnectionMonitorObserver, 
       
    51                                      public MWsfWlanConnectionDetailsProvider
       
    52     {
       
    53     private:
       
    54         /**
       
    55         * Connecting states when creating an owned connection
       
    56         */
       
    57         enum TWsfConnectingState 
       
    58             {
       
    59             /**
       
    60             * Not connected, neither requested
       
    61             */
       
    62             ECsIdle,
       
    63             
       
    64             /**
       
    65             * Requested to connect
       
    66             */
       
    67             ECsNotConnected,
       
    68             
       
    69             /**
       
    70             * Socket server and connection handler opened
       
    71             */
       
    72             ECsSocketOpened,
       
    73             
       
    74             /**
       
    75             * Connection has been established
       
    76             */
       
    77             ECsConnectionCreated,
       
    78             
       
    79             /**
       
    80             * Connection environment fully initialized
       
    81             */
       
    82             ECsConnected
       
    83             };
       
    84         
       
    85         
       
    86     public:     // Constructors and destructor
       
    87         /**
       
    88         * Factory function.
       
    89         * @since S60 5.0
       
    90         * @param aServerCloser Reference to the server closer object. 
       
    91         *                      Ownership not passed.
       
    92         * @return Class instance
       
    93         */
       
    94         static CWsfWlanBearerConnectionMonitor* NewL( 
       
    95                                  MWsfServerCloserAdapter& aServerCloser );
       
    96                                  
       
    97         /**
       
    98         * Factory function.
       
    99         * @since S60 5.0
       
   100         * @param aServerCloser Reference to the server closer object. 
       
   101         *                      Ownership not passed.
       
   102         * @return Class instance
       
   103         */
       
   104         static CWsfWlanBearerConnectionMonitor* NewLC( 
       
   105                                  MWsfServerCloserAdapter& aServerCloser );
       
   106                                  
       
   107         /**
       
   108         * Destructor.
       
   109         */
       
   110         ~CWsfWlanBearerConnectionMonitor();
       
   111 
       
   112     private:    // Constructors
       
   113         /**
       
   114         * Constructor
       
   115         * @since S60 5.0
       
   116         * @param aServerCloser Reference to the server closer object. 
       
   117         *                      Ownership not passed.
       
   118         */
       
   119         CWsfWlanBearerConnectionMonitor( 
       
   120                                  MWsfServerCloserAdapter& aServerCloser );
       
   121 
       
   122         /**
       
   123         * Second-phase constructor.
       
   124         * @since S60 5.0
       
   125         */
       
   126         void ConstructL();
       
   127 
       
   128     public:     // New methods
       
   129         
       
   130         /**
       
   131         * Returns the name of the active wlan connection
       
   132         * @since S60 5.0
       
   133         * @return Connection name or KNullDesC if not connected
       
   134         */
       
   135         const TDesC& GetWlanBearerNameL();
       
   136 
       
   137         /* 
       
   138         * Starts monitoring WLAN events through the given observer
       
   139         * @since S60 5.0
       
   140         * @param aObserver The object to use for monitoring. Ownership 
       
   141         *                  not passed.
       
   142         */    
       
   143         void StartMonitoringL( MWsfWlanMonitorObserver* aObserver );
       
   144         
       
   145         /*
       
   146         * Stops monitoring WLAN events
       
   147         * @since S60 5.0
       
   148         */
       
   149         void StopMonitoring();
       
   150         
       
   151         /*
       
   152         * Connects to the given IAP
       
   153         * @since S60 5.0
       
   154         * @param aIapId WLAN IAP id to connect to.
       
   155         * @param aConnectOnly ETrue if Connect selected
       
   156         * @param aTestAccessPoint ETrue if accesspoint needs testing
       
   157         * @return KErrNone on success, error code otherwise
       
   158         */
       
   159         TInt ConnectBearer( TUint32 aIapId,
       
   160                             TBool aConnectOnly,
       
   161                             TBool aTestAccessPoint );
       
   162 
       
   163         /*
       
   164         * Disconnects active connection
       
   165         * @since S60 5.0
       
   166         * @return ETrue if the was something to disconnect otherwise EFalse
       
   167         */
       
   168         TBool DisconnectBearer();
       
   169  
       
   170         /**
       
   171         * Starts to monitor Access Point
       
   172         * @since S60 5.0
       
   173         * @param aIapId Access point to be monitored
       
   174         */
       
   175         void MonitorAccessPoint( TUint32 aIapId );   
       
   176         
       
   177         /**
       
   178         * Queries if there is an active WLAN connection.
       
   179         * @since S60 5.0
       
   180         * @return ETrue if there is an active WLAN connection, 
       
   181         *         EFalse otherwise.
       
   182         */
       
   183         TBool IsConnected();
       
   184 
       
   185         /**
       
   186         * Aborts the currently ongoing connecting process
       
   187         * @since S60 5.0
       
   188         * @return KErrNone on success, error code otherwise
       
   189         */
       
   190         TInt AbortConnecting();
       
   191     
       
   192         /**
       
   193         * Controls the auto-disconnect timer in the server 
       
   194         * for owned connections
       
   195         * @since S60 5.0
       
   196         * @param aAdcCommand Command for the timer,
       
   197         *                    see TWsfAutoDisconnectCommand
       
   198         * @return ETrue if the timer has been started (also if it had been 
       
   199         *         started earlier), EFalse if the timer couldn't be started
       
   200         *         (e.g. because there is no owned connection).
       
   201         */
       
   202         TBool ControlDisconnectTimer( TUint aAdcCommand );
       
   203         
       
   204    
       
   205     private:    // From CActive
       
   206         /**
       
   207         * Implements cancellation of an outstanding request.
       
   208         * @since S60 5.0
       
   209         */
       
   210         void DoCancel();
       
   211 
       
   212         /**
       
   213         * Handles an active object's request completion event.
       
   214         * @since S60 5.0
       
   215         */
       
   216         void RunL();
       
   217 
       
   218         /**
       
   219         * Handles a leave occurring in RunL().
       
   220         * @since S60 5.0
       
   221         * @param aError Leave code
       
   222         * @return aError
       
   223         */
       
   224         TInt RunError( TInt aError );
       
   225     
       
   226     
       
   227     protected:  // From MConnectionMonitorObserver
       
   228     
       
   229         /**
       
   230         * Event method is called every time an event occures.
       
   231         * @since S60 5.0
       
   232         * @param aConnMonEvent The event information.
       
   233         */        
       
   234         void EventL( const CConnMonEventBase& aConnMonEvent );
       
   235     
       
   236         
       
   237     public: // from MWsfWlanConnectionDetailsProvider
       
   238     
       
   239         /**
       
   240         * Fills TWsfWlanInfo with the connected wlan's properties
       
   241         * @since S60 5.0
       
   242         * @param aWlanInfo The wlaninfo structure to be filled
       
   243         * @return ETrue if there is a connection and returned data is valid, 
       
   244         *         EFalse otherwise
       
   245         */ 
       
   246         TBool ConnectedWlanConnectionDetailsL( TWsfWlanInfo* aWlanInfo );
       
   247     
       
   248         
       
   249     private:    // New methods
       
   250     
       
   251         /**
       
   252         * Loops through the list of current connections and searches for one
       
   253         * with wlan bearer
       
   254         * @since S60 5.0
       
   255         */ 
       
   256         void FindWlanBearerConnectedL();
       
   257 
       
   258         /**
       
   259         * Checks connection details and retrieves WLAN connection name
       
   260         * @since S60 5.0
       
   261         * @param aConnectionId The connection in question
       
   262         * @return ETrue on success (WLAN connection was found), 
       
   263         *         EFalse otherwise
       
   264         */
       
   265         TBool CheckConnectionDetailsL( TUint aConnectionId );
       
   266         
       
   267         /**
       
   268         * Shuts down the owned connection 
       
   269         * @since S60 5.0
       
   270         */
       
   271         void ShutdownOwnedConnectionL();
       
   272 
       
   273         /**
       
   274         * Cleanup function to release the shutdown mutex if shutdown leaves
       
   275         * @since S60 5.0
       
   276         * @param aPtr Pointer for this class
       
   277         */
       
   278         static void ReleaseShutdownMutex( TAny* aPtr );
       
   279 
       
   280         /**
       
   281         * Callback for CPeriodic to check the client count and 
       
   282         * start inactivity timer if needed.
       
   283         * @since S60 5.0
       
   284         * @param aPtr Pointer for this class
       
   285         * @return KErrNone if successful, system-wide error code otherwise.
       
   286         */
       
   287         static TInt CheckClientCount( TAny* aPtr );
       
   288 
       
   289         /**
       
   290         * Function that does actual processing in checking the client count.
       
   291         * Called by CheckClientCount().
       
   292         * @since S60 5.0
       
   293         */
       
   294         void CheckClientCountL();
       
   295         
       
   296         
       
   297     private:    // Data
       
   298         
       
   299         /**
       
   300         * Reference to the observer of this class (not owned)
       
   301         */
       
   302         MWsfWlanMonitorObserver* iObserver;
       
   303         
       
   304         /**
       
   305         * Handle to the connection monitor
       
   306         */
       
   307         RConnectionMonitor iMonitor;
       
   308         
       
   309         /**
       
   310         * Name of the currently active WLAN connection
       
   311         */
       
   312         TBuf<KWlanMaxAccessPointNameLength> iWlanNetworkName;
       
   313         
       
   314         /**
       
   315         * Id of the currently active WLAN connection
       
   316         */
       
   317         TInt iConnectionId;
       
   318         
       
   319         /**
       
   320         * Indicates whether connection monitoring is on
       
   321         */
       
   322         TBool iMonitoring;
       
   323         
       
   324         /**
       
   325         * The access point to be monitored
       
   326         */
       
   327         TUint32 iMonitoredAp;
       
   328 
       
   329         /**
       
   330         * Handle to the socket server for making a connection
       
   331         */
       
   332         RSocketServ iSocketServ;
       
   333         
       
   334         /**
       
   335         * Handle to the owned connection
       
   336         */
       
   337         RConnection iConnection;
       
   338         
       
   339         /**
       
   340         * Indicates whether the connection was initiated from within Sniffer
       
   341         */
       
   342         TBool iConnectionOwned;
       
   343         
       
   344         /**
       
   345         * Default connection settings before creating an own connection
       
   346         */
       
   347         TCmDefConnValue iOriginalDefConn;
       
   348         
       
   349         /**
       
   350         * Default connection settings after the owned connection has been
       
   351         * established
       
   352         */
       
   353         TCmDefConnValue iCurrentDefConn;
       
   354         
       
   355         /**
       
   356         * Periodic polling for connection client count
       
   357         */    
       
   358         CPeriodic* iClientPoll;
       
   359         
       
   360         /**
       
   361         * Indicates whether timer-based auto-disconnect is enabled
       
   362         */
       
   363         TBool iAutoDisconnect;
       
   364         
       
   365         /**
       
   366         * Count of clients using the connection
       
   367         */
       
   368         TInt iClientCount;
       
   369         
       
   370         /**
       
   371         * Timer to measure time elapsed without activity          
       
   372         */
       
   373         TTime iInactivityStart;
       
   374     
       
   375         /**
       
   376         * Status of currently ongoing connecting process
       
   377         */
       
   378         TWsfConnectingState iConnectingState;
       
   379 
       
   380         /**
       
   381         * IAP id to connect to. Used by the connecting active object.
       
   382         */
       
   383         TUint32 iConnIap;        
       
   384         
       
   385         /**
       
   386         * Indicates whether the connection is being aborted
       
   387         */
       
   388         TBool iAborting;
       
   389         
       
   390         /**
       
   391         * Asserts that the shutdown process is not reentered
       
   392         */
       
   393         TBool iShutdownMutex;
       
   394         
       
   395         /**
       
   396         * Asserts that the client counting process is not reentered
       
   397         */
       
   398         TBool iClientCountMutex;
       
   399         
       
   400         /**
       
   401         * Handle to the CmManager
       
   402         */
       
   403         RCmManagerExt iCmMgr;
       
   404         
       
   405         /**
       
   406         * Reference to the server closer (not owned)
       
   407         */
       
   408         MWsfServerCloserAdapter& iServerCloser;
       
   409         
       
   410         /**
       
   411         * Reference to ICT handler
       
   412         */
       
   413         CWsfIct* iIct;
       
   414         
       
   415     };
       
   416 
       
   417 
       
   418 #endif // C_WSFWLANBEARERCONNECTIONMONITOR_H
       
   419