1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/traceservices/commsdebugutility/INC/comsdbgsvr.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,205 @@
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) server side header
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 + @internalComponent
1.24 +*/
1.25 +
1.26 +#ifndef __COMSDBGSVR_H__
1.27 +#define __COMSDBGSVR_H__
1.28 +
1.29 +#include <f32file.h>
1.30 +#include <comms-infras/commsdebugutility.h>
1.31 +
1.32 +class CLogMessageBase;
1.33 +class CIniFileWatcher;
1.34 +class CIniFileParser;
1.35 +class CTimeManager;
1.36 +class CLogStringMessage;
1.37 +class CLogCommentMessage;
1.38 +class CSecondaryThread;
1.39 +class CShutDownMessage;
1.40 +
1.41 +_LIT(KFloggerIniInROM, "Z:\\resource\\commsdbg.ini");
1.42 +_LIT(KFloggerIniFile, "commsdbg.ini");
1.43 +_LIT(KFloggerIniOldFile, "comsdbg.ini");
1.44 +_LIT(KFloggerIniOldFilePartialPath, ":\\logs\\comsdbg.ini");
1.45 +_LIT(KFloggerIniDir, "\\logs\\");
1.46 +_LIT(KFloggerIniRscDir, "\\resource\\");
1.47 +_LIT(KFloggerDfltIniPartialPath, ":\\logs\\commsdbg.ini");
1.48 +
1.49 +_LIT8(KFileMedia, "File");
1.50 +_LIT8(KSerial1Media, "Serial::1");
1.51 +_LIT8(KSerial2Media, "Serial::2");
1.52 +_LIT8(KRDebugMedia, "RDebug");
1.53 +_LIT8(KOSTv2Media, "OSTv2");
1.54 +_LIT8(KDefaultMedia, "Default"); // This is not supplied in the ini file, but is used to set the media
1.55 + // before the media is read from the ini file.
1.56 +const TInt KMaxMediaStringLength = 9; //This ties in with the above three strings
1.57 +
1.58 +const TInt KMaxLoggingPathStringLength = 100; // Given that "c:\logs\log.txt" = 15, 100 should be enough.
1.59 + // The whole purpose is just to allow someone to output to a different drive
1.60 +typedef TBuf8<KMaxLoggingPathStringLength> TFilePath;
1.61 +
1.62 +_LIT(KFloggerServerPanic, "Comsdbg internal");
1.63 +
1.64 +typedef TBuf8<KMaxTagLength> TNameTag;
1.65 +
1.66 +enum TFloggerServerPanics
1.67 + {
1.68 + ENullMessageInArray,
1.69 + ENoLoggingMediaSetUp,
1.70 + EBadMessageFunction
1.71 + };
1.72 +
1.73 +enum TFlushStates
1.74 + {
1.75 + ENoValue,
1.76 + EFlushOn,
1.77 + EFlushOff
1.78 + }; ///< Stops us switching between flushing and nonflushing: We can only move from ENoValue to one of the others
1.79 +
1.80 +/**
1.81 + * MLogArrayAccess - Provides an interface for other classes to interact with the log queue in CFileLoggerServer.
1.82 + *
1.83 + * Overridden by CFileLoggerServer.
1.84 + */
1.85 +class MLogArrayAccess
1.86 + {
1.87 +public:
1.88 + virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage) = 0;
1.89 + virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage) = 0;
1.90 + virtual void PutOOMErrorInLog() = 0;
1.91 + virtual void SignalCompletionSemaphore() = 0;
1.92 + };
1.93 +
1.94 +#if defined (__WINS__)
1.95 +class CDebugPortProtocol;
1.96 +#endif
1.97 +
1.98 +/**
1.99 + * CFileLoggerServer - maintain server state
1.100 + *
1.101 + * This class is responsible for maintaining the server state. It provides
1.102 + * control of the second thread, the ini file change notifier, the current
1.103 + * list of valid logs and other ini file settings, and
1.104 + * the log queue.
1.105 + */
1.106 +class CFileLoggerServer : public CServer2, public MLogArrayAccess
1.107 + {
1.108 +public:
1.109 + static CFileLoggerServer* NewL();
1.110 + ~CFileLoggerServer();
1.111 +// CServer
1.112 + virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
1.113 +// MLogArrayAccess
1.114 + virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage);
1.115 + virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage);
1.116 + virtual void PutOOMErrorInLog();
1.117 + virtual void SignalCompletionSemaphore();
1.118 +
1.119 + void IniFileChanged(TDesC& aIniFile);
1.120 +#ifdef _DEBUG
1.121 + void __DbgKillTimeManager();
1.122 +#endif
1.123 +protected:
1.124 + virtual TInt RunError(TInt aError);
1.125 +private:
1.126 + CFileLoggerServer();
1.127 + void ConstructL();
1.128 + void UpdateMediaL();
1.129 + void RePrepareForOOML();
1.130 +private:
1.131 + RPointerArray<CLogMessageBase> iLogMessageArray;
1.132 + TBool iArrayHasSpaceForWrite;
1.133 + RSemaphore iCompletionSemaphore; ///< used to signal completion of write when flushing
1.134 + RCriticalSection iCriticalSection; ///< manages atomic access to array of log messages.
1.135 + CIniFileWatcher* iIniFileWatcher;
1.136 + CIniFileWatcher* iIniOldFileWatcher;
1.137 + CIniFileParser* iIniFileParser;
1.138 + CTimeManager* iTimeManager;
1.139 + CLogCommentMessage* iPreAllocatedErrorMessage; ///< For error mesg to be allocated before all memory is consumed.
1.140 + CSecondaryThread* iSecondaryThread;
1.141 + RFs iFs;
1.142 +
1.143 +#if defined (__WINS__)
1.144 + CDebugPortProtocol* iDebugWriter; ///< Win32 debug port support provider
1.145 +#endif
1.146 + };
1.147 +
1.148 +class MIniFlushModeAndLogValidQuery;
1.149 +class MIniLoggingMediaQuery;
1.150 +
1.151 +/**
1.152 + * CFileLogSession -
1.153 + *
1.154 + * This class is responsible for servicing the client requests sent. It forms the back-end server side of
1.155 + * each client connection to flogger server and implements the ServiceL() to service all client requests.
1.156 + */
1.157 +class CFileLogSession : public CSession2
1.158 + {
1.159 +public:
1.160 + static CFileLogSession* NewL(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery);
1.161 + ~CFileLogSession();
1.162 + // CSession
1.163 + virtual void ServiceL(const RMessage2& aMessage);
1.164 + //
1.165 + void IniFileChanged();
1.166 + void SetLoggingOnOffInClient();
1.167 +private:
1.168 + CFileLogSession(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery);
1.169 + void CheckClientHasSetTagsL(const RMessage2& aMessage);
1.170 +private:
1.171 + TNameTag iSubsystem;
1.172 + TNameTag iComponent;
1.173 + MLogArrayAccess& iArrayAccess;
1.174 + const MIniFlushModeAndLogValidQuery& iFlushModeLogValidQuery;
1.175 + TBool iLogValid;
1.176 + RMessage2 iSetLogMessage;
1.177 + TThreadId iThreadId;
1.178 + };
1.179 +
1.180 +/**
1.181 + * CSecondaryThread - An active object who's sole purpose is to start the second thread and keep it alive.
1.182 + *
1.183 + * .
1.184 + */
1.185 +class CSecondaryThread : public CActive
1.186 + {
1.187 +public:
1.188 + static CSecondaryThread* NewL(MLogArrayAccess& aArrayAccess, TBool aFlushOn);
1.189 + virtual void RunL();
1.190 + virtual void DoCancel();
1.191 + TInt RunError(TInt aError);
1.192 + void SignalRequestSemaphore();
1.193 + ~CSecondaryThread();
1.194 +private:
1.195 + CSecondaryThread(MLogArrayAccess& aArrayAccess, TBool aFlushOn);
1.196 + void ConstructL();
1.197 + void StartSecondaryThreadL(TBool aRestarting);
1.198 +private:
1.199 + MLogArrayAccess& iArrayAccess;
1.200 + CShutDownMessage* iShutDownMessage;
1.201 + RThread iSecondaryThread;
1.202 + TBool iFlushingOn;
1.203 + };
1.204 +
1.205 +
1.206 +
1.207 +#endif // __COMSDBGSVR_H__
1.208 +