os/ossrv/genericservices/taskscheduler/Test/MinimalTaskHandler/minimaltaskhandler.cpp
First public contribution.
1 // Copyright (c) 2000-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
17 #include <schinfointernal.h>
24 _LIT(KMinimalTaskConsoleName, "MinimalTaskExecutor");
26 static void SignalTestExe()
28 _LIT(KSchSemaphoreName, "SCHMinimalTaskHandler");
30 TInt ret = sem.OpenGlobal(KSchSemaphoreName);
38 //***********************************************************************************
39 LOCAL_D TInt GetRandomNumber(const TInt aLow, const TInt aHigh, TInt64& aSeed)
41 TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow));
44 // Round to 0 decimal places, ie. the nearest whole numer
45 Math::Round(initialRand, initialRand, 0);
46 Math::Int(rand, initialRand);
51 //***********************************************************************************
52 LOCAL_D void ConstructConsoleL(RFile& aTaskFile)
54 CConsoleBase* console=Console::NewL(KMinimalTaskConsoleName, TSize(KConsFullScreen, KConsFullScreen));
55 CleanupStack::PushL(console);
56 console->Printf(_L(" contents of task file\n"));
60 store = CDirectFileStore::FromLC(aTaskFile);//pushes store
61 RStoreReadStream instream;
62 instream.OpenLC(*store,store->Root());//pushes instream
65 TInt count = instream.ReadInt32L();
66 for (TInt i=0;i<count;i++)
68 CScheduledTask* task = CScheduledTask::NewLC(instream);
71 buf.Format(_L("Running task \"%S\""), &task->Info().iName);
72 User::LeaveIfError(User::InfoPrint(buf));
74 console->Printf(task->Info().iName);
75 console->Printf(_L("\n"));
76 HBufC* data = const_cast<HBufC*>(&(task->Data()));
77 console->Printf(*data);
78 console->Printf(_L("\n"));
79 console->Printf(_L("%d \n"),task->Info().iTaskId);
80 TTsTime tstime = task->ValidUntil();
81 const TTime time = tstime.GetLocalTime();
83 time.FormatL(dateString,(_L("%H%:1%T%*E%*D%X%*N%Y %1 %2 %3")));
84 console->Printf(_L(":%S\n"), &dateString);
85 CleanupStack::PopAndDestroy(task);
87 console->Printf(_L("Pausing for a one second..."));
89 CleanupStack::PopAndDestroy(3); //console, store, instream
93 //***********************************************************************************
94 LOCAL_D TInt Execute()
96 TInt err = KErrNoMemory;
97 CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail
102 // Adopt the task file from the Task Scheduler
103 err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
104 TScheduledTaskFile::FileHandleIndex());
108 // The aParam is the name of a file where the relevant CTaskExCmdLine is
110 TRAPD(err, ConstructConsoleL(file));
113 // Sometimes we want to return a bogus error value,
114 // sometimes we don't.
117 TInt64 seed = now.Int64();
118 err = GetRandomNumber(-50, 200, seed); //20% chance of error being returned
121 file.Close();// Close the file
129 //***********************************************************************************
130 GLDEF_C TInt E32Main()