libraries/btrace_parser/src/btrace_textonscreen.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // btrace_textonscreen.cpp
       
     2 // 
       
     3 // Copyright (c) 2008 - 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 <fshell/ltkutils.h>
       
    14 #include "btrace_parser.h"
       
    15 
       
    16 
       
    17 EXPORT_C CBtraceTextOnScreen* CBtraceTextOnScreen::NewL(CBtraceReader& aReader)
       
    18 	{
       
    19 	CBtraceTextOnScreen* self = new (ELeave) CBtraceTextOnScreen(aReader);
       
    20 	CleanupStack::PushL(self);
       
    21 	self->ConstructL();
       
    22 	CleanupStack::Pop(self);
       
    23 	return self;
       
    24 	}
       
    25 
       
    26 CBtraceTextOnScreen::CBtraceTextOnScreen(CBtraceReader& aReader)
       
    27 	: iReader(aReader)
       
    28 	{
       
    29 	}
       
    30 
       
    31 EXPORT_C CBtraceTextOnScreen::~CBtraceTextOnScreen()
       
    32 	{
       
    33 	iReader.RemoveObserver(KAmTraceCategory, *this);
       
    34 	iScreenNotifs.Close();
       
    35 	}
       
    36 
       
    37 void CBtraceTextOnScreen::ConstructL()
       
    38 	{
       
    39 	iReader.AddObserverL(KAmTraceCategory, *this);
       
    40 	
       
    41 	LtkUtils::W32CrackL(); // In case no-one's called it yet
       
    42 	}
       
    43 
       
    44 //
       
    45 // CBtraceTextOnScreen::HandleBtraceFrameL
       
    46 // process the btrace frame, stripping out the relevant text
       
    47 //
       
    48 void CBtraceTextOnScreen::HandleBtraceFrameL(const TBtraceFrame& aFrame)
       
    49 	{
       
    50 	if (aFrame.iCategory == KAmTraceCategory && aFrame.iSubCategory == EAmTraceSubCategoryScreenText)
       
    51 		{
       
    52 		// First 2 words have packed windowgroup id and coordinates of text - TODO
       
    53 		TUint16 windowGroupId = *((const TUint16*)aFrame.iData.Mid(2).Ptr());
       
    54 		TPtrC8 data = aFrame.iData.Mid(8);
       
    55 		TPtrC text((const TUint16*)data.Ptr(), data.Length() / 2);
       
    56 		SeenL(aFrame.iTickCount, text, windowGroupId);
       
    57 		}
       
    58 	}
       
    59 
       
    60 //
       
    61 // CBtraceTextOnScreen::Seen
       
    62 // inform any observers that text has arrived on-screen, passing a reference to the text
       
    63 // note the observer may ask for any or a specific pattern of text to be notified on
       
    64 //
       
    65 void CBtraceTextOnScreen::SeenL(const TBtraceTickCount& aTickCount, const TDesC& aData, TInt aWindowGroupId)
       
    66 	{
       
    67 	iReader.Log(_L("Screen text: '%S' (%d)\r\n"), &aData, aWindowGroupId);
       
    68 	TInt ii = iScreenNotifs.Count();
       
    69 	while (--ii >= 0)
       
    70 		{
       
    71 		TTextOnScreenNotif& nt = iScreenNotifs[ii];
       
    72 
       
    73 		if (nt.iWindowGroupId && (nt.iWindowGroupId != aWindowGroupId))
       
    74 			{
       
    75 			continue;
       
    76 			}
       
    77 
       
    78 
       
    79 		switch (nt.iMatchMode)
       
    80 			{
       
    81 			case EWildNonSpanning:
       
    82 				{
       
    83 				if (aData.MatchF(nt.iTxtPtr) != KErrNotFound)
       
    84 					{
       
    85 					MBtraceTextOnScreenObserver* observer = nt.iObserver;
       
    86 					if (nt.iPersistence == ENotificationOneShot)
       
    87 						{
       
    88 						iScreenNotifs.Remove(ii);
       
    89 						}
       
    90 					observer->HandleTextSeenL(aTickCount, aData, aWindowGroupId);
       
    91 					}
       
    92 				break;
       
    93 				}
       
    94 			case ESpanningNonWild:
       
    95 				{
       
    96 				const TInt length = aData.Length();
       
    97 				for (TInt i = 0; i < length; ++i)
       
    98 					{
       
    99 					if (aData[i] == nt.iTxtPtr[nt.iMatchedChars])
       
   100 						{
       
   101 						++nt.iMatchedChars;
       
   102 						}
       
   103 					else
       
   104 						{
       
   105 						nt.iMatchedChars = 0;
       
   106 						}
       
   107 
       
   108 					if (nt.iMatchedChars == nt.iTxtPtr.Length())
       
   109 						{
       
   110 						MBtraceTextOnScreenObserver* observer = nt.iObserver;
       
   111 						if (nt.iPersistence == ENotificationOneShot)
       
   112 							{
       
   113 							iScreenNotifs.Remove(ii);
       
   114 							}
       
   115 						observer->HandleTextSeenL(aTickCount, aData, aWindowGroupId);
       
   116 						break;
       
   117 						}
       
   118 					}
       
   119 				break;
       
   120 				}
       
   121 			default:
       
   122 				ASSERT(EFalse);
       
   123 			}
       
   124 		}	
       
   125 	}
       
   126 
       
   127 //
       
   128 // CBtraceTextOnScreen::NotifyTextOnScreenL
       
   129 // called by the client to register an interest in any text drawn to screen (via wserv only)
       
   130 //
       
   131 EXPORT_C void CBtraceTextOnScreen::NotifyTextOnScreenL(const TDesC& aText, MBtraceTextOnScreenObserver& aObserver)
       
   132 	{
       
   133 	NotifyTextOnScreenL(aText, aObserver, ENotificationOneShot);
       
   134 	}
       
   135 	
       
   136 EXPORT_C void CBtraceTextOnScreen::NotifyTextOnScreenL(const TDesC& aText, MBtraceTextOnScreenObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
   137 	{
       
   138 	TTextOnScreenNotif notify(aText, aObserver, aPersistence);
       
   139 	iScreenNotifs.AppendL(notify);
       
   140 	}
       
   141 
       
   142 EXPORT_C void CBtraceTextOnScreen::NotifyTextOnScreenL(const TDesC& aText, TMatchMode aMatchMode, MBtraceTextOnScreenObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
   143 	{
       
   144 	TTextOnScreenNotif notify(aText, aMatchMode, aObserver, aPersistence);
       
   145 	iScreenNotifs.AppendL(notify);
       
   146 	}
       
   147 
       
   148 EXPORT_C void CBtraceTextOnScreen::NotifyTextOnScreenL(const TDesC& aText, TInt aWindowGroupId, TMatchMode aMatchMode, MBtraceTextOnScreenObserver& aObserver)
       
   149 	{
       
   150 	NotifyTextOnScreenL(aText, aWindowGroupId, aMatchMode, aObserver, ENotificationOneShot);
       
   151 	}
       
   152 	
       
   153 EXPORT_C void CBtraceTextOnScreen::NotifyTextOnScreenL(const TDesC& aText, TInt aWindowGroupId, TMatchMode aMatchMode, MBtraceTextOnScreenObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
   154 	{
       
   155 	TTextOnScreenNotif notify(aText, aWindowGroupId, aMatchMode, aObserver, aPersistence);
       
   156 	iScreenNotifs.AppendL(notify);
       
   157 	}
       
   158 
       
   159 EXPORT_C void CBtraceTextOnScreen::CancelNotifyTextOnScreen(MBtraceTextOnScreenObserver& aObserver)
       
   160 	{
       
   161 	for (TInt i = iScreenNotifs.Count()-1; i>=0; i--)
       
   162 		{
       
   163 		if (iScreenNotifs[i].iObserver == &aObserver)
       
   164 			{
       
   165 			iScreenNotifs.Remove(i);
       
   166 			}
       
   167 		}
       
   168 	}
       
   169 
       
   170 //
       
   171 // TTextOnScreenNotif
       
   172 //
       
   173 CBtraceTextOnScreen::TTextOnScreenNotif::TTextOnScreenNotif(const TDesC& aText, MBtraceTextOnScreenObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
   174 	: iTxtPtr(aText), iWindowGroupId(0), iMatchedChars(0), iMatchMode(EWildNonSpanning), iObserver(&aObserver), iPersistence(aPersistence)
       
   175 	{
       
   176 	}
       
   177 
       
   178 CBtraceTextOnScreen::TTextOnScreenNotif::TTextOnScreenNotif(const TDesC& aText, TMatchMode aMatchMode, MBtraceTextOnScreenObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
   179 	: iTxtPtr(aText), iWindowGroupId(0), iMatchedChars(0), iMatchMode(aMatchMode), iObserver(&aObserver), iPersistence(aPersistence)
       
   180 	{
       
   181 	}
       
   182 
       
   183 CBtraceTextOnScreen::TTextOnScreenNotif::TTextOnScreenNotif(const TDesC& aText, TInt aWindowGroupId, TMatchMode aMatchMode, MBtraceTextOnScreenObserver& aObserver, TBtraceNotificationPersistence aPersistence)
       
   184 	: iTxtPtr(aText), iWindowGroupId(aWindowGroupId), iMatchedChars(0), iMatchMode(aMatchMode), iObserver(&aObserver), iPersistence(aPersistence)
       
   185 	{
       
   186 	}