genericservices/taskscheduler/SCHSVR/SCHINFO.CPP
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     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 #include "SCHINFO.H"
       
    17 #include "SCHEXEC.H"
       
    18 
       
    19 /**
       
    20 Persists flag value, used by TScheduleState2
       
    21 @internalComponent
       
    22 */
       
    23 const TUint32 KPersists = 0x00000001;
       
    24 
       
    25 
       
    26 /**
       
    27 IsEnabled flag value, used by TScheduleState2
       
    28 @internalComponent
       
    29 */
       
    30 const TUint32 KIsEnabled = 0x00000002;
       
    31 
       
    32 
       
    33 EXPORT_C TTaskInfo::TTaskInfo(TInt aTaskId, TName& aName, TInt aPriority, TInt aRepeat)
       
    34 				:iRepeat(aRepeat), iTaskId(aTaskId), iName(aName), iPriority(aPriority)
       
    35 /** Constructor taking the specified parameters.
       
    36 
       
    37 @param aTaskId The task Id.
       
    38 @param aName The name of the task.
       
    39 @param aPriority The task priority.
       
    40 @param aRepeat How often the task is to be repeated */
       
    41 	{
       
    42 	} 
       
    43 
       
    44 EXPORT_C TTaskInfo::TTaskInfo()
       
    45 /** Default constructor. */
       
    46 	{
       
    47 	}
       
    48 
       
    49 EXPORT_C TTaskInfo& TTaskInfo::operator=(const TTaskInfo& aTaskInfo)
       
    50 	{
       
    51 	Mem::Copy(this,&aTaskInfo,sizeof(*this));
       
    52 	return *this;
       
    53 	}
       
    54 
       
    55 EXPORT_C void TTaskInfo::ExternalizeL(RWriteStream& aWriteStream) const
       
    56 /** Externalises an object of this class to a write stream.
       
    57 	
       
    58 	The presence of this function means that the standard templated operator<<() 
       
    59 	can be used to externalise objects of this class.
       
    60 	
       
    61 	@param aStream Stream to which the object should be externalised. */
       
    62 	{
       
    63 	aWriteStream << iName;
       
    64 	aWriteStream.WriteInt32L(iTaskId);
       
    65 	aWriteStream.WriteInt32L(iRepeat);
       
    66 	aWriteStream.WriteInt32L(iPriority);
       
    67 	}
       
    68 
       
    69 EXPORT_C void TTaskInfo::InternalizeL(RReadStream& aReadStream)
       
    70 	/** Internalises an object of this class from a read stream.
       
    71 	
       
    72 	The presence of this function means that the standard templated operator>>() 
       
    73 	can be used to internalise objects of this class.
       
    74 	
       
    75 	Note that the function has assignment semantics. It replaces the old value 
       
    76 	of the object with a new value read from the read stream.
       
    77 	
       
    78 	@param aStream Stream from which the object is to be internalised. */
       
    79 	{
       
    80 	aReadStream >> iName;
       
    81 	iTaskId = aReadStream.ReadInt32L();
       
    82 	iRepeat = aReadStream.ReadInt32L();
       
    83 	iPriority = aReadStream.ReadInt32L();
       
    84 	}
       
    85 
       
    86 //
       
    87 /**
       
    88 Externalizes the ScheduleEntryInfo
       
    89 @internalComponent only used by server
       
    90 */
       
    91 void TScheduleEntryInfo::ExternalizeL(RWriteStream& aStream) const
       
    92 	{
       
    93 	aStream.WriteInt32L(iValidityPeriod.Int());
       
    94 	aStream.WriteInt32L(iInterval);
       
    95 	aStream.WriteInt8L(iIntervalType);
       
    96 	TInt64 asInt = iStartTime.Int64();
       
    97 	aStream.WriteInt32L(I64LOW(asInt));
       
    98 	aStream.WriteInt32L(I64HIGH(asInt));
       
    99 	}
       
   100 
       
   101 /**
       
   102 Internalizes the ScheduleEntryInfo
       
   103 @internalComponent only used by server
       
   104 */
       
   105 void TScheduleEntryInfo::InternalizeL(RReadStream& aStream)
       
   106 	{
       
   107 	iValidityPeriod = aStream.ReadInt32L();
       
   108 	iInterval = aStream.ReadInt32L();
       
   109 	iIntervalType = TIntervalType(aStream.ReadInt8L());
       
   110 	TInt64 asInt;
       
   111 	TInt lo;
       
   112 	TInt hi;
       
   113 	lo=aStream.ReadInt32L();
       
   114 	hi=aStream.ReadInt32L();
       
   115 	asInt = MAKE_TINT64(hi,lo);
       
   116 	iStartTime = asInt;
       
   117 	}
       
   118 
       
   119 
       
   120 
       
   121 /**
       
   122 TScheduleEntryInfo2 Default constructor. 
       
   123 It sets the object's members data to the following default values.
       
   124 iIntervalType : EHourly
       
   125 iStartTime : UTC time set to 0
       
   126 iInterval : 0
       
   127 iValidityPeriod : 0
       
   128 */
       
   129 EXPORT_C TScheduleEntryInfo2::TScheduleEntryInfo2() :
       
   130 		iInterval(0),
       
   131 		iIntervalType(TIntervalType(0)),
       
   132 		iValidityPeriod(0),
       
   133 		iReserved(NULL)
       
   134 	{
       
   135 		
       
   136 	}
       
   137 	
       
   138 /**
       
   139 Copy constructor for TScheduleEntryInfo2
       
   140 Sets the parameter's data to this object.
       
   141 @param aEntryInfo The TScheduleEntryInfo2 object to be copied
       
   142 */	
       
   143 EXPORT_C TScheduleEntryInfo2::TScheduleEntryInfo2(const TScheduleEntryInfo2& aEntryInfo)
       
   144 	{
       
   145 	*this = aEntryInfo;
       
   146 	}
       
   147 
       
   148 /**
       
   149 TScheduleEntryInfo2 constructor taking the specified parameters.
       
   150 
       
   151 @param aStartTime The first time that the entry will cause execution of tasks
       
   152 @param aIntervalType Defines the type of time-frame relative to which execution of tasks is timed; 
       
   153 for example, EHourly implies relative to the current hour, EDaily implies 
       
   154 relative to the current day
       
   155 @param aInterval The interval between execution of tasks
       
   156 For a schedule entry interval to be valid, it should be greater than or equal to 1
       
   157 @param aIntervalMinutes The period for which the entry is valid
       
   158 */	
       
   159 EXPORT_C TScheduleEntryInfo2::TScheduleEntryInfo2(const TTsTime& aStartTime, TIntervalType aIntervalType, TInt aInterval, TTimeIntervalMinutes aValidityPeriod)
       
   160 	{
       
   161 	iStartTime = aStartTime;
       
   162 	iIntervalType = aIntervalType;
       
   163 	iInterval = aInterval;
       
   164 	iValidityPeriod = aValidityPeriod ;
       
   165 	iReserved = NULL;
       
   166 	}
       
   167 
       
   168 /**
       
   169 Returns the Interval Type
       
   170 @return The type of interval used between due times for this schedule entry.
       
   171 The type of interval used may be EHourly, EDaily, EMonthly or EYearly.
       
   172 @see TIntervalType
       
   173 */
       
   174 EXPORT_C TIntervalType TScheduleEntryInfo2::IntervalType() const
       
   175 	{
       
   176 	return iIntervalType;	
       
   177 	}
       
   178 
       
   179 /**
       
   180 Sets the type of interval used between due times for this schedule entry.
       
   181 The type of interval used may be EHourly, EDaily, EMonthly or EYearly.
       
   182 @param aIntervalType The type of interval to be used.
       
   183 @see TIntervalType
       
   184 */	
       
   185 EXPORT_C void TScheduleEntryInfo2::SetIntervalType(TIntervalType aIntervalType)
       
   186 	{
       
   187 	iIntervalType = aIntervalType;	
       
   188 	}
       
   189 
       
   190 /**
       
   191 Returns the first time at which the entry will cause execution of tasks.
       
   192 @return Start time - this TTsTime value may be either UTC or local time based.
       
   193 Entries with local time based start times will remain at that local time regardless of
       
   194 timezone or DST changes (ie. will float). Entries with UTC based start times, will
       
   195 remain at the given UTC time (will not float).
       
   196 @see TTsTime
       
   197 */
       
   198 EXPORT_C const TTsTime& TScheduleEntryInfo2::StartTime() const
       
   199 	{
       
   200 	return iStartTime;	
       
   201 	}
       
   202 
       
   203 /**
       
   204 Sets the first time the entry will cause execution of tasks.
       
   205 @param aStartTime This TTsTime value may be either UTC or local time based.
       
   206 If this is a local time based value, the schedule entry will remain
       
   207 at that local time regardless of timezone and DST changes (ie. it will float)
       
   208 If the value is UTC based, the schedule entry will remain at that UTC time (will not float).
       
   209 @see TTsTime
       
   210 */
       
   211 EXPORT_C void TScheduleEntryInfo2::SetStartTime(const TTsTime& aStartTime)
       
   212 	{
       
   213 	iStartTime = aStartTime;
       
   214 	}
       
   215 	
       
   216 /**
       
   217 Returns the interval between execution of tasks.
       
   218 @return Interval between execution of tasks. 
       
   219 For a schedule entry interval to be valid, it should be greater than or equal to 1.
       
   220 @see TScheduleEntryInfo2::SetInterval
       
   221 */	
       
   222 EXPORT_C TInt TScheduleEntryInfo2::Interval() const
       
   223 	{
       
   224 	return 	iInterval;
       
   225 	}
       
   226 
       
   227 /**
       
   228 Sets the interval between execution of tasks.
       
   229 The way that this value is interpreted depends on the value of iIntervalType. 
       
   230 For example, if the interval is 2 and iIntervalType has a value of EMonthly, 
       
   231 then the interval is 2 months. 
       
   232 @param aInterval For a schedule entry interval to be valid, it should be greater than or equal to 1.
       
   233 */	
       
   234 EXPORT_C void TScheduleEntryInfo2::SetInterval(TInt aInterval)
       
   235 	{
       
   236 	iInterval = aInterval;	
       
   237 	}
       
   238 
       
   239 /**
       
   240 Return the period for which the entry is valid.
       
   241 After the validity period has expired, tasks associated with the entry will 
       
   242 not be eligible for execution
       
   243 @return TTimeIntervalMinutes
       
   244 */
       
   245 EXPORT_C TTimeIntervalMinutes TScheduleEntryInfo2::ValidityPeriod() const
       
   246 	{
       
   247 	return iValidityPeriod;	
       
   248 	}
       
   249 	
       
   250 /**
       
   251 Sets the period for which the entry is valid.
       
   252 After the validity period has expired, tasks associated with the entry will 
       
   253 not be eligible for execution
       
   254 @param aValidityPeriod, the period for which the entry is valid
       
   255 @see TTimeIntervalMinutes
       
   256 */	
       
   257 EXPORT_C void TScheduleEntryInfo2::SetValidityPeriod(TTimeIntervalMinutes aValidityPeriod)
       
   258 	{
       
   259 	iValidityPeriod = aValidityPeriod;	
       
   260 	}
       
   261 
       
   262 
       
   263 /**
       
   264 Non exported constructor accepting a TScheduleEntryInfo parameter
       
   265 This constructor is provided for use with the deprecated APIs.
       
   266 This will assume home time in order to maintain backwards compatibility and will create a #
       
   267 TScheduleEntryInfo2 object with a local time based start time.
       
   268 @param aEntryInfo Entry info of deprecated type TScheduleEntryInfo
       
   269 @see TScheduleEntryInfo
       
   270 */
       
   271 TScheduleEntryInfo2::TScheduleEntryInfo2(const TScheduleEntryInfo& aEntryInfo)
       
   272 	{	
       
   273 	iStartTime.SetLocalTime(aEntryInfo.iStartTime);
       
   274 	iIntervalType = aEntryInfo.iIntervalType;
       
   275 	iInterval = aEntryInfo.iInterval;
       
   276 	iValidityPeriod = aEntryInfo.iValidityPeriod ;	
       
   277 	}
       
   278 
       
   279 
       
   280 /**
       
   281 Externalises an object of this class to a write stream.
       
   282 The presence of this function means that the standard templated operator<<() 
       
   283 can be used to externalise objects of this class.
       
   284 	
       
   285 @param aStream Stream to which the object should be externalised.
       
   286 @internalComponent only used by server
       
   287 */
       
   288 void TScheduleEntryInfo2::ExternalizeL(RWriteStream& aStream) const
       
   289 	{
       
   290 	aStream << iStartTime;
       
   291 	aStream.WriteInt32L(iIntervalType);	
       
   292 	aStream.WriteInt32L(iInterval);
       
   293 	aStream.WriteInt32L(iValidityPeriod.Int());	
       
   294 	}
       
   295 
       
   296 	
       
   297 /**
       
   298 Internalises an object of this class from a read stream.
       
   299 The presence of this function means that the standard templated operator>>() 
       
   300 can be used to internalise objects of this class.
       
   301 		
       
   302 @param aStream Stream from which the object is to be internalised.
       
   303 @internalComponent only used by server
       
   304 */	
       
   305 void TScheduleEntryInfo2::InternalizeL(RReadStream& aStream)
       
   306 	{
       
   307 	aStream >> iStartTime;
       
   308 	iIntervalType = TIntervalType(aStream.ReadInt32L());
       
   309 	iInterval = aStream.ReadInt32L();
       
   310 	iValidityPeriod = aStream.ReadInt32L();
       
   311 	}
       
   312 	
       
   313 /**
       
   314 Calls ProcessOffsetEvent() on TScheduleEntryInfo's start time member
       
   315 @see TTsTime::ProcessOffsetEvent
       
   316 @internalComponent only used by the server
       
   317 */
       
   318 void TScheduleEntryInfo2::ProcessOffsetEvent()
       
   319 	{
       
   320 	iStartTime.ProcessOffsetEvent();
       
   321 	}
       
   322 
       
   323 /**
       
   324 Assignment operator for TScheduleEntryInfo2
       
   325 @see Mem::Copy
       
   326 */
       
   327 EXPORT_C TScheduleEntryInfo2& TScheduleEntryInfo2::operator=(const TScheduleEntryInfo2& aEntryInfo)
       
   328 	{
       
   329 	Mem::Copy(this,&aEntryInfo,sizeof(*this));
       
   330 	return *this;
       
   331 	}
       
   332 	
       
   333 /**
       
   334 Default Constructor for TScheduleState2.
       
   335 By default, this state: has an empty string name, is non persistent, non enabled and its due time is set to zero.
       
   336 */
       
   337 EXPORT_C TScheduleState2::TScheduleState2():
       
   338 	iName(_L("")),
       
   339 	iFlags(0),
       
   340 	iReserved(NULL)
       
   341 	{
       
   342 		
       
   343 	}
       
   344 
       
   345 /**
       
   346 Copy constructor for TScheduleState2
       
   347 @param aScheduleState The TScheduleState2 object to be copied
       
   348 */	
       
   349 EXPORT_C TScheduleState2::TScheduleState2(const TScheduleState2& aScheduleState)
       
   350 	{
       
   351 	*this = aScheduleState;
       
   352 	}
       
   353 
       
   354 /**
       
   355 Constructor taking the specified parameters.
       
   356 @param	aName The name of the schedule
       
   357 @param 	aDueTime The time when the schedule is next due.
       
   358 @param 	aPersists Boolean to indicate whether the schedule is persistent or not.
       
   359 if a schedule is persistent, its lifetime is not limited to the lifetime of 
       
   360 the tasks associated with it.
       
   361 If a schedule is transient, it is created together with a new scheduled task, 
       
   362 and is destroyed when the task is destroyed
       
   363 @param 	aEnabled Boolean to indicate whether the shedule is enabled or not.
       
   364 */	
       
   365 EXPORT_C TScheduleState2::TScheduleState2(const TName& aName, const TTsTime& aDueTime, TBool aPersists, TBool aEnabled)
       
   366 	{
       
   367 	iName = aName;
       
   368 	iDueTime = aDueTime;
       
   369 	SetPersists(aPersists);
       
   370 	SetEnabled(aEnabled);
       
   371 	iReserved = NULL;
       
   372 	
       
   373 	}
       
   374 		
       
   375 /**
       
   376 @return  The name of the schedule
       
   377 */
       
   378 EXPORT_C const TName& TScheduleState2::Name() const
       
   379 	{
       
   380 	return iName;	
       
   381 	}
       
   382 	
       
   383 /**
       
   384 Sets the name of the schedule
       
   385 @param aName The name of the schedule
       
   386 */	
       
   387 EXPORT_C void TScheduleState2::SetName(const TName& aName)
       
   388 	{
       
   389 	iName = aName;	
       
   390 	}
       
   391 
       
   392 
       
   393 /**
       
   394 Returns the time when the schedule is next due.
       
   395 @return The time when the schedule is next due. This time could be either home time (for floating schedules) or UTC time.
       
   396 @see TTsTime
       
   397 */
       
   398 EXPORT_C const TTsTime& TScheduleState2::DueTime() const
       
   399 	{
       
   400 	return iDueTime;	
       
   401 	}
       
   402 
       
   403 	
       
   404 /**
       
   405 Sets the time when the schedule is next due.
       
   406 @param aDueTime The time when the schedule is next due. This time could be either home time (for floating schedules) or UTC time.
       
   407 @see TTsTime
       
   408 */	
       
   409 EXPORT_C void TScheduleState2::SetDueTime(const TTsTime& aDueTime)
       
   410 	{
       
   411 	iDueTime = aDueTime;
       
   412 	}
       
   413 
       
   414 
       
   415 /**
       
   416 Returns a boolean whether this schedule perists or not.
       
   417 @return Etrue if this schedule persists, EFalse if this schedule doen't persist.
       
   418 */
       
   419 EXPORT_C TBool TScheduleState2::Persists() const
       
   420 	{
       
   421 	return iFlags & KPersists ? ETrue: EFalse;		
       
   422 	}
       
   423 
       
   424 	
       
   425 
       
   426 /**
       
   427 Sets a boolean whether this schedule perists or not.
       
   428 @param aPersists Etrue if this schedule persits, EFalse if this schedule doen't persist.
       
   429 */	
       
   430 EXPORT_C void TScheduleState2::SetPersists(TBool aPersists)
       
   431 	{
       
   432 	if(aPersists )
       
   433 		iFlags |= KPersists;
       
   434 	else
       
   435 		iFlags &= ~KPersists;
       
   436 	}
       
   437 
       
   438 
       
   439 /**
       
   440 Returns information on whether this schedule is enabled or not.
       
   441 @return Etrue if the schedule is enabled, EFalse id the schedule is not enabled.
       
   442 */
       
   443 EXPORT_C TBool TScheduleState2::Enabled() const
       
   444 	{
       
   445 	return iFlags & KIsEnabled ? ETrue: EFalse;	
       
   446 	}
       
   447 
       
   448 	
       
   449 /**
       
   450 Sets information on whether this schedule is enabled or not.
       
   451 @param aEnabled 
       
   452 */	
       
   453 EXPORT_C void TScheduleState2::SetEnabled(TBool aEnabled)
       
   454 	{
       
   455 	if(aEnabled )
       
   456 		iFlags |= KIsEnabled;
       
   457 	else
       
   458 		iFlags &= ~KIsEnabled;	
       
   459 	}
       
   460 
       
   461 /**
       
   462 Assigns a TScheduleState2 to this object.
       
   463 @see Mem::Copy
       
   464 */
       
   465 EXPORT_C TScheduleState2& TScheduleState2::operator=(const TScheduleState2& aScheduleState)
       
   466 	{
       
   467 	Mem::Copy(this,&aScheduleState,sizeof(*this));
       
   468 	return *this;
       
   469 	}
       
   470 
       
   471 /**
       
   472 A constructor for TScheduleState that takes a TScheduleState2 parameter,
       
   473 for use with the deprecated APIs. All TScheduleStates created will have 
       
   474 local time based iDueTime data members.
       
   475 @internalComponent
       
   476 */
       
   477 TScheduleState::TScheduleState(const TScheduleState2& aScheduleState2)
       
   478 	{
       
   479 	iName = aScheduleState2.Name();	
       
   480 	iPersists = aScheduleState2.Persists();
       
   481 	iEnabled = aScheduleState2.Enabled();
       
   482 	
       
   483 	// iDueTime is local time based for backwards compatibility
       
   484 	iDueTime = aScheduleState2.DueTime().GetLocalTime();
       
   485 	}