libraries/btrace_parser/src/btrace_focuschange.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // btrace_focuschange.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include "btrace_parser.h"
       
    14 
       
    15 EXPORT_C CBtraceFocusChange* CBtraceFocusChange::NewL(CBtraceReader& aReader, CBtraceContext& aContext)
       
    16 	{
       
    17 	CBtraceFocusChange* self = new(ELeave) CBtraceFocusChange(aReader, aContext);
       
    18 	CleanupStack::PushL(self);
       
    19 	self->ConstructL();
       
    20 	CleanupStack::Pop(self);
       
    21 	return self;
       
    22 	}
       
    23 
       
    24 CBtraceFocusChange::CBtraceFocusChange(CBtraceReader& aReader, CBtraceContext& aContext)
       
    25 	: iReader(aReader), iContext(aContext)
       
    26 	{
       
    27 	}
       
    28 
       
    29 EXPORT_C CBtraceFocusChange::~CBtraceFocusChange()
       
    30 	{
       
    31 	iNotifs.Close();
       
    32 	iReader.RemoveObserver(KAmTraceCategory, *this);
       
    33 	}
       
    34 
       
    35 void CBtraceFocusChange::ConstructL()
       
    36 	{
       
    37 	iReader.AddObserverL(KAmTraceCategory, *this);
       
    38 	}
       
    39 
       
    40 EXPORT_C void CBtraceFocusChange::NotifyFocusChangedL(const TDesC& aWindowGroupNamePattern, MBtraceFocusChangeObserver& aObserver)
       
    41 	{
       
    42 	NotifyFocusChangedL(aWindowGroupNamePattern, aObserver, ENotificationOneShot);
       
    43 	}
       
    44 
       
    45 EXPORT_C void CBtraceFocusChange::NotifyFocusChangedL(const TDesC& aWindowGroupNamePattern, MBtraceFocusChangeObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
    46 	{
       
    47 	iNotifs.AppendL(TFocusChangeNotif(aWindowGroupNamePattern, aObserver, aPersistence));
       
    48 	}
       
    49 
       
    50 EXPORT_C void CBtraceFocusChange::CancelNotifyFocusChanged(MBtraceFocusChangeObserver& aObserver)
       
    51 	{
       
    52 	for (TInt i = (iNotifs.Count() - 1); i >= 0; --i)
       
    53 		{
       
    54 		if (&iNotifs[i].iObserver == &aObserver)
       
    55 			{
       
    56 			iNotifs.Remove(i);
       
    57 			}
       
    58 		}
       
    59 	}
       
    60 
       
    61 void CBtraceFocusChange::HandleBtraceFrameL(const TBtraceFrame& aFrame)
       
    62 	{
       
    63 	if (aFrame.iSubCategory == EAmTraceSubCategoryWindowGroupFocus)
       
    64 		{
       
    65 		const TInt32* data = (const TInt32*)aFrame.iData.Ptr();
       
    66 		TInt wservWindowGroupId = *data;
       
    67 		const TBtraceWindowGroupId* windowGroupId = iContext.FindWindowGroup(wservWindowGroupId);
       
    68 		__ASSERT_ALWAYS(windowGroupId, Panic(EBtpPanicWservWindowGroupIdNotFound));
       
    69 		const TDesC& windowGroupName = iContext.WindowGroupName(*windowGroupId);
       
    70 		
       
    71 		for (TInt i = (iNotifs.Count() - 1); i >= 0; --i)
       
    72 			{
       
    73 			const TFocusChangeNotif& thisNotif = iNotifs[i];
       
    74 			if (windowGroupName.MatchF(thisNotif.iWindowGroupNamePattern) != KErrNotFound)
       
    75 				{
       
    76 				MBtraceFocusChangeObserver& observer = thisNotif.iObserver;
       
    77 				if (thisNotif.iPersistence == ENotificationOneShot)
       
    78 					{
       
    79 					iNotifs.Remove(i);
       
    80 					}
       
    81 				observer.HandleFocusChangedL(aFrame.iTickCount, *windowGroupId);
       
    82 				}
       
    83 			}
       
    84 		}
       
    85 	}
       
    86 
       
    87 CBtraceFocusChange::TFocusChangeNotif::TFocusChangeNotif(const TDesC& aWindowGroupNamePattern, MBtraceFocusChangeObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
    88 	: iWindowGroupNamePattern(aWindowGroupNamePattern), iObserver(aObserver), iPersistence(aPersistence)
       
    89 	{
       
    90 	}