genericservices/taskscheduler/SCHCLI/CSCH_CLI.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 // Implements RScheduler functions: client-side session with the task scheduler
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "CSCH_CLI.H"	//definition of RScheduler
       
    19 #include "CSCHCODE.H"	//opcodes
       
    20 #include "SCHEXE.H"
       
    21 #include <schinfointernal.h>
       
    22 
       
    23 /** Default constructor. */
       
    24 EXPORT_C RScheduler::RScheduler()
       
    25     {
       
    26     }
       
    27 
       
    28 /** 
       
    29 Connects a client to the Task Scheduler server, creating a session with that 
       
    30 server.
       
    31 
       
    32 @return KErrNone, if successful; otherwise one of the other system wide error 
       
    33 codes. 
       
    34 */
       
    35 EXPORT_C TInt RScheduler::Connect()
       
    36 	{
       
    37 	TInt r=CreateSession(KSchSvrName, Version(),0);
       
    38 	if (r==KErrNotFound)
       
    39 		{
       
    40 		r=StartSch32();
       
    41 		if (r!=KErrNone)
       
    42 			return r;
       
    43 		r=CreateSession(KSchSvrName, Version(),0);
       
    44 	    }
       
    45 	return(r); 
       
    46 	}
       
    47 	
       
    48 /** 
       
    49 Gets the client side version number.
       
    50 
       
    51 @return The version number. 
       
    52 */
       
    53 EXPORT_C TVersion RScheduler::Version() const
       
    54 	{
       
    55 	return(TVersion(KESchMajorVersionNumber,KESchMinorVersionNumber,KESchBuildVersionNumber));
       
    56 	}
       
    57 
       
    58 /** 
       
    59 Registers a client with the Task Scheduler.
       
    60 
       
    61 A client must register with the Task Scheduler before scheduling any tasks, 
       
    62 but does not need to register just to create and edit schedules.
       
    63 
       
    64 @param aFileName The name and full path of a program that encapsulates the 
       
    65 client-specific knowledge for implementing tasks. On the emulator, the program 
       
    66 should be a DLL; on an ARM processor, it should be an executable.
       
    67 @param aPriority A priority value.
       
    68 @return KErrNone, if successful; otherwise one of the other system wide error 
       
    69 codes. 
       
    70 */
       
    71 EXPORT_C TInt RScheduler::Register(const TFileName& aFileName,const TInt aPriority)
       
    72 	{
       
    73 	return SendReceive(ERegisterClient,TIpcArgs(&aFileName,aPriority));
       
    74 	}
       
    75 
       
    76 /** 
       
    77 Creates a persistent time based schedule.
       
    78 
       
    79 This schedule has no tasks associated with it but merely contains information
       
    80 about start and finish times.
       
    81 
       
    82 @capability WriteDeviceData
       
    83 @param aRef Definition of the new schedule.  On return this contains a valid
       
    84 handle to the newly created schedule.
       
    85 @param aEntryList The set of schedule entries that make up the new schedule.
       
    86 @return KErrNone, if successful, KErrArgument if the condition array is 
       
    87 empty, or an entry has an interval less than 1, KErrServerBusy, if a backup or 
       
    88 restore operation is taking place, KErrPermissionDenied if the client 
       
    89 does not have WriteDeviceData capability. 
       
    90 Otherwise one of the other system wide error codes.
       
    91 @see TScheduleEntryInfo2
       
    92 */
       
    93 EXPORT_C TInt RScheduler::CreatePersistentSchedule(TSchedulerItemRef& aRef, 
       
    94 							const CArrayFixFlat<TScheduleEntryInfo2>& aEntryList)
       
    95 	{
       
    96 	TScheduleSettings2 settings;
       
    97 	settings.iPersists = ETrue;
       
    98 	settings.iEntryCount = aEntryList.Count();
       
    99 	settings.iName = aRef.iName;
       
   100 	return CreateSchedule(aRef, aEntryList, settings);
       
   101 	}
       
   102 
       
   103 /** 
       
   104 Creates a persistent condition based schedule.
       
   105 
       
   106 This schedule has no tasks associated with it but merely contains information
       
   107 about conditions that must be satified to complete this schedule.
       
   108 
       
   109 @capability WriteDeviceData
       
   110 @param aRef Definition of the new schedule.  On return this contains a valid
       
   111 handle to the newly created schedule.
       
   112 @param aConditions An array of system agent conditons 
       
   113 that make up the schedule.
       
   114 @param aDefaultRunTime The time at which the schedule with run if no
       
   115 conditions are met. If this is a local time based value, the schedule will remain
       
   116 at that local time regardless of timezone and DST changes (ie. it will float)
       
   117 If the value is UTC based, the schedule will remain at that UTC time (will not float).
       
   118 @return KErrNone, if successful, KErrArgument if the condition array is 
       
   119 empty or if the publish and subscribe variables have an invalid category, 
       
   120 KErrServerBusy, if a backup or restore operation is taking place,
       
   121 KErrPermissionDenied if the client does not have WriteDeviceData capability. 
       
   122 Otherwise one of the other system wide error codes.
       
   123 @see TTaskSchedulerCondition 
       
   124 @internalAll
       
   125 */
       
   126 EXPORT_C TInt RScheduler::CreatePersistentSchedule(TSchedulerItemRef& aRef, 
       
   127 							const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   128 							const TTsTime& aDefaultRunTime)
       
   129 	{
       
   130 	TScheduleSettings2 settings;
       
   131 	settings.iPersists = ETrue;
       
   132 	settings.iEntryCount = aConditions.Count();
       
   133 	settings.iName = aRef.iName;
       
   134 	return CreateSchedule(aRef, aConditions, aDefaultRunTime, settings);	
       
   135 	}
       
   136 
       
   137 static TBool ScheduleEntriesAreBad(const CArrayFixFlat<TScheduleEntryInfo2>& aEntries)
       
   138 	{//must have at least 1 entry, each entry's interval must be at least 1
       
   139 	TInt count = aEntries.Count();
       
   140 	if (count==0)
       
   141 		return ETrue;
       
   142 	for (TInt i=0; i < count; i++)
       
   143 		{
       
   144 		const TScheduleEntryInfo2* entry = &(aEntries.At(i));
       
   145 		if (entry->Interval() < 1)
       
   146 			return ETrue;
       
   147 		}
       
   148 	return EFalse;
       
   149 	}
       
   150 
       
   151 TInt RScheduler::CreateSchedule(TSchedulerItemRef& aRef, 
       
   152 			const CArrayFixFlat<TScheduleEntryInfo2>& aEntryList, 
       
   153 			const TScheduleSettings2& aSettings)
       
   154 	{//check critical aspects of input here (client-side)
       
   155 	if (ScheduleEntriesAreBad(aEntryList))
       
   156 		return KErrArgument;
       
   157 	
       
   158 	//write settings (entry count + persists flag + name)
       
   159 	TPckgC<TScheduleSettings2> pSettings(aSettings);
       
   160 	//write entries
       
   161 	TPtrC8 pA((TUint8*)&aEntryList.At(0), sizeof(TScheduleEntryInfo2)*aSettings.iEntryCount); 
       
   162 	
       
   163 	//read back generated ID
       
   164 	TPckg<TInt> id(aRef.iHandle);
       
   165 	return SendReceive(ECreateTimeSchedule, TIpcArgs(&pSettings, &pA, &id));
       
   166 	}
       
   167 	
       
   168 static TBool ScheduleEntriesAreBad(const CArrayFixFlat<TTaskSchedulerCondition>& aConditions)
       
   169 	{//must have at least 1 condition in array. The category for a condition cannot be KNullUid.
       
   170 	TInt count = aConditions.Count();
       
   171 	if (count==0)
       
   172 		return ETrue;
       
   173 	for (TInt i=0; i < count; i++)
       
   174 		{
       
   175 		const TTaskSchedulerCondition* entry = &(aConditions.At(i));
       
   176 		if (entry->iCategory == KNullUid)
       
   177 			return ETrue;
       
   178 		}
       
   179 	return EFalse;
       
   180 	}
       
   181 
       
   182 TInt RScheduler::CreateSchedule(TSchedulerItemRef& aRef, 
       
   183 			const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   184 			const TTsTime& aDefaultRunTime, 
       
   185 			const TScheduleSettings2& aSettings)
       
   186 	{//check critical aspects of input here (client-side)
       
   187 	if (ScheduleEntriesAreBad(aConditions))
       
   188 		return KErrArgument;
       
   189 	
       
   190 	//write settings (entry count + persists flag + name)
       
   191 	TPckgC<TScheduleSettings2> pSettings(aSettings);
       
   192 	//write entries
       
   193 	TPtrC8 pA((TUint8*)&aConditions.At(0), sizeof(TTaskSchedulerCondition)*aSettings.iEntryCount); 
       
   194 	//write Time
       
   195 	TPckgC<TTsTime> pTime(aDefaultRunTime);
       
   196 	
       
   197 	//read back generated ID
       
   198 	TPckg<TInt> id(aRef.iHandle);
       
   199 	return SendReceive(ECreateConditionSchedule, TIpcArgs(&pSettings, &pA, &pTime, &id));
       
   200 	}
       
   201 
       
   202 /** 
       
   203 Changes a time based schedule.
       
   204 
       
   205 Note that changing a schedule is implemented by supplying a replacement set 
       
   206 of schedule entries.
       
   207 
       
   208 @capability Note Only clients with the same SID as the schedule creator, or 
       
   209 WriteDeviceData capability can sucessfully call this API.
       
   210 
       
   211 @param aScheduleHandle The Id that identifies the schedule.
       
   212 @param aEntryList The set of schedule entries that will make up the new schedule.
       
   213 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   214 the specified Id, KErrArgument if the schedule is not a time based one, 
       
   215 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   216 creator or has WriteDeviceData capability, KErrServerBusy, if a backup or 
       
   217 restore operation is taking place or any of the other system wide error 
       
   218 codes.
       
   219 @see TScheduleEntryInfo2
       
   220 */
       
   221 EXPORT_C TInt RScheduler::EditSchedule(const TInt aScheduleHandle, const CArrayFixFlat<TScheduleEntryInfo2>& aEntryList)
       
   222 	{
       
   223 	if (ScheduleEntriesAreBad(aEntryList))
       
   224 		return KErrArgument;
       
   225 	TInt count = aEntryList.Count();
       
   226 	TPtrC8 pA((TUint8*) &aEntryList.At(0), sizeof(TScheduleEntryInfo2)*count);
       
   227 	return SendReceive(EEditTimeSchedule, TIpcArgs(count, aScheduleHandle, &pA));
       
   228 	}
       
   229 
       
   230 /** 
       
   231 Changes a condition based schedule.
       
   232 
       
   233 Note that changing a schedule is implemented by supplying a replacement set 
       
   234 of schedule conditons and time.
       
   235 
       
   236 @capability Note Only clients with the same SID as the schedule creator, or 
       
   237 WriteDeviceData capability can sucessfully call this API.
       
   238 
       
   239 @param aScheduleHandle The Id that identifies the schedule.
       
   240 @param aConditions An array of system agent conditons 
       
   241 that make up the schedule.
       
   242 @param aDefaultRunTime The time at which the schedule with run if no
       
   243 conditions are met. If this is a local time based value, the schedule will remain
       
   244 at that local time regardless of timezone and DST changes (ie. it will float)
       
   245 If the value is UTC based, the schedule will remain at that UTC time (will not float).
       
   246 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   247 the specified Id, KErrArgument if the schedule is not a condition based one
       
   248 or if the publish and subscribe variables, defined by aConditions category 
       
   249 and key values, do not exist or are not of integral type, 
       
   250 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   251 creator or has WriteDeviceData capability, KErrServerBusy, if a backup or 
       
   252 restore operation is taking place, or any of the other system wide error 
       
   253 codes.
       
   254 
       
   255 @internalAll
       
   256 */	
       
   257 EXPORT_C TInt RScheduler::EditSchedule(TInt aScheduleHandle, 
       
   258 						const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   259 						const TTsTime& aDefaultRunTime)
       
   260 	{
       
   261 	TInt count = aConditions.Count();
       
   262 	TPtrC8 pA((TUint8*) &aConditions.At(0), sizeof(TTaskSchedulerCondition)*count);
       
   263 	//write Time
       
   264 	TPckgC<TTsTime> pTime(aDefaultRunTime);
       
   265 	return SendReceive(EEditConditionSchedule, TIpcArgs(count, aScheduleHandle, &pA, &pTime));	
       
   266 	}
       
   267 
       
   268 
       
   269 /** 
       
   270 Deletes the specified schedule.
       
   271 
       
   272 @capability Note Only clients with the same SID as the schedule creator, or 
       
   273 WriteDeviceData capability can sucessfully call this API.
       
   274 
       
   275 Note that a schedule cannot be deleted if there are tasks associated with 
       
   276 it; the tasks must be explicitly deleted first.
       
   277 
       
   278 @param aScheduleHandle The Id that identifies the schedule.
       
   279 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   280 the specified Id, KErrArgument if there are outstanding tasks associated with 
       
   281 the schedule, KErrPermissionDenied if the client does not have the same SID as 
       
   282 the schedules creator or has WriteDeviceData capability, KErrServerBusy, if a 
       
   283 backup or restore operation is taking place or any of the other 
       
   284 system wide error codes.
       
   285 */
       
   286 EXPORT_C TInt RScheduler::DeleteSchedule(const TInt aScheduleHandle) const
       
   287 	{
       
   288 	return SendReceive(EDeleteSchedule, TIpcArgs(aScheduleHandle));
       
   289 	}
       
   290 
       
   291 /** 
       
   292 Disables the specified schedule.
       
   293 
       
   294 @capability Note Only clients with the same SID as the schedule creator, or 
       
   295 WriteDeviceData capability can sucessfully call this API.
       
   296 
       
   297 @param aScheduleHandle The Id that identifies the schedule.
       
   298 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   299 the specified Id, KErrPermissionDenied if the client does not have the same SID 
       
   300 as the schedules creator or has WriteDeviceData capability, KErrServerBusy, if a 
       
   301 backup or restore operation is taking place or any of the other 
       
   302 system wide error codes.
       
   303 */
       
   304 EXPORT_C TInt RScheduler::DisableSchedule(const TInt aScheduleHandle) const
       
   305 	{
       
   306 	return SendReceive(EDisableSchedule, TIpcArgs(aScheduleHandle));
       
   307 	}
       
   308 
       
   309 /** 
       
   310 Enables the specified schedule.
       
   311 
       
   312 @capability Note Only clients with the same SID as the schedule creator, or 
       
   313 WriteDeviceData capability can sucessfully call this API.
       
   314 
       
   315 @param aScheduleHandle The Id that identifies the schedule.
       
   316 @return KErrNone if successful. KErrNotFound if there is no schedule with 
       
   317 the specified Id, KErrPermissionDenied if the client does not have the same SID 
       
   318 as the schedules creator or has WriteDeviceData capability, KErrServerBusy, if a 
       
   319 backup or restore operation is taking place or any of the other 
       
   320 system wide error codes.
       
   321 */
       
   322 EXPORT_C TInt RScheduler::EnableSchedule(const TInt aScheduleHandle) const
       
   323 	{
       
   324 	return SendReceive(EEnableSchedule, TIpcArgs(aScheduleHandle));
       
   325 	}
       
   326 
       
   327 /** 
       
   328 Adds a task to an existing persistent schedule.
       
   329 
       
   330 Behaviour of execution after a Backup and Restore operation should be 
       
   331 considered when adding tasks to a persistent schedule. Persistent schedules might be 
       
   332 backed up when a one-off task might be pending, and become due and executed some time 
       
   333 after the backup operation. When the backup is restored, the tasks might be executed 
       
   334 again if they are still valid (restore done during the validation period for time-based 
       
   335 schedules, or conditions satisfied after restore for condition-based schedules). Clients 
       
   336 should refrain from creating tasks that might have undesired effects under these 
       
   337 conditions (e.g. by incurring a cost to the user by sending an SMS twice). 
       
   338 
       
   339 @capability Note Only clients with the same SID as the schedule creator, or 
       
   340 WriteDeviceData capability can sucessfully call this API.
       
   341 
       
   342 @param aTaskInfo Information about the task to be added to the schedule. On return
       
   343 the task Id is written into this class.
       
   344 @param aTaskData Data that is passed to the task on execution.
       
   345 @param aScheduleHandle The Id that identifies the schedule to be used.
       
   346 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   347 the specified Id, KErrArgument if a task with a repeat vale other than 0 is 
       
   348 being tried to be assigned to a condition based schedule, 
       
   349 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   350 creator or has WriteDeviceData capability, KErrServerBusy, if a backup or 
       
   351 restore operation is taking place or any of the other system wide error 
       
   352 codes.
       
   353 @panic CTaskScheduler 0 The client has not registered. The client must register 
       
   354 before adding tasks to the schedule. 
       
   355 */
       
   356 EXPORT_C TInt RScheduler::ScheduleTask(TTaskInfo& aTaskInfo, 
       
   357 									HBufC& aTaskData, 
       
   358 									const TInt aScheduleHandle)
       
   359 	{
       
   360 	TPckgC<TTaskInfo> pI(aTaskInfo);
       
   361 	//scheduler writes back task id
       
   362 	TPckg<TInt> id(aTaskInfo.iTaskId);
       
   363 	TPtr pD(aTaskData.Des());
       
   364 	return SendReceive(EScheduleTask, TIpcArgs(&pI,aScheduleHandle,&id, &pD));
       
   365 	}
       
   366 
       
   367 /** 
       
   368 Creates a new, transient, time based schedule and adds a task to it.
       
   369 
       
   370 Note that a transient schedule is destroyed when the task is destroyed or 
       
   371 power is lost.
       
   372 
       
   373 @param aTaskInfo Information about the task to be added to the transient schedule. 
       
   374 On return the task Id is written into this class.
       
   375 @param aTaskData Data that is passed to the task on execution.
       
   376 @param aRef Definition of the new transient schedule.
       
   377 @param aEntryList The set of schedule entries that make up the new transient 
       
   378 schedule.
       
   379 @return KErrNone, if successful, or any of the other system wide error codes.
       
   380 @panic CTaskScheduler 0 The client has not registered. The client must register 
       
   381 before adding tasks to the schedule.
       
   382 @see TScheduleEntryInfo2 
       
   383 */
       
   384 EXPORT_C TInt RScheduler::ScheduleTask(TTaskInfo& aTaskInfo, 
       
   385 									HBufC& aTaskData, 
       
   386 									TSchedulerItemRef& aRef,
       
   387 									const CArrayFixFlat<TScheduleEntryInfo2>& aEntryList)
       
   388 	{
       
   389 	TScheduleSettings2 settings;
       
   390 	settings.iPersists = EFalse;
       
   391 	settings.iEntryCount = aEntryList.Count();
       
   392 	settings.iName = aRef.iName;
       
   393 	TInt res = CreateSchedule(aRef, aEntryList, settings);
       
   394 	if (res==KErrNone)
       
   395 		{
       
   396 		res = ScheduleTask(aTaskInfo, aTaskData, aRef.iHandle);
       
   397 		//the schedule here needs a task: so if we can't schedule a task,
       
   398 		//need to delete schedule
       
   399 		if (res!=KErrNone)
       
   400 			DeleteSchedule(aRef.iHandle);
       
   401 		}
       
   402 	return res;
       
   403 	}
       
   404 
       
   405 /** 
       
   406 Creates a new, transient, condition based schedule and adds a task to it.
       
   407 
       
   408 Note that a transient schedule is destroyed when the task is destroyed or
       
   409 power is lost.
       
   410 
       
   411 @param aTaskInfo Information about the task to be added to the transient schedule. 
       
   412 On return the task Id is written into this class.
       
   413 @param aTaskData Data that is passed to the task on execution.
       
   414 @param aRef Definition of the new transient schedule.
       
   415 @param aConditions An array of schedule conditons that make up the schedule.
       
   416 @param aDefaultRunTime The time at which the schedule will run if no
       
   417 conditions are met. If this is a local time based value, the schedule will remain
       
   418 at that local time regardless of timezone and DST changes (ie. it will float)
       
   419 If the value is UTC based, the schedule will remain at that UTC time (will not float).
       
   420 @return KErrNone, if successful, KErrArgument if the publish and subscribe 
       
   421 variables, defined by aConditions category and key values, do not exist or 
       
   422 are not of integral type, or any of the other system wide error codes.
       
   423 @panic CTaskScheduler 0 The client has not registered. The client must register 
       
   424 before adding tasks to the schedule.
       
   425 
       
   426 @internalAll
       
   427 */
       
   428 EXPORT_C TInt RScheduler::ScheduleTask(TTaskInfo& aTaskInfo, 
       
   429 								HBufC& aTaskData, 
       
   430 								TSchedulerItemRef& aRef, 
       
   431 								const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   432 								const TTsTime& aDefaultRunTime)
       
   433 	{
       
   434 	TScheduleSettings2 settings;
       
   435 	settings.iPersists = EFalse;
       
   436 	settings.iEntryCount = aConditions.Count();
       
   437 	settings.iName = aRef.iName;
       
   438 	TInt res = CreateSchedule(aRef, aConditions, aDefaultRunTime, settings);
       
   439 	if (res==KErrNone)
       
   440 		{
       
   441 		res = ScheduleTask(aTaskInfo, aTaskData, aRef.iHandle);
       
   442 		//the schedule here needs a task: so if we can't schedule a task,
       
   443 		//need to delete schedule
       
   444 		if (res!=KErrNone)
       
   445 			DeleteSchedule(aRef.iHandle);
       
   446 		}
       
   447 	return res;
       
   448 	}
       
   449 
       
   450 /** 
       
   451 Deletes the specified task.
       
   452 
       
   453 @capability Note Only clients with the same SID as the relevant schedule
       
   454 creator, or WriteDeviceData capability can sucessfully call this API.
       
   455 
       
   456 @param aTaskId The Id that identifies the task.
       
   457 @return KErrNone if successful, KErrNotFound if there is no task with the 
       
   458 specified Id, KErrPermissionDenied if the client does not have the same SID as 
       
   459 the schedules creator or has WriteDeviceData capability, KErrServerBusy, if a 
       
   460 backup or restore operation is taking place or any of the 
       
   461 other system wide error codes.
       
   462 */
       
   463 EXPORT_C TInt RScheduler::DeleteTask(const TInt aTaskId) const
       
   464 	{
       
   465 	return SendReceive(EDeleteTask, TIpcArgs(aTaskId));
       
   466 	}
       
   467 
       
   468 /** 
       
   469 Gets a list of all schedules, or a subset of schedules.
       
   470 
       
   471 @capability Note A call to this API will only retrieve schedules created with
       
   472 the caller's SID.  If the caller has WriteDeviceData capability all schedules
       
   473 will be retrieved.
       
   474 
       
   475 @param aScheduleRefArray On return, a populated array of schedule definitions. 
       
   476 Note that populating the array could cause this function to leave because 
       
   477 of an out of memory condition.
       
   478 @param aFilter The schedule filter.
       
   479 @return KErrNone if successful otherwise one of the other system wide error 
       
   480 codes.
       
   481 @see TSchedulerItemRef 
       
   482 */
       
   483 EXPORT_C TInt RScheduler::GetScheduleRefsL(CArrayFixFlat<TSchedulerItemRef>& aScheduleRefArray,
       
   484 									const TScheduleFilter aFilter)
       
   485 	{
       
   486 	//1) get number of refs
       
   487 	TInt count;//scheduler writes back count
       
   488 	TPckg<TInt> pCount(count);
       
   489 	TInt res = SendReceive(ECountSchedules, TIpcArgs(&pCount, aFilter));
       
   490 	if (res!=KErrNone)
       
   491 		return res;
       
   492 	aScheduleRefArray.ResizeL(count);
       
   493 	//2) get refs, if there are any
       
   494 	if (count>0)
       
   495 		{
       
   496 		TPtr8 sPtr((TUint8*)&(aScheduleRefArray.At(0)), count*sizeof(TSchedulerItemRef));
       
   497 		res = SendReceive(EGetScheduleRefs, TIpcArgs(count, aFilter, &sPtr));
       
   498 		}
       
   499 	return res;
       
   500 	}
       
   501 
       
   502 /** 
       
   503 Gets information relating to a specified time based schedule.
       
   504 
       
   505 @capability Note Only clients with the same SID as the schedule creator, or 
       
   506 WriteDeviceData capability can sucessfully call this API.
       
   507 
       
   508 @param aScheduleHandle The Id that identifies the schedule.
       
   509 @param aState On return, the state of the specified schedule.
       
   510 @param aEntries On return, a populated array of schedule entries that make 
       
   511 up the schedule. Note that populating the array could cause this function 
       
   512 to leave because of an out of memory condition.
       
   513 @param aTasks On return, a populated array of tasks associated with the schedule. 
       
   514 Note that populating the array could cause this function to leave because 
       
   515 of an out of memory condition.
       
   516 @param aDueTime On return, the time that the schedule is next due. This value may
       
   517 be local time or UTC based,dependent on the type of time used for schedule entries.
       
   518 Comparisons used within the scheduler to find the next due time are UTC based.
       
   519 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   520 the specified Id, KErrArgument if the schedule is not a time based one, 
       
   521 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   522 creator or has WriteDeviceData capability, or any of the other system wide error 
       
   523 codes.
       
   524 @see TScheduleEntryInfo2
       
   525 @see TTaskInfo 
       
   526 */
       
   527 EXPORT_C TInt RScheduler::GetScheduleL(const TInt aScheduleHandle, 
       
   528 									TScheduleState2& aState, 
       
   529 									CArrayFixFlat<TScheduleEntryInfo2>& aEntries, 
       
   530 									CArrayFixFlat<TTaskInfo>& aTasks, 
       
   531 									TTsTime& aDueTime)
       
   532 	{
       
   533 	TScheduleInfo info;
       
   534 	TInt res = GetScheduleInfo(aScheduleHandle, info, aDueTime);
       
   535 	if (res != KErrNone)
       
   536 		return res;
       
   537 	aState = info.iState;
       
   538 	res = GetScheduleDataL(aScheduleHandle, info, aEntries);
       
   539 	if (res != KErrNone)
       
   540 		return res;
       
   541 	res = GetTaskDataL(aScheduleHandle, info, aTasks);							
       
   542 	return res;
       
   543 	}
       
   544 
       
   545 /** 
       
   546 Gets information relating to a specified condition based schedule.
       
   547 
       
   548 @capability Note Only clients with the same SID as the schedule creator, or 
       
   549 WriteDeviceData capability can sucessfully call this API.
       
   550 
       
   551 @param aScheduleHandle The Id that identifies the schedule.
       
   552 @param aState On return, the state of the specified schedule.
       
   553 @param aConditions On return, a populated array of schedule conditons 
       
   554 that make up the schedule. Note that populating the array could cause 
       
   555 this function to leave because of an out of memory condition.
       
   556 @param aDefaultRunTime On return, the time at which the schedule with run if
       
   557 no conditions are met. If this is a local time based value, the schedule will remain
       
   558 at that local time regardless of timezone and DST changes (ie. it will float)
       
   559 If the value is UTC based, the schedule will remain at that UTC time (will not float).
       
   560 @param aTasks On return, a populated array of tasks associated with the schedule. 
       
   561 Note that populating the array could cause this function to leave because 
       
   562 of an out of memory condition.
       
   563 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   564 the specified Id, KErrArgument if the schedule is not a condition based one, 
       
   565 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   566 creator or has WriteDeviceData capability, or any of the other system wide error 
       
   567 codes.
       
   568 @see TTaskSchedulerCondition
       
   569 @see TTaskInfo 
       
   570 
       
   571 @internalAll
       
   572 */
       
   573 EXPORT_C TInt RScheduler::GetScheduleL(TInt aScheduleHandle, 
       
   574 							TScheduleState2& aState, 
       
   575 							CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   576 							TTsTime& aDefaultRunTime,
       
   577 							CArrayFixFlat<TTaskInfo>& aTasks)
       
   578 	{
       
   579 	TScheduleInfo info;
       
   580 	TTsTime dummyTime;
       
   581 	TInt res = GetScheduleInfo(aScheduleHandle, info, dummyTime);
       
   582 	if (res != KErrNone)
       
   583 		return res;
       
   584 	aState = info.iState;
       
   585 	res = GetScheduleDataL(aScheduleHandle, 
       
   586 							info, 
       
   587 							aConditions, 
       
   588 							aDefaultRunTime);
       
   589 	if (res != KErrNone)
       
   590 		return res;
       
   591 	res = GetTaskDataL(aScheduleHandle, info, aTasks);							
       
   592 	return res;
       
   593 	}
       
   594 
       
   595 /**
       
   596 Gets the schedule type.
       
   597 
       
   598 @capability Note Only clients with the same SID as the schedule creator, or 
       
   599 WriteDeviceData capability can sucessfully call this API.
       
   600 
       
   601 @param aScheduleHandle The Id that identifies the schedule
       
   602 @param aScheduleType On return the type of schedule relating to the handle.
       
   603 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   604 the specified Id, KErrPermissionDenied if the client does not have the same SID 
       
   605 as the schedules creator or has WriteDeviceData capability, or any of the other 
       
   606 system wide error codes.
       
   607 
       
   608 @internalAll
       
   609 */
       
   610 EXPORT_C TInt RScheduler::GetScheduleTypeL(TInt aScheduleHandle,
       
   611 											TScheduleType& aScheduleType)
       
   612 	{
       
   613 	TPckg<TScheduleType> id(aScheduleType);
       
   614 	return SendReceive(EGetScheduleType, TIpcArgs(aScheduleHandle, &id));
       
   615 	}
       
   616 
       
   617 /** 
       
   618 Gets a list of all tasks, or a subset of tasks.
       
   619 
       
   620 Note that if more than one client has supplied the same information when registering, 
       
   621 then it is possible for a list of tasks to be returned, which the calling 
       
   622 client has not scheduled.
       
   623 
       
   624 @capability Note A call to this API will only retrieve tasks created with
       
   625 the caller's SID.  If the caller has WriteDeviceData capability all tasks
       
   626 will be retrieved.
       
   627 
       
   628 @param aTasks On return, a populated array of schedule definitions. The schedule 
       
   629 definitions are those whose associated tasks satisfy the selection criteria. 
       
   630 Note that populating the array could cause this function to leave because 
       
   631 of an out of memory condition.
       
   632 @param aScheduleFilter The schedule filter.
       
   633 @param aTaskFilter The task filter.
       
   634 @return KErrNone if successful otherwise one of the other system wide error 
       
   635 codes.
       
   636 @see TSchedulerItemRef 
       
   637 */
       
   638 EXPORT_C TInt RScheduler::GetTaskRefsL(CArrayFixFlat<TSchedulerItemRef>& aTasks,
       
   639 										const TScheduleFilter aScheduleFilter,
       
   640 										const TTaskFilter aTaskFilter)
       
   641 	{
       
   642 	//1)get number of tasks
       
   643 	TInt count;
       
   644 	TPckg<TInt> pCount(count);
       
   645 	TInt res = SendReceive(ECountTasks, TIpcArgs(&pCount, aScheduleFilter, aTaskFilter));
       
   646 	if (res!=KErrNone)
       
   647 		return res;
       
   648 	aTasks.ResizeL(count);
       
   649 	//2)get taskrefs
       
   650 	if (count >0)
       
   651 		{
       
   652 		TPtr8 pTasks(REINTERPRET_CAST(TUint8*, &(aTasks.At(0))), count*sizeof(TSchedulerItemRef));
       
   653 		res = SendReceive(EGetTaskRefs, TIpcArgs(count, aScheduleFilter, aTaskFilter, &pTasks));
       
   654 		}
       
   655 	return res;
       
   656 	}
       
   657 
       
   658 /** 
       
   659 Gets information relating to a specified task.
       
   660 
       
   661 @capability Note Only clients with the same SID as the relevant schedule
       
   662 creator, or WriteDeviceData capability can sucessfully call this API.
       
   663 
       
   664 @param aTaskId The Id that identifies the task.
       
   665 @param aTaskInfo On return, information about the task.
       
   666 @param aTaskData On return, a pointer descriptor representing the data that 
       
   667 is passed to the program to be executed. The caller must set up this pointer 
       
   668 descriptor before calling the function. The required length of the descriptor 
       
   669 can be found by calling GetTaskDataSize().
       
   670 @param aRef On return, the associated schedule definition.
       
   671 @param aNextDue On return, the time that the task is next due. This value may
       
   672 be local time or UTC based. Comparisons used to find the next due time are based on UTC.
       
   673 @return KErrNone, if successful. KErrNotFound, if there is no task with the 
       
   674 specified Id, KErrPermissionDenied if the client does not have the same SID as 
       
   675 the schedules creator or has WriteDeviceData capability. 
       
   676 */
       
   677 EXPORT_C TInt RScheduler::GetTaskInfoL(const TInt aTaskId, TTaskInfo& aTaskInfo, TPtr& aTaskData, TSchedulerItemRef& aRef, TTsTime& aNextDue)
       
   678 	{
       
   679 	// First of all retrieve the normal stuff
       
   680 	TPtr8 pInfo((TUint8*)&aTaskInfo,sizeof(TTaskInfo));
       
   681 	TInt size = aTaskData.MaxLength();
       
   682 	TInt res = SendReceive(EGetTask, TIpcArgs(aTaskId, &pInfo, size, &aTaskData));
       
   683 	if (res != KErrNone)
       
   684 		return res;
       
   685 
       
   686 	// Next retrieve the TSchedulerItemRef and next due time
       
   687 	TPtr8 pItemRef((TUint8*)&aRef, sizeof(TSchedulerItemRef));
       
   688 	TPtr8 pDueTime((TUint8*)&aNextDue, sizeof(TTsTime));
       
   689 	return SendReceive(EGetSchedulerItemRefAndNextDueTime, TIpcArgs(aTaskId, &pItemRef, &pDueTime));
       
   690 	}
       
   691 
       
   692 /** 
       
   693 Gets the size of the data to be passed to the task's program.
       
   694 
       
   695 This function should be called before calling GetTaskInfoL() so that a descriptor 
       
   696 of the correct size can be set up.
       
   697 
       
   698 @capability Note Only clients with the same SID as the relevant schedule
       
   699 creator, or WriteDeviceData capability can sucessfully call this API.
       
   700 
       
   701 @param aTaskId The Id that identifies the task.
       
   702 @param aSize The size of the task's data.
       
   703 @return KErrNone if successful, KErrNotFound if there is no task with the 
       
   704 specified Id, KErrPermissionDenied if the client does not have the same SID as 
       
   705 the schedules creator or has WriteDeviceData capability, otherwise any of the 
       
   706 other system wide error codes.
       
   707 */
       
   708 EXPORT_C TInt RScheduler::GetTaskDataSize(const TInt aTaskId, TInt& aSize)
       
   709 	{
       
   710 	TPckg<TInt> pSize(aSize);
       
   711 	return SendReceive(EGetTaskDataSize, TIpcArgs(aTaskId, &pSize));
       
   712 	}
       
   713 
       
   714 //Converts array of TScheduleEntryInfos to an array of TScheduleEntryInfo2s.
       
   715 void ConvertArrayToEntryInfo2L(const CArrayFixFlat<TScheduleEntryInfo>& aEntryList,
       
   716 							CArrayFixFlat<TScheduleEntryInfo2>& aEntry2List)
       
   717 	{
       
   718 	aEntry2List.ResizeL(aEntryList.Count());
       
   719 	
       
   720 	TScheduleEntryInfo entryInfo;
       
   721 	for (TInt i=0; i < aEntryList.Count(); i++)
       
   722 		{
       
   723 		entryInfo = aEntryList.At(i);
       
   724 		//create new TScheduleEntryInfo2 object from old TScheduleEntryInfo object
       
   725 		//assume local time for backwards compatibility
       
   726 		TScheduleEntryInfo2 entryInfo2(entryInfo);	
       
   727 		aEntry2List.At(i) = entryInfo2;
       
   728 		}	
       
   729 	}
       
   730 
       
   731 //Converts array of TScheduleEntryInfo2s to an array of TScheduleEntryInfos.
       
   732 void ConvertArrayFromEntryInfo2L(const CArrayFixFlat<TScheduleEntryInfo2>& aEntry2List,
       
   733 							CArrayFixFlat<TScheduleEntryInfo>& aEntryList)
       
   734 	{
       
   735 	TScheduleEntryInfo entryInfo;
       
   736 	TScheduleEntryInfo2 entryInfo2;
       
   737 	
       
   738 	aEntryList.ResizeL(aEntry2List.Count());
       
   739 	for(TInt i=0; i<aEntry2List.Count(); i++)
       
   740 		{
       
   741 		entryInfo2 = aEntry2List.At(i);
       
   742 		
       
   743 		//use local time for backwards compatibility
       
   744 		entryInfo.iStartTime = entryInfo2.StartTime().GetLocalTime(); 
       
   745 		entryInfo.iIntervalType = entryInfo2.IntervalType();
       
   746 		entryInfo.iInterval = entryInfo2.Interval();
       
   747 		entryInfo.iValidityPeriod = entryInfo2.ValidityPeriod();
       
   748 		
       
   749 		aEntryList.At(i) = entryInfo;
       
   750 		}
       
   751 	}
       
   752 
       
   753 /** 
       
   754 Creates a persistent time based schedule.
       
   755 
       
   756 This schedule has no tasks associated with it but merely contains information
       
   757 about start and finish times.
       
   758 
       
   759 @capability WriteDeviceData
       
   760 @param aRef Definition of the new schedule.  On return this contains a valid
       
   761 handle to the newly created schedule.
       
   762 @param aEntryList The set of schedule entries that make up the new schedule.
       
   763 Start times of all entries are assumed to be local time based.
       
   764 @return KErrNone, if successful, KErrArgument if the condition array is 
       
   765 empty, or an entry has an interval less than 1, KErrServerBusy, if a backup or 
       
   766 restore operation is taking place, KErrPermissionDenied if the 
       
   767 client does not have WriteDeviceData capability. 
       
   768 Otherwise one of the other system wide error codes.
       
   769 @see TScheduleEntryInfo 
       
   770 @deprecated See note in CSch_Cli.h
       
   771 */
       
   772 EXPORT_C TInt RScheduler::CreatePersistentSchedule(TSchedulerItemRef& aRef, 
       
   773 							const CArrayFixFlat<TScheduleEntryInfo>& aEntryList)
       
   774 	{
       
   775 	//create schedule settings object
       
   776 	TScheduleSettings2 settings;
       
   777 	settings.iPersists = ETrue;
       
   778 	settings.iName = aRef.iName;
       
   779 	settings.iEntryCount = aEntryList.Count();
       
   780 	
       
   781 	//create array of TScheduleEntryInfo2's from array of TScheduleEntryInfo's.
       
   782 	//assume local time for backwards compatibility.
       
   783 	CArrayFixFlat<TScheduleEntryInfo2>* entryInfo2List = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
       
   784 	CleanupStack::PushL(entryInfo2List);
       
   785 	ConvertArrayToEntryInfo2L(aEntryList, *entryInfo2List);
       
   786 
       
   787 	//create schedule using new array of TScheduleEntryInfo2s.
       
   788 	TInt err = CreateSchedule(aRef, *entryInfo2List, settings);
       
   789 	
       
   790 	CleanupStack::PopAndDestroy(entryInfo2List);
       
   791 	return err;
       
   792 	}
       
   793 	
       
   794 
       
   795 	
       
   796 /** 
       
   797 Creates a persistent condition based schedule.
       
   798 
       
   799 This schedule has no tasks associated with it but merely contains information
       
   800 about conditions that must be satified to complete this schedule.
       
   801 
       
   802 @capability WriteDeviceData
       
   803 @param aRef Definition of the new schedule.  On return this contains a valid
       
   804 handle to the newly created schedule.
       
   805 @param aConditions An array of system agent conditons 
       
   806 that make up the schedule.
       
   807 @param aDefaultRunTime The time at which the schedule with run if no
       
   808 conditions are met. Default run times of all schedules created 
       
   809 using this API are assumed to be local time based.
       
   810 @return KErrNone, if successful, KErrArgument if the condition array is 
       
   811 empty or if the publish and subscribe variables have an invalid category.
       
   812 KErrServerBusy, if a backup or restore operation is taking place.
       
   813 KErrPermissionDenied if the client does not have WriteDeviceData capability. 
       
   814 Otherwise one of the other system wide error codes.
       
   815 @see TTaskSchedulerCondition 
       
   816 @internalAll
       
   817 @deprecated See note in CSch_Cli.h 
       
   818 */
       
   819 EXPORT_C TInt RScheduler::CreatePersistentSchedule(TSchedulerItemRef& aRef, 
       
   820 							const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   821 							const TTime& aDefaultRunTime)
       
   822 	{
       
   823 	//create schedule settings object
       
   824 	TScheduleSettings2 settings;
       
   825 	settings.iPersists = ETrue;
       
   826 	settings.iEntryCount = aConditions.Count();
       
   827 	settings.iName = aRef.iName;
       
   828 	
       
   829 	// create TTsTime object from TTime argument aDefaultRunTime.
       
   830 	// assume aDefaultTime is local time based for backwards compatibility
       
   831 	TTsTime defaultRunTime(aDefaultRunTime, EFalse);	
       
   832 	
       
   833 	return CreateSchedule(aRef, aConditions, defaultRunTime, settings);	
       
   834 	}
       
   835 
       
   836 
       
   837 /** 
       
   838 Changes a time based schedule.
       
   839 
       
   840 Note that changing a schedule is implemented by supplying a replacement set 
       
   841 of schedule entries.
       
   842 
       
   843 @capability Note Only clients with the same SID as the schedule creator, or 
       
   844 WriteDeviceData capability can sucessfully call this API.
       
   845 
       
   846 @param aScheduleHandle The Id that identifies the schedule.
       
   847 @param aEntryList The set of schedule entries that will make up the new schedule.
       
   848 Start times of all entries are assumed to be local time based.
       
   849 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   850 the specified Id, KErrArgument if the schedule is not a time based one, 
       
   851 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   852 creator or has WriteDeviceData capability, KErrServerBusy, if a backup or 
       
   853 restore operation is taking place or any of the other system wide error 
       
   854 codes.
       
   855 @see TScheduleEntryInfo 
       
   856 @deprecated See note in CSch_Cli.h
       
   857 */
       
   858 EXPORT_C TInt RScheduler::EditSchedule(const TInt aScheduleHandle, const CArrayFixFlat<TScheduleEntryInfo>& aEntryList)
       
   859 	{
       
   860 	TInt count = aEntryList.Count();
       
   861 	
       
   862 	CArrayFixFlat<TScheduleEntryInfo2>* entryInfo2List = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
       
   863 	CleanupStack::PushL(entryInfo2List);
       
   864 	
       
   865 	//creates array of TScheduleEntryInfo2's from array of TScheduleEntryInfo's.
       
   866 	//assumes local time for backwards compatibility.
       
   867 	ConvertArrayToEntryInfo2L(aEntryList, *entryInfo2List);
       
   868 	
       
   869 	if (ScheduleEntriesAreBad(*entryInfo2List))
       
   870 		return KErrArgument;
       
   871 		
       
   872 	TPtrC8 pA((TUint8*) &entryInfo2List->At(0), sizeof(TScheduleEntryInfo2)*count);
       
   873 	TInt err = SendReceive(EEditTimeSchedule, TIpcArgs(count, aScheduleHandle, &pA));
       
   874 	CleanupStack::PopAndDestroy(entryInfo2List);
       
   875 	return err;
       
   876 	}
       
   877 
       
   878 /**  
       
   879 Changes a condition based schedule.
       
   880 
       
   881 Note that changing a schedule is implemented by supplying a replacement set 
       
   882 of schedule conditons and time.
       
   883 
       
   884 @capability Note Only clients with the same SID as the schedule creator, or 
       
   885 WriteDeviceData capability can sucessfully call this API.
       
   886 
       
   887 @param aScheduleHandle The Id that identifies the schedule.
       
   888 @param aConditions An array of system agent conditons 
       
   889 that make up the schedule.
       
   890 @param aDefaultRunTime The time at which the schedule with run if no
       
   891 conditions are met. Note that this parameter is assumed to be local time based.
       
   892 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
   893 the specified Id, KErrArgument if the schedule is not a condition based one
       
   894 or if the publish and subscribe variables, defined by aConditions category 
       
   895 and key values, do not exist or are not of integral type, 
       
   896 KErrPermissionDenied if the client does not have the same SID as the schedules
       
   897 creator or has WriteDeviceData capability, KErrServerBusy, if a backup or 
       
   898 restore operation is taking place or any of the other system wide error 
       
   899 codes.
       
   900 
       
   901 @internalAll
       
   902 @deprecated See note in CSch_Cli.h
       
   903 */	
       
   904 EXPORT_C TInt RScheduler::EditSchedule(TInt aScheduleHandle, 
       
   905 						const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   906 						const TTime& aDefaultRunTime)
       
   907 	{
       
   908 	TInt count = aConditions.Count();
       
   909 	TPtrC8 pA((TUint8*) &aConditions.At(0), sizeof(TTaskSchedulerCondition)*count);
       
   910 	
       
   911 	// create TTsTime object from aDefaultRunTime. 
       
   912 	// aDefaultRunTime is assumed to be local time based for backwards compatibility
       
   913 	TTsTime defaultRunTime(aDefaultRunTime, EFalse);	
       
   914 	//write Time
       
   915 	TPckgC<TTsTime> pTime(defaultRunTime);
       
   916 	return SendReceive(EEditConditionSchedule, TIpcArgs(count, aScheduleHandle, &pA, &pTime));	
       
   917 	}
       
   918 
       
   919 
       
   920 /** 
       
   921 Creates a new, transient, time based schedule and adds a task to it.
       
   922 
       
   923 Note that a transient schedule is destroyed when the task is destroyed or 
       
   924 power is lost.
       
   925 
       
   926 @param aTaskInfo Information about the task to be added to the transient schedule. 
       
   927 On return the task Id is written into this class.
       
   928 @param aTaskData Data that is passed to the task on execution.
       
   929 @param aRef Definition of the new transient schedule.
       
   930 @param aEntryList The set of schedule entries that make up the new transient 
       
   931 schedule. All entry start times are assumed to be local time based.
       
   932 @return KErrNone, if successful, otherwise one of the other system wide error 
       
   933 codes.
       
   934 @panic CTaskScheduler 0 The client has not registered. The client must register 
       
   935 before adding tasks to the schedule.
       
   936 @see TScheduleEntryInfo 
       
   937 @deprecated See note in CSch_Cli.h
       
   938 */
       
   939 EXPORT_C TInt RScheduler::ScheduleTask(TTaskInfo& aTaskInfo, 
       
   940 									HBufC& aTaskData, 
       
   941 									TSchedulerItemRef& aRef,
       
   942 									const CArrayFixFlat<TScheduleEntryInfo>& aEntryList)
       
   943 	{
       
   944 	TScheduleSettings2 settings;
       
   945 	settings.iPersists = EFalse;
       
   946 	settings.iEntryCount = aEntryList.Count();
       
   947 	settings.iName = aRef.iName;
       
   948 	
       
   949 	CArrayFixFlat<TScheduleEntryInfo2>* entryInfo2List = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
       
   950 	CleanupStack::PushL(entryInfo2List);
       
   951 
       
   952 	//creates array of TScheduleEntryInfo2's from array of TScheduleEntryInfo's.
       
   953 	//assumes local time for backwards compatibility.
       
   954 	ConvertArrayToEntryInfo2L(aEntryList, *entryInfo2List);
       
   955 
       
   956 	TInt res = CreateSchedule(aRef, *entryInfo2List, settings);
       
   957 	CleanupStack::PopAndDestroy(entryInfo2List);
       
   958 	
       
   959 	if (res==KErrNone)
       
   960 		{
       
   961 		res = ScheduleTask(aTaskInfo, aTaskData, aRef.iHandle);
       
   962 		//the schedule here needs a task: so if we can't schedule a task,
       
   963 		//need to delete schedule
       
   964 		if (res!=KErrNone)
       
   965 			DeleteSchedule(aRef.iHandle);
       
   966 		}
       
   967 	return res;
       
   968 	}
       
   969 
       
   970 
       
   971 /** 
       
   972 Creates a new, transient, condition based schedule and adds a task to it.
       
   973 
       
   974 Note that a transient schedule is destroyed when the task is destroyed or
       
   975 power is lost.
       
   976 
       
   977 @param aTaskInfo Information about the task to be added to the transient schedule. 
       
   978 On return the task Id is written into this class.
       
   979 @param aTaskData Data that is passed to the task on execution.
       
   980 @param aRef Definition of the new transient schedule.
       
   981 @param aConditions An array of schedule conditons that make up the schedule.
       
   982 @param aDefaultRunTime The time at which the schedule with run if no
       
   983 conditions are met. aDefaultRunTime is assumed to be local time based.
       
   984 @return KErrNone, if successful, KErrArgument if the publish and subscribe 
       
   985 variables, defined by aConditions category and key values, do not exist or 
       
   986 are not of integral type, otherwise one of the other system wide error codes.
       
   987 @panic CTaskScheduler 0 The client has not registered. The client must register 
       
   988 before adding tasks to the schedule.
       
   989 
       
   990 @internalAll
       
   991 @deprecated See note in CSch_Cli.h
       
   992 */
       
   993 EXPORT_C TInt RScheduler::ScheduleTask(TTaskInfo& aTaskInfo, 
       
   994 								HBufC& aTaskData, 
       
   995 								TSchedulerItemRef& aRef, 
       
   996 								const CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
   997 								const TTime& aDefaultRunTime)
       
   998 	{
       
   999 	// create schedule settings object
       
  1000 	TScheduleSettings2 settings;
       
  1001 	settings.iPersists = EFalse;
       
  1002 	settings.iEntryCount = aConditions.Count();
       
  1003 	settings.iName = aRef.iName;
       
  1004 	
       
  1005 	// create TTsTime object from aDefaultRunTime.
       
  1006 	// assumes aDefaultRunTime is local time based for backwards compatibility
       
  1007 	TTsTime defaultRunTime(aDefaultRunTime, EFalse);
       
  1008 	
       
  1009 	TInt res = CreateSchedule(aRef, aConditions, defaultRunTime, settings);
       
  1010 	if (res==KErrNone)
       
  1011 		{
       
  1012 		res = ScheduleTask(aTaskInfo, aTaskData, aRef.iHandle);
       
  1013 		//the schedule here needs a task: so if we can't schedule a task,
       
  1014 		//need to delete schedule
       
  1015 		if (res!=KErrNone)
       
  1016 			DeleteSchedule(aRef.iHandle);
       
  1017 		}
       
  1018 	return res;
       
  1019 	}
       
  1020 
       
  1021 
       
  1022 /** 
       
  1023 Gets information relating to a specified time based schedule.
       
  1024 
       
  1025 @capability Note Only clients with the same SID as the schedule creator, or 
       
  1026 WriteDeviceData capability can sucessfully call this API.
       
  1027 
       
  1028 @param aScheduleHandle The Id that identifies the schedule.
       
  1029 @param aState On return, the state of the specified schedule.
       
  1030 On return, aState will have a local time based iDueTime member, regardless 
       
  1031 of whether the schedule is UTC or local time based. If the schedule is UTC 
       
  1032 based, the due time will be converted to a local time based value before returning.
       
  1033 @param aEntries On return, a populated array of schedule entries that make 
       
  1034 up the schedule. All entry start times returned will be local time based, 
       
  1035 though they may be UTC or local time based within the scheduler. The scheduler will
       
  1036 convert any UTC based times to local time before returning.
       
  1037 Note that populating the array could cause this function 
       
  1038 to leave because of an out of memory condition.
       
  1039 @param aTasks On return, a populated array of tasks associated with the schedule. 
       
  1040 Note that populating the array could cause this function to leave because 
       
  1041 of an out of memory condition.
       
  1042 @param aDueTime On return, the time that the schedule is next due. This value
       
  1043 will be local time based, regardless of whether the schedule is UTC or local 
       
  1044 time based. If the schedule is UTC based, the due time will be converted to 
       
  1045 a local time based value before returning.
       
  1046 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
  1047 the specified Id, KErrArgument if the schedule is not a time based one, 
       
  1048 KErrPermissionDenied if the client does not have the same SID as the schedules
       
  1049 creator or has WriteDeviceData capability, or any of the other system wide error 
       
  1050 codes.
       
  1051 @see TScheduleEntryInfo
       
  1052 @see TTaskInfo 
       
  1053 @deprecated See note in CSch_Cli.h
       
  1054 */
       
  1055 EXPORT_C TInt RScheduler::GetScheduleL(const TInt aScheduleHandle, 
       
  1056 									TScheduleState& aState, 
       
  1057 									CArrayFixFlat<TScheduleEntryInfo>& aEntries, 
       
  1058 									CArrayFixFlat<TTaskInfo>& aTasks, 
       
  1059 									TTime& aDueTime)
       
  1060 	{
       
  1061 	// set up vars required->scheduleState, entries, and time
       
  1062 	TTsTime dueTime;
       
  1063 	TScheduleState2 state;
       
  1064 	CArrayFixFlat<TScheduleEntryInfo2>* entryInfo2List = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
       
  1065 	CleanupStack::PushL(entryInfo2List);
       
  1066 	
       
  1067 	// call new API	
       
  1068 	TInt res = GetScheduleL(aScheduleHandle,
       
  1069 							state,
       
  1070 							*entryInfo2List,
       
  1071 							aTasks, 
       
  1072 							dueTime);
       
  1073 							
       
  1074 	// convert vars back to old versions
       
  1075 	// use local time for backwards compatibility
       
  1076 	aDueTime = dueTime.GetLocalTime();	
       
  1077 	aState = TScheduleState(state);
       
  1078 	ConvertArrayFromEntryInfo2L(*entryInfo2List, aEntries);
       
  1079 			
       
  1080 	CleanupStack::PopAndDestroy(entryInfo2List);
       
  1081 	return res;
       
  1082 	
       
  1083 	}
       
  1084 
       
  1085 /** 
       
  1086 Gets information relating to a specified condition based schedule.
       
  1087 
       
  1088 @capability Note Only clients with the same SID as the schedule creator, or 
       
  1089 WriteDeviceData capability can sucessfully call this API.
       
  1090 
       
  1091 @param aScheduleHandle The Id that identifies the schedule.
       
  1092 @param aState On return, the state of the specified schedule.
       
  1093 On return, aState will have a local time based iDueTime member, regardless 
       
  1094 of whether the schedule is UTC or local time based. If the schedule is UTC 
       
  1095 based, the due time will be converted to a local time based value before returning.
       
  1096 @param aConditions On return, a populated array of schedule conditons 
       
  1097 that make up the schedule. Note that populating the array could cause 
       
  1098 this function to leave because of an out of memory condition.
       
  1099 @param aDefaultRunTime On return, the time at which the schedule with run if
       
  1100 no conditions are met. This value will be local time based, regardless of 
       
  1101 whether the schedule is UTC or local time based. If the schedule is UTC based, 
       
  1102 the due time will be converted to a local time based value before returning.
       
  1103 @param aTasks On return, a populated array of tasks associated with the schedule. 
       
  1104 Note that populating the array could cause this function to leave because 
       
  1105 of an out of memory condition.
       
  1106 @return KErrNone if successful, KErrNotFound if there is no schedule with 
       
  1107 the specified Id, KErrArgument if the schedule is not a condition based one, 
       
  1108 KErrPermissionDenied if the client does not have the same SID as the schedules
       
  1109 creator or has WriteDeviceData capability, or any of the other system wide error 
       
  1110 codes.
       
  1111 @see TTaskSchedulerCondition
       
  1112 @see TTaskInfo 
       
  1113 
       
  1114 @internalAll
       
  1115 @deprecated See note in CSch_Cli.h
       
  1116 */
       
  1117 EXPORT_C TInt RScheduler::GetScheduleL(TInt aScheduleHandle, 
       
  1118 							TScheduleState& aState, 
       
  1119 							CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
  1120 							TTime& aDefaultRunTime,
       
  1121 							CArrayFixFlat<TTaskInfo>& aTasks)
       
  1122 	{
       
  1123 	TScheduleInfo info;
       
  1124 	TTsTime dummyTime;
       
  1125 	TInt res = GetScheduleInfo(aScheduleHandle, info, dummyTime);
       
  1126 	if (res != KErrNone)
       
  1127 		return res;
       
  1128 	aState = TScheduleState(info.iState);
       
  1129 	TTsTime defaultRunTime;
       
  1130 	res = GetScheduleDataL(aScheduleHandle, 
       
  1131 							info, 
       
  1132 							aConditions, 
       
  1133 							defaultRunTime);
       
  1134 							
       
  1135 	//uses local time for backwards compatibility							
       
  1136 	aDefaultRunTime = defaultRunTime.GetLocalTime();
       
  1137 	
       
  1138 	if (res != KErrNone)
       
  1139 		return res;
       
  1140 	res = GetTaskDataL(aScheduleHandle, info, aTasks);							
       
  1141 	return res;
       
  1142 	}
       
  1143  
       
  1144 	
       
  1145 /** 
       
  1146 Gets information relating to a specified task.
       
  1147 
       
  1148 @capability Note Only clients with the same SID as the relevant schedule
       
  1149 creator, or WriteDeviceData capability can sucessfully call this API.
       
  1150 
       
  1151 @param aTaskId The Id that identifies the task.
       
  1152 @param aTaskInfo On return, information about the task.
       
  1153 @param aTaskData On return, a pointer descriptor representing the data that 
       
  1154 is passed to the program to be executed. The caller must set up this pointer 
       
  1155 descriptor before calling the function. The required length of the descriptor 
       
  1156 can be found by calling GetTaskDataSize().
       
  1157 @param aRef On return, the associated schedule definition.
       
  1158 @param aNextDue On return, the time that the task is next due. This value
       
  1159 will be local time based, regardless of whether the schedule is UTC or local 
       
  1160 time based. If the schedule is UTC based, the due time will be converted to 
       
  1161 a local time based value before returning.
       
  1162 @return KErrNone, if successful. KErrNotFound, if there is no task with the 
       
  1163 specified Id, KErrPermissionDenied if the client does not have the same SID as 
       
  1164 the schedules creator or has WriteDeviceData capability. 
       
  1165 @deprecated See note in CSch_Cli.h
       
  1166 */
       
  1167 EXPORT_C TInt RScheduler::GetTaskInfoL(const TInt aTaskId, TTaskInfo& aTaskInfo, TPtr& aTaskData, TSchedulerItemRef& aRef, TTime& aNextDue)
       
  1168 	{
       
  1169 	// First of all retrieve the normal stuff
       
  1170 	TPtr8 pInfo((TUint8*)&aTaskInfo,sizeof(TTaskInfo));
       
  1171 	TInt size = aTaskData.MaxLength();
       
  1172 	TInt res = SendReceive(EGetTask, TIpcArgs(aTaskId, &pInfo, size, &aTaskData));
       
  1173 	if (res != KErrNone)
       
  1174 		return res;
       
  1175 
       
  1176 	// Next retrieve the TSchedulerItemRef and next due time
       
  1177 	TTsTime nextDueTime;
       
  1178 	TPtr8 pItemRef((TUint8*)&aRef, sizeof(TSchedulerItemRef));
       
  1179 	TPtr8 pDueTime((TUint8*)&nextDueTime, sizeof(TTsTime));
       
  1180 	res = SendReceive(EGetSchedulerItemRefAndNextDueTime, TIpcArgs(aTaskId, &pItemRef, &pDueTime));
       
  1181 	
       
  1182 	// use local time for backwards compatibility
       
  1183 	aNextDue = nextDueTime.GetLocalTime();
       
  1184 	return res;
       
  1185 	}
       
  1186 
       
  1187 
       
  1188 //private
       
  1189 // TScheduleInfo.iEntryCount is number of schedule entries for time schedules
       
  1190 // and number of conditions for condition based schedules.
       
  1191 TInt RScheduler::GetScheduleInfo(const TInt aScheduleHandle, TScheduleInfo& aInfo, TTsTime& aNextDue)
       
  1192 	{	
       
  1193 	TPtr8 pInfo((TUint8*)&aInfo,sizeof(TScheduleInfo));//scheduler writes back info
       
  1194 	TPtr8 pDueTime((TUint8*)&aNextDue,sizeof(TTsTime));//scheduler writes back dueTime
       
  1195 	// get info for number of entries & tasks
       
  1196 	TInt res = SendReceive(EGetScheduleInfo, TIpcArgs(aScheduleHandle, &pInfo, &pDueTime));
       
  1197 	return res;
       
  1198 	}
       
  1199 	
       
  1200 TInt RScheduler::GetTaskDataL(const TInt aScheduleHandle, 
       
  1201 								const TScheduleInfo& aInfo,
       
  1202 								CArrayFixFlat<TTaskInfo>& aTasks)
       
  1203 	{
       
  1204 	// resize array
       
  1205 	aTasks.ResizeL(aInfo.iTaskCount);
       
  1206 
       
  1207 	// get entries & taskrefs & flags
       
  1208 	TPBScheduleInfo pckgInfo(aInfo);
       
  1209 	TInt res = KErrNone;
       
  1210 	if (aInfo.iTaskCount > 0)
       
  1211 		{
       
  1212 		TPtr8 pTasks((TUint8*)&(aTasks.At(0)), aInfo.iTaskCount*sizeof(TTaskInfo));
       
  1213 		res = SendReceive(EGetTaskData, TIpcArgs(aScheduleHandle, &pckgInfo, &pTasks));
       
  1214 		}
       
  1215 	return res;
       
  1216 	}
       
  1217 
       
  1218 TInt RScheduler::GetScheduleDataL(const TInt aScheduleHandle, 
       
  1219 								const TScheduleInfo& aInfo,
       
  1220 								CArrayFixFlat<TScheduleEntryInfo2>& aEntries)
       
  1221 	{
       
  1222 	// resize array	
       
  1223 	aEntries.ResizeL(aInfo.iEntryCount);
       
  1224 
       
  1225 	// get entries
       
  1226 	TPBScheduleInfo pckgInfo(aInfo);
       
  1227 	TPtr8 pEntries((TUint8*)&(aEntries.At(0)), aInfo.iEntryCount*sizeof(TScheduleEntryInfo2));
       
  1228 	return SendReceive(EGetTimeScheduleData, TIpcArgs(aScheduleHandle, &pckgInfo, &pEntries));
       
  1229 	}
       
  1230 	
       
  1231 TInt RScheduler::GetScheduleDataL(const TInt aScheduleHandle, 
       
  1232 								const TScheduleInfo& aInfo,
       
  1233 								CArrayFixFlat<TTaskSchedulerCondition>& aConditions,
       
  1234 								TTsTime& aDefaultRunTime)
       
  1235 	{
       
  1236 	// resize arrays	
       
  1237 	aConditions.ResizeL(aInfo.iEntryCount);
       
  1238 
       
  1239 	// get entries
       
  1240 	TPtr8 pDefaultTime((TUint8*)&aDefaultRunTime,sizeof(TTsTime));//scheduler writes back defaultTime
       
  1241 	TPBScheduleInfo pckgInfo(aInfo);
       
  1242 	TPtr8 pEntries((TUint8*)&(aConditions.At(0)), aInfo.iEntryCount*sizeof(TTaskSchedulerCondition));
       
  1243 	return SendReceive(EGetConditionScheduleData, TIpcArgs(aScheduleHandle, &pckgInfo, &pEntries, &pDefaultTime));
       
  1244 	}	
       
  1245 	
       
  1246 
       
  1247 #if defined (_DEBUG)
       
  1248 /** 
       
  1249 Marks the start of checking the current thread's heap.
       
  1250 
       
  1251 This is used for debugging, and is only implemented in debug builds.
       
  1252 
       
  1253 @return In debug builds, KErrNone, if successful, otherwise one of the other 
       
  1254 system wide error codes. In release builds, KErrNone always.
       
  1255 @see __UHEAP_MARK 
       
  1256 @internalComponent
       
  1257 */
       
  1258 EXPORT_C TInt RScheduler::__DbgMarkHeap()
       
  1259 	{
       
  1260 	return SendReceive(ESchDbgMarkHeap);
       
  1261 	}
       
  1262 
       
  1263 /** 
       
  1264 Checks that the number of allocated cells on the current thread's heap is the 
       
  1265 same as the specified value.
       
  1266 
       
  1267 This is used for debugging, and is only implemented in debug builds.
       
  1268 
       
  1269 @param aCount In debug builds, the number of heap cells expected to be allocated. 
       
  1270 In release builds, this parameter is not used.
       
  1271 @return In debug builds, KErrNone, if successful, otherwise one of the other 
       
  1272 system wide error codes. In release builds, KErrNone always.
       
  1273 @see __UHEAP_CHECK 
       
  1274 @internalComponent
       
  1275 */
       
  1276 EXPORT_C TInt RScheduler::__DbgCheckHeap(TInt aCount)
       
  1277 	{
       
  1278 	return SendReceive(ESchDbgCheckHeap,TIpcArgs(aCount));
       
  1279 	}
       
  1280 
       
  1281 /** 
       
  1282 Marks the end of checking the current thread's heap.
       
  1283 
       
  1284 This is used for debugging, and is only implemented in debug builds.
       
  1285 
       
  1286 @param aCount In debug builds, the number of heap cells expected to remain 
       
  1287 allocated. In release builds, this parameter is not used.
       
  1288 @return In debug builds, KErrNone, if successful, otherwise one of the other 
       
  1289 system wide error codes. In release builds, KErrNone always.
       
  1290 @see __UHEAP_MARKENDC 
       
  1291 @internalComponent
       
  1292 */
       
  1293 EXPORT_C TInt RScheduler::__DbgMarkEnd(TInt aCount)
       
  1294 	{
       
  1295 	return SendReceive(ESchDbgMarkEnd,TIpcArgs(aCount));
       
  1296 	}
       
  1297 
       
  1298 /** 
       
  1299 Simulates heap allocation failure.
       
  1300 
       
  1301 This is used for debugging, and is only implemented in debug builds.
       
  1302 
       
  1303 @param aCount In debug builds, the rate of failure - heap allocation fails 
       
  1304 every aCount attempts. In release builds, this parameter is not used.
       
  1305 @return In debug builds, KErrNone, if successful, otherwise one of the other 
       
  1306 system wide error codes. In release builds, KErrNone always.
       
  1307 @see __UHEAP_FAILNEXT 
       
  1308 @internalComponent
       
  1309 */
       
  1310 EXPORT_C TInt RScheduler::__DbgFailNext(TInt aCount)
       
  1311 	{
       
  1312 	return SendReceive(ESchDbgFailNext,TIpcArgs(aCount));
       
  1313 	}
       
  1314 
       
  1315 /** 
       
  1316 Cancels simulated heap allocation failure for the current thread's heap.
       
  1317 
       
  1318 This is used for debugging, and is only implemented in debug builds.
       
  1319 
       
  1320 @return In debug builds, KErrNone, if successful, otherwise one of the other 
       
  1321 system wide error codes. In release builds, KErrNone always.
       
  1322 @see __UHEAP_RESET 
       
  1323 @internalComponent
       
  1324 */
       
  1325 EXPORT_C TInt RScheduler::__DbgResetHeap()
       
  1326 	{
       
  1327 	return SendReceive(ESchDbgResetHeap);
       
  1328 	}
       
  1329 
       
  1330 
       
  1331 /** 
       
  1332 It tries to kill the server (schsvr).
       
  1333 
       
  1334 This is used for debugging, and is only implemented in debug builds.
       
  1335 
       
  1336 @return In debug builds, KErrNone, if successful, otherwise one of the other 
       
  1337 system wide error codes. In release builds, KErrNone always. 
       
  1338 @internalComponent
       
  1339 */
       
  1340 EXPORT_C TInt RScheduler::__FaultServer()
       
  1341 	{
       
  1342 	return SendReceive(ESchFaultServer);
       
  1343 	}
       
  1344 
       
  1345 #else
       
  1346 //release build exports empty versions of these for rel/deb compatibility
       
  1347 EXPORT_C TInt RScheduler::__DbgMarkHeap()
       
  1348 	{
       
  1349 	return KErrNone;
       
  1350 	}
       
  1351 
       
  1352 EXPORT_C TInt RScheduler::__DbgCheckHeap(TInt /*aCount*/)
       
  1353 	{
       
  1354 	return KErrNone;
       
  1355 	}
       
  1356 
       
  1357 EXPORT_C TInt RScheduler::__DbgMarkEnd(TInt /*aCount*/)
       
  1358 	{
       
  1359 	return KErrNone;
       
  1360 	}
       
  1361 
       
  1362 EXPORT_C TInt RScheduler::__DbgFailNext(TInt /*aCount*/)
       
  1363 	{
       
  1364 	return KErrNone;
       
  1365 	}
       
  1366 
       
  1367 EXPORT_C TInt RScheduler::__DbgResetHeap()
       
  1368 	{
       
  1369 	return KErrNone;
       
  1370 	}
       
  1371 
       
  1372 EXPORT_C TInt RScheduler::__FaultServer()
       
  1373 	{
       
  1374 	return KErrNone;
       
  1375 	}
       
  1376 
       
  1377 #endif // _DEBUG
       
  1378 
       
  1379 
       
  1380 
       
  1381 
       
  1382