mmsharing/mmshavailability/inc/musavaoptionhandler.h
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 15:12:07 +0300
branchRCL_3
changeset 22 73a1feb507fb
parent 0 f0cf47e981f9
child 23 bc78a40cd63c
permissions -rw-r--r--
Revision: 201032 Kit: 201035

/*
* Copyright (c) 2005-2007 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:  Provide interface for the client request in capabilty
*                availability.
*
*/

#ifndef __MUSAVAOPTIONHANDLER_H__
#define __MUSAVAOPTIONHANDLER_H__

#include <e32base.h>
#include <badesca.h>
#include "musavaavailability.h"
#include "musavaobserver.h"
#include "musunittesting.h"
#include "mmusavacapabilityqueryobserver.h"

class CMusAvaSharedObject;
class MMusAvaAvailabilityObserver;
class CMusAvaCapabilitySipAgent;
class CMusAvaCapabilityExchange;
class CMusAvaCapability;
class CMusAvaCapabilityQueryBase;
class CMusAvaSettingsImp;


/**
 *  Implements handling of non-desired SIP invites.
 *
 *  Provide interface for the client to availability class.
 *
 *  @lib musavailabilityplugin.lib
 *  @since S60 v3.2
 */
class CMusAvaOptionHandler : public CMusAvaAvailability,
                             public MMusAvaCapabilityQueryObserver
	{
public:
	/**
     * Two-phased constructor
     *
     * @param aObserver Pointer to observer intercase
     * @param aSettings Availability settings.
     * @return Returns pointer to CMusAvaInterface object
     */
    static CMusAvaOptionHandler* NewL(
        MMusAvaAvailabilityObserver& aObserver,
        CMusAvaSettingsImp& aSettings );

	/**
     * Two-phased constructor
     *
     * @param aObserver Pointer to observer intercase
     * @param aSettings Availability settings.
     * @return Returns pointer to CMusAvaInterface object
     */
	static CMusAvaOptionHandler* NewLC(
        MMusAvaAvailabilityObserver& aObserver,
        CMusAvaSettingsImp& aSettings );

	/**
     * Destructor
     */
	~CMusAvaOptionHandler();

protected:

	/**
     * Constructor
     *
     * @since S60 v3.2
     * @param aObserver Pointer to observer intercase
     * @param aName availability name
     * @param aModules is data container
     */

	CMusAvaOptionHandler(
	    MMusAvaAvailabilityObserver& aObserver,
        CMusAvaSettingsImp& aSettings );

	void ConstructL();

    void ConstructCapabilityExchangeL();

    HBufC8* ConstructTerminalIdL();

public: // from base class CMusAvaAvailability

    /**
     * Executes for the availability.
     *
     * @since S60 v3.2
     * @return KErrNone if ExecutePatternL operation was
     *         successfully executed; system wide error otherwise
     */
    virtual void DoExecuteL();


    /**
     * Stop the execution.
     *
     * @since S60 v3.2
     * @return KErrNone if stop operation was successfully executed;
     *         system wide error otherwise
     */
    virtual void Stop();

    /**
     * From CMusAvaAvailability.
     * Returns availability name.
     *
     * @return Name of *this* availability.
     */
    virtual MMusAvaObserver::TAvailabilityName Name();
    
    /**
    * Invitation has been received.
    */  
    virtual void PrepareForReceivedInviteL();
    

public: // functions from base class MMusAvaCapabilityQueryObserver

    void CapabilitiesResolved( const CMusAvaCapabilityQueryBase& aSentQuery );

    void CapabilitiesResolvedL( const TDesC& aUri );

    void SetCapabilitiesResolvedForCingular();

    TBool CapabilitiesResolvedForCingular();   
    
    /**
     * This is to advertise MMusAvaCapabilityQueryObserver implementors
     * about sip header change. It is mainly used in below scneraio but could
     * be used in future if anyother sip headers has to be set.
     * 
     * Incase if we receive OPTIONS request already and 
     * P-Asserted-Identity Header is present then OPTIONS
     * request should be sent to this ID. This function should be
     * called to configure this id in CMusAvaSettingsImp& iSettings
     *
     * @aHeaders Array of SIP Headers.    
     * @aHeaderType Type of the header.
     * Leavs if Array is empty or pointer is NULL.
     * Ownership Transferred.
     */
    void SipHeadersL(const MDesCArray& aHeaders,
                          SipStrConsts::TStrings aHeaderType);

    /**
     * Advertise about video codec capabilities     
     */
    void VideoCodecsResolvedL( const MDesCArray& aVideoCodecs );

    TBool CapabilityQueryAnswered( TBool aAnswered );

    void FastModeResolved( MusSettingsKeys::TFastMode aMode );

private:
    
    /**
    * Change state.
    * @param aNewState, proposed new state
    * @return KErrNone if successfull
    */
    TInt DoSetState( MMusAvaObserver::TAvailabilityStatus aNewState );
    
    /**
    * Handle state change in fast mode, state change may be modified
    * based on fast mode session setup progress.
    * @param aNewState, proposed new state
    * @param aCouldNotProceed, ETrue if state change occured because
    *       couldn't proceed (e.g. missing information)
    * @return new state to set
    */
    MMusAvaObserver::TAvailabilityStatus HandleFastModeL( 
        MMusAvaObserver::TAvailabilityStatus aNewState );
    
    MMusAvaObserver::TAvailabilityStatus HandleFastModeAvailableL(
        MMusAvaObserver::TAvailabilityStatus aNewState );
    
    MMusAvaObserver::TAvailabilityStatus HandleFastModeOptionsNotSentL(
        MMusAvaObserver::TAvailabilityStatus aNewState );
    
    MMusAvaObserver::TAvailabilityStatus HandleFastModeOptionNotAvailableL(
        MMusAvaObserver::TAvailabilityStatus aNewState );
    
    void HandleFastModeQueryAnswered();
    
    TBool FastModeNegotiatedByAnswerMT();
    
    TBool FastModeNegotiationFailedMO();
    
private:

    /**
     * Reference to availability settings (data store)
     */
    CMusAvaSettingsImp&         iSettings;

	/**
     * Pointer to CMusAvaSharedObject object
     */
	CMusAvaSharedObject*        iSharedObj;

    CMusAvaCapabilitySipAgent*  iSipAgent;
    CMusAvaCapabilityExchange*  iCapabilityExchange;
    CMusAvaCapability*          iSwisCapability;
    TBool                       iCapabilitiesRequestAnswered;
    TBool                       iCapabilityQueryAnswered;
    
    TBool                       iFastModeCapable;
    TBool                       iFastModeAvailabilityDelayed;
    
    MUS_UNITTEST ( UT_CMusAvaOptionHandler )
    MUS_UNITTEST ( UT_CMusAvaCapabilityExchange )
    MUS_UNITTEST ( UT_CMusAvaCapability )
    MUS_UNITTEST ( UT_CMusAvaTerminal )
    MUS_UNITTEST ( UT_CMusAvaCapabilitySipAgent )
    MUS_UNITTEST ( UT_CMusAvaCapabilityQuery )
    };

#endif // __MUSAVAOPTIONHANDLER_H__