sipplugins/sippsystemstatemonitor/inc/sipsnapavailabilitymonitor.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 15 Mar 2010 12:42:05 +0200
branchRCL_3
changeset 3 dc4cddf5f2f8
parent 0 307788aac0a8
child 4 c2e8c8b73582
permissions -rw-r--r--
Revision: 201009 Kit: 201010

/*
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  
*
*/

#ifndef CSIPSNAPAVAILABILITYMONITOR_H
#define CSIPSNAPAVAILABILITYMONITOR_H

// INCLUDES
#include "MSystemStateConnUsagePermissionObserver.h"
#include <sipsystemstatemonitor.h>
#include <rconnmon.h>
#include <e32base.h>

// FORWARD DECLARATIONS
class MSipSystemStateObserver;

// CLASS DEFINITION
/**
* A class for monitoring the availability of a SNAP.
*/
class CSipSnapAvailabilityMonitor : 
    public CActive, 
    public MConnectionMonitorObserver,
    public MSystemStateConnUsagePermissionObserver
    {
    public:    // Constructors and destructor

        /**
        * Static constructor
        * @param aSnapId the ID of the SNAP to be monitored
        * @param aPermissionToUseNetwork the current permission to use network
        * @param aObserver observer to be notified about SNAP availability
        * @return An initialized instance of this class.
        */
        static CSipSnapAvailabilityMonitor* NewL( 
            TUint32 aSnapId,
            TBool aPermissionToUseNetwork,
            MSipSystemStateObserver& aObserver );

        /**
        * Static constructor
        * @param aSnapId the ID of the SNAP to be monitored
        * @param aPermissionToUseNetwork the current permission to use network
        * @param aObserver observer to be notified about SNAP availability        
        * @return An initialized instance of this class.
        */
        static CSipSnapAvailabilityMonitor* NewLC( 
            TUint32 aSnapId,
            TBool aPermissionToUseNetwork,
            MSipSystemStateObserver& aObserver );

        /// Destructor
        ~CSipSnapAvailabilityMonitor();

    public: // From CActive
    
        void RunL();        

        void DoCancel();

    public: // From MConnectionMonitorObserver

        void EventL( const CConnMonEventBase &aConnMonEvent );

    public: // from MSystemStateConnUsagePermissionObserver
    
        void UsagePermissionChanged( TBool aPermissionToUse, TInt aError );
        
    public: // New functions
    
        TUint32 SnapId() const;

        CSipSystemStateMonitor::TSnapAvailability SnapAvailability() const;

        void AddObserverL( MSipSystemStateObserver& aObserver );

        void RemoveObserver( MSipSystemStateObserver& aObserver );

        TBool HasObservers() const;

    private: // Constructors

        CSipSnapAvailabilityMonitor( 
            TUint32 aSnapId,
            TBool aPermissionToUseNetwork );
            
        void ConstructL( MSipSystemStateObserver& aObserver );
        
    private: // Private methods

        TBool IsSnapAvailable( 
            const TConnMonSNAPInfo& aSnapInfo, 
            TUint32 aSnapId ) const;
            
        void NotifyObservers() const;
        
        TBool SetCurrentState( 
            TBool aPermissionToUseNetwork,
            TBool aSnapAvailable );        

        TBool CanSnapBeUsed() const;

    private: // Data

        TUint32 iSnapId;
        TBool iPermissionToUseNetwork;
        TBool iSnapAvailable;
        // Observers not owned
        RPointerArray<MSipSystemStateObserver> iObservers; 
        /// Connection monitor session. Owned.
        RConnectionMonitor iConnMon;
        TConnMonSNAPInfoBuf iSnapInfoBuf;
        // ETrue if successfully connected to Connection Monitor Server
        // (iConnMon).
        TBool iIsConnected;
        
    private: // For unit testing purposes
    
        friend class CSipSnapAvailabilityMonitorTest;  
    };

#endif // CSIPSNAPAVAILABILITYMONITOR_H