testexecmdw/filelogger/src/server.cpp
author Johnson Ma <johnson.ma@nokia.com>
Mon, 08 Mar 2010 15:03:44 +0800
changeset 0 3e07fef1e154
permissions -rw-r--r--
Initial EPL Contribution
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     1
/*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     8
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    11
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    12
* Contributors:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    13
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    14
* Description:  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    15
* Main log server engine.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    16
* Process log requests from multiple clients simultaneously.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    17
*
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    18
*/
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    19
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    20
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    21
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    22
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    23
 @file server.cpp
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    24
*/
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    25
#include "server.h"
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    26
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    27
CLogServer* CLogServer::NewL()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    28
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    29
 * @return - Instance of the log server
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    30
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    31
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    32
	CLogServer * server = new (ELeave) CLogServer();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    33
	CleanupStack::PushL(server);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    34
	server->ConstructL();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    35
	// CServer base class call
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    36
	server->StartL(KFileLogrerServerName);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    37
	CleanupStack::Pop(server);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    38
	return server;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    39
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    40
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    41
void CLogServer::ConstructL()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    42
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    43
 * Second phase construction
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    44
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    45
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    46
	User::LeaveIfError(Fs().Connect());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    47
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    48
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    49
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    50
CLogServer::CLogServer() : CServer2(EPriorityStandard,ESharableSessions)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    51
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    52
 * Constructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    53
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    54
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    55
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    56
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    57
CLogServer::~CLogServer()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    58
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    59
 * Destructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    60
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    61
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    62
	// Close the array of control structures
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    63
	LogControl().Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    64
	Fs().Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    65
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    66
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    67
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    68
CSession2* CLogServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& /*aMessage*/) const
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    69
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    70
 * @param RMessage - RMessage for the session open
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    71
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    72
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    73
	// Just create the session
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    74
	CLogSession* session = new (ELeave) CLogSession();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    75
	return session;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    76
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    77
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    78
void CLogServer::ControlComplete(CLogFileControl& aControl)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    79
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    80
 * @param aControl - Logfile control class reference
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    81
 *
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    82
 * Checks to see if this control session can be removed 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    83
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    84
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    85
	// Check session count and the data buffers on the queue 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    86
	if(aControl.SessionCount() || !aControl.QueueEmpty())
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    87
		return;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    88
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    89
	// There are no subsessions mapped to the logfile control class and
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    90
	// no data buffers on its write queue
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    91
	// Loop through the server's control array and remove it then delete it
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    92
	TInt i;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    93
	for(i=0;i<LogControl().Count();i++)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    94
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    95
		if(&aControl == LogControl()[i])
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    96
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    97
			// Done
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    98
			LogControl().Remove(i);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
    99
			delete &aControl;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   100
			break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   101
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   102
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   103
	// If it's the last one then exit the server
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   104
	if(!LogControl().Count())
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   105
		CActiveScheduler::Stop();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   106
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   107
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   108
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   109
///////
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   110
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   111
CLogSession::CLogSession()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   112
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   113
 * Constructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   114
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   115
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   116
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   117
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   118
CLogSession::~CLogSession()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   119
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   120
 * Destructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   121
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   122
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   123
	// Check for null
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   124
	// Session close without a createlog call leaves iControl null
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   125
	if(!iControl)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   126
		return;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   127
	// A logfile control structure can have multiple server sessions
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   128
	// decrement its server session count
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   129
	iControl->RemoveSession();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   130
	CLogServer* p=(CLogServer*) Server();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   131
	// Shuts Down the server if this is the last open session
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   132
	p->ControlComplete(*iControl);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   133
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   134
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   135
void CLogSession::ServiceL(const RMessage2& aMessage)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   136
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   137
 * @param aMessage - Function and data for the session
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   138
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   139
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   140
	switch(aMessage.Function())
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   141
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   142
		// API CreateLog() call
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   143
		case RFileFlogger::ECreateLog :
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   144
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   145
			// Sanity check to make sure it's not been called multiple times
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   146
			if(iControl)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   147
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   148
				aMessage.Complete(KErrInUse);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   149
				break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   150
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   151
			// Get the filepath
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   152
			// size policed on the client side
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   153
			TBuf<KMaxLoggerFilePath> logFilePath;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   154
			// Read it
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   155
			aMessage.ReadL(0,logFilePath);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   156
			// Get the log mode in the second argument
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   157
			RFileFlogger::TLogMode logMode;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   158
			logMode = (RFileFlogger::TLogMode)aMessage.Int1();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   159
			// Get a pointer to the parent server
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   160
			CLogServer* server=(CLogServer*) Server();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   161
			// For compare's convert the whole path to lower case
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   162
			logFilePath.LowerCase();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   163
			// Get rid of leading and trailing spaces.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   164
			logFilePath.Trim();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   165
						
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   166
			// Loop the through the server's logfile control class list
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   167
			// to see if there's a match.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   168
			TInt i;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   169
			for(i=0;i<server->LogControl().Count();i++)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   170
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   171
				if(server->LogControl()[i]->LogFile() == logFilePath)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   172
					// This file's already in open so we don't have to open it
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   173
					break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   174
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   175
			TInt err = KErrNone;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   176
			// Check the count
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   177
			if(i < server->LogControl().Count())
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   178
				// Map this session to an existing logfile control class in the list
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   179
				iControl = server->LogControl()[i];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   180
			else
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   181
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   182
				// Create a new logfile control class
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   183
				// creates/opens the logfile
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   184
				TRAP(err,iControl = CLogFileControl::NewL(*server,logFilePath,logMode));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   185
				if(!err)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   186
					{  // nancy
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   187
					// find out the type of output format and assign to this new created control
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   188
					TInt error = logFilePath.Find(_L(".xml"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   189
					if(error==KErrNotFound) iControl->SetLogType(CLogFileControl::ETxt);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   190
					else iControl->SetLogType(CLogFileControl::EXml);					
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   191
					// end nancy
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   192
					// Append it to the logfile control class list
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   193
					server->LogControl().Append(iControl);					
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   194
					}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   195
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   196
			if(!err)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   197
				// Increment its session count
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   198
				iControl->AddSession();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   199
			aMessage.Complete(err);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   200
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   201
			break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   202
		// One of the API write calls
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   203
		case RFileFlogger::EWriteLog :
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   204
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   205
			// Sanity check
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   206
			if(!iControl)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   207
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   208
				aMessage.Complete(KErrNotFound);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   209
				break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   210
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   211
			// Data can be any size
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   212
			// Get the length from second argument
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   213
			TInt bufferLength = aMessage.Int1();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   214
			// Get a heap buffer of the right size
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   215
			HBufC8* buffer = HBufC8::NewLC(bufferLength);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   216
			TPtr8 ptr(buffer->Des());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   217
			// read the data
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   218
			aMessage.ReadL(0,ptr);			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   219
			// Get a buffer control class contructed with the heap data
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   220
			// takes ownership
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   221
			CLogBuffer* logBuffer = new (ELeave) CLogBuffer(*buffer);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   222
			CleanupStack::Pop(buffer);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   223
			// Add it to the logfile control class buffer queue
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   224
			iControl->AddLogBuffer(*logBuffer);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   225
			if(!iControl->IsActive())
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   226
				// AO is idle, kick into life
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   227
				iControl->Kick();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   228
			aMessage.Complete(KErrNone);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   229
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   230
			break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   231
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   232
		default:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   233
			break;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   234
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   235
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   236
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   237
///////
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   238
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   239
CLogFileControl* CLogFileControl::NewL(CLogServer& aParent, const TDesC& aLogFilePath,RFileFlogger::TLogMode aMode)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   240
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   241
 * @param aParent - Server reference for callback
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   242
 * @param aLogFilePath - Full path and filename of the logfile
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   243
 * @param aMode - Overwrite or Append
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   244
 *
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   245
 * First phase construction for logfile control class
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   246
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   247
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   248
	CLogFileControl* self = new (ELeave) CLogFileControl(aParent,aLogFilePath);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   249
	CleanupStack::PushL(self);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   250
	self->ConstructL(aMode);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   251
	CleanupStack::Pop();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   252
	return self;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   253
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   254
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   255
CLogFileControl::CLogFileControl(CLogServer& aParent,const TDesC& aLogFilePath) :
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   256
	iParent(aParent),
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   257
	iLogFileName(aLogFilePath),
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   258
	iTransmitted(EFalse)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   259
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   260
 * @param aParent - Server reference for callback
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   261
 * @param aLogFilePath - Full path and filename of the logfile
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   262
 *
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   263
 * Constructor - Safe initialisation
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   264
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   265
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   266
	iQueue.SetOffset(CLogBuffer::LinkOffset());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   267
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   268
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   269
void CLogFileControl::ConstructL(RFileFlogger::TLogMode aMode)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   270
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   271
 * @param aMode - Overwrite or Append
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   272
 *
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   273
 * Second phase construction - Create or open the logfile
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   274
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   275
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   276
	if(aMode == RFileFlogger::ELogModeOverWrite)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   277
		// In overwrite mode replace
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   278
		User::LeaveIfError(iLogFile.Replace(iParent.Fs(),iLogFileName,EFileWrite));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   279
	else
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   280
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   281
		// For append try open then replace
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   282
		TInt err = iLogFile.Open(iParent.Fs(),iLogFileName,EFileWrite);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   283
		if(err != KErrNone)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   284
			// Bomb out if replace fails
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   285
			User::LeaveIfError(iLogFile.Replace(iParent.Fs(),iLogFileName,EFileWrite));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   286
		else
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   287
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   288
			// Open worked. Position at EOF
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   289
			TInt pos;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   290
			iLogFile.Size(pos);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   291
			User::LeaveIfError(iLogFile.Seek(ESeekEnd,pos));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   292
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   293
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   294
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   295
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   296
CLogFileControl::~CLogFileControl()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   297
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   298
 * Destructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   299
 * The server maintains a list of these classes and will not destruct one if there
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   300
 * is data on its queue
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   301
 * Destructor just closes the file handle.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   302
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   303
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   304
	iLogFile.Close();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   305
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   306
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   307
void CLogFileControl::RunL()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   308
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   309
 * Main File writing pump
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   310
 * Called on write completion or Kick() by the session that accepts the data
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   311
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   312
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   313
#if (defined _DEBUG)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   314
	_LIT(KPanic,"LogEng RunL()");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   315
#endif
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   316
	__ASSERT_DEBUG(iStatus.Int() == KErrNone,User::Panic(KPanic,iStatus.Int()));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   317
	// Check to see if this is the result of write completion
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   318
	if(iTransmitted)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   319
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   320
		// Write completed
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   321
		// Remove the buffer at the head of the queue and free it
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   322
		CLogBuffer* buffer = iQueue.First();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   323
		iQueue.Remove(*buffer);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   324
		delete buffer;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   325
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   326
	// Check to see if there's more on the queue
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   327
	if(!iQueue.IsEmpty())
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   328
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   329
		// There is so write the head of the queue
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   330
		CLogBuffer* buffer = iQueue.First();	
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   331
		SetActive();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   332
		// Set the flag to say we've transmitted
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   333
		iTransmitted = ETrue;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   334
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   335
//  ------------------------------------
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   336
		if(iLogFormat==ETxt)  WriteTxt(buffer->Buf());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   337
		else WriteXml(buffer->Buf());
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   338
		} 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   339
	else
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   340
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   341
		// Nothing on the queue
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   342
		iTransmitted = EFalse;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   343
		// Call into the server to check if this resource can be freed
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   344
		iParent.ControlComplete(*this);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   345
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   346
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   347
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   348
void CLogFileControl::WriteXml(const TDesC8 &aDes)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   349
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   350
 * @param aDes - send a aDes string in xml format to a log file
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   351
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   352
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   353
/*--------- Maintaince Warning:  -----------------------------------
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   354
******* the fomat of below is sensible from client original format.  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   355
******* Any change should match actual string formated from client. 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   356
******* Double check the code on client side 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   357
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   358
* The current assumtion of format:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   359
* First string values are seperated by sign " - " and extra pair of fields are
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   360
* seperated from main log message  by long unusual string "LogFieldsRequiredBeingAddedToAboveLogMessage"
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   361
* The \t used to seperate field name and field value and \r\n used to seperate
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   362
* each other from those pairs of field
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   363
* \t\t\t\t\t\t is used to end of whole string
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   364
--------------------------------------------------------------------------------*/
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   365
		_LIT8(KxmlHeader,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<LOGFILE>");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   366
		//The order of variables:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   367
		// time 		- aTime
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   368
		// Severity 	- aSeverity
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   369
		// Thread 		- aThread
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   370
		// Filename 	- aFilename
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   371
		// Linenumber 	- aLinenumber
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   372
		// Text 		- aText
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   373
		
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   374
		// Start of string retrive/deformating 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   375
		HBufC8* pBuf1 = HBufC8::NewL(KMaxLoggerLineLength*2); //(aDes.Length()+200);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   376
		if(!pBuf1)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   377
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   378
			return; // no memory 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   379
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   380
		TPtr8 aPtr(pBuf1->Des());  // used for searching
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   381
		TPtr8 alogbuf(pBuf1->Des());  //used for final log
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   382
		aPtr.Append(aDes);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   383
		TPtrC8 SearchBuf;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   384
		TInt aCount[8]; 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   385
		aCount[0]=0;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   386
		TInt posI(0);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   387
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   388
// retrive log message:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   389
		// Retrive common part of log message:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   390
		for(TInt i = 1; i<6; i++)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   391
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   392
			SearchBuf.Set(aPtr.Mid(posI));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   393
			aCount[i]=SearchBuf.Find(KSeperation8)+posI;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   394
			posI=aCount[i]+3;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   395
			if(aCount[i]<aCount[i-1])	return; // wrong format string from client
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   396
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   397
		// seperating common log message and extra log fields will be easy for future maintaince.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   398
		TLogField8* alogField = new TLogField8[6];  // the common part of log message for both 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   399
								  					// with and without extra log fields
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   400
		if(!alogField) return; // no memory
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   401
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   402
		TLogField8* extralogField=NULL; // only applied to extra log fields
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   403
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   404
		TInt alength=0;  // a length of array of extra log fields
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   405
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   406
		alogField[0].iLogTag8.Copy(_L8("TIME"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   407
		alogField[1].iLogTag8.Copy(_L8("SEVERITY"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   408
		alogField[2].iLogTag8.Copy(_L8("THREAD"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   409
		alogField[3].iLogTag8.Copy(_L8("FILENAME"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   410
		alogField[4].iLogTag8.Copy(_L8("LINENUMBER"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   411
		alogField[5].iLogTag8.Copy(_L8("TEXT"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   412
			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   413
		alogField[0].iLogValue8.Copy(aPtr.Mid(aCount[0],aCount[1]-aCount[0]));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   414
		for(TInt i=1; i<5; i++)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   415
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   416
			alogField[i].iLogValue8.Copy(aPtr.Mid(aCount[i]+3,aCount[i+1]-aCount[i]-3));				
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   417
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   418
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   419
		SearchBuf.Set(aPtr.Mid(posI));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   420
		aCount[6]=SearchBuf.Find(_L8("LogFieldsRequiredBeingAddedToAboveLogMessage"))+posI; 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   421
		if(aCount[6]<posI)  // no addtional fields. Find return value is KErrNotFound or >0
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   422
			{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   423
			TInt currentLength = alogField[5].iLogValue8.Length() ;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   424
			//this sentence will append the log info without buffer limit.
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   425
			TInt newAppendLength = aDes.Length()-aCount[5]-5;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   426
			//The max length for log buff in this
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   427
			TInt bufferLeft = alogField[5].iLogValue8.MaxLength() - currentLength;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   428
			// get the smaller one between the two
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   429
			TInt enabledLength = bufferLeft > newAppendLength ? newAppendLength : bufferLeft ;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   430
			alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,enabledLength));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   431
			//alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aDes.Length()-aCount[5]-5));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   432
			}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   433
		else
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   434
		{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   435
			alogField[5].iLogValue8.Copy(aPtr.Mid(aCount[5]+3,aCount[6]-aCount[5]-5));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   436
			posI=aCount[6]+45;  //45 is from the length of long string and a tab
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   437
			SearchBuf.Set(aPtr.Mid(posI));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   438
			aCount[7]=SearchBuf.Find(_L8("\r\n"))+posI;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   439
			TLex8 lex(aPtr.Mid(posI,aCount[7]-posI));  // get the length
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   440
			TInt err=lex.Val(alength); 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   441
			if (err)	alength=0; // ignor the extra log fields. Let the log go
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   442
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   443
			// Retrive the extra log fields
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   444
			extralogField = new TLogField8[alength];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   445
			if(!extralogField) return; // no memory
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   446
			for(TInt i=0; i<alength; i++)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   447
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   448
				aCount[6]=aCount[7]+2;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   449
				SearchBuf.Set(aPtr.Mid(aCount[6]));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   450
				aCount[7]=SearchBuf.Find(_L8("\t"))+aCount[6];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   451
				extralogField[i].iLogTag8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6]));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   452
				aCount[6]=aCount[7]+1;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   453
				SearchBuf.Set(aPtr.Mid(aCount[6]));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   454
				aCount[7]=SearchBuf.Find(_L8("\r\n"))+aCount[6];
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   455
				extralogField[i].iLogValue8.Copy(aPtr.Mid(aCount[6],aCount[7]-aCount[6]));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   456
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   457
		}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   458
			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   459
			// Start to organize an XML format: 			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   460
			TInt afileSize;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   461
			_LIT(KLogMutex, "LoggingServerMutex");
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   462
			RMutex mutex;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   463
			TInt r = mutex.CreateGlobal(KLogMutex);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   464
			if(r==KErrAlreadyExists)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   465
				r = mutex.OpenGlobal(KLogMutex);  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   466
			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   467
			if(!r)	mutex.Wait();  // if still failed, let logging go 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   468
									//without bother the mutex
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   469
			  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   470
			iLogFile.Size(afileSize);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   471
			if(afileSize<12) // 12 is from charters of "\r\n</LOGFILE>" 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   472
						//It shoud happened once at the beginning of the file
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   473
						// such as overwrite mode
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   474
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   475
				afileSize=12; // used for lock position
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   476
    			alogbuf.Copy(KxmlHeader);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   477
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   478
			alogbuf.Append(_L8("\r\n<MESSAGE>\r\n"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   479
			for(TInt i=0; i<6; i++)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   480
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   481
				alogbuf.Append(_L8("  <"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   482
				alogbuf.Append(alogField[i].iLogTag8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   483
				alogbuf.Append(_L8(">"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   484
				alogbuf.Append(alogField[i].iLogValue8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   485
				alogbuf.Append(_L8("</"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   486
				alogbuf.Append(alogField[i].iLogTag8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   487
				alogbuf.Append(_L8(">\r\n"));				
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   488
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   489
			for(TInt i=0; i<alength; i++)  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   490
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   491
				alogbuf.Append(_L8("  <"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   492
				alogbuf.Append(extralogField[i].iLogTag8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   493
				alogbuf.Append(_L8(">"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   494
				alogbuf.Append(extralogField[i].iLogValue8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   495
				alogbuf.Append(_L8("</"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   496
				alogbuf.Append(extralogField[i].iLogTag8);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   497
				alogbuf.Append(_L8(">\r\n"));				
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   498
				}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   499
			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   500
    		alogbuf.Append(_L8("</MESSAGE>"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   501
    		alogbuf.Append(_L8("\r\n</LOGFILE>"));
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   502
    		
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   503
    		iLogFile.Write(afileSize-12,alogbuf,iStatus);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   504
    		iLogFile.Flush();							
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   505
			
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   506
			if(!r)	
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   507
				{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   508
				mutex.Signal();
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   509
				mutex.Close();				
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   510
				} 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   511
				
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   512
		if(extralogField) delete[] extralogField;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   513
		delete[] alogField;	
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   514
		delete pBuf1;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   515
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   516
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   517
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   518
void CLogFileControl::WriteTxt(const TDesC8 &aDes)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   519
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   520
 * @param aDes - send a aDes string in xml format to a log file
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   521
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   522
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   523
/*--------- Maintaince Warning for aLogBuffer -----------------------------------
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   524
******* the fomat of below is sensible from client original format.  
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   525
******* Any change should match actual string formated from client. 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   526
******* Double check the code on client side 
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   527
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   528
* The current assumtion of format:
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   529
* First string values are seperated by sign " - " and extra pair of fields are
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   530
* seperated from main log message  by long unusual string "LogFieldsRequiredBeingAddedToAboveLogMessage"
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   531
* The \t used to seperate field name and field value and \r\n used to seperate
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   532
* each other from those pairs of field
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   533
--------------------------------------------------------------------------------*/
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   534
	iLogFile.Write(aDes,iStatus);
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   535
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   536
///////
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   537
CLogBuffer::CLogBuffer(HBufC8& aLogBuffer) : iLogBuffer(aLogBuffer)
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   538
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   539
 * @param aLogBuffer - Heap descriptor. This class takes ownership
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   540
 * Constructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   541
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   542
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   543
	}
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   544
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   545
CLogBuffer::~CLogBuffer()
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   546
/**
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   547
 * Destructor
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   548
 * This class owns a heap buffer so just free it
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   549
 */
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   550
	{
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   551
	delete &iLogBuffer;
3e07fef1e154 Initial EPL Contribution
Johnson Ma <johnson.ma@nokia.com>
parents:
diff changeset
   552
	}