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