commonappservices/alarmserver/Server/Include/ASSrvAlarm.h
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 1999-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 __ASSRVALARM_H__
       
    17 #define __ASSRVALARM_H__
       
    18 
       
    19 // System includes
       
    20 #include <e32base.h>
       
    21 
       
    22 // User includes
       
    23 #include <asshdalarm.h>
       
    24 #include <asshddefs.h>
       
    25 #include "ASSrvDefs.h"
       
    26 #include "ASSrvTimerObserver.h"
       
    27 
       
    28 // Constants
       
    29 const TASSrvAlarmSoundCycleNumber KUndefinedCycleIndex = -1;
       
    30 const TInt KAlarmServerCTimerFudgeTimeInSeconds = 2;
       
    31 const TInt KAlarmServerDefaultAlowableWindowInSeconds = 0;
       
    32 const TInt KAlarmServerStartupExpireWindowInSeconds = 59;
       
    33 
       
    34 // Enumerations
       
    35 
       
    36 // Classes referenced
       
    37 class CASSrvServerWideData;
       
    38 
       
    39 
       
    40 //
       
    41 // ----> TASSrvAlarm (header)
       
    42 //
       
    43 /**
       
    44  * The server-side representation of an alarm - now based on a UTC alarm.
       
    45  */
       
    46 class TASSrvAlarm : public TASShdAlarm, public MASSrvAlarmTimerObserver
       
    47 	{
       
    48 //
       
    49 public:										// ENUMERATIONS
       
    50 //
       
    51 	/**
       
    52 	 * Used to keep track of whether the alarm has been snoozed
       
    53 	 * and which time to next use as the basis for alarm expiry
       
    54 	 */
       
    55 	enum TTimeType
       
    56 		{
       
    57 		ETimeTypeNextDue					= 0,
       
    58 		ETimeTypeOriginalExpiry
       
    59 		};
       
    60 
       
    61 	/**
       
    62 	 * Internal flags used within the Alarm Server
       
    63 	 */
       
    64 	enum TInternalServerFlags
       
    65 		{
       
    66 		/**
       
    67 		 * The alarm server has a handle to a client's
       
    68 		 * TRequestStatus (via an RMessage2) which it
       
    69 		 * will complete when this alarm expires.
       
    70 		 */ 
       
    71 		EInternalServerFlagsNotifyPending	= 0,
       
    72 		/**
       
    73 		 * This alarm sound playing has been paused
       
    74 		 */ 
       
    75 		EASShdAlarmFlagsSoundHasBeenPaused
       
    76 		};
       
    77 
       
    78 	/**
       
    79 	 * The state of this alarm with respect to sound
       
    80 	 */
       
    81 	enum TSoundState
       
    82 		{
       
    83 		/**
       
    84 		 * This alarm is not playing a sound
       
    85 		 */
       
    86 		ESoundStatePlayingNothing			= 0,
       
    87 
       
    88 		/**
       
    89 		 * This alarm is playing a sound
       
    90 		 */
       
    91 		ESoundStatePlayingSound
       
    92 		};
       
    93 	
       
    94 //
       
    95 public:										// STATIC CONSTRUCT / DESTRUCT
       
    96 //
       
    97 
       
    98 	TASSrvAlarm(CASSrvServerWideData& aData);
       
    99 
       
   100 //
       
   101 public:										// OPERATORS
       
   102 //
       
   103 
       
   104 	TASSrvAlarm&							operator=(const TASSrvAlarm& aAlarm);
       
   105 
       
   106 //
       
   107 public:										// ACCESS - SETTERS
       
   108 //
       
   109 
       
   110 	TInt									SetStatus(TAlarmStatus aStatus);
       
   111 
       
   112 	void									SetState(TAlarmState aState);
       
   113 
       
   114 	void									SetCharacteristicsL(TAlarmCharacteristicsFlags aFlags, TASSrvSessionId aSessionChangingFlags);
       
   115 
       
   116 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   117 	void									SetWakeupAndNotifyQueueL(TBool aEnable);
       
   118 #endif
       
   119 	
       
   120 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
   121 	void									SetAlarmDaysL(TUint8 aAlarmDays);
       
   122 #endif
       
   123 	
       
   124 	void									SetAlarmOrphaned();//set alarm orphaned when the owner session has been closed
       
   125 
       
   126 	void									SetOriginatingSessionId(TASSrvSessionId aId);
       
   127 
       
   128 //
       
   129 public:										// ACCESS - GETTERS
       
   130 //
       
   131 
       
   132 	/**
       
   133 	 * Access the originating session id for this alarm.
       
   134 	 */
       
   135 	TASSrvSessionId 						OriginatingSessionId() const;
       
   136 
       
   137 	/**
       
   138 	 * Access the sound state for this alarm
       
   139 	 */
       
   140 	TSoundState 							SoundState() const;
       
   141 
       
   142 //
       
   143 public:										// ACCESS - MISC
       
   144 //
       
   145 
       
   146 	void									RequestExpiryNotificationL(const RMessage2& aMessage);
       
   147 
       
   148 	void									RequestExpiryNotificationComplete(TInt aErrorCode);
       
   149 
       
   150 	/**
       
   151 	 * Does this alarm have an owning session and 
       
   152 	 */
       
   153 	TBool									HasNotificationRequestPending() const;
       
   154 
       
   155 	void									RoundDownTimeToMinute(TTimeType aType);
       
   156 
       
   157 	void									DeQueue();
       
   158 
       
   159 	void									Reset();
       
   160 	
       
   161 	void									ClearFlags();
       
   162 
       
   163 	/**
       
   164 	 * Update the sound state of this alarm
       
   165 	 */
       
   166 	void									SetSoundState(TSoundState aSoundState);
       
   167 
       
   168 	void									ToggleSoundState();
       
   169 
       
   170 	void									ReinitializeSoundState(const TTime& aBaselineForSoundTiming);
       
   171 
       
   172 	TTime									CalculateAndPrepareNextSoundCycle();
       
   173 
       
   174 	TInt									ValidateAndEnable(TTimeIntervalSeconds aAllowableWindow = KAlarmServerStartupExpireWindowInSeconds, TBool aAllowAnyOnceAlarmInThePast = EFalse, TBool aEnable = ETrue);
       
   175 
       
   176 	void									Snooze(const TTime& aTimeToAwaken);
       
   177 
       
   178 	/**
       
   179 	 * Has the alarm sound playing been paused?
       
   180 	 */
       
   181 	TBool									HasSoundPaused() const;
       
   182 
       
   183 	/**
       
   184 	 * Set the EASShdAlarmFlagsSoundHasBeenPaused flag
       
   185 	 */
       
   186 	void									SetSoundPausedFlag();
       
   187 
       
   188 	/**
       
   189 	 * Clear the EASShdAlarmFlagsSoundHasBeenPaused flag
       
   190 	 */
       
   191 	void									ClearSoundPausedFlag();
       
   192 
       
   193 //
       
   194 public:										// DATA RELATED
       
   195 //
       
   196 
       
   197 	void									DataAttachL(HBufC8* aData);
       
   198 
       
   199 	void									DataDetachL();
       
   200 
       
   201 	TInt									DataSizeL() const;
       
   202 
       
   203 	const TDesC8&							DataL() const;
       
   204 
       
   205 	const TDesC8&							Data() const;
       
   206 
       
   207 //
       
   208 public:										// EVENT HANDLERS
       
   209 //
       
   210 
       
   211 	void									HandleTimerError(TInt aErrorCode);
       
   212 
       
   213 	void									HandleDeQueue();
       
   214 
       
   215 	TBool									HandleDateTimeChangedL(TUint aWorkdays, TBool aWorkdaysChanged);
       
   216 
       
   217 //
       
   218 private:									// FROM MASSrvAlarmTimerObserver
       
   219 //
       
   220 
       
   221 	void									MATimerHandleAlarmExpired(TAlarmTimerEvent aEvent, TAlarmId aAlarmId);
       
   222 
       
   223 //
       
   224 private:									// INTERNAL
       
   225 //
       
   226 
       
   227 	/**
       
   228 	 * Return the server data object
       
   229 	 */
       
   230 	CASSrvServerWideData&					ServerData() const;
       
   231 
       
   232 	void									NotificationMessageComplete(TInt aCompletionCode);
       
   233 
       
   234 	TInt									PrepareForNextRepeat(TTimeIntervalSeconds aAllowableWindow = KAlarmServerDefaultAlowableWindowInSeconds);
       
   235 
       
   236 //
       
   237 private:									// INTERNAL - SOUND TIMING RELATED
       
   238 //
       
   239 
       
   240 	/**
       
   241 	 * Set the sound cycle
       
   242 	 */
       
   243 	void									SetSoundTimingCycleIndex(TASSrvAlarmSoundCycleNumber aSoundNumber);
       
   244 
       
   245 	/**
       
   246 	 * Access the sound cycle
       
   247 	 */
       
   248 	TASSrvAlarmSoundCycleNumber			SoundTimingCycleIndex() const;
       
   249 
       
   250 //
       
   251 public:										// Helper for AlarmQueue Internalize
       
   252 //
       
   253 
       
   254 	/**
       
   255 	 * Internalize of the Alarm Queue after a Restore (from a backup)
       
   256 	 * deletes the old queue.  This method sends a Cancel notification for
       
   257 	 * a 'Session Alarm' to its the TRequestStatus object.
       
   258 	 */
       
   259 	void									CancelSessionAlarm();
       
   260 
       
   261 //
       
   262 private:									// INTERNAL - Set Alarm Status
       
   263 //
       
   264 
       
   265 	/**
       
   266 	 * Internally used function for set alarm status.
       
   267 	 */
       
   268 	TInt									doSetStatus(TAlarmStatus aStatus, TBool aAutoDisabled);
       
   269 
       
   270 //
       
   271 private:									// MEMBER DATA
       
   272 //
       
   273 
       
   274 	/**
       
   275 	 * When an alarm plays, it has a controlling time period which specifies how
       
   276 	 * long the sound should be played for (before it is automatically made silent again).
       
   277 	 * Typically there are a series of cycles, each with a custom-defined duration
       
   278 	 * for the sound. This attribute specifies which cycle is currently being timed.
       
   279 	 */
       
   280 	TASSrvAlarmSoundCycleNumber			iSoundPeriodCycleNumber;
       
   281 
       
   282 	/**
       
   283 	 * Ordinarily, an alarm is first "heard" when at its due time. However, if
       
   284 	 * the alarm is snoozed, or there is a quiet period, the alarm's original due
       
   285 	 * time cannot be used for sound-timing related calcualtions. Therefore, by
       
   286 	 * default, this value is initialized to the due time when the alarm first
       
   287 	 * expires, and is updated with a new time when the alarm is snoozed or
       
   288 	 * the sound is paused.
       
   289 	 */
       
   290 	TTime									iStartTimeForSoundCalculations;
       
   291 
       
   292 	/**
       
   293 	 * When an alarm is notifying it either is playing a sound or silent (depending
       
   294 	 * on the alarm sound play intervals). This enumeration represents that state.
       
   295 	 */
       
   296 	TSoundState								iSoundState;
       
   297 
       
   298 	/**
       
   299 	 * Internal flags used by the server side representation of an alarm object.
       
   300 	 */
       
   301 	TBitFlags								iInternalServerFlags;
       
   302 
       
   303 	/**
       
   304 	 * The session which originally created this alarm
       
   305 	 */
       
   306 	TASSrvSessionId							iOriginatingSessionId;
       
   307 
       
   308 	/**
       
   309 	 * The request status object that is completed when the alarm expires or is
       
   310 	 * cancelled.
       
   311 	 */
       
   312 	RMessagePtr2							iNotificationMessage;
       
   313 
       
   314 	/**
       
   315 	 * A handle to the server wide data.
       
   316 	 */
       
   317 	CASSrvServerWideData&					iServerWideData;
       
   318 	};
       
   319 
       
   320 
       
   321 #endif
       
   322 
       
   323