telephonyserverplugins/simtsy/inc/CSimReduceTimers.h
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CSIMREDUCETIMERS_H__
       
    17 #define __CSIMREDUCETIMERS_H__
       
    18 
       
    19 /**
       
    20  * @file
       
    21  *
       
    22  * Definition of the observer pattern, which is used in the simulator,
       
    23  * to give the functionality of reducing the timers that are used
       
    24  * throughout.
       
    25  */
       
    26 
       
    27 #include <simtsy.h>
       
    28 #include "CSimPubSub.h"
       
    29 
       
    30 
       
    31 const TInt KTimerDelayOnReduceTimeSignal = 3;		//< Constant value of seconds delay to give timers before stopping.
       
    32 
       
    33 /**
       
    34 Definition of the observer required for a CSimTimer object.
       
    35 */
       
    36 class MSimTimerUpdateObserver
       
    37 	{
       
    38 public:
       
    39 	/**
       
    40 	Method to be used for updating the timer associated with this
       
    41 	observer.
       
    42 
       
    43 	@param aSecsOffTimer The number of seconds to reduce off the
       
    44 	                     remaining time duration in this objects
       
    45 	                     corresponding timer.
       
    46 	*/
       
    47 	virtual void Update(TInt aSecsOffTimer) =0;
       
    48 	/**
       
    49 	Method for obtaining information regarding this observer, which in
       
    50 	this case is the time duration remaining on the corresponding
       
    51 	timer.
       
    52 
       
    53 	@return The number of seconds remaining on this object's
       
    54 	        corresponding timer.
       
    55 	*/
       
    56 	virtual TInt GetRemainingSeconds() const =0;
       
    57 	/**
       
    58 	Method for obtaining information regarding this observer, which in
       
    59 	this case is the event assocated with the timer
       
    60 	
       
    61 	@return The timer event ID as defined in TTimerEventId in simtsy.h
       
    62 	*/
       
    63 	virtual TInt GetTimerEventInfo() const =0;
       
    64 	};
       
    65 
       
    66 /**
       
    67 Defines the requirements of a subject for observing and updating
       
    68 CSimTimer objects.  This is particularly useful for reducing the time
       
    69 durations originally given to the simulator.
       
    70 */
       
    71 class MSimTimersSubject
       
    72 	{
       
    73 public:
       
    74 	/**
       
    75 	Method used to remove an observer, aObserver, from this
       
    76 	object's list of attached/registered observers.
       
    77 
       
    78 	@param aObserver The observer to add to this subject's list of
       
    79 	                 observers.
       
    80 	*/
       
    81 	virtual void AttachL(MSimTimerUpdateObserver* aObserver) =0;
       
    82 	/**
       
    83 	Method used to remove an observer, aObserver, from this
       
    84 	object's list of attached/registered observers.
       
    85 
       
    86 	@param aObserver The observer to remove from this subject's list of
       
    87 	                 observers.
       
    88 	*/
       
    89 	virtual void DetachL(MSimTimerUpdateObserver* aObserver) =0;
       
    90 
       
    91 private:
       
    92 	/**
       
    93 	Method for notifying all attached/registered observers that a
       
    94 	change has occurred.
       
    95 	*/
       
    96 	virtual void Notify() =0;
       
    97 	/**
       
    98 	Method for notifying an attached/registered observer with specific
       
    99 	timer event ID and lowest remaining time, that a change has occurred
       
   100 	*/
       
   101 	virtual void Notify(TInt aTimerEventId) =0;
       
   102 	};
       
   103 
       
   104 
       
   105 /**
       
   106 Implementation of MSimTimersSubject, used to listen to events
       
   107 indicating a request to reduce the timers running in the simulator.
       
   108 This implementation currently uses the Publish & Subscribe API to get a
       
   109 notification of when a particular property is changed.  On
       
   110 notification, all registered timer observers will be required to reduce
       
   111 their timer's duration by the minimum time duration of all these
       
   112 timers.
       
   113 
       
   114 The notification must be made by changing a specific property, category
       
   115 KUidPSSimTsyCategory and sub-key KPSSimTsyTimersReduceTime, to the
       
   116 value KReduceSimTsyTimers.  (These constants are defined in "SimTsy.h")
       
   117 
       
   118 Example:
       
   119 
       
   120 @code
       
   121 // Optional, but safe to attempt defining property.
       
   122 TInt ret = RProperty::Define(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime,
       
   123 								KPSSimTsyTimersReduceTimeSignalKeyType);
       
   124 if (ret != KErrNone && ret != KErrAlreadyExists)
       
   125 	{
       
   126 	User::Leave(ret);
       
   127 	}
       
   128 
       
   129 RProperty stopTimerProperty;
       
   130 // User's code must create a property handle attached to a property with the
       
   131 // category KUidPSSimTsyCategory and sub-key KPSSimTsyTimersReduceTime.
       
   132 User::LeaveIfError(stopTimerProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime));
       
   133 CleanupClosePushL(stopTimerProperty);
       
   134 
       
   135 //... Use the simulator.
       
   136 
       
   137 // The property must then be set to KReduceSimTsyTimers in order to indicate that
       
   138 // the simulator is no longer required to continue running and thus timers can be reduced.
       
   139 User::LeaveIfError(stopTimerProperty.Set(KUidPSSimTsyCategory, KPSSimTsyTimersReduceTime,
       
   140 											KReduceSimTsyTimers));
       
   141 
       
   142 CleanupStack::PopAndDestroy(&stopTimerProperty);
       
   143 @endcode
       
   144 */
       
   145 class CSimReduceTimers : public CBase, MPSSimObserver, MSimTimersSubject
       
   146 	{
       
   147 public:
       
   148 	static CSimReduceTimers* NewL();
       
   149 	~CSimReduceTimers();
       
   150 	void SimPSEvent(const CSimPubSub::TPubSubProperty aProperty, TInt aStatus);
       
   151 
       
   152 	void AttachL(MSimTimerUpdateObserver* aObserver);
       
   153 	void DetachL(MSimTimerUpdateObserver* aObserver);
       
   154 
       
   155 private:
       
   156 	CSimReduceTimers();
       
   157 	void ConstructL();
       
   158 	void Notify();
       
   159 	void Notify(TInt aTimerEventId);
       
   160 private:
       
   161 	/** The Publish & Subscribe notification object.  This will call
       
   162 	    the SimPSEvent() method when the specified property
       
   163 	    (iPSProperty) is changed.*/
       
   164 	CSimPubSub* iSimPubSub;
       
   165 	/**	The property this object subscribes to, in order to listen to
       
   166 	    value changes indicating a request for timers to be reduced.*/
       
   167 	CSimPubSub::TPubSubProperty iPSProperty;
       
   168 	/**	Maintains a list of timers currently active, which can
       
   169 	    therefore have their duration reduced.*/
       
   170 	RPointerArray<MSimTimerUpdateObserver> iObservers;
       
   171 	};
       
   172 
       
   173 #endif