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 |
// HotKey user interface to the PC-sampling Profiler engine in E32utils
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32base.h>
|
sl@0
|
19 |
#include <w32std.h>
|
sl@0
|
20 |
#include <profiler.h>
|
sl@0
|
21 |
|
sl@0
|
22 |
class CKeys : public CActive, private MProfilerController
|
sl@0
|
23 |
{
|
sl@0
|
24 |
class THotKey
|
sl@0
|
25 |
{
|
sl@0
|
26 |
enum {KAllModifiers = EModifierFunc|EModifierCtrl|EModifierShift};
|
sl@0
|
27 |
public:
|
sl@0
|
28 |
inline THotKey()
|
sl@0
|
29 |
:iCapture(-1)
|
sl@0
|
30 |
{}
|
sl@0
|
31 |
inline void CaptureL(RWindowGroup& aWg, TUint aKey)
|
sl@0
|
32 |
{iCapture=User::LeaveIfError(aWg.CaptureKey(aKey,KAllModifiers,KAllModifiers));}
|
sl@0
|
33 |
inline void Release(RWindowGroup& aWg)
|
sl@0
|
34 |
{if (iCapture != -1) aWg.CancelCaptureKey(iCapture);}
|
sl@0
|
35 |
private:
|
sl@0
|
36 |
TInt32 iCapture;
|
sl@0
|
37 |
};
|
sl@0
|
38 |
public:
|
sl@0
|
39 |
IMPORT_C static MProfilerController* NewL(TInt aPriority, MProfilerEngine& aEngine);
|
sl@0
|
40 |
private:
|
sl@0
|
41 |
CKeys(TInt aPriority, MProfilerEngine& aEngine);
|
sl@0
|
42 |
void ConstructL();
|
sl@0
|
43 |
~CKeys();
|
sl@0
|
44 |
void Release();
|
sl@0
|
45 |
//
|
sl@0
|
46 |
void Queue();
|
sl@0
|
47 |
//
|
sl@0
|
48 |
void RunL();
|
sl@0
|
49 |
void DoCancel();
|
sl@0
|
50 |
//
|
sl@0
|
51 |
private:
|
sl@0
|
52 |
RWsSession iWs;
|
sl@0
|
53 |
RWindowGroup iWg;
|
sl@0
|
54 |
THotKey iStartKey;
|
sl@0
|
55 |
THotKey iStopKey;
|
sl@0
|
56 |
THotKey iCloseKey;
|
sl@0
|
57 |
THotKey iUnloadKey;
|
sl@0
|
58 |
THotKey iTestKey;
|
sl@0
|
59 |
};
|
sl@0
|
60 |
|
sl@0
|
61 |
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
EXPORT_C MProfilerController* CKeys::NewL(TInt aPriority, MProfilerEngine& aEngine)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
CKeys* self = new(ELeave) CKeys(aPriority, aEngine);
|
sl@0
|
67 |
CleanupStack::PushL(self);
|
sl@0
|
68 |
self->ConstructL();
|
sl@0
|
69 |
CleanupStack::Pop();
|
sl@0
|
70 |
return self;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
CKeys::CKeys(TInt aPriority, MProfilerEngine& aEngine)
|
sl@0
|
74 |
:CActive(aPriority), MProfilerController(aEngine)
|
sl@0
|
75 |
{
|
sl@0
|
76 |
CActiveScheduler::Add(this);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
|
sl@0
|
79 |
void CKeys::ConstructL()
|
sl@0
|
80 |
{
|
sl@0
|
81 |
User::LeaveIfError(iWs.Connect());
|
sl@0
|
82 |
iWg = iWs;
|
sl@0
|
83 |
User::LeaveIfError(iWg.Construct(0,EFalse));
|
sl@0
|
84 |
iWg.AutoForeground(EFalse);
|
sl@0
|
85 |
iStartKey.CaptureL(iWg, '1');
|
sl@0
|
86 |
iStopKey.CaptureL(iWg, '2');
|
sl@0
|
87 |
iCloseKey.CaptureL(iWg, '3');
|
sl@0
|
88 |
iUnloadKey.CaptureL(iWg, '4');
|
sl@0
|
89 |
iTestKey.CaptureL(iWg, '0');
|
sl@0
|
90 |
Queue();
|
sl@0
|
91 |
}
|
sl@0
|
92 |
|
sl@0
|
93 |
CKeys::~CKeys()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
Cancel();
|
sl@0
|
96 |
iStartKey.Release(iWg);
|
sl@0
|
97 |
iStopKey.Release(iWg);
|
sl@0
|
98 |
iCloseKey.Release(iWg);
|
sl@0
|
99 |
iUnloadKey.Release(iWg);
|
sl@0
|
100 |
iTestKey.Release(iWg);
|
sl@0
|
101 |
iWg.Close();
|
sl@0
|
102 |
iWs.Close();
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
void CKeys::Release()
|
sl@0
|
106 |
{
|
sl@0
|
107 |
delete this;
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
void CKeys::Queue()
|
sl@0
|
111 |
{
|
sl@0
|
112 |
iWs.EventReady(&iStatus);
|
sl@0
|
113 |
SetActive();
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
void CKeys::RunL()
|
sl@0
|
117 |
{
|
sl@0
|
118 |
TWsEvent ev;
|
sl@0
|
119 |
iWs.GetEvent(ev);
|
sl@0
|
120 |
if (ev.Type() == EEventKey)
|
sl@0
|
121 |
{
|
sl@0
|
122 |
switch (ev.Key()->iCode)
|
sl@0
|
123 |
{
|
sl@0
|
124 |
case '0':
|
sl@0
|
125 |
{
|
sl@0
|
126 |
_LIT(KTestPrint,"Profiler is ");
|
sl@0
|
127 |
static const TText* const KStates[] = {_S("running"),_S("waiting"),_S("loaded"),_S("?")};
|
sl@0
|
128 |
TBuf<60> info(KTestPrint);
|
sl@0
|
129 |
info.Append(TPtrC(KStates[GetState()]));
|
sl@0
|
130 |
User::InfoPrint(info);
|
sl@0
|
131 |
}
|
sl@0
|
132 |
break;
|
sl@0
|
133 |
case '1':
|
sl@0
|
134 |
case '2':
|
sl@0
|
135 |
case '3':
|
sl@0
|
136 |
case '4':
|
sl@0
|
137 |
Control(Profiler::TState(ev.Key()->iCode - '1'));
|
sl@0
|
138 |
break;
|
sl@0
|
139 |
}
|
sl@0
|
140 |
}
|
sl@0
|
141 |
Queue();
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
void CKeys::DoCancel()
|
sl@0
|
145 |
{
|
sl@0
|
146 |
iWs.EventReadyCancel();
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
|