commonappservices/alarmserver/Shared/Source/ASShdAlarm.cpp
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 #include <asshdalarm.h>
       
    17 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    18 #include "ASShdAlarm_internal.h"
       
    19 #endif
       
    20 
       
    21 // NOTE: Remember to change this version whenever the data format changes!
       
    22 const TUint16 KAlarmExternalizedVersion = 2;
       
    23 #ifndef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    24 const TUint16 KAlarmExternalizedSkipCount = 0; // Number of bytes to be skipped in data stream
       
    25 #endif
       
    26 
       
    27 /**
       
    28 Default constructor. 
       
    29 
       
    30 Initializes all member data to default values.
       
    31 */
       
    32 EXPORT_C TASShdAlarm::TASShdAlarm()
       
    33 	{
       
    34 	Reset();
       
    35 	}
       
    36 
       
    37 /**
       
    38 Internalizes the alarm's data from a read stream.
       
    39 
       
    40 @param aStream The stream to read from.
       
    41 */
       
    42 EXPORT_C void TASShdAlarm::InternalizeL(RReadStream& aStream)
       
    43 	{
       
    44 	// Read and ignore version (until its needed)
       
    45 	aStream.ReadUint16L();
       
    46 	iFlags.SetValue(aStream.ReadInt8L());
       
    47 	// Session no longer valid!
       
    48 	iFlags.Clear(EASShdAlarmFlagsHasOwningSession);
       
    49 	iCharacteristics.SetValue(aStream.ReadInt8L());
       
    50 	// Session alarms should be imported as orphaned
       
    51 	// because there is no valid TRequestStatus to notify
       
    52 	if (iCharacteristics.IsSet(EAlarmCharacteristicsSessionSpecific))
       
    53 		{
       
    54 		iCharacteristics.Clear(EAlarmCharacteristicsSessionSpecific);
       
    55 		iFlags.Set(EASShdAlarmFlagsHasBecomeOrphaned);
       
    56 		}
       
    57 	iAlarmId = aStream.ReadInt32L();
       
    58 	iStatus = static_cast<TAlarmStatus>(aStream.ReadInt8L());
       
    59 	iState = static_cast<TAlarmState>(aStream.ReadInt8L());
       
    60 	iDayOrTimed = static_cast<TAlarmDayOrTimed>(aStream.ReadInt8L());
       
    61 	iRepeatDefinition = static_cast<TAlarmRepeatDefinition>(aStream.ReadInt8L());
       
    62 	aStream >> iCategory;
       
    63 	TInt64 tempInt64;
       
    64 	aStream >> tempInt64;
       
    65 	iNextDueTime = TTime(tempInt64);
       
    66 	aStream >> tempInt64;
       
    67 	iOriginalExpiryTime = TTime(tempInt64);
       
    68 	aStream >> iMessage;
       
    69 	aStream >> iSoundName;
       
    70 	iClientFlags.SetValue(aStream.ReadInt16L());
       
    71 	iClientData1 = aStream.ReadInt32L();
       
    72 	iClientData2 = aStream.ReadInt32L();
       
    73 	//Only read the SID in the secured platform
       
    74 	iTASShdAlarmSID = aStream.ReadUint32L();
       
    75 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
    76 	iFlags2.SetValue(aStream.ReadInt16L());
       
    77 #else
       
    78 	// Read and ignore the skip count until its needed. When new data is written
       
    79 	// to the end of the alarm, be sure to use the version information as a means
       
    80 	// of establishing exactly how much data can be read. This enables the alarm
       
    81 	// server to remain data compatible going forwards...
       
    82 	aStream.ReadUint16L();
       
    83 #endif
       
    84 	}
       
    85 
       
    86 /**
       
    87 Externalizes the alarm's member data to a write stream.
       
    88 
       
    89 @param aStream The stream to write to.
       
    90 */
       
    91 EXPORT_C void TASShdAlarm::ExternalizeL(RWriteStream& aStream) const
       
    92 	{
       
    93 	// Write version
       
    94 	aStream.WriteUint16L(KAlarmExternalizedVersion);
       
    95 	aStream.WriteInt8L(iFlags.Value());
       
    96 	aStream.WriteInt8L(iCharacteristics.Value());
       
    97 	aStream.WriteInt32L(iAlarmId);
       
    98 	aStream.WriteInt8L(static_cast<TInt8>(iStatus));
       
    99 	aStream.WriteInt8L(static_cast<TInt8>(iState));
       
   100 	aStream.WriteInt8L(static_cast<TInt8>(iDayOrTimed));
       
   101 	aStream.WriteInt8L(static_cast<TInt8>(iRepeatDefinition));
       
   102 	aStream << iCategory;
       
   103 	aStream << iNextDueTime.Int64();
       
   104 	aStream << iOriginalExpiryTime.Int64();
       
   105 	aStream << iMessage;
       
   106 	aStream << iSoundName;
       
   107 	aStream.WriteInt16L(iClientFlags.Value());
       
   108 	aStream.WriteInt32L(iClientData1);
       
   109 	aStream.WriteInt32L(iClientData2);
       
   110 	//Only store the SID in the secured platform
       
   111 	aStream.WriteUint32L(iTASShdAlarmSID);
       
   112 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   113 	aStream.WriteInt16L(iFlags2.Value());
       
   114 #else
       
   115 	// Write skip count
       
   116 	aStream.WriteUint16L(KAlarmExternalizedSkipCount);
       
   117 #endif
       
   118 	}
       
   119 
       
   120 /**
       
   121 Resets the alarm back to a default, uninitialized state.
       
   122 */
       
   123 EXPORT_C void TASShdAlarm::Reset()
       
   124 	{
       
   125 	iFlags = 0,
       
   126 	iCharacteristics = 0;
       
   127 	iAlarmId = KNullAlarmId;
       
   128 	iStatus = EAlarmStatusDisabled;
       
   129 	iState = EAlarmStateInPreparation;
       
   130 	iDayOrTimed = EASShdAlarmTypeTimed;
       
   131 	iRepeatDefinition = EAlarmRepeatDefintionRepeatOnce;
       
   132 	iCategory = KNullUid;
       
   133 	iNextDueTime = Time::NullTTime();
       
   134 	iOriginalExpiryTime = Time::NullTTime();
       
   135 	iMessage = KNullDesC;
       
   136 	iSoundName = KNullDesC;
       
   137 	iClientFlags.ClearAll();
       
   138 	iClientData1 = 0;
       
   139 	iClientData2 = 0;
       
   140 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   141 	iFlags2 = 0;
       
   142 #endif
       
   143 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
   144 	iFlags2 = 0;
       
   145 	// By default, an alarm with a repeat definition of EAlarmRepeatDefinition-
       
   146 	// DailyOnGivenDays is active on all days.
       
   147 	SetAlarmDays(EAlarmDayMonday | EAlarmDayTuesday | EAlarmDayWednesday |
       
   148 		EAlarmDayThursday | EAlarmDayFriday | EAlarmDaySaturday |
       
   149 		EAlarmDaySunday);
       
   150 #endif
       
   151 	}	
       
   152 
       
   153 /**
       
   154 Using this API to set the next due time of an alarm will make it a fixed alarm, that
       
   155 is going to expire at the given UTC time. The alarm will not be rescheduled when the UTC offset is changed.
       
   156 
       
   157 @param aUtcTime The due time of the alarm should be given in UTC.
       
   158 */
       
   159 EXPORT_C void TASShdAlarm::SetUtcNextDueTime(TTime aUtcTime)
       
   160 	{
       
   161 	iNextDueTime = aUtcTime;
       
   162 	iCharacteristics.Set(EAlarmCharacteristicsIsFixed);	
       
   163 	}
       
   164 
       
   165 /**
       
   166 Using this API to tell the alarmserver not to notify the Agenda alarms if
       
   167 its due time is in the past after system time has been changed.
       
   168 */
       
   169 EXPORT_C void TASShdAlarm::SetDeQueueIfDueTimeInPast()
       
   170 	{
       
   171 	iCharacteristics.Set(EAlarmCharacteristicsDeQueueIfDueTimeInPast);	
       
   172 	}
       
   173 
       
   174 #ifdef SYMBIAN_SYSTEM_STATE_MANAGEMENT
       
   175 EXPORT_C void TASShdAlarm::SetWakeup(TBool aEnabled)
       
   176 	{
       
   177 	if (aEnabled)
       
   178 		{
       
   179 		iFlags2.Set(EASShdAlarmFlag2Wakeup);
       
   180 		}
       
   181 	else
       
   182 		{
       
   183 		iFlags2.Clear(EASShdAlarmFlag2Wakeup);
       
   184 		}
       
   185 	}
       
   186 
       
   187 EXPORT_C TBool TASShdAlarm::IsWakeup() const
       
   188 	{
       
   189 	return iFlags2.IsSet(EASShdAlarmFlag2Wakeup);
       
   190 	}
       
   191 #endif
       
   192 
       
   193 #ifdef SYMBIAN_ALARM_REPEAT_EXTENSIONS
       
   194 /**
       
   195 Sets which days of the week an alarm with a repeat definition of
       
   196 EAlarmRepeatDefintionRepeatDailyOnGivenDays activates on.  By default, an alarm
       
   197 with a repeat definition of EAlarmRepeatDefinitionRepeatDailyOnGivenDays will be
       
   198 active on all days of the week.
       
   199 
       
   200 @prototype
       
   201 
       
   202 @param aAlarmDays
       
   203 	The days of the week that the alarm activates on.  Days are combined using
       
   204 	the bitwise OR operator e.g. EAlarmDayMonday|EAlarmDayTuesday.
       
   205 
       
   206 @return
       
   207 	KErrNone if successful, KErrArgument if aAlarmDays is an invalid value.
       
   208 */
       
   209 EXPORT_C TInt TASShdAlarm::SetAlarmDays(TUint8 aAlarmDays)
       
   210 	{
       
   211 	TUint8 alarmDaysMask = ~(EAlarmDayMonday | EAlarmDayTuesday |
       
   212 		EAlarmDayWednesday | EAlarmDayThursday | EAlarmDayFriday |
       
   213 		EAlarmDaySaturday | EAlarmDaySunday);
       
   214 	
       
   215 	if ((aAlarmDays == 0) || ((aAlarmDays & alarmDaysMask) != 0))
       
   216 		{
       
   217 		return KErrArgument;
       
   218 		}
       
   219 		
       
   220 	iFlags2.Assign(EASShdAlarmFlag2AlarmDayMonday,
       
   221 		aAlarmDays & EAlarmDayMonday);
       
   222 
       
   223 	iFlags2.Assign(EASShdAlarmFlag2AlarmDayTuesday,
       
   224 		aAlarmDays & EAlarmDayTuesday);
       
   225 	
       
   226 	iFlags2.Assign(EASShdAlarmFlag2AlarmDayWednesday,
       
   227 		aAlarmDays & EAlarmDayWednesday);
       
   228 
       
   229 	iFlags2.Assign(EASShdAlarmFlag2AlarmDayThursday,
       
   230 		aAlarmDays & EAlarmDayThursday);
       
   231 
       
   232 	iFlags2.Assign(EASShdAlarmFlag2AlarmDayFriday,
       
   233 		aAlarmDays & EAlarmDayFriday);
       
   234 
       
   235 	iFlags2.Assign(EASShdAlarmFlag2AlarmDaySaturday,
       
   236 		aAlarmDays & EAlarmDaySaturday);
       
   237 
       
   238 	iFlags2.Assign(EASShdAlarmFlag2AlarmDaySunday,
       
   239 		aAlarmDays & EAlarmDaySunday);
       
   240 
       
   241 	return KErrNone;
       
   242 	}
       
   243 
       
   244 /**
       
   245 Returns the days of the week that the alarm activates on.  This value is only
       
   246 applicable if the alarm’s repeat definition is
       
   247 EAlarmRepeatDefinitionRepeatDailyOnGivenDays.  By default, an alarm with a
       
   248 repeat definition of EAlarmRepeatDefinitionRepeatDailyOn-GivenDays will be
       
   249 active on all days of the week.
       
   250 
       
   251 @prototype
       
   252 
       
   253 @return
       
   254 	The days of the week the alarm activates on.
       
   255 */
       
   256 EXPORT_C TUint8 TASShdAlarm::AlarmDays() const
       
   257 	{
       
   258 	TUint8 alarmDays = 0;
       
   259 	
       
   260 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDayMonday))
       
   261 		{
       
   262 		alarmDays |= EAlarmDayMonday;
       
   263 		}
       
   264 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDayTuesday))
       
   265 		{
       
   266 		alarmDays |= EAlarmDayTuesday;
       
   267 		}
       
   268 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDayWednesday))
       
   269 		{
       
   270 		alarmDays |= EAlarmDayWednesday;
       
   271 		}
       
   272 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDayThursday))
       
   273 		{
       
   274 		alarmDays |= EAlarmDayThursday;
       
   275 		}
       
   276 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDayFriday))
       
   277 		{
       
   278 		alarmDays |= EAlarmDayFriday;
       
   279 		}
       
   280 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDaySaturday))
       
   281 		{
       
   282 		alarmDays |= EAlarmDaySaturday;
       
   283 		}
       
   284 	if (iFlags2.IsSet(EASShdAlarmFlag2AlarmDaySunday))
       
   285 		{
       
   286 		alarmDays |= EAlarmDaySunday;
       
   287 		}
       
   288 	
       
   289 	return alarmDays;
       
   290 	}
       
   291 
       
   292 /**
       
   293 Sets whether or not the alarm is continuous.
       
   294 
       
   295 @prototype
       
   296 
       
   297 @param aContinuous
       
   298 	ETrue if the alarm is continuous, EFalse if the alarm is not continuous.
       
   299 */
       
   300 EXPORT_C void TASShdAlarm::SetContinuous(TBool aContinuous)
       
   301 	{
       
   302 	iFlags2.Assign(EASShdAlarmFlag2Continuous, aContinuous);
       
   303 	}
       
   304 
       
   305 /**
       
   306 Returns the continuous state for the alarm.
       
   307 
       
   308 @prototype
       
   309 
       
   310 @return
       
   311 	ETrue if the alarm is continuous, EFalse if the alarm is not continuous.
       
   312 */
       
   313 EXPORT_C TBool TASShdAlarm::Continuous()
       
   314 	{
       
   315 	return iFlags2.IsSet(EASShdAlarmFlag2Continuous);
       
   316 	}
       
   317 
       
   318 #endif
       
   319 	
       
   320 
       
   321 /** Tests whether the alarm has any associated data. 
       
   322 	
       
   323 @return True if the alarm has associated data. */
       
   324 EXPORT_C TBool TASShdAlarm::HasAssociatedData() const
       
   325 
       
   326 	{
       
   327 	return iFlags.IsSet(EASShdAlarmFlagsHasAssociatedData);
       
   328 	}
       
   329 
       
   330 
       
   331 /** Tests whether the alarm has an active owning session.
       
   332 
       
   333 @return True if the alarm has an active owning session. */
       
   334 EXPORT_C TBool TASShdAlarm::HasOwningSession() const
       
   335 
       
   336 	{
       
   337 	return iFlags.IsSet(EASShdAlarmFlagsHasOwningSession);
       
   338 	}
       
   339 
       
   340 EXPORT_C TBool TASShdAlarm::HasBecomeOrphaned() const
       
   341 /** Tests whether the alarm is orphaned. 
       
   342 
       
   343 An alarm is ophaned if it used to have an owning session, but no longer does. 
       
   344 If an alarm is owned by a session, it is removed from the queue when the session 
       
   345 disconnects. However, orphaned alarms stay in the queue.
       
   346 	
       
   347 @return True if the alarm has becomed orphaned. */
       
   348 	{
       
   349 	return iFlags.IsSet(EASShdAlarmFlagsHasBecomeOrphaned);
       
   350 	}
       
   351 	
       
   352