os/graphics/windowing/windowserver/profiler/ProfilerKeys.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // HotKey user interface to the PC-sampling Profiler engine in E32utils
    15 // 
    16 //
    17 
    18 #include <e32base.h>
    19 #include <w32std.h>
    20 #include <profiler.h>
    21 
    22 class CKeys : public CActive, private MProfilerController
    23 	{
    24 	class THotKey
    25 		{
    26 		enum {KAllModifiers = EModifierFunc|EModifierCtrl|EModifierShift};
    27 	public:
    28 		inline THotKey()
    29 			:iCapture(-1)
    30 			{}
    31 		inline void CaptureL(RWindowGroup& aWg, TUint aKey)
    32 			{iCapture=User::LeaveIfError(aWg.CaptureKey(aKey,KAllModifiers,KAllModifiers));}
    33 		inline void Release(RWindowGroup& aWg)
    34 			{if (iCapture != -1) aWg.CancelCaptureKey(iCapture);}
    35 	private:
    36 		TInt32 iCapture;
    37 		};
    38 public:
    39 	IMPORT_C static MProfilerController* NewL(TInt aPriority, MProfilerEngine& aEngine);
    40 private:
    41 	CKeys(TInt aPriority, MProfilerEngine& aEngine);
    42 	void ConstructL();
    43 	~CKeys();
    44 	void Release();
    45 //
    46 	void Queue();
    47 //
    48 	void RunL();
    49 	void DoCancel();
    50 //
    51 private:
    52 	RWsSession iWs;
    53 	RWindowGroup iWg;
    54 	THotKey iStartKey;
    55 	THotKey iStopKey;
    56 	THotKey iCloseKey;
    57 	THotKey iUnloadKey;
    58 	THotKey iTestKey;
    59 	};
    60 
    61 
    62 
    63 
    64 EXPORT_C MProfilerController* CKeys::NewL(TInt aPriority, MProfilerEngine& aEngine)
    65 	{
    66 	CKeys* self = new(ELeave) CKeys(aPriority, aEngine);
    67 	CleanupStack::PushL(self);
    68 	self->ConstructL();
    69 	CleanupStack::Pop();
    70 	return self;
    71 	}
    72 
    73 CKeys::CKeys(TInt aPriority, MProfilerEngine& aEngine)
    74 	:CActive(aPriority), MProfilerController(aEngine)
    75 	{
    76 	CActiveScheduler::Add(this);
    77 	}
    78 
    79 void CKeys::ConstructL()
    80 	{
    81 	User::LeaveIfError(iWs.Connect());
    82 	iWg = iWs;
    83 	User::LeaveIfError(iWg.Construct(0,EFalse));
    84 	iWg.AutoForeground(EFalse);
    85 	iStartKey.CaptureL(iWg, '1');
    86 	iStopKey.CaptureL(iWg, '2');
    87 	iCloseKey.CaptureL(iWg, '3');
    88 	iUnloadKey.CaptureL(iWg, '4');
    89 	iTestKey.CaptureL(iWg, '0');
    90 	Queue();
    91 	}
    92 
    93 CKeys::~CKeys()
    94 	{
    95 	Cancel();
    96 	iStartKey.Release(iWg);
    97 	iStopKey.Release(iWg);
    98 	iCloseKey.Release(iWg);
    99 	iUnloadKey.Release(iWg);
   100 	iTestKey.Release(iWg);
   101 	iWg.Close();
   102 	iWs.Close();
   103 	}
   104 
   105 void CKeys::Release()
   106 	{
   107 	delete this;
   108 	}
   109 
   110 void CKeys::Queue()
   111 	{
   112 	iWs.EventReady(&iStatus);
   113 	SetActive();
   114 	}
   115 
   116 void CKeys::RunL()
   117 	{
   118 	TWsEvent ev;
   119 	iWs.GetEvent(ev);
   120 	if (ev.Type() == EEventKey)
   121 		{
   122 		switch (ev.Key()->iCode)
   123 			{
   124 		case '0':
   125 			{
   126 			_LIT(KTestPrint,"Profiler is ");
   127 			static const TText* const KStates[] = {_S("running"),_S("waiting"),_S("loaded"),_S("?")};
   128 			TBuf<60> info(KTestPrint);
   129 			info.Append(TPtrC(KStates[GetState()]));
   130 			User::InfoPrint(info);
   131 			}
   132 			break;
   133 		case '1':
   134 		case '2':
   135 		case '3':
   136 		case '4':
   137 			Control(Profiler::TState(ev.Key()->iCode - '1'));
   138 			break;
   139 			}
   140 		}
   141 	Queue();
   142 	}
   143 
   144 void CKeys::DoCancel()
   145 	{
   146 	iWs.EventReadyCancel();
   147 	}
   148 
   149