00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00042 #include <schtask.h>
00043 #include <e32cons.h>
00044
00045 _LIT(KTaskConsoleName, "TaskExecutor");
00046 _LIT(KContent,"\nContents of task file:\n");
00047 _LIT(KTask,"\nRunning task: %S");
00048 _LIT(KTaskData,"\nThis is the task data for a");
00049 _LIT(KTaskId,"\nThe task Id is: %d\n");
00050 _LIT(KValidity,"Task is valid until %S\n");
00051 _LIT(KDateString,"%H%:1%T %*E%*D%X%*N%Y %1 %2 %3");
00052 _LIT(KPressAnyKey,"Press any key to continue \n");
00053 _LIT(KAbort,"\nCapabilities of the task scheduler and the executor do not match. Task aborted\n");
00054 _LIT(KSidMismatch,"SID of the task executor is not same as that of the scheduler. Task aborted\n");
00055
00056 const TUint32 KTaskSchedulerSid = 0xE80000B5;
00057 const TCapability KTaskCapability = ECapabilityWriteDeviceData;
00058
00065 void TaskExecuteL(RFile& aTaskFile)
00066 {
00067
00068 CConsoleBase* console = Console::NewL(KTaskConsoleName, TSize(KConsFullScreen, KConsFullScreen));
00069 CleanupStack::PushL(console);
00070 console->Printf(KContent);
00071
00072
00073 CFileStore* store = CDirectFileStore::FromLC(aTaskFile);
00074 RStoreReadStream instream;
00075
00076
00077 instream.OpenLC(*store,store->Root());
00078
00079
00080 TInt count = instream.ReadInt32L();
00081 for (TInt i=0;i<count;i++)
00082 {
00083 CScheduledTask* task = CScheduledTask::NewLC(instream);
00084
00085
00086 if(task->SecurityInfo().iSecureId == KTaskSchedulerSid)
00087 {
00088
00089
00090
00091 if(task->SecurityInfo().iCaps.HasCapability(KTaskCapability))
00092 {
00093 TBuf<50> buf;
00094 buf.Format(KTask, &task->Info().iName);
00095 console->Printf(buf);
00096
00097 HBufC* data = const_cast<HBufC*>(&(task->Data()));
00098
00099 console->Printf(KTaskData);
00100 console->Printf(*data);
00101
00102 console->Printf(KTaskId,task->Info().iTaskId);
00103
00104
00105 TTsTime tstime = task->ValidUntil();
00106 const TTime time = tstime.GetLocalTime();
00107 TBuf<30> dateString;
00108 time.FormatL(dateString,(KDateString));
00109 console->Printf(KValidity, &dateString);
00110 }
00111 else
00112 {
00113 console->Printf(KAbort);
00114 }
00115 }
00116 else
00117 {
00118 console->Printf(KSidMismatch);
00119 }
00120 console->Printf(KPressAnyKey);
00121 console->Getch();
00122
00123 CleanupStack::PopAndDestroy(task);
00124
00125 }
00126
00127 CleanupStack::PopAndDestroy(3);
00128 }
00129
00130
00131 TInt Execute()
00132 {
00133 TInt err = KErrNoMemory;
00134 CTrapCleanup* cleanup = CTrapCleanup::New();
00135 if (cleanup)
00136 {
00137 RFile file;
00138
00139
00140
00141 err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
00142 TScheduledTaskFile::FileHandleIndex());
00143 if (err != KErrNone)
00144 {
00145 return err;
00146 }
00147
00148
00149 TRAPD(err,TaskExecuteL(file));
00150 if(err != KErrNone)
00151 {
00152 User::Panic(_L("Failed to complete"),err);
00153 }
00154
00155
00156 file.Close();
00157 delete cleanup;
00158 }
00159 return err;
00160 }
00161
00162
00163 GLDEF_C TInt E32Main()
00164 {
00165 return Execute();
00166 }