sl@0
|
1 |
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <schinfo.h>
|
sl@0
|
17 |
#include <schinfointernal.h>
|
sl@0
|
18 |
#include <schtask.h>
|
sl@0
|
19 |
#include <s32file.h>
|
sl@0
|
20 |
#include <e32math.h>
|
sl@0
|
21 |
#include <e32cons.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
// Constants
|
sl@0
|
24 |
_LIT(KMinimalTaskConsoleName, "MinimalTaskExecutor");
|
sl@0
|
25 |
|
sl@0
|
26 |
static void SignalTestExe()
|
sl@0
|
27 |
{
|
sl@0
|
28 |
_LIT(KSchSemaphoreName, "SCHMinimalTaskHandler");
|
sl@0
|
29 |
RSemaphore sem;
|
sl@0
|
30 |
TInt ret = sem.OpenGlobal(KSchSemaphoreName);
|
sl@0
|
31 |
if (ret == KErrNone)
|
sl@0
|
32 |
{
|
sl@0
|
33 |
sem.Signal();
|
sl@0
|
34 |
sem.Close();
|
sl@0
|
35 |
}
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
//***********************************************************************************
|
sl@0
|
39 |
LOCAL_D TInt GetRandomNumber(const TInt aLow, const TInt aHigh, TInt64& aSeed)
|
sl@0
|
40 |
{
|
sl@0
|
41 |
TReal initialRand = (Math::FRand(aSeed) * (aHigh - aLow));
|
sl@0
|
42 |
TInt32 rand;
|
sl@0
|
43 |
|
sl@0
|
44 |
// Round to 0 decimal places, ie. the nearest whole numer
|
sl@0
|
45 |
Math::Round(initialRand, initialRand, 0);
|
sl@0
|
46 |
Math::Int(rand, initialRand);
|
sl@0
|
47 |
|
sl@0
|
48 |
return (aLow + rand);
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
//***********************************************************************************
|
sl@0
|
52 |
LOCAL_D void ConstructConsoleL(RFile& aTaskFile)
|
sl@0
|
53 |
{
|
sl@0
|
54 |
CConsoleBase* console=Console::NewL(KMinimalTaskConsoleName, TSize(KConsFullScreen, KConsFullScreen));
|
sl@0
|
55 |
CleanupStack::PushL(console);
|
sl@0
|
56 |
console->Printf(_L(" contents of task file\n"));
|
sl@0
|
57 |
|
sl@0
|
58 |
CFileStore* store;
|
sl@0
|
59 |
// Open the filestore
|
sl@0
|
60 |
store = CDirectFileStore::FromLC(aTaskFile);//pushes store
|
sl@0
|
61 |
RStoreReadStream instream;
|
sl@0
|
62 |
instream.OpenLC(*store,store->Root());//pushes instream
|
sl@0
|
63 |
|
sl@0
|
64 |
// Get task count
|
sl@0
|
65 |
TInt count = instream.ReadInt32L();
|
sl@0
|
66 |
for (TInt i=0;i<count;i++)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
CScheduledTask* task = CScheduledTask::NewLC(instream);
|
sl@0
|
69 |
|
sl@0
|
70 |
TBuf<150> buf;
|
sl@0
|
71 |
buf.Format(_L("Running task \"%S\""), &task->Info().iName);
|
sl@0
|
72 |
User::LeaveIfError(User::InfoPrint(buf));
|
sl@0
|
73 |
|
sl@0
|
74 |
console->Printf(task->Info().iName);
|
sl@0
|
75 |
console->Printf(_L("\n"));
|
sl@0
|
76 |
HBufC* data = const_cast<HBufC*>(&(task->Data()));
|
sl@0
|
77 |
console->Printf(*data);
|
sl@0
|
78 |
console->Printf(_L("\n"));
|
sl@0
|
79 |
console->Printf(_L("%d \n"),task->Info().iTaskId);
|
sl@0
|
80 |
TTsTime tstime = task->ValidUntil();
|
sl@0
|
81 |
const TTime time = tstime.GetLocalTime();
|
sl@0
|
82 |
TBuf<30> dateString;
|
sl@0
|
83 |
time.FormatL(dateString,(_L("%H%:1%T%*E%*D%X%*N%Y %1 %2 %3")));
|
sl@0
|
84 |
console->Printf(_L(":%S\n"), &dateString);
|
sl@0
|
85 |
CleanupStack::PopAndDestroy(task);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
console->Printf(_L("Pausing for a one second..."));
|
sl@0
|
88 |
User::After(1000000);
|
sl@0
|
89 |
CleanupStack::PopAndDestroy(3); //console, store, instream
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
//***********************************************************************************
|
sl@0
|
94 |
LOCAL_D TInt Execute()
|
sl@0
|
95 |
{
|
sl@0
|
96 |
TInt err = KErrNoMemory;
|
sl@0
|
97 |
CTrapCleanup* cleanup=CTrapCleanup::New(); //can fail
|
sl@0
|
98 |
if (cleanup)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
RFile file;
|
sl@0
|
101 |
|
sl@0
|
102 |
// Adopt the task file from the Task Scheduler
|
sl@0
|
103 |
err = file.AdoptFromCreator(TScheduledTaskFile::FsHandleIndex(),
|
sl@0
|
104 |
TScheduledTaskFile::FileHandleIndex());
|
sl@0
|
105 |
if (err != KErrNone)
|
sl@0
|
106 |
return err;
|
sl@0
|
107 |
|
sl@0
|
108 |
// The aParam is the name of a file where the relevant CTaskExCmdLine is
|
sl@0
|
109 |
// do the executing
|
sl@0
|
110 |
TRAPD(err, ConstructConsoleL(file));
|
sl@0
|
111 |
if(err == KErrNone)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
// Sometimes we want to return a bogus error value,
|
sl@0
|
114 |
// sometimes we don't.
|
sl@0
|
115 |
TTime now;
|
sl@0
|
116 |
now.HomeTime();
|
sl@0
|
117 |
TInt64 seed = now.Int64();
|
sl@0
|
118 |
err = GetRandomNumber(-50, 200, seed); //20% chance of error being returned
|
sl@0
|
119 |
}
|
sl@0
|
120 |
|
sl@0
|
121 |
file.Close();// Close the file
|
sl@0
|
122 |
delete cleanup;
|
sl@0
|
123 |
}
|
sl@0
|
124 |
SignalTestExe();
|
sl@0
|
125 |
return err;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
|
sl@0
|
129 |
//***********************************************************************************
|
sl@0
|
130 |
GLDEF_C TInt E32Main()
|
sl@0
|
131 |
{
|
sl@0
|
132 |
return Execute();
|
sl@0
|
133 |
}
|