libraries/extrabtrace/inc/extrabtracek.h
changeset 0 7f656887cf89
child 22 30834c0f3179
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // extrabtracek.h
       
     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 #ifndef EXTRABTRACEK_H
       
    13 #define EXTRABTRACEK_H
       
    14 
       
    15 #include <fshell/extrabtrace.h>
       
    16 #include <kernel/kern_priv.h>
       
    17 
       
    18 // This class avoids exporting functions from extrabtracek.ldd - something that has proved problematic on certain platforms
       
    19 class MExtraBtrace
       
    20 	{
       
    21 public:
       
    22 	typedef void (*TCpuUsageCallback)(NThread*, NThread*); // First arg is previous thread, second is current
       
    23 	virtual void SetCpuUsageSampling(TCpuUsageCallback aCallbackFn)=0;
       
    24 	virtual void SetProfilingSampling(TBool aEnabled)=0;
       
    25 
       
    26 	virtual TAny* GetVersion(TInt aVersion)=0;
       
    27 	virtual void MExtraBtrace_Close()=0;
       
    28 	};
       
    29 
       
    30 
       
    31 class DCpuSampler;
       
    32 class DExtraBtraceEventHandler;
       
    33 
       
    34 class DExtraBTraceFactory : public DLogicalDevice, public MExtraBtrace
       
    35 	{
       
    36 public:
       
    37 	virtual TInt Install();
       
    38 	virtual void GetCaps(TDes8& aDes) const;
       
    39 	virtual TInt Create(DLogicalChannelBase*& aChannel);
       
    40 	~DExtraBTraceFactory();
       
    41 
       
    42 public: // From MExtraBtrace
       
    43 	void SetCpuUsageSampling(TCpuUsageCallback aCallbackFn);
       
    44 	void SetProfilingSampling(TBool aEnabled);
       
    45 	TAny* GetVersion(TInt aVersion);
       
    46 	void MExtraBtrace_Close();
       
    47 
       
    48 public:
       
    49 	DCpuSampler* iSampler;
       
    50 	DExtraBtraceEventHandler* iEventHandler;
       
    51 	};
       
    52 
       
    53 
       
    54 // This function avoids using WSD in extrabtracek.ldd - something that, again, has proved problematic on certain platforms
       
    55 // (And it's inline because of aforementioned exports problem)
       
    56 
       
    57 static MExtraBtrace* OpenExtraBtrace()
       
    58 	{
       
    59 	__ASSERT_CRITICAL;
       
    60 	// Find the extrabtrace DLogicalDevice
       
    61 	DLogicalDevice* ldd = NULL;
       
    62 	DObjectCon* ldds = Kern::Containers()[ELogicalDevice];
       
    63 	_LIT(KLogicalDeviceName, "extrabtrace");
       
    64 	TKName resultname;
       
    65 #ifdef FSHELL_9_1_SUPPORT
       
    66 	TInt findHandle;
       
    67 #else
       
    68 	TFindHandle findHandle;
       
    69 #endif
       
    70 	TInt found = ldds->FindByName(findHandle, KLogicalDeviceName, resultname);
       
    71 	if (found == KErrNone)
       
    72 		{
       
    73 		ldds->Wait();
       
    74 #ifdef FSHELL_9_1_SUPPORT
       
    75 		ldd = static_cast<DLogicalDevice*>(ldds->At(findHandle));
       
    76 #else
       
    77 		if (findHandle.Index() <= ldds->Count()) ldd = static_cast<DLogicalDevice*>((*ldds)[findHandle.Index()]);
       
    78 #endif
       
    79 		if (ldd && ldd->Open() != KErrNone) ldd = NULL;
       
    80 		ldds->Signal();
       
    81 
       
    82 		if (ldd)
       
    83 			{
       
    84 			return static_cast<DExtraBTraceFactory*>(ldd);
       
    85 			}
       
    86 		}
       
    87 	return NULL;
       
    88 	}
       
    89 
       
    90 #endif