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