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: // HotKey user interface to the PC-sampling Profiler engine in E32utils sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: class CKeys : public CActive, private MProfilerController sl@0: { sl@0: class THotKey sl@0: { sl@0: enum {KAllModifiers = EModifierFunc|EModifierCtrl|EModifierShift}; sl@0: public: sl@0: inline THotKey() sl@0: :iCapture(-1) sl@0: {} sl@0: inline void CaptureL(RWindowGroup& aWg, TUint aKey) sl@0: {iCapture=User::LeaveIfError(aWg.CaptureKey(aKey,KAllModifiers,KAllModifiers));} sl@0: inline void Release(RWindowGroup& aWg) sl@0: {if (iCapture != -1) aWg.CancelCaptureKey(iCapture);} sl@0: private: sl@0: TInt32 iCapture; sl@0: }; sl@0: public: sl@0: IMPORT_C static MProfilerController* NewL(TInt aPriority, MProfilerEngine& aEngine); sl@0: private: sl@0: CKeys(TInt aPriority, MProfilerEngine& aEngine); sl@0: void ConstructL(); sl@0: ~CKeys(); sl@0: void Release(); sl@0: // sl@0: void Queue(); sl@0: // sl@0: void RunL(); sl@0: void DoCancel(); sl@0: // sl@0: private: sl@0: RWsSession iWs; sl@0: RWindowGroup iWg; sl@0: THotKey iStartKey; sl@0: THotKey iStopKey; sl@0: THotKey iCloseKey; sl@0: THotKey iUnloadKey; sl@0: THotKey iTestKey; sl@0: }; sl@0: sl@0: sl@0: sl@0: sl@0: EXPORT_C MProfilerController* CKeys::NewL(TInt aPriority, MProfilerEngine& aEngine) sl@0: { sl@0: CKeys* self = new(ELeave) CKeys(aPriority, aEngine); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CKeys::CKeys(TInt aPriority, MProfilerEngine& aEngine) sl@0: :CActive(aPriority), MProfilerController(aEngine) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: void CKeys::ConstructL() sl@0: { sl@0: User::LeaveIfError(iWs.Connect()); sl@0: iWg = iWs; sl@0: User::LeaveIfError(iWg.Construct(0,EFalse)); sl@0: iWg.AutoForeground(EFalse); sl@0: iStartKey.CaptureL(iWg, '1'); sl@0: iStopKey.CaptureL(iWg, '2'); sl@0: iCloseKey.CaptureL(iWg, '3'); sl@0: iUnloadKey.CaptureL(iWg, '4'); sl@0: iTestKey.CaptureL(iWg, '0'); sl@0: Queue(); sl@0: } sl@0: sl@0: CKeys::~CKeys() sl@0: { sl@0: Cancel(); sl@0: iStartKey.Release(iWg); sl@0: iStopKey.Release(iWg); sl@0: iCloseKey.Release(iWg); sl@0: iUnloadKey.Release(iWg); sl@0: iTestKey.Release(iWg); sl@0: iWg.Close(); sl@0: iWs.Close(); sl@0: } sl@0: sl@0: void CKeys::Release() sl@0: { sl@0: delete this; sl@0: } sl@0: sl@0: void CKeys::Queue() sl@0: { sl@0: iWs.EventReady(&iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CKeys::RunL() sl@0: { sl@0: TWsEvent ev; sl@0: iWs.GetEvent(ev); sl@0: if (ev.Type() == EEventKey) sl@0: { sl@0: switch (ev.Key()->iCode) sl@0: { sl@0: case '0': sl@0: { sl@0: _LIT(KTestPrint,"Profiler is "); sl@0: static const TText* const KStates[] = {_S("running"),_S("waiting"),_S("loaded"),_S("?")}; sl@0: TBuf<60> info(KTestPrint); sl@0: info.Append(TPtrC(KStates[GetState()])); sl@0: User::InfoPrint(info); sl@0: } sl@0: break; sl@0: case '1': sl@0: case '2': sl@0: case '3': sl@0: case '4': sl@0: Control(Profiler::TState(ev.Key()->iCode - '1')); sl@0: break; sl@0: } sl@0: } sl@0: Queue(); sl@0: } sl@0: sl@0: void CKeys::DoCancel() sl@0: { sl@0: iWs.EventReadyCancel(); sl@0: } sl@0: sl@0: