libraries/extrabtrace/src/extrabtracek.cpp
changeset 0 7f656887cf89
child 22 30834c0f3179
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // extrabtracek.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 <fshell/extrabtracek.h>
       
    14 #include <kern_priv.h>
       
    15 
       
    16 #include "common.h"
       
    17 #include "sampler.h"
       
    18 #include "eventhandler.h"
       
    19 
       
    20 class DExtraBTraceChannel : public DLogicalChannelBase
       
    21 	{
       
    22 public:
       
    23 	DExtraBTraceChannel();
       
    24 	virtual ~DExtraBTraceChannel();
       
    25 	//	Inherited from DObject
       
    26 	virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
       
    27 	// Inherited from DLogicalChannelBase
       
    28 	virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
       
    29 	virtual TInt Request(TInt aReqNo, TAny* a1, TAny* a2);
       
    30 private:
       
    31 	DCpuSampler* Sampler();
       
    32 	};
       
    33 
       
    34 TInt DExtraBTraceFactory::Install()
       
    35 	{
       
    36 	TInt err = SetName(&KLogicalDeviceName);
       
    37 	if (err) return err;
       
    38 	err = Open();
       
    39 	if (err) return err;
       
    40 
       
    41 	iSampler = new DCpuSampler();
       
    42 	if (!iSampler) err = KErrNoMemory;
       
    43 
       
    44 	if (!err) iEventHandler = new DExtraBtraceEventHandler(this);
       
    45 	if (!iEventHandler) err = KErrNoMemory;
       
    46 
       
    47 	if (err)
       
    48 		{
       
    49 		Close(NULL);
       
    50 		}
       
    51 	else
       
    52 		{
       
    53 		iEventHandler->Add();
       
    54 		// We must NOT call anything that could fail from this point on - otherwise it is impossible to safely close the DExtraBtraceEventHandler (looks like a bug in constructing a DKernelEventHandler from DLogicalDevice::Install())
       
    55 		}
       
    56 	return err;
       
    57 	}
       
    58 
       
    59 
       
    60 void DExtraBTraceFactory::GetCaps(TDes8& /*aDes*/) const
       
    61 	{
       
    62 	//Kern::InfoCopy(aDes,0,0);
       
    63 	}
       
    64 
       
    65 TInt DExtraBTraceFactory::Create(DLogicalChannelBase*& aChannel)
       
    66 	{
       
    67 	aChannel=new DExtraBTraceChannel();
       
    68 	if(!aChannel)
       
    69 		return KErrNoMemory;
       
    70 	return KErrNone;
       
    71 	}
       
    72 
       
    73 DExtraBTraceFactory::~DExtraBTraceFactory()
       
    74 	{
       
    75 	delete iSampler;
       
    76 	delete iEventHandler;
       
    77 	}
       
    78 
       
    79 void DExtraBTraceFactory::SetCpuUsageSampling(MExtraBtrace::TCpuUsageCallback aCallbackFn)
       
    80 	{
       
    81 	iSampler->SetCpuUsageSampling(aCallbackFn);
       
    82 	}
       
    83 
       
    84 void DExtraBTraceFactory::SetProfilingSampling(TBool aEnabled)
       
    85 	{
       
    86 	iSampler->SetProfilingSampling(aEnabled);
       
    87 	}
       
    88 
       
    89 TAny* DExtraBTraceFactory::GetVersion(TInt /*aVersion*/)
       
    90 	{
       
    91 	return NULL; // We don't have any versions yet - this is like CBase::_Extension, just in case
       
    92 	}
       
    93 
       
    94 void DExtraBTraceFactory::MExtraBtrace_Close()
       
    95 	{
       
    96 	Close(NULL);
       
    97 	}
       
    98 
       
    99 //
       
   100 
       
   101 DExtraBTraceChannel::DExtraBTraceChannel()
       
   102 	{
       
   103 	}
       
   104 
       
   105 DExtraBTraceChannel::~DExtraBTraceChannel()
       
   106 	{
       
   107 	}
       
   108 
       
   109 TInt DExtraBTraceChannel::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/)
       
   110 	{
       
   111 	return KErrNone;
       
   112 	}
       
   113 
       
   114 DCpuSampler* DExtraBTraceChannel::Sampler()
       
   115 	{
       
   116 	return static_cast<DExtraBTraceFactory*>(iDevice)->iSampler;
       
   117 	}
       
   118 
       
   119 TInt DExtraBTraceChannel::RequestUserHandle(DThread* /*aThread*/, TOwnerType /*aType*/)
       
   120 	{
       
   121 	//if (aType!=EOwnerThread || aThread!=iClient)
       
   122 	//	return KErrAccessDenied;
       
   123 	return KErrNone;
       
   124 	}
       
   125 
       
   126 TInt DExtraBTraceChannel::Request(TInt aReqNo, TAny* a1, TAny* /*a2*/)
       
   127 	{
       
   128 	switch (aReqNo)
       
   129 		{
       
   130 	case EControlEnableProfiling:
       
   131 		{
       
   132 		TInt enable = (a1 == 0) ? 0 : 1; // We still ignore the rate, currently
       
   133 		TInt err = BTrace::SetFilter(BTrace::EProfiling, enable);
       
   134 		if (err >= 0)
       
   135 			{
       
   136 			Sampler()->SetProfilingSampling(enable);
       
   137 			}
       
   138 		return err;
       
   139 		}
       
   140 	default:
       
   141 		return KErrNotSupported;
       
   142 		}
       
   143 	}
       
   144 
       
   145 DECLARE_EXTENSION_LDD()
       
   146 	{
       
   147 	return new DExtraBTraceFactory;
       
   148 	}
       
   149 
       
   150 DECLARE_STANDARD_EXTENSION()
       
   151 	{
       
   152 	return KErrNone;
       
   153 	}
       
   154