traceservices/commsdebugutility/INC/comsdbgsvr.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) server side header
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #ifndef __COMSDBGSVR_H__
       
    24 #define __COMSDBGSVR_H__
       
    25 
       
    26 #include <f32file.h>
       
    27 #include <comms-infras/commsdebugutility.h>
       
    28 
       
    29 class CLogMessageBase;
       
    30 class CIniFileWatcher;
       
    31 class CIniFileParser;
       
    32 class CTimeManager;
       
    33 class CLogStringMessage;
       
    34 class CLogCommentMessage;
       
    35 class CSecondaryThread;
       
    36 class CShutDownMessage;
       
    37 
       
    38 _LIT(KFloggerIniInROM, "Z:\\resource\\commsdbg.ini");
       
    39 _LIT(KFloggerIniFile, "commsdbg.ini");
       
    40 _LIT(KFloggerIniOldFile, "comsdbg.ini");
       
    41 _LIT(KFloggerIniOldFilePartialPath, ":\\logs\\comsdbg.ini");
       
    42 _LIT(KFloggerIniDir, "\\logs\\");
       
    43 _LIT(KFloggerIniRscDir, "\\resource\\");
       
    44 _LIT(KFloggerDfltIniPartialPath, ":\\logs\\commsdbg.ini");
       
    45 
       
    46 _LIT8(KFileMedia, "File");
       
    47 _LIT8(KSerial1Media, "Serial::1");
       
    48 _LIT8(KSerial2Media, "Serial::2");
       
    49 _LIT8(KRDebugMedia, "RDebug");
       
    50 _LIT8(KOSTv2Media, "OSTv2");
       
    51 _LIT8(KDefaultMedia, "Default");		// This is not supplied in the ini file, but is used to set the media
       
    52 										// before the media is read from the ini file.
       
    53 const TInt KMaxMediaStringLength = 9;	//This ties in with the above three strings
       
    54 
       
    55 const TInt KMaxLoggingPathStringLength = 100;	// Given that "c:\logs\log.txt" = 15, 100 should be enough.
       
    56                                                 // The whole purpose is just to allow someone to output to a different drive
       
    57 typedef TBuf8<KMaxLoggingPathStringLength> TFilePath;
       
    58 
       
    59 _LIT(KFloggerServerPanic, "Comsdbg internal");
       
    60 
       
    61 typedef TBuf8<KMaxTagLength> TNameTag;
       
    62 
       
    63 enum TFloggerServerPanics
       
    64 	{
       
    65 	ENullMessageInArray,
       
    66 	ENoLoggingMediaSetUp,
       
    67 	EBadMessageFunction
       
    68 	};
       
    69 
       
    70 enum TFlushStates 
       
    71 	{
       
    72 	ENoValue,
       
    73 	EFlushOn, 
       
    74 	EFlushOff
       
    75 	}; ///< Stops us switching between flushing and nonflushing: We can only move from ENoValue to one of the others
       
    76 
       
    77 /**
       
    78  * MLogArrayAccess - Provides an interface for other classes to interact with the log queue in CFileLoggerServer.
       
    79  *
       
    80  * Overridden by CFileLoggerServer.
       
    81  */
       
    82 class MLogArrayAccess
       
    83 	{
       
    84 public:
       
    85 	virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage) = 0;
       
    86 	virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage) = 0;
       
    87 	virtual void PutOOMErrorInLog() = 0;
       
    88 	virtual void SignalCompletionSemaphore() = 0;
       
    89 	};
       
    90 
       
    91 #if defined (__WINS__)
       
    92 class CDebugPortProtocol;
       
    93 #endif
       
    94 
       
    95 /**
       
    96  * CFileLoggerServer - maintain server state
       
    97  *
       
    98  * This class is responsible for maintaining the server state. It provides
       
    99  * control of the second thread, the ini file change notifier, the current
       
   100  * list of valid logs and other ini file settings, and
       
   101  * the log queue.
       
   102  */
       
   103 class CFileLoggerServer : public CServer2, public MLogArrayAccess
       
   104 	{
       
   105 public:
       
   106 	static CFileLoggerServer* NewL();
       
   107 	~CFileLoggerServer();
       
   108 // CServer
       
   109 	virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
       
   110 // MLogArrayAccess
       
   111 	virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage);
       
   112 	virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage);
       
   113 	virtual void PutOOMErrorInLog();
       
   114 	virtual void SignalCompletionSemaphore();
       
   115 
       
   116 	void IniFileChanged(TDesC& aIniFile);
       
   117 #ifdef _DEBUG
       
   118 	void __DbgKillTimeManager();
       
   119 #endif
       
   120 protected:
       
   121 	virtual TInt RunError(TInt aError);
       
   122 private:
       
   123 	CFileLoggerServer();
       
   124 	void ConstructL();
       
   125 	void UpdateMediaL();
       
   126 	void RePrepareForOOML();
       
   127 private:
       
   128 	RPointerArray<CLogMessageBase> iLogMessageArray;
       
   129 	TBool iArrayHasSpaceForWrite;
       
   130 	RSemaphore iCompletionSemaphore;     ///< used to signal completion of write when flushing
       
   131 	RCriticalSection iCriticalSection;         ///< manages atomic access to array of log messages.
       
   132 	CIniFileWatcher* iIniFileWatcher;
       
   133 	CIniFileWatcher* iIniOldFileWatcher;
       
   134 	CIniFileParser* iIniFileParser;
       
   135 	CTimeManager* iTimeManager;
       
   136 	CLogCommentMessage* iPreAllocatedErrorMessage;	///< For error mesg to be allocated before all memory is consumed.
       
   137 	CSecondaryThread* iSecondaryThread;
       
   138 	RFs iFs;
       
   139 
       
   140 #if defined (__WINS__)
       
   141 	CDebugPortProtocol* iDebugWriter;   ///< Win32 debug port support provider
       
   142 #endif
       
   143 	};	
       
   144 
       
   145 class MIniFlushModeAndLogValidQuery;
       
   146 class MIniLoggingMediaQuery;
       
   147 
       
   148 /**
       
   149  * CFileLogSession -  
       
   150  *
       
   151  * This class is responsible for servicing the client requests sent. It forms the back-end server side of
       
   152  * each client connection to flogger server and implements the ServiceL() to service all client requests.
       
   153  */
       
   154 class CFileLogSession : public CSession2
       
   155 	{
       
   156 public:
       
   157 	static CFileLogSession* NewL(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery);
       
   158 	~CFileLogSession();
       
   159 	// CSession
       
   160 	virtual void ServiceL(const RMessage2& aMessage);
       
   161 	//
       
   162 	void IniFileChanged();
       
   163 	void SetLoggingOnOffInClient();
       
   164 private:
       
   165 	CFileLogSession(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery);
       
   166 	void CheckClientHasSetTagsL(const RMessage2& aMessage);
       
   167 private:
       
   168 	TNameTag iSubsystem;
       
   169 	TNameTag iComponent;
       
   170 	MLogArrayAccess& iArrayAccess;
       
   171 	const MIniFlushModeAndLogValidQuery& iFlushModeLogValidQuery;
       
   172 	TBool iLogValid;
       
   173 	RMessage2 iSetLogMessage;
       
   174 	TThreadId iThreadId;
       
   175 	};
       
   176 
       
   177 /**
       
   178  * CSecondaryThread - An active object who's sole purpose is to start the second thread and keep it alive.
       
   179  *
       
   180  * .
       
   181  */
       
   182 class CSecondaryThread : public CActive
       
   183 	{
       
   184 public:
       
   185 	static CSecondaryThread* NewL(MLogArrayAccess& aArrayAccess, TBool aFlushOn);
       
   186 	virtual void RunL();
       
   187 	virtual void DoCancel();
       
   188 	TInt RunError(TInt aError);
       
   189 	void SignalRequestSemaphore();
       
   190 	~CSecondaryThread();
       
   191 private:
       
   192 	CSecondaryThread(MLogArrayAccess& aArrayAccess, TBool aFlushOn);
       
   193 	void ConstructL();
       
   194 	void StartSecondaryThreadL(TBool aRestarting);
       
   195 private:
       
   196 	MLogArrayAccess& iArrayAccess;
       
   197 	CShutDownMessage* iShutDownMessage;
       
   198 	RThread iSecondaryThread;
       
   199 	TBool iFlushingOn;
       
   200 	};
       
   201 
       
   202 
       
   203 
       
   204 #endif // __COMSDBGSVR_H__
       
   205