sl@0: // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // Constants sl@0: _LIT(KMinimalTaskConsoleName, "MinimalTaskExecutor"); sl@0: sl@0: static void SignalTestExe() sl@0: { sl@0: _LIT(KSchSemaphoreName, "SCHMinimalTaskHandler"); sl@0: RSemaphore sem; sl@0: TInt ret = sem.OpenGlobal(KSchSemaphoreName); sl@0: if (ret == KErrNone) sl@0: { sl@0: sem.Signal(); sl@0: sem.Close(); sl@0: } sl@0: } sl@0: sl@0: //*********************************************************************************** sl@0: LOCAL_D TInt GetRandomNumber(const TInt aLow, const TInt aHigh, TInt64& aSeed) sl@0: { sl@0: TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow)); sl@0: TInt32 rand; sl@0: sl@0: // Round to 0 decimal places, ie. the nearest whole numer sl@0: Math::Round(initialRand, initialRand, 0); sl@0: Math::Int(rand, initialRand); sl@0: sl@0: return (aLow + rand); sl@0: } sl@0: sl@0: //*********************************************************************************** sl@0: LOCAL_D void ConstructConsoleL(RFile& aTaskFile) sl@0: { sl@0: CConsoleBase* console=Console::NewL(KMinimalTaskConsoleName, TSize(KConsFullScreen, KConsFullScreen)); sl@0: CleanupStack::PushL(console); sl@0: console->Printf(_L(" contents of task file\n")); sl@0: sl@0: CFileStore* store; sl@0: // Open the filestore sl@0: store = CDirectFileStore::FromLC(aTaskFile);//pushes store sl@0: RStoreReadStream instream; sl@0: instream.OpenLC(*store,store->Root());//pushes instream sl@0: sl@0: // Get task count sl@0: TInt count = instream.ReadInt32L(); sl@0: for (TInt i=0;i buf; sl@0: buf.Format(_L("Running task \"%S\""), &task->Info().iName); sl@0: User::LeaveIfError(User::InfoPrint(buf)); sl@0: sl@0: console->Printf(task->Info().iName); sl@0: console->Printf(_L("\n")); sl@0: HBufC* data = const_cast(&(task->Data())); sl@0: console->Printf(*data); sl@0: console->Printf(_L("\n")); sl@0: console->Printf(_L("%d \n"),task->Info().iTaskId); sl@0: TTsTime tstime = task->ValidUntil(); sl@0: const TTime time = tstime.GetLocalTime(); sl@0: TBuf<30> dateString; sl@0: time.FormatL(dateString,(_L("%H%:1%T%*E%*D%X%*N%Y %1 %2 %3"))); sl@0: console->Printf(_L(":%S\n"), &dateString); sl@0: CleanupStack::PopAndDestroy(task); sl@0: } sl@0: console->Printf(_L("Pausing for a one second...")); sl@0: User::After(1000000); sl@0: CleanupStack::PopAndDestroy(3); //console, store, instream sl@0: } sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: LOCAL_D TInt Execute() sl@0: { sl@0: TInt err = KErrNoMemory; sl@0: CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail sl@0: if (cleanup) sl@0: { sl@0: RFile file; sl@0: sl@0: // Adopt the task file from the Task Scheduler sl@0: err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(), sl@0: TScheduledTaskFile::FileHandleIndex()); sl@0: if (err != KErrNone) sl@0: return err; sl@0: sl@0: // The aParam is the name of a file where the relevant CTaskExCmdLine is sl@0: // do the executing sl@0: TRAPD(err, ConstructConsoleL(file)); sl@0: if(err == KErrNone) sl@0: { sl@0: // Sometimes we want to return a bogus error value, sl@0: // sometimes we don't. sl@0: TTime now; sl@0: now.HomeTime(); sl@0: TInt64 seed = now.Int64(); sl@0: err = GetRandomNumber(-50, 200, seed); //20% chance of error being returned sl@0: } sl@0: sl@0: file.Close();// Close the file sl@0: delete cleanup; sl@0: } sl@0: SignalTestExe(); sl@0: return err; sl@0: } sl@0: sl@0: sl@0: //*********************************************************************************** sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: return Execute(); sl@0: }