Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Flogger (File and Serial logger) server side header
23 #ifndef __COMSDBGSVR_H__
24 #define __COMSDBGSVR_H__
27 #include <comms-infras/commsdebugutility.h>
29 class CLogMessageBase;
30 class CIniFileWatcher;
33 class CLogStringMessage;
34 class CLogCommentMessage;
35 class CSecondaryThread;
36 class CShutDownMessage;
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");
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
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;
59 _LIT(KFloggerServerPanic, "Comsdbg internal");
61 typedef TBuf8<KMaxTagLength> TNameTag;
63 enum TFloggerServerPanics
75 }; ///< Stops us switching between flushing and nonflushing: We can only move from ENoValue to one of the others
78 * MLogArrayAccess - Provides an interface for other classes to interact with the log queue in CFileLoggerServer.
80 * Overridden by CFileLoggerServer.
85 virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage) = 0;
86 virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage) = 0;
87 virtual void PutOOMErrorInLog() = 0;
88 virtual void SignalCompletionSemaphore() = 0;
91 #if defined (__WINS__)
92 class CDebugPortProtocol;
96 * CFileLoggerServer - maintain server state
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
103 class CFileLoggerServer : public CServer2, public MLogArrayAccess
106 static CFileLoggerServer* NewL();
107 ~CFileLoggerServer();
109 virtual CSession2* NewSessionL(const TVersion& aVersion,const RMessage2& aMessage) const;
111 virtual TInt AppendAndGiveOwnership(CLogMessageBase* aMessage);
112 virtual void GetFirstMessageAndTakeOwnership(CLogMessageBase*& aMessage);
113 virtual void PutOOMErrorInLog();
114 virtual void SignalCompletionSemaphore();
116 void IniFileChanged(TDesC& aIniFile);
118 void __DbgKillTimeManager();
121 virtual TInt RunError(TInt aError);
126 void RePrepareForOOML();
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;
140 #if defined (__WINS__)
141 CDebugPortProtocol* iDebugWriter; ///< Win32 debug port support provider
145 class MIniFlushModeAndLogValidQuery;
146 class MIniLoggingMediaQuery;
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.
154 class CFileLogSession : public CSession2
157 static CFileLogSession* NewL(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery);
160 virtual void ServiceL(const RMessage2& aMessage);
162 void IniFileChanged();
163 void SetLoggingOnOffInClient();
165 CFileLogSession(MLogArrayAccess& aArrayAccess, const MIniFlushModeAndLogValidQuery& aLogValidQuery);
166 void CheckClientHasSetTagsL(const RMessage2& aMessage);
170 MLogArrayAccess& iArrayAccess;
171 const MIniFlushModeAndLogValidQuery& iFlushModeLogValidQuery;
173 RMessage2 iSetLogMessage;
178 * CSecondaryThread - An active object who's sole purpose is to start the second thread and keep it alive.
182 class CSecondaryThread : public CActive
185 static CSecondaryThread* NewL(MLogArrayAccess& aArrayAccess, TBool aFlushOn);
187 virtual void DoCancel();
188 TInt RunError(TInt aError);
189 void SignalRequestSemaphore();
192 CSecondaryThread(MLogArrayAccess& aArrayAccess, TBool aFlushOn);
194 void StartSecondaryThreadL(TBool aRestarting);
196 MLogArrayAccess& iArrayAccess;
197 CShutDownMessage* iShutDownMessage;
198 RThread iSecondaryThread;
204 #endif // __COMSDBGSVR_H__