1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/windowing/windowserver/profiler/ProfilerKeys.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,149 @@
1.4 +// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// HotKey user interface to the PC-sampling Profiler engine in E32utils
1.18 +//
1.19 +//
1.20 +
1.21 +#include <e32base.h>
1.22 +#include <w32std.h>
1.23 +#include <profiler.h>
1.24 +
1.25 +class CKeys : public CActive, private MProfilerController
1.26 + {
1.27 + class THotKey
1.28 + {
1.29 + enum {KAllModifiers = EModifierFunc|EModifierCtrl|EModifierShift};
1.30 + public:
1.31 + inline THotKey()
1.32 + :iCapture(-1)
1.33 + {}
1.34 + inline void CaptureL(RWindowGroup& aWg, TUint aKey)
1.35 + {iCapture=User::LeaveIfError(aWg.CaptureKey(aKey,KAllModifiers,KAllModifiers));}
1.36 + inline void Release(RWindowGroup& aWg)
1.37 + {if (iCapture != -1) aWg.CancelCaptureKey(iCapture);}
1.38 + private:
1.39 + TInt32 iCapture;
1.40 + };
1.41 +public:
1.42 + IMPORT_C static MProfilerController* NewL(TInt aPriority, MProfilerEngine& aEngine);
1.43 +private:
1.44 + CKeys(TInt aPriority, MProfilerEngine& aEngine);
1.45 + void ConstructL();
1.46 + ~CKeys();
1.47 + void Release();
1.48 +//
1.49 + void Queue();
1.50 +//
1.51 + void RunL();
1.52 + void DoCancel();
1.53 +//
1.54 +private:
1.55 + RWsSession iWs;
1.56 + RWindowGroup iWg;
1.57 + THotKey iStartKey;
1.58 + THotKey iStopKey;
1.59 + THotKey iCloseKey;
1.60 + THotKey iUnloadKey;
1.61 + THotKey iTestKey;
1.62 + };
1.63 +
1.64 +
1.65 +
1.66 +
1.67 +EXPORT_C MProfilerController* CKeys::NewL(TInt aPriority, MProfilerEngine& aEngine)
1.68 + {
1.69 + CKeys* self = new(ELeave) CKeys(aPriority, aEngine);
1.70 + CleanupStack::PushL(self);
1.71 + self->ConstructL();
1.72 + CleanupStack::Pop();
1.73 + return self;
1.74 + }
1.75 +
1.76 +CKeys::CKeys(TInt aPriority, MProfilerEngine& aEngine)
1.77 + :CActive(aPriority), MProfilerController(aEngine)
1.78 + {
1.79 + CActiveScheduler::Add(this);
1.80 + }
1.81 +
1.82 +void CKeys::ConstructL()
1.83 + {
1.84 + User::LeaveIfError(iWs.Connect());
1.85 + iWg = iWs;
1.86 + User::LeaveIfError(iWg.Construct(0,EFalse));
1.87 + iWg.AutoForeground(EFalse);
1.88 + iStartKey.CaptureL(iWg, '1');
1.89 + iStopKey.CaptureL(iWg, '2');
1.90 + iCloseKey.CaptureL(iWg, '3');
1.91 + iUnloadKey.CaptureL(iWg, '4');
1.92 + iTestKey.CaptureL(iWg, '0');
1.93 + Queue();
1.94 + }
1.95 +
1.96 +CKeys::~CKeys()
1.97 + {
1.98 + Cancel();
1.99 + iStartKey.Release(iWg);
1.100 + iStopKey.Release(iWg);
1.101 + iCloseKey.Release(iWg);
1.102 + iUnloadKey.Release(iWg);
1.103 + iTestKey.Release(iWg);
1.104 + iWg.Close();
1.105 + iWs.Close();
1.106 + }
1.107 +
1.108 +void CKeys::Release()
1.109 + {
1.110 + delete this;
1.111 + }
1.112 +
1.113 +void CKeys::Queue()
1.114 + {
1.115 + iWs.EventReady(&iStatus);
1.116 + SetActive();
1.117 + }
1.118 +
1.119 +void CKeys::RunL()
1.120 + {
1.121 + TWsEvent ev;
1.122 + iWs.GetEvent(ev);
1.123 + if (ev.Type() == EEventKey)
1.124 + {
1.125 + switch (ev.Key()->iCode)
1.126 + {
1.127 + case '0':
1.128 + {
1.129 + _LIT(KTestPrint,"Profiler is ");
1.130 + static const TText* const KStates[] = {_S("running"),_S("waiting"),_S("loaded"),_S("?")};
1.131 + TBuf<60> info(KTestPrint);
1.132 + info.Append(TPtrC(KStates[GetState()]));
1.133 + User::InfoPrint(info);
1.134 + }
1.135 + break;
1.136 + case '1':
1.137 + case '2':
1.138 + case '3':
1.139 + case '4':
1.140 + Control(Profiler::TState(ev.Key()->iCode - '1'));
1.141 + break;
1.142 + }
1.143 + }
1.144 + Queue();
1.145 + }
1.146 +
1.147 +void CKeys::DoCancel()
1.148 + {
1.149 + iWs.EventReadyCancel();
1.150 + }
1.151 +
1.152 +