sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Flogger (File and Serial logger) server side header sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalComponent sl@0: */ sl@0: sl@0: #ifndef __COMSDBGSVR_H__ sl@0: #define __COMSDBGSVR_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: class CLogMessageBase; sl@0: class CIniFileWatcher; sl@0: class CIniFileParser; sl@0: class CTimeManager; sl@0: class CLogStringMessage; sl@0: class CLogCommentMessage; sl@0: class CSecondaryThread; sl@0: class CShutDownMessage; sl@0: sl@0: _LIT(KFloggerIniInROM, "Z:\\resource\\commsdbg.ini"); sl@0: _LIT(KFloggerIniFile, "commsdbg.ini"); sl@0: _LIT(KFloggerIniOldFile, "comsdbg.ini"); sl@0: _LIT(KFloggerIniOldFilePartialPath, ":\\logs\\comsdbg.ini"); sl@0: _LIT(KFloggerIniDir, "\\logs\\"); sl@0: _LIT(KFloggerIniRscDir, "\\resource\\"); sl@0: _LIT(KFloggerDfltIniPartialPath, ":\\logs\\commsdbg.ini"); sl@0: sl@0: _LIT8(KFileMedia, "File"); sl@0: _LIT8(KSerial1Media, "Serial::1"); sl@0: _LIT8(KSerial2Media, "Serial::2"); sl@0: _LIT8(KRDebugMedia, "RDebug"); sl@0: _LIT8(KOSTv2Media, "OSTv2"); sl@0: _LIT8(KDefaultMedia, "Default"); // This is not supplied in the ini file, but is used to set the media sl@0: // before the media is read from the ini file. sl@0: const TInt KMaxMediaStringLength = 9; //This ties in with the above three strings sl@0: sl@0: const TInt KMaxLoggingPathStringLength = 100; // Given that "c:\logs\log.txt" = 15, 100 should be enough. sl@0: // The whole purpose is just to allow someone to output to a different drive sl@0: typedef TBuf8 TFilePath; sl@0: sl@0: _LIT(KFloggerServerPanic, "Comsdbg internal"); sl@0: sl@0: typedef TBuf8 TNameTag; sl@0: sl@0: enum TFloggerServerPanics sl@0: { sl@0: ENullMessageInArray, sl@0: ENoLoggingMediaSetUp, sl@0: EBadMessageFunction sl@0: }; sl@0: sl@0: enum TFlushStates sl@0: { sl@0: ENoValue, sl@0: EFlushOn, sl@0: EFlushOff sl@0: }; ///< Stops us switching between flushing and nonflushing: We can only move from ENoValue to one of the others sl@0: sl@0: /** sl@0: * MLogArrayAccess - Provides an interface for other classes to interact with the log queue in CFileLoggerServer. sl@0: * sl@0: * Overridden by CFileLoggerServer. sl@0: */ sl@0: class MLogArrayAccess sl@0: { sl@0: public: sl@0: virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage) = 0; sl@0: virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage) = 0; sl@0: virtual void PutOOMErrorInLog() = 0; sl@0: virtual void SignalCompletionSemaphore() = 0; sl@0: }; sl@0: sl@0: #if defined (__WINS__) sl@0: class CDebugPortProtocol; sl@0: #endif sl@0: sl@0: /** sl@0: * CFileLoggerServer - maintain server state sl@0: * sl@0: * This class is responsible for maintaining the server state. It provides sl@0: * control of the second thread, the ini file change notifier, the current sl@0: * list of valid logs and other ini file settings, and sl@0: * the log queue. sl@0: */ sl@0: class CFileLoggerServer : public CServer2, public MLogArrayAccess sl@0: { sl@0: public: sl@0: static CFileLoggerServer* NewL(); sl@0: ~CFileLoggerServer(); sl@0: // CServer sl@0: virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const; sl@0: // MLogArrayAccess sl@0: virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage); sl@0: virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage); sl@0: virtual void PutOOMErrorInLog(); sl@0: virtual void SignalCompletionSemaphore(); sl@0: sl@0: void IniFileChanged(TDesC& aIniFile); sl@0: #ifdef _DEBUG sl@0: void __DbgKillTimeManager(); sl@0: #endif sl@0: protected: sl@0: virtual TInt RunError(TInt aError); sl@0: private: sl@0: CFileLoggerServer(); sl@0: void ConstructL(); sl@0: void UpdateMediaL(); sl@0: void RePrepareForOOML(); sl@0: private: sl@0: RPointerArray iLogMessageArray; sl@0: TBool iArrayHasSpaceForWrite; sl@0: RSemaphore iCompletionSemaphore; ///< used to signal completion of write when flushing sl@0: RCriticalSection iCriticalSection; ///< manages atomic access to array of log messages. sl@0: CIniFileWatcher* iIniFileWatcher; sl@0: CIniFileWatcher* iIniOldFileWatcher; sl@0: CIniFileParser* iIniFileParser; sl@0: CTimeManager* iTimeManager; sl@0: CLogCommentMessage* iPreAllocatedErrorMessage; ///< For error mesg to be allocated before all memory is consumed. sl@0: CSecondaryThread* iSecondaryThread; sl@0: RFs iFs; sl@0: sl@0: #if defined (__WINS__) sl@0: CDebugPortProtocol* iDebugWriter; ///< Win32 debug port support provider sl@0: #endif sl@0: }; sl@0: sl@0: class MIniFlushModeAndLogValidQuery; sl@0: class MIniLoggingMediaQuery; sl@0: sl@0: /** sl@0: * CFileLogSession - sl@0: * sl@0: * This class is responsible for servicing the client requests sent. It forms the back-end server side of sl@0: * each client connection to flogger server and implements the ServiceL() to service all client requests. sl@0: */ sl@0: class CFileLogSession : public CSession2 sl@0: { sl@0: public: sl@0: static CFileLogSession* NewL(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery); sl@0: ~CFileLogSession(); sl@0: // CSession sl@0: virtual void ServiceL(const RMessage2& aMessage); sl@0: // sl@0: void IniFileChanged(); sl@0: void SetLoggingOnOffInClient(); sl@0: private: sl@0: CFileLogSession(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery); sl@0: void CheckClientHasSetTagsL(const RMessage2& aMessage); sl@0: private: sl@0: TNameTag iSubsystem; sl@0: TNameTag iComponent; sl@0: MLogArrayAccess& iArrayAccess; sl@0: const MIniFlushModeAndLogValidQuery& iFlushModeLogValidQuery; sl@0: TBool iLogValid; sl@0: RMessage2 iSetLogMessage; sl@0: TThreadId iThreadId; sl@0: }; sl@0: sl@0: /** sl@0: * CSecondaryThread - An active object who's sole purpose is to start the second thread and keep it alive. sl@0: * sl@0: * . sl@0: */ sl@0: class CSecondaryThread : public CActive sl@0: { sl@0: public: sl@0: static CSecondaryThread* NewL(MLogArrayAccess& aArrayAccess, TBool aFlushOn); sl@0: virtual void RunL(); sl@0: virtual void DoCancel(); sl@0: TInt RunError(TInt aError); sl@0: void SignalRequestSemaphore(); sl@0: ~CSecondaryThread(); sl@0: private: sl@0: CSecondaryThread(MLogArrayAccess& aArrayAccess, TBool aFlushOn); sl@0: void ConstructL(); sl@0: void StartSecondaryThreadL(TBool aRestarting); sl@0: private: sl@0: MLogArrayAccess& iArrayAccess; sl@0: CShutDownMessage* iShutDownMessage; sl@0: RThread iSecondaryThread; sl@0: TBool iFlushingOn; sl@0: }; sl@0: sl@0: sl@0: sl@0: #endif // __COMSDBGSVR_H__ sl@0: