symbian 调度 RScheduler

Scheduler and its Usage


RScheduler

Purpose


RScheduler is a client-side interface to the Task Scheduler.

UseCase


This class can be used for scheduling a task(s), which should be running at regular interval of time for example some Server Application.

We will be specifying the time for the task to be started and also the periodical check say Hourly,Daily,Monthly or yearly from the start time.If that task doesnt exist at that time mentioned, then Scheduler will start this task.

Example Codes

Header Files

1.#include <csch_cli.h> // RScheduler

2.#include <schinfo.h> // TScheduleEntryInfo, TSchedulerItemRef,TTaskInfo

Libraries

schsvr.lib

Capabilities

None


The following are the steps followed to schedule a task:

1.Connect to the Task Scheduler.
2.Register to the Task Scheduler.
3.Create a time based Schedule i.e., information about the Start and End Time.
4.Schedule the Task i.e., Add this to the Schedule.
5.Disconnect to the Task Scheduler.


Connecting to the Task Scheduler

1.The following code snippet is used to Connect to the Task Scheduler:


RScheduler scheduler;
User::LeaveIfError(scheduler.Connect());



Register to the Task Scheduler

2.The following code snippet is used to Register to the Task Scheduler:


TFileName fileName;
fileName = _L("ExeName_to_be_Scheduled.exe");
User::LeaveIfError(scheduler.Register( fileName, CActive::EPriorityStandard ));



Create a time based Schedule i.e., information about the Start and End Time

3.The following code snippet is used to Create a time based Schedule:

First we set the Time when the Scheduler should start:

3.a.The following code snippet is used to retrieve the current time:


TTime lTime;
lTime.HomeTime();

TTsTime startTime;
startTime.SetLocalTime( lTime );


3.b.The following code snippet is used to set Start Time for the Scheduler:


TScheduleEntryInfo2 lScheduleInfo2(startTime, EHourly, 1, KMaxTInt);

This will be scheduling the task every one hour with maximum validity period.


3.c.The following code snippet is used to Add the created ScheduledInfo into Scheduled entries:


CArrayFixFlat<TScheduleEntryInfo2>* array;
array = new (ELeave) CArrayFixFlat<TScheduleEntryInfo2>(1);
array->AppendL( lScheduleInfo2 );


TSchedulerItemRef class is used to uniquely identify the schedule.

TSchedulerItemRef itemRef;
User::LeaveIfError(scheduler.CreatePersistentSchedule( itemRef, *array ));


On execution of the above code, itemRef contains the Id(iHandle) for this Schedule using which we can refer this schedule in the future.


Schedule the Task i.e., Add this to the Schedule

4.The following code snippet is used to Schedule the Task:

TTaskInfo contains the information regarding the Task like its Id,Name,Priority,Repeater.

We pass the Schedule Id to the ScheduleTask().


TName taskName = _L("Test");
TTaskInfo taskInfo;
taskInfo.iTaskId = 0;
taskInfo.iName = taskName;
taskInfo.iPriority = CActive::EPriorityStandard;
taskInfo.iRepeat = -1;

HBufC* passData;
passData = KNullDesC().AllocL();

User::LeaveIfError(scheduler.ScheduleTask( taskInfo, *passData, itemRef.iHandle));



Disconnect to the Task Scheduler

5.The following code snippet is used to Disconnect from the Task Scheduler:


scheduler.Close();



The following code snippet is used to query the information regarding a particular schedule:


TScheduleState2 lSchState;
CArrayFixFlat< TScheduleEntryInfo2 >* entryArray = new (ELeave)
CArrayFixFlat<TScheduleEntryInfo2>(1);
CArrayFixFlat< TTaskInfo >* tskInfoArray = new (ELeave) 
         CArrayFixFlat< TTaskInfo >(1);
TTsTime dueTime;

//We pass the Id of the Schedule to this API using iHandle member of 
//TSchedulerItemRef class

User::LeaveIfError(scheduler.GetScheduleL(itemRef.iHandle, 
lSchState, *entryArray, *tskInfoArray, dueTime));

TBuf<20> lBuf;
lBuf = lSchState.Name();
CEikonEnv::Static()->InfoWinL(_L("Name "), lBuf);

if ( lSchState.Persists() != 0 )
	{
	CEikonEnv::Static()->InfoWinL(_L("Persists"), _L("True"));
	}
else 	
	{
	CEikonEnv::Static()->InfoWinL(_L("Persists"), _L("False"));
	}	

if ( lSchState.Enabled() != 0 )
	{
	CEikonEnv::Static()->InfoWinL(_L("Enabled"), _L("True"));
	}
else 	
	{
	CEikonEnv::Static()->InfoWinL(_L("Enabled"), _L("False"));
	}	
TTime schLocalTime = dueTime.GetLocalTime();




The following code snippet is used to query the information regarding a particular task associated with a schedule:


TTaskInfo taskInfoRet;
TSchedulerItemRef itemRefRet;
startTime taskDueTime;
TInt dataSize;

User::LeaveIfError(scheduler.GetTaskDataSize(taskInfo.iTaskId, dataSize );

HBufC* lDataBuf = HBufC::NewL(dataSize);
TPtr16 ptr=lDataBuf->Des();

//We pass the Id of the Task to this API using iTaskId member of TTaskInfo class
User::LeaveIfError(scheduler.GetTaskInfoL(taskInfo.iTaskId, taskInfoRet,
 ptr, itemRefRet,taskDueTime ));

CEikonEnv::Static()->InfoWinL(_L("Task Name"), taskInfo.iName);

TBuf<5> repeatBuf;
repeatBuf.AppendNum(taskInfo.iRepeat);
CEikonEnv::Static()->InfoWinL(_L("Task repeat"), repeatBuf);

TTime taskLocalTime1 = taskDueTime.GetLocalTime();



The following code snippet is used to delete a specified task:


User::LeaveIfError(schedule.DeleteTask(taskInfo.iTaskId));



The following code snippet is used to delete a specified Schedule:


//Note that all the Tasks associated with this Scheduler must be deleted
// before executing this code.
User::LeaveIfError(schedule.DeleteDeleteSchedule(itemRef.iHandle));



Example Project

File:RScheduler Example.zip


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值