1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/commsdebugutility/INC/comsdbgwriter.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,215 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// Flogger File and Serial logger header
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalComponent
1.24 +*/
1.25 +
1.26 +#ifndef __COMSDBGWRITER_H__
1.27 +#define __COMSDBGWRITER_H__
1.28 +
1.29 +#include <e32base.h>
1.30 +#include <f32file.h>
1.31 +#include <s32file.h>
1.32 +#include <d32comm.h>
1.33 +#include <platform/opensystemtrace.h>
1.34 +
1.35 +#include "comsdbgsvr.h"
1.36 +
1.37 +_LIT8(KTimeFormat,"#Time = hh:mm:ss\r\n");
1.38 +const TInt KHourOffset = 8;
1.39 +const TInt KMinuteOffset = 11;
1.40 +const TInt KSecondOffset = 14;
1.41 +const TInt KTimeStringLength = 18;
1.42 +
1.43 +class MLogMessageProtocol
1.44 + {
1.45 +public:
1.46 + virtual void ClearLog(const TFullName& aName) = 0;
1.47 + virtual void SetTimeL(const TTime& aTime) = 0;
1.48 + virtual void LogString(const TDesC8& aLogString, const TDesC8& aSubSystem, const TDesC8& aComponent, const TThreadId& aThreadId) = 0;
1.49 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent) = 0;
1.50 + virtual void LogComment(const TDesC8& aComment) = 0;
1.51 + virtual void MediaUpdate(const TDesC8& aMediaSetting, const TBool aForceFlush, const TDesC8& aLogPathSetting) = 0;
1.52 + virtual void ShutDown() = 0;
1.53 + };
1.54 +
1.55 +
1.56 +class CLoggerMediaBase;
1.57 +class MLogArrayAccess;
1.58 +
1.59 +/**
1.60 + * CLogManager - second/consumer/slave thread
1.61 + *
1.62 + * This class is responsible for implementing the second thread which
1.63 + * removes items from the logging queue and writes them to disk.
1.64 + * Maintains a pointer to the server's log queue, and a pointer to the
1.65 + * media base in use.
1.66 + */
1.67 +class CLogManager : public CBase, public MLogMessageProtocol
1.68 + {
1.69 +public:
1.70 + ~CLogManager();
1.71 + static CLogManager* NewL(MLogArrayAccess& aArrayAccess);
1.72 + static TInt ThreadEntryPoint(TAny* aPtr);
1.73 + static void DoRunThreadL(MLogArrayAccess& aArrayAccess);
1.74 + //from MLogMessageProtocol
1.75 + virtual void ClearLog(const TFullName& aName);
1.76 + virtual void SetTimeL(const TTime& aTime);
1.77 + virtual void LogString(const TDesC8& aLogString, const TDesC8& aSubSystem, const TDesC8& aComponent, const TThreadId& aThreadId);
1.78 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.79 + virtual void LogComment(const TDesC8& aComment);
1.80 + virtual void MediaUpdate(const TDesC8& aMediaSetting,const TBool aForceFlushOn, const TDesC8& aLogPathSetting);
1.81 + virtual void ShutDown();
1.82 +private:
1.83 + void WriteDateIntoLog(TBool firstTime);
1.84 + CLogManager(MLogArrayAccess& aArrayAccess);
1.85 + void ConstructL();
1.86 + void ConvertToNarrow(const TDesC& aSource, TDes8& aDestination);
1.87 + void DoMediaUpdateL(const TDesC8& aMediaSetting,const TBool aForceFlushOn, const TDesC8& aLogPathSetting);
1.88 + void DoStart();
1.89 +private:
1.90 + MLogArrayAccess& iArrayAccess;
1.91 + CLoggerMediaBase* iLogger;
1.92 + TBuf8<KTimeStringLength> iTimeString;
1.93 + TBuf8<KMaxMediaStringLength> iCurrentMediaSetting;
1.94 + TUint iTicksSinceLastLog;
1.95 + TBool iShutDown;
1.96 + TTimeIntervalDays iCurrentDate; ///< store date as # days since 1st Jan 0 AD so we can check when date changes
1.97 + TBool iLoggingEnabled;
1.98 + TFilePath iLogPath; // location of output. stored for comparison with next ini files changes
1.99 + };
1.100 +
1.101 +class CLoggerMediaBase : public CBase
1.102 + {
1.103 +public:
1.104 + virtual void LogString(const TDesC8& aString) = 0;
1.105 + virtual void ClearLogL() = 0;
1.106 + virtual void FlushLogL() = 0;
1.107 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent) = 0;
1.108 + virtual void SetForceFlush(const TBool aOn) = 0;
1.109 + TBool iForceBufferFlushAlways;
1.110 + };
1.111 +
1.112 +class CSerialWriter : public CLoggerMediaBase
1.113 + {
1.114 +public:
1.115 + ~CSerialWriter();
1.116 + static CSerialWriter* NewL();
1.117 + virtual void LogString(const TDesC8& aString);
1.118 + virtual void ClearLogL();
1.119 + virtual void FlushLogL();
1.120 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.121 + virtual void SetForceFlush(const TBool aOn);
1.122 + TInt LoadDevices();
1.123 + TInt OpenPort(TInt aPortNumber);
1.124 + TInt SetPortConfig();
1.125 +private:
1.126 + void ConstructL();
1.127 +private:
1.128 + RBusDevComm iSerialPort;
1.129 + RTimer iTimeoutTimer;
1.130 + TInt iInvalidCounter;
1.131 + };
1.132 +
1.133 +class CFileWriter : public CLoggerMediaBase
1.134 + {
1.135 +public:
1.136 + ~CFileWriter();
1.137 + static CFileWriter* NewL();
1.138 + virtual void LogString(const TDesC8& aString);
1.139 + virtual void ClearLogL();
1.140 + virtual void FlushLogL();
1.141 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.142 + virtual void SetForceFlush(const TBool aOn);
1.143 + void SetLogPath(const TDesC8& aLogPathSetting);
1.144 +private:
1.145 + void ConstructL();
1.146 + void DoFlushBufferToFileL();
1.147 + void DoLogBinaryDumpL(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.148 +private:
1.149 + RFs iFs;
1.150 + HBufC8* iHBuf;
1.151 + TBool iForceBufferFlushAlways;
1.152 + TFilePath iLogPath; // We can specifie a path in commsdbg.ini
1.153 + TName iLogFileName;
1.154 + };
1.155 +
1.156 +class CRDebugWriter : public CLoggerMediaBase
1.157 + {
1.158 +public:
1.159 + ~CRDebugWriter();
1.160 + static CRDebugWriter* NewL();
1.161 + virtual void LogString(const TDesC8& aString);
1.162 + virtual void ClearLogL();
1.163 + virtual void FlushLogL();
1.164 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.165 + virtual void SetForceFlush(const TBool aOn);
1.166 + };
1.167 +
1.168 +class COstv2Writer : public CLoggerMediaBase
1.169 + {
1.170 +public:
1.171 + static COstv2Writer* NewL();
1.172 +
1.173 + COstv2Writer() : iContext(0x101fe69e, TRACE_STATE) {};
1.174 +
1.175 + virtual void LogString(const TDesC8& aString);
1.176 + virtual void ClearLogL();
1.177 + virtual void FlushLogL();
1.178 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.179 + virtual void SetForceFlush(const TBool aOn);
1.180 +
1.181 +private:
1.182 + TTraceContext iContext;
1.183 + };
1.184 +
1.185 +#if defined (__WINS__)
1.186 +
1.187 +class CDebugPortWriter : public CLoggerMediaBase
1.188 + {
1.189 +public:
1.190 + static CDebugPortWriter* NewL();
1.191 + virtual void LogString(const TDesC8& aString);
1.192 + virtual void ClearLogL();
1.193 + virtual void FlushLogL();
1.194 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.195 + virtual void SetForceFlush(const TBool aOn);
1.196 +private:
1.197 + };
1.198 +
1.199 +class CDebugPortProtocol : public MLogMessageProtocol
1.200 + {
1.201 +public:
1.202 + static CDebugPortProtocol* NewL();
1.203 + ~CDebugPortProtocol();
1.204 + virtual void ClearLog(const TFullName& aName);
1.205 + virtual void SetTimeL(const TTime& aTime);
1.206 + virtual void LogString(const TDesC8& aLogString, const TDesC8& aSubSystem, const TDesC8& aComponent, const TThreadId& aThreadId);
1.207 + virtual void LogBinaryDump(const TDesC8& aBinaryString, const TDesC8& aSubSystem, const TDesC8& aComponent);
1.208 + virtual void LogComment(const TDesC8& aComment);
1.209 + virtual void MediaUpdate(const TDesC8& aMediaSetting, const TBool aForceFlushOn, const TDesC8& aLogPathSetting);
1.210 + virtual void ShutDown();
1.211 +private:
1.212 + void ConstructL();
1.213 + CDebugPortWriter* iDebugWriter;
1.214 + };
1.215 +
1.216 +#endif
1.217 +
1.218 +#endif //__COMSDBGWRITER_H__