sysanadatacapture/piprofiler/piprofiler/engine/inc/ProfilerEngine.h
changeset 1 3ff3fecb12fe
equal deleted inserted replaced
0:f0f2b8682603 1:3ff3fecb12fe
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __PROFILERENGINE__
       
    20 #define __PROFILERENGINE__
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <e32svr.h>
       
    24 #include <piprofiler/EngineUIDs.h>
       
    25 #include <e32property.h> 
       
    26 
       
    27 #include <piprofiler/SamplerPluginInterface.h>
       
    28 #include <piprofiler/WriterPluginInterface.h>
       
    29 #include <piprofiler/ProfilerSession.h>
       
    30 #include <piprofiler/ProfilerAttributes.h>	// internal settings format presentations 
       
    31 
       
    32 #include "SamplerController.h"
       
    33 #include "WriterController.h"
       
    34 #include "ProfilerErrorChecker.h"
       
    35 
       
    36 // CONSTANTS
       
    37 const TInt KProfilerPrefixMaxLength = 32;
       
    38 const TInt KSettingsFileSize = 4096;
       
    39 
       
    40 /*
       
    41  * This is an internal interface to the profiling engine which allows
       
    42  * an additional control DLL to be loaded, replacing the profiler's
       
    43  * default console UI
       
    44  */
       
    45 
       
    46 /**
       
    47  * Implementation class providing access to the profiler engine
       
    48  */
       
    49 
       
    50 class MProfilerEngine
       
    51 {
       
    52 public:
       
    53 	virtual TInt				ControlL(TInt aCommand) =0;
       
    54 	virtual TInt				ControlDataL(TInt aCommand, TAny* data1 = 0, TAny* data2 = 0) = 0; 
       
    55 	
       
    56 	virtual TInt                GetSamplerAttributesL(const RMessage2& aMessage) = 0;
       
    57     virtual TInt                GetSamplerAttributeCountL(const RMessage2& aMessage) = 0;
       
    58 	virtual TInt                SetSamplerAttributesL(const RMessage2& aMessage) = 0;
       
    59 	virtual TInt                GetGeneralAttributesL(const RMessage2& aMessage) = 0;
       
    60 	virtual TInt                SetGeneralAttributesL(const RMessage2& aMessage) = 0;
       
    61     virtual TInt                 RefreshStatus(const RMessage2& aMessage) = 0;
       
    62 	virtual RProfiler::TSamplerState 	State() const =0;
       
    63 };
       
    64 
       
    65 /**
       
    66  * The interface that the extra controller must implement to access
       
    67  * the profiler.
       
    68  */
       
    69 class MProfilerController
       
    70 {
       
    71 	public:
       
    72 		/** Release the controller from the profiler. This is invoked when the profiler is unloading. */
       
    73 		virtual void				Release() = 0;
       
    74 		/** Ask the profiler to change state */
       
    75 		inline TInt					ControlL(TInt aCommand) const;
       
    76 		/** Ask the profiler to change state */
       
    77 		inline TInt					ControlDataL(TInt aCommand, TAny* data1 = 0, TAny* data2 = 0) const;
       
    78 		
       
    79 		inline TInt                 GetSamplerAttributesL(const RMessage2& aMessage) const;
       
    80         inline TInt                 SetSamplerAttributesL(const RMessage2& aMessage) const;
       
    81         inline TInt                 GetGeneralAttributesL(const RMessage2& aMessage) const;
       
    82         inline TInt                 SetGeneralAttributesL(const RMessage2& aMessage) const;
       
    83         inline TInt                 GetSamplerAttributeCountL(const RMessage2& aMessage) const;
       
    84         inline TInt                 RefreshStatus(const RMessage2& aMessage) const;
       
    85 		/* Query the profiler state */
       
    86 		inline RProfiler::TSamplerState	GeTComand() const;
       
    87 	protected:
       
    88 		inline						MProfilerController(MProfilerEngine& aEngine);
       
    89 	private:
       
    90 		MProfilerEngine& iEngine;
       
    91 };
       
    92 
       
    93 /** The signature of ordinal 1 in the controller DLL */
       
    94 typedef MProfilerController* (*TProfilerControllerFactoryL)(TInt aPriority, MProfilerEngine& aEngine);
       
    95 /** The second UID required by the controller DLL */
       
    96 const TUid KUidProfilerKeys={0x1000945c};
       
    97 
       
    98 inline MProfilerController::MProfilerController(MProfilerEngine& aEngine)
       
    99 	:iEngine(aEngine)
       
   100 {
       
   101 
       
   102 }
       
   103 
       
   104 inline TInt MProfilerController::ControlL(TInt aCommand) const
       
   105 {
       
   106 	return iEngine.ControlL(aCommand);
       
   107 }
       
   108 
       
   109 inline TInt MProfilerController::ControlDataL(TInt aCommand,TAny* data1, TAny* data2) const
       
   110 {
       
   111 	return iEngine.ControlDataL(aCommand,data1,data2);
       
   112 }
       
   113 
       
   114 inline TInt MProfilerController::GetSamplerAttributesL(const RMessage2& aMessage) const
       
   115 {
       
   116     return iEngine.GetSamplerAttributesL(aMessage);
       
   117 }
       
   118 
       
   119 inline TInt MProfilerController::SetSamplerAttributesL(const RMessage2& aMessage) const
       
   120 {
       
   121     return iEngine.SetSamplerAttributesL(aMessage);
       
   122 }
       
   123 
       
   124 inline TInt MProfilerController::GetGeneralAttributesL(const RMessage2& aMessage) const
       
   125 {
       
   126     return iEngine.GetGeneralAttributesL(aMessage);
       
   127 }
       
   128 
       
   129 inline TInt MProfilerController::GetSamplerAttributeCountL(const RMessage2& aMessage) const
       
   130 {
       
   131     return iEngine.GetSamplerAttributeCountL(aMessage);
       
   132 }
       
   133 
       
   134 inline TInt MProfilerController::SetGeneralAttributesL(const RMessage2& aMessage) const
       
   135 {
       
   136     return iEngine.SetGeneralAttributesL(aMessage);
       
   137 }
       
   138 
       
   139 inline TInt MProfilerController::RefreshStatus(const RMessage2& aMessage) const
       
   140 {
       
   141     return iEngine.RefreshStatus(aMessage);
       
   142 }
       
   143 
       
   144 inline RProfiler::TSamplerState MProfilerController::GeTComand() const
       
   145 {
       
   146 	return iEngine.State();
       
   147 }
       
   148 
       
   149 class CSamplerController;
       
   150 class CWriterController;
       
   151 class MSamplerControllerObserver;
       
   152 class MProfilerErrorObserver;
       
   153 
       
   154 class CProfiler : public CBase, private MProfilerEngine, 
       
   155     MSamplerControllerObserver, 
       
   156     MProfilerErrorObserver
       
   157 {
       
   158 	public:
       
   159 		
       
   160 		static CProfiler*	NewLC(const TDesC& aSettingsFile);
       
   161 
       
   162 		/**
       
   163 		 * Method for control commands, i.e. start, stop and exit 
       
   164 		 * 
       
   165 		 * @param aCommand command to be parsed and executed
       
   166 		 * @return TInt KErrNone if succeed, else error code
       
   167 		 */
       
   168 		TInt				ControlL(TInt aCommand);
       
   169 
       
   170 		/**
       
   171          * Method for control data, e.g. settings
       
   172          * 
       
   173          * @param aCommand command to be parsed and executed
       
   174          * @param value1 can contain any value, integer or string, depends on use case 
       
   175          * @param value2 can contain any value, integer or string, depends on use case 
       
   176          * @return TInt KErrNone if succeed, else error code
       
   177          */
       
   178 		TInt				ControlDataL(TInt aCommand, TAny* value1 = 0, TAny* value2 = 0);	
       
   179 
       
   180 		// setting attributes manipulation
       
   181 		TInt  GetGeneralAttributesL(const RMessage2& aMessage);
       
   182 		TInt  GetSamplerAttributesL(const RMessage2& aMessage);
       
   183 		TInt  SetGeneralAttributesL(const RMessage2& aMessage);
       
   184 		TInt  SetSamplerAttributesL(const RMessage2& aMessage);
       
   185 		TInt  GetSamplerAttributeCountL(const RMessage2& aMessage);
       
   186 		TInt  RefreshStatus(const RMessage2& /*aMessage*/);
       
   187 
       
   188 		// from CProfilerErrorChecker
       
   189 		void  HandleSamplerControllerReadyL();
       
   190 		void  NotifyRequesterForSettingsUpdate();
       
   191 		void  HandleProfilerErrorChangeL( TInt aError );
       
   192 	    
       
   193 		void 				Finalise();
       
   194 		CProfilerSampleStream* GetSamplerStream();
       
   195 	    void  HandleError(TInt aErr);
       
   196 	    static TBool CheckLocationSanity(RFs& fs, const TDesC8& aLocation);
       
   197 private:
       
   198 							CProfiler(const TDesC& aSettingsFile);
       
   199 							~CProfiler();
       
   200 		void				ConstructL();
       
   201 		TInt 				LoadSettingsL(/*const TDesC& configFile*/);		
       
   202 		void                DoGetValueFromSettingsArray(CDesC8ArrayFlat* aLineArray, const TDesC8& aAttribute, TDes8& aValue);
       
   203 		void                UpdateSavedGeneralAttributes(CDesC8ArrayFlat* aSavedAttributes);
       
   204 		template<class T> CBufFlat* ExternalizeLC(const T& aElements);
       
   205 		
       
   206 		RProfiler::TSamplerState	State() const;
       
   207 
       
   208 		void DrainSampleStream();
       
   209 		void InstallStreamForActiveTraces(CSamplerPluginInterface& aSampler, CWriterPluginInterface& aWriter, TDesC& totalPrefix);
       
   210 		void SaveSettingsL();
       
   211 		
       
   212 		TInt HandleGeneralSettingsChange();
       
   213 		TInt CheckOldProfilerRunning();
       
   214 public:
       
   215         // trace file settings
       
   216 		TBuf8<KProfilerPrefixMaxLength>	iFilePrefix;
       
   217 		TBuf8<KProfilerPrefixMaxLength>	iDriveLetter;
       
   218 		TBuf8<KProfilerPrefixMaxLength*2> iTotalPrefix;
       
   219 
       
   220 		TBuf<256>                       iSettingsFileLocation;
       
   221 		
       
   222 		MProfilerController*			iServer;
       
   223 		RProfiler::TSamplerState		iState;
       
   224 		
       
   225 		CProfilerSampleStream* 			iUserStream;
       
   226 		
       
   227 		// plug-in controllers
       
   228 		CWriterController*				iWriterHandler;
       
   229 		CSamplerController*				iSamplerHandler;
       
   230 
       
   231 		// setting attribute containers
       
   232 		TGeneralAttributes				iGeneralAttributes;
       
   233 		CArrayFixFlat<TSamplerAttributes>*	iDefaultSamplerAttributesArray;
       
   234 		
       
   235 		// temporary settings file array container
       
   236 		CDesC8ArrayFlat*                iSavedLineArray;	
       
   237 		TInt                            iSavedLinesCount;
       
   238 	    // saved settings, add extra 1 byte space to end buffer with a '\n'
       
   239 	    TBuf8<KSettingsFileSize + 1>   iSettingsBuffer;   
       
   240 
       
   241 	    // P&S status properties
       
   242 		RProperty						iEngineStatus;
       
   243         RProperty                       iUpdateStatus;
       
   244 	    TBuf<128>                       iFileNameStream;
       
   245 private:
       
   246         TBool                           iSettingsFileLoaded;
       
   247         CProfilerErrorChecker*          iErrorChecker;
       
   248 };
       
   249 
       
   250 #include <piprofiler/ProfilerGenericClassesUsr.h>
       
   251 #endif	// __PROFILERENGINE__
       
   252