mmsharing/mmshavailability/inc/musavaavailability.h
changeset 15 ccd8e69b5392
parent 2 b31261fd4e04
child 20 e8be2c2e049d
child 22 496ad160a278
equal deleted inserted replaced
2:b31261fd4e04 15:ccd8e69b5392
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Provide interface for the client requestin availability class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __CMUSAVAAVAILABILITY_H__
       
    21 #define __CMUSAVAAVAILABILITY_H__
       
    22 
       
    23 
       
    24 #include <e32def.h>
       
    25 #include <e32base.h>
       
    26 #include "musavaobserver.h"
       
    27 #include "musavaavailabilityobserver.h"
       
    28 #include "muslogger.h"
       
    29 #include "musunittesting.h"
       
    30 
       
    31 class MMusAvaAvailabilityObserver;
       
    32 
       
    33 /**
       
    34  *  Availability interface class definition.
       
    35  *
       
    36  *  Provide interface for the client to availability class.
       
    37  *
       
    38  *  @lib musavailabilityplugin.lib
       
    39  */
       
    40 class CMusAvaAvailability : public CBase
       
    41 	{
       
    42 
       
    43 public:
       
    44 
       
    45 	/**
       
    46 	* Current availability plugin state.
       
    47 	*
       
    48 	* @return Availability state
       
    49 	*/
       
    50 	MMusAvaObserver::TAvailabilityStatus AvailabilityPluginState()
       
    51 		{
       
    52 		return iObserver.AvailabilityPluginState();
       
    53 		}
       
    54 
       
    55 	/**
       
    56 	* Executes for the availability.
       
    57 	*
       
    58 	* @since S60 v3.2
       
    59 	* @return KErrNone if ExecutePatternL operation was successfully executed;
       
    60 	*         system wide error otherwise
       
    61 	*/
       
    62     void Execute()
       
    63         {
       
    64         MMusAvaObserver::TAvailabilityName name = Name();
       
    65         MUS_LOG1( "mus: [MUSAVA]  -> CMusAvaAvailability::Execute(%d)", name )
       
    66         if ( !Executing() && !Available() )
       
    67             {
       
    68             TRAPD( error, DoExecuteL() )
       
    69             if ( error )
       
    70                 {
       
    71                 MUS_LOG1( "mus: [MUSAVA]     CMusAvaAvailability::Execute error:%d", error )
       
    72                 iObserver.AvailabilityError( name, (MMusAvaObserver::TAvailabilityStatus)error );
       
    73                 }
       
    74             }
       
    75         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaAvailability::Execute()" )
       
    76         }
       
    77 
       
    78 	/**
       
    79 	* Executes *this*  availability.
       
    80 	*
       
    81 	*/
       
    82     virtual void DoExecuteL() = 0;
       
    83 
       
    84 	/**
       
    85 	* Returns availability name.
       
    86 	*
       
    87 	* @return Name of *this* availability.
       
    88 	*/
       
    89     virtual MMusAvaObserver::TAvailabilityName Name() = 0;
       
    90 
       
    91 	/**
       
    92 	 * Returns execution state.
       
    93 	 *
       
    94 	 * @return KErrNone if ExecutePatternL operation was successfully executed;
       
    95 	 *         system wide error otherwise
       
    96 	 */
       
    97     TBool Executing()
       
    98         {
       
    99         return iState == MMusAvaObserver::EMusAvaStatusInProgress;
       
   100         }
       
   101 
       
   102 	/**
       
   103 	* Returns *this* availability state.
       
   104 	*
       
   105 	* @return ETrue if is available, EFalse otherwise
       
   106 	*/
       
   107     TBool Available()
       
   108         {
       
   109         return iState == MMusAvaObserver::EMusAvaStatusAvailable;
       
   110         }
       
   111 
       
   112 	/**
       
   113 	* Stop the execution.
       
   114 	*
       
   115 	* @since S60 v3.2
       
   116 	* @return KErrNone if stop operation was successfully executed;
       
   117 	*         system wide error otherwise
       
   118 	*/
       
   119     virtual void Stop()
       
   120         {
       
   121         MUS_LOG( "mus: [MUSAVA]  -> CMusAvaAvailability::Stop()" )
       
   122         iState = MMusAvaObserver::EMusAvaStatusNotExecuted;
       
   123         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaAvailability::Stop()" )
       
   124         }
       
   125 
       
   126 	/**
       
   127 	* Returns *this* availability state.
       
   128 	*
       
   129 	* @return Availability state.
       
   130 	*/
       
   131     MMusAvaObserver::TAvailabilityStatus State()
       
   132         {
       
   133         return iState;
       
   134         }
       
   135 
       
   136 	/**
       
   137 	* Set availability state.
       
   138 	*
       
   139 	*/
       
   140     void SetState( MMusAvaObserver::TAvailabilityStatus aState )
       
   141         {
       
   142         MUS_LOG1( "mus: [MUSAVA]  -> CMusAvaAvailability::SetState(%d)", aState )
       
   143         if ( iState != aState )
       
   144             {
       
   145             iState = aState;
       
   146             iObserver.AvailabilityChanged( Name(), iState );
       
   147             }
       
   148         MUS_LOG( "mus: [MUSAVA]  <- CMusAvaAvailability::SetState" )
       
   149         }
       
   150    
       
   151    /**
       
   152 	* Returns specific availability state.
       
   153 	*
       
   154 	* @return Availability state.
       
   155 	*/    
       
   156     TBool Available( MMusAvaObserver::TAvailabilityName aAvailability )
       
   157         {
       
   158         return iObserver.Available( aAvailability );
       
   159         }
       
   160         
       
   161 
       
   162     virtual ~CMusAvaAvailability() {};
       
   163 
       
   164 protected:
       
   165     CMusAvaAvailability( MMusAvaAvailabilityObserver& aObserver )
       
   166         :iObserver( aObserver ),
       
   167         iState( MMusAvaObserver::EMusAvaStatusNotExecuted ) {}
       
   168 
       
   169 protected: // data
       
   170     MMusAvaAvailabilityObserver& iObserver;
       
   171     MMusAvaObserver::TAvailabilityStatus iState;
       
   172 
       
   173 	MUS_UNITTEST ( CMusAvaAvailabilityStub )
       
   174 	MUS_UNITTEST ( CMusAvaDefaultImp )
       
   175 	MUS_UNITTEST ( UT_CMusAvaConnectionAvailability )
       
   176     MUS_UNITTEST ( UT_CMusAvaDefaultImp )
       
   177     MUS_UNITTEST ( UT_CMusAvaOptionHandler )
       
   178     MUS_UNITTEST ( UT_CMusAvaDefaultOptionHandler )
       
   179     MUS_UNITTEST ( UT_CMusAvaSettingAvailability )
       
   180     };
       
   181 
       
   182 
       
   183 #endif // __CMUSAVAAVAILABILITY_H__