traceservices/commsdebugutility/INC/comsdbgwriter.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Flogger File and Serial logger header
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22  
       
    23 #ifndef __COMSDBGWRITER_H__
       
    24 #define __COMSDBGWRITER_H__
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <f32file.h>
       
    28 #include <s32file.h>
       
    29 #include <d32comm.h>
       
    30 #include <platform/opensystemtrace.h>
       
    31 
       
    32 #include "comsdbgsvr.h"
       
    33 
       
    34 _LIT8(KTimeFormat,"#Time = hh:mm:ss\r\n");
       
    35 const TInt KHourOffset = 8;
       
    36 const TInt KMinuteOffset = 11;
       
    37 const TInt KSecondOffset = 14;
       
    38 const TInt KTimeStringLength = 18;
       
    39 
       
    40 class MLogMessageProtocol
       
    41 	{
       
    42 public:
       
    43 	virtual void ClearLog(const TFullName& aName) = 0;
       
    44 	virtual void SetTimeL(const TTime& aTime) = 0;
       
    45 	virtual void LogString(const TDesC8& aLogString, const TDesC8& aSubSystem, const TDesC8& aComponent, const TThreadId& aThreadId) = 0;
       
    46 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent) = 0;
       
    47 	virtual void LogComment(const TDesC8& aComment) = 0;
       
    48 	virtual void MediaUpdate(const TDesC8& aMediaSetting, const TBool aForceFlush, const TDesC8& aLogPathSetting) = 0;
       
    49 	virtual void ShutDown() = 0;
       
    50 	};
       
    51 
       
    52 
       
    53 class CLoggerMediaBase;
       
    54 class MLogArrayAccess;
       
    55 
       
    56 /**
       
    57  * CLogManager - second/consumer/slave thread
       
    58  *
       
    59  * This class is responsible for implementing the second thread which
       
    60  * removes items from the logging queue and writes them to disk.
       
    61  * Maintains a pointer to the server's log queue, and a pointer to the
       
    62  * media base in use.
       
    63  */
       
    64 class CLogManager : public CBase, public MLogMessageProtocol
       
    65 	{
       
    66 public:
       
    67 	~CLogManager();
       
    68 	static CLogManager* NewL(MLogArrayAccess& aArrayAccess);
       
    69 	static TInt ThreadEntryPoint(TAny* aPtr);
       
    70 	static void DoRunThreadL(MLogArrayAccess& aArrayAccess);
       
    71 	//from MLogMessageProtocol
       
    72 	virtual void ClearLog(const TFullName& aName);
       
    73 	virtual void SetTimeL(const TTime& aTime);
       
    74 	virtual void LogString(const TDesC8& aLogString, const TDesC8& aSubSystem, const TDesC8& aComponent, const TThreadId& aThreadId);
       
    75 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
    76 	virtual void LogComment(const TDesC8& aComment);
       
    77 	virtual void MediaUpdate(const TDesC8& aMediaSetting,const TBool aForceFlushOn, const TDesC8& aLogPathSetting);
       
    78 	virtual void ShutDown();
       
    79 private:
       
    80 	void WriteDateIntoLog(TBool firstTime);
       
    81 	CLogManager(MLogArrayAccess& aArrayAccess);
       
    82 	void ConstructL();
       
    83 	void ConvertToNarrow(const TDesC& aSource, TDes8& aDestination);
       
    84 	void DoMediaUpdateL(const TDesC8& aMediaSetting,const TBool aForceFlushOn, const TDesC8& aLogPathSetting);
       
    85 	void DoStart();
       
    86 private:
       
    87 	MLogArrayAccess& iArrayAccess;
       
    88 	CLoggerMediaBase* iLogger;
       
    89 	TBuf8<KTimeStringLength> iTimeString;
       
    90 	TBuf8<KMaxMediaStringLength> iCurrentMediaSetting;
       
    91 	TUint iTicksSinceLastLog;
       
    92 	TBool iShutDown;
       
    93 	TTimeIntervalDays iCurrentDate;			///< store date as # days since 1st Jan 0 AD so we can check when date changes
       
    94 	TBool iLoggingEnabled;
       
    95 	TFilePath iLogPath;	// location of output. stored for comparison with next ini files changes
       
    96 	};
       
    97 
       
    98 class CLoggerMediaBase : public CBase
       
    99 	{
       
   100 public:
       
   101 	virtual void LogString(const TDesC8& aString) = 0;
       
   102 	virtual void ClearLogL() = 0;
       
   103 	virtual void FlushLogL() = 0;
       
   104 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent) = 0;
       
   105 	virtual void SetForceFlush(const TBool aOn) = 0;
       
   106 	TBool iForceBufferFlushAlways;
       
   107 	};
       
   108 
       
   109 class CSerialWriter : public CLoggerMediaBase
       
   110 	{
       
   111 public:
       
   112 	~CSerialWriter();
       
   113 	static CSerialWriter* NewL();
       
   114 	virtual void LogString(const TDesC8& aString);
       
   115 	virtual void ClearLogL();
       
   116 	virtual void FlushLogL();
       
   117 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   118 	virtual void SetForceFlush(const TBool aOn);
       
   119 	TInt LoadDevices();
       
   120 	TInt OpenPort(TInt aPortNumber);
       
   121 	TInt SetPortConfig();
       
   122 private:
       
   123 	void ConstructL();
       
   124 private:
       
   125 	RBusDevComm iSerialPort;
       
   126 	RTimer iTimeoutTimer;
       
   127 	TInt iInvalidCounter;
       
   128 	};
       
   129 
       
   130 class CFileWriter : public CLoggerMediaBase
       
   131 	{
       
   132 public:
       
   133 	~CFileWriter();
       
   134 	static CFileWriter* NewL();
       
   135 	virtual void LogString(const TDesC8& aString);
       
   136 	virtual void ClearLogL();
       
   137 	virtual void FlushLogL();
       
   138 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   139 	virtual void SetForceFlush(const TBool aOn);
       
   140 	void SetLogPath(const TDesC8& aLogPathSetting);
       
   141 private:
       
   142 	void ConstructL();
       
   143 	void DoFlushBufferToFileL();
       
   144 	void DoLogBinaryDumpL(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   145 private:
       
   146 	RFs iFs;
       
   147 	HBufC8* iHBuf;
       
   148 	TBool iForceBufferFlushAlways;
       
   149 	TFilePath iLogPath;	// We can specifie a path in commsdbg.ini
       
   150 	TName iLogFileName;	
       
   151 	};
       
   152 
       
   153 class CRDebugWriter : public CLoggerMediaBase
       
   154 	{
       
   155 public:
       
   156 	~CRDebugWriter();
       
   157 	static CRDebugWriter* NewL();
       
   158 	virtual void LogString(const TDesC8& aString);
       
   159 	virtual void ClearLogL();
       
   160 	virtual void FlushLogL();
       
   161 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   162 	virtual void SetForceFlush(const TBool aOn);
       
   163 	};
       
   164 
       
   165 class COstv2Writer : public CLoggerMediaBase
       
   166 	{
       
   167 public:
       
   168 	static COstv2Writer* NewL();
       
   169 
       
   170 	COstv2Writer() : iContext(0x101fe69e, TRACE_STATE) {};
       
   171 	
       
   172 	virtual void LogString(const TDesC8& aString);
       
   173 	virtual void ClearLogL();
       
   174 	virtual void FlushLogL();
       
   175 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   176 	virtual void SetForceFlush(const TBool aOn);
       
   177 	
       
   178 private:
       
   179 	TTraceContext iContext;
       
   180 	};
       
   181 
       
   182 #if defined (__WINS__)
       
   183 
       
   184 class CDebugPortWriter : public CLoggerMediaBase
       
   185 	{
       
   186 public:
       
   187 	static CDebugPortWriter* NewL();
       
   188 	virtual void LogString(const TDesC8& aString);
       
   189 	virtual void ClearLogL();
       
   190 	virtual void FlushLogL();
       
   191 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   192 	virtual void SetForceFlush(const TBool aOn);
       
   193 private:
       
   194 	};
       
   195 
       
   196 class CDebugPortProtocol : public MLogMessageProtocol
       
   197 	{
       
   198 public:
       
   199 	static CDebugPortProtocol* NewL();
       
   200 	~CDebugPortProtocol();
       
   201 	virtual void ClearLog(const TFullName& aName);
       
   202 	virtual void SetTimeL(const TTime& aTime);
       
   203 	virtual void LogString(const TDesC8& aLogString, const TDesC8& aSubSystem, const TDesC8& aComponent, const TThreadId& aThreadId);
       
   204 	virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
       
   205 	virtual void LogComment(const TDesC8& aComment);
       
   206 	virtual void MediaUpdate(const TDesC8& aMediaSetting, const TBool aForceFlushOn, const TDesC8& aLogPathSetting);
       
   207 	virtual void ShutDown();
       
   208 private:
       
   209 	void ConstructL();
       
   210 	CDebugPortWriter* iDebugWriter;
       
   211 	};
       
   212 
       
   213 #endif
       
   214 
       
   215 #endif //__COMSDBGWRITER_H__