os/persistentdata/loggingservices/filelogger/SSVR/FLOGSVR.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1997-2010 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
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
*/
sl@0
    19
sl@0
    20
#include "FLOGSVR.H"
sl@0
    21
#include "FLOGMAN.H"
sl@0
    22
#include "FLOGSTD.H"
sl@0
    23
sl@0
    24
/**
sl@0
    25
@internalComponent
sl@0
    26
*/
sl@0
    27
const TInt KOpenLogFilesGranularity=5;
sl@0
    28
sl@0
    29
/* Internal error. Use positive number to ensure no conflict with other error code
sl@0
    30
    Indicate that client message has panic'ed and should not be completed.
sl@0
    31
*/
sl@0
    32
const TInt KErrMessagePanic = 1;  
sl@0
    33
sl@0
    34
/**
sl@0
    35
panics for log client
sl@0
    36
sl@0
    37
@internalComponent
sl@0
    38
*/
sl@0
    39
enum TLogClientPanic 
sl@0
    40
    {
sl@0
    41
	ELogDirectoryNameDoesNotExist =1,   ///<  panic if no log directory name 
sl@0
    42
	ELogFileNameDoesNotExist	        ///< panic if file name doesnot exist 
sl@0
    43
	};
sl@0
    44
sl@0
    45
/**
sl@0
    46
CFileLoggerServer class definition
sl@0
    47
*/
sl@0
    48
sl@0
    49
CFileLoggerServer* CFileLoggerServer::NewL()
sl@0
    50
/**
sl@0
    51
Creates new CFileLoggerServer object
sl@0
    52
sl@0
    53
@return Pointer to CFileLoggerServer object
sl@0
    54
*/
sl@0
    55
	{
sl@0
    56
sl@0
    57
	CFileLoggerServer* r=new(ELeave) CFileLoggerServer();
sl@0
    58
	CleanupStack::PushL(r);
sl@0
    59
	r->ConstructL();
sl@0
    60
	r->StartL(KFLoggerServerName);
sl@0
    61
	CleanupStack::Pop();
sl@0
    62
	return r;
sl@0
    63
	}
sl@0
    64
sl@0
    65
CFileLoggerServer::CFileLoggerServer()
sl@0
    66
 	: CServer2(EPriority)
sl@0
    67
 	{}
sl@0
    68
sl@0
    69
void CFileLoggerServer::ConstructL()
sl@0
    70
	{
sl@0
    71
sl@0
    72
	iLoggerManager=CFileLoggerManager::NewL();
sl@0
    73
	iSessionCounter=CFileLogSessionCounter::NewL();
sl@0
    74
	}
sl@0
    75
sl@0
    76
CFileLoggerServer::~CFileLoggerServer()
sl@0
    77
/**
sl@0
    78
Destructor
sl@0
    79
*/
sl@0
    80
	{
sl@0
    81
sl@0
    82
	delete iSessionCounter;
sl@0
    83
	delete iLoggerManager;
sl@0
    84
	}
sl@0
    85
sl@0
    86
CFileLogSessionCounter* CFileLoggerServer::SessionCounter() const
sl@0
    87
	{
sl@0
    88
sl@0
    89
	return iSessionCounter;
sl@0
    90
	}
sl@0
    91
sl@0
    92
void CFileLoggerServer::Error(TInt aError)
sl@0
    93
	{
sl@0
    94
sl@0
    95
	Message().Complete(aError);
sl@0
    96
	ReStart();
sl@0
    97
	}
sl@0
    98
sl@0
    99
CSession2* CFileLoggerServer::NewSessionL(const TVersion &aVersion, const RMessage2& /* aMessage */) const
sl@0
   100
/**
sl@0
   101
Create a new server session. Check we're the right version and make a new session
sl@0
   102
sl@0
   103
@param aVersion version of new session
sl@0
   104
*/
sl@0
   105
	{
sl@0
   106
sl@0
   107
	TVersion v(KFLogSrvMajorVersionNumber,KFLogSrvMinorVersionNumber,KFLogSrvBuildVersionNumber);
sl@0
   108
	if (!User::QueryVersionSupported(v,aVersion))
sl@0
   109
		User::Leave(KErrNotSupported);
sl@0
   110
	
sl@0
   111
	iSessionCounter->CancelTimer();
sl@0
   112
	return CFileLogSession::NewL(CONST_CAST(CFileLoggerServer*,this),iLoggerManager);
sl@0
   113
	}
sl@0
   114
/**
sl@0
   115
CFileLogSessionCounter class definition 
sl@0
   116
*/
sl@0
   117
sl@0
   118
CFileLogSessionCounter* CFileLogSessionCounter::NewL()
sl@0
   119
/**
sl@0
   120
Creates new CFileLogSessionCounter object
sl@0
   121
sl@0
   122
@return Pointer to CFileLogSessionCounter object
sl@0
   123
*/
sl@0
   124
	{
sl@0
   125
	
sl@0
   126
	CFileLogSessionCounter* r=new(ELeave) CFileLogSessionCounter();
sl@0
   127
	CleanupStack::PushL(r);
sl@0
   128
	r->ConstructL();
sl@0
   129
	CleanupStack::Pop();
sl@0
   130
	return r;
sl@0
   131
	}
sl@0
   132
sl@0
   133
CFileLogSessionCounter::~CFileLogSessionCounter()
sl@0
   134
/**
sl@0
   135
Destructor
sl@0
   136
*/
sl@0
   137
	{
sl@0
   138
sl@0
   139
	delete iShutdownTimer;
sl@0
   140
	}
sl@0
   141
sl@0
   142
CFileLogSessionCounter::CFileLogSessionCounter()
sl@0
   143
	: iSessionCount(0)
sl@0
   144
/**
sl@0
   145
Default Constructor
sl@0
   146
*/
sl@0
   147
	{}
sl@0
   148
sl@0
   149
void CFileLogSessionCounter::ConstructL()
sl@0
   150
	{
sl@0
   151
sl@0
   152
	iShutdownTimer=CShutdownTimer::NewL();
sl@0
   153
	}
sl@0
   154
	
sl@0
   155
void CFileLogSessionCounter::IncrementSessionCount()
sl@0
   156
/**
sl@0
   157
Increments the Session count 
sl@0
   158
*/
sl@0
   159
	{
sl@0
   160
sl@0
   161
	iSessionCount++;
sl@0
   162
	}
sl@0
   163
sl@0
   164
void CFileLogSessionCounter::DecrementSessionCount()
sl@0
   165
/**
sl@0
   166
Decrements the Session count
sl@0
   167
*/
sl@0
   168
	{
sl@0
   169
sl@0
   170
	iSessionCount--;
sl@0
   171
	if (iSessionCount<=0)
sl@0
   172
		iShutdownTimer->After(KShutdownPause);
sl@0
   173
	}
sl@0
   174
sl@0
   175
void CFileLogSessionCounter::CancelTimer()
sl@0
   176
/**
sl@0
   177
Cancels the timer 
sl@0
   178
*/
sl@0
   179
	{
sl@0
   180
sl@0
   181
	iShutdownTimer->Cancel();
sl@0
   182
	}	
sl@0
   183
sl@0
   184
/**
sl@0
   185
CShutdownTimer class definitions
sl@0
   186
*/
sl@0
   187
sl@0
   188
CShutdownTimer* CShutdownTimer::NewL()
sl@0
   189
/**
sl@0
   190
Creates new CShutdownTimer object
sl@0
   191
@return Pointer to CShutdownTimer object
sl@0
   192
*/
sl@0
   193
	{
sl@0
   194
sl@0
   195
	CShutdownTimer* r=new(ELeave) CShutdownTimer();
sl@0
   196
	CleanupStack::PushL(r);
sl@0
   197
	r->ConstructL();
sl@0
   198
	CleanupStack::Pop();
sl@0
   199
	return r;
sl@0
   200
	}
sl@0
   201
sl@0
   202
CShutdownTimer::~CShutdownTimer()
sl@0
   203
/**
sl@0
   204
Destructor
sl@0
   205
*/
sl@0
   206
	{}
sl@0
   207
sl@0
   208
CShutdownTimer::CShutdownTimer()
sl@0
   209
	: CTimer(EPriorityIdle)
sl@0
   210
/**
sl@0
   211
Default Constructor
sl@0
   212
*/
sl@0
   213
	{
sl@0
   214
	CActiveScheduler::Add(this);
sl@0
   215
	}
sl@0
   216
sl@0
   217
void CShutdownTimer::RunL()
sl@0
   218
/**
sl@0
   219
*/
sl@0
   220
	{
sl@0
   221
sl@0
   222
	CActiveScheduler::Stop();
sl@0
   223
	}
sl@0
   224
sl@0
   225
/**
sl@0
   226
CFileLogSession class definition
sl@0
   227
*/
sl@0
   228
sl@0
   229
CFileLogSession* CFileLogSession::NewL(CFileLoggerServer* aServer, CFileLoggerManager* aManager)
sl@0
   230
 	{
sl@0
   231
   
sl@0
   232
 	CFileLogSession* r=new(ELeave) CFileLogSession(aServer,aManager);
sl@0
   233
 	CleanupStack::PushL(r);
sl@0
   234
 	r->ConstructL();
sl@0
   235
 	CleanupStack::Pop();
sl@0
   236
 	return r;
sl@0
   237
 	}
sl@0
   238
sl@0
   239
CFileLogSession::CFileLogSession( CFileLoggerServer* aServer, CFileLoggerManager* aManager)
sl@0
   240
 	: CSession2(), iLoggerServer(aServer), iLoggerManager(aManager)
sl@0
   241
 	{}
sl@0
   242
sl@0
   243
void CFileLogSession::ConstructL()
sl@0
   244
	{
sl@0
   245
sl@0
   246
	iLoggerServer->SessionCounter()->IncrementSessionCount();		// should be done first because it will be decremented in the destructor
sl@0
   247
	iOpenLogFiles=new(ELeave) CArrayFixFlat<TLogFile>(KOpenLogFilesGranularity);
sl@0
   248
 	}
sl@0
   249
sl@0
   250
CFileLogSession::~CFileLogSession()
sl@0
   251
/**
sl@0
   252
Destructor
sl@0
   253
*/
sl@0
   254
	{
sl@0
   255
	if  (iOpenLogFiles)
sl@0
   256
		{
sl@0
   257
	TInt count=iOpenLogFiles->Count();
sl@0
   258
	TInt i;
sl@0
   259
	for (i=0; i<count; i++)
sl@0
   260
		{
sl@0
   261
		iLoggerManager->CloseLog(iOpenLogFiles->At(i));
sl@0
   262
		}
sl@0
   263
	iOpenLogFiles->Delete(0,count);
sl@0
   264
	delete iOpenLogFiles;
sl@0
   265
		}
sl@0
   266
	iLoggerServer->SessionCounter()->DecrementSessionCount();		// starts the timer if this is the last session
sl@0
   267
	}
sl@0
   268
sl@0
   269
void CFileLogSession::ServiceL(const RMessage2& aMessage)
sl@0
   270
/**
sl@0
   271
@internalTechnology
sl@0
   272
*/
sl@0
   273
	{
sl@0
   274
  
sl@0
   275
 	TRAPD(ret,DispatchMessageL(aMessage));
sl@0
   276
 	if (ret!=KErrMessagePanic)
sl@0
   277
 	    {
sl@0
   278
        aMessage.Complete(ret);
sl@0
   279
 	    }
sl@0
   280
 	}
sl@0
   281
sl@0
   282
void CFileLogSession::DispatchMessageL(const RMessage2& aMessage)
sl@0
   283
 	{
sl@0
   284
 
sl@0
   285
 	TInt func=aMessage.Function();
sl@0
   286
 	if (func!=ECreateLog && func!=EWriteLog && func!=ECloseLog && func!=ECreateWriteAndCloseLog)
sl@0
   287
 		User::Leave(KErrNotSupported);
sl@0
   288
 
sl@0
   289
 	TLogFile log;
sl@0
   290
 	TPckg<TLogFile> logPckg(log);
sl@0
   291
 	aMessage.ReadL(0,logPckg);
sl@0
   292
 	if (log.Directory().Length()<=0)
sl@0
   293
        {
sl@0
   294
        aMessage.Panic(KFLoggerServerName,ELogDirectoryNameDoesNotExist);
sl@0
   295
        User::Leave(KErrMessagePanic);
sl@0
   296
        }
sl@0
   297
    
sl@0
   298
    if (log.Name().Length()<=0)
sl@0
   299
        {
sl@0
   300
        aMessage.Panic(KFLoggerServerName,ELogFileNameDoesNotExist);
sl@0
   301
        User::Leave(KErrMessagePanic);
sl@0
   302
        }
sl@0
   303
 
sl@0
   304
 //	TBuf8<KLogBufferSize> buf;
sl@0
   305
 	TBuf8<1600> buf;
sl@0
   306
 	if (func==EWriteLog || func==ECreateWriteAndCloseLog)
sl@0
   307
 	    {
sl@0
   308
 		aMessage.ReadL(1,buf);
sl@0
   309
 	    }
sl@0
   310
 
sl@0
   311
 	switch (func)
sl@0
   312
 		{
sl@0
   313
 	case ECreateLog:
sl@0
   314
 		OpenLogL(log);
sl@0
   315
 		aMessage.WriteL(0,logPckg);
sl@0
   316
 		break;
sl@0
   317
 
sl@0
   318
 	case EWriteLog:
sl@0
   319
 		iLoggerManager->WriteToLogL(log,buf);
sl@0
   320
 		break;
sl@0
   321
 
sl@0
   322
 	case ECloseLog:
sl@0
   323
 		CloseLog(log);
sl@0
   324
 		break;
sl@0
   325
 
sl@0
   326
 	case ECreateWriteAndCloseLog:
sl@0
   327
  		{
sl@0
   328
  		OpenLogL(log); // Ok to leave here; assume that log not left open
sl@0
   329
 		TInt rc = aMessage.Write(0,logPckg);
sl@0
   330
  		if (rc == KErrNone && log.Valid())
sl@0
   331
  			TRAP(rc,iLoggerManager->WriteToLogL(log,buf));
sl@0
   332
    		CloseLog(log);
sl@0
   333
  		User::LeaveIfError(rc);
sl@0
   334
    		break;
sl@0
   335
  		}
sl@0
   336
 
sl@0
   337
 	default:
sl@0
   338
 		User::Leave(KErrNotSupported);
sl@0
   339
 		break;
sl@0
   340
 		}
sl@0
   341
 	}
sl@0
   342
 
sl@0
   343
sl@0
   344
void CFileLogSession::OpenLogL(TLogFile& aLogFile)
sl@0
   345
/**
sl@0
   346
Opens log file
sl@0
   347
sl@0
   348
@param aLogFile Log file name
sl@0
   349
*/
sl@0
   350
	{
sl@0
   351
sl@0
   352
	iOpenLogFiles->AppendL(aLogFile);
sl@0
   353
	iLoggerManager->FindOrCreateLogL(aLogFile);
sl@0
   354
	}
sl@0
   355
sl@0
   356
void CFileLogSession::CloseLog(TLogFile& aLogFile)
sl@0
   357
/**
sl@0
   358
Closes the log file
sl@0
   359
sl@0
   360
@param aLogFile Log file name
sl@0
   361
*/
sl@0
   362
	{
sl@0
   363
sl@0
   364
	iLoggerManager->CloseLog(aLogFile);
sl@0
   365
	TInt count=iOpenLogFiles->Count();
sl@0
   366
	TInt i=0;
sl@0
   367
	for (i=0; i<count; i++)
sl@0
   368
		{
sl@0
   369
		if (iOpenLogFiles->At(i)==aLogFile)
sl@0
   370
			{
sl@0
   371
			iOpenLogFiles->Delete(i,1);
sl@0
   372
			break;
sl@0
   373
			}
sl@0
   374
		}	
sl@0
   375
sl@0
   376
	__ASSERT_DEBUG(i<=count, User::Invariant());
sl@0
   377
	}
sl@0
   378