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