loggingservices/eventlogger/LogServ/src/LogServCacheConfig.cpp
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "LogServCacheConfig.h"
       
    17 #include "LOGQUERY.H"
       
    18 #include "logservpanic.h"
       
    19 #include "LogServDatabaseTransactionInterface.h"
       
    20 
       
    21 /////////////////////////////////////////////////////////////////////////////////////////
       
    22 // -----> CLogServCacheConfig (source)
       
    23 /////////////////////////////////////////////////////////////////////////////////////////
       
    24 
       
    25 CLogServCacheConfig::CLogServCacheConfig(MLogServDatabaseTransactionInterface& aDatabase)
       
    26 :	iDatabase(aDatabase)
       
    27 	{
       
    28 	}
       
    29 
       
    30 CLogServCacheConfig::~CLogServCacheConfig()
       
    31 	{
       
    32 	}
       
    33 
       
    34 void CLogServCacheConfig::ConstructL()
       
    35 	{
       
    36 	ReadL();
       
    37 	}
       
    38 
       
    39 CLogServCacheConfig* CLogServCacheConfig::NewL(MLogServDatabaseTransactionInterface& aDatabase)
       
    40 	{
       
    41 	CLogServCacheConfig* self = new(ELeave) CLogServCacheConfig(aDatabase);
       
    42 	CleanupStack::PushL(self);
       
    43 	self->ConstructL();
       
    44 	CleanupStack::Pop(self);
       
    45 	return self;
       
    46 	}
       
    47 
       
    48 /**
       
    49 Get the current configuration
       
    50 */
       
    51 const TLogConfig& CLogServCacheConfig::Config() const
       
    52 	{
       
    53 	return iConfig;
       
    54 	}
       
    55 
       
    56 /**
       
    57 Update the config table
       
    58 */
       
    59 void CLogServCacheConfig::UpdateL(const TLogConfig& aConfig)
       
    60 	{
       
    61     RLogConfigDbTable tbl;
       
    62     tbl.OpenLC(iDatabase.DTIDatabase());
       
    63     if(!tbl.FirstL())
       
    64         {
       
    65         User::Leave(KErrNotFound);
       
    66         }
       
    67     tbl.UpdateL();
       
    68     tbl.SetColL(RLogConfigDbTable::iAgeColNo, aConfig.iMaxEventAge);
       
    69     tbl.SetColL(RLogConfigDbTable::iSizeColNo, aConfig.iMaxLogSize);
       
    70     tbl.SetColL(RLogConfigDbTable::iRecentColNo, aConfig.iMaxRecentLogSize);
       
    71     tbl.PutL();
       
    72     CleanupStack::PopAndDestroy(&tbl);
       
    73     iRequestedConfiguration = aConfig;
       
    74     iInTransaction = ETrue;
       
    75 	}
       
    76 
       
    77 /**
       
    78 Commit the requested configuration
       
    79 */
       
    80 void CLogServCacheConfig::Commit()
       
    81     {
       
    82     __ASSERT_ALWAYS(iInTransaction, Panic(ELogCacheConfigNotInTransaction));
       
    83     iConfig = iRequestedConfiguration;
       
    84     iInTransaction = EFalse;
       
    85     }
       
    86 
       
    87 /////////////////////////////////////////////////////////////////////////////////////////
       
    88 /////////////////////////////////////////////////////////////////////////////////////////
       
    89 /////////////////////////////////////////////////////////////////////////////////////////
       
    90 
       
    91 void CLogServCacheConfig::ReadL()
       
    92 	{
       
    93 	RLogConfigDbTable tbl;
       
    94 	tbl.OpenLC(iDatabase.DTIDatabase(), RDbRowSet::EReadOnly);
       
    95 	if(!tbl.FirstL())
       
    96 		{
       
    97 		User::Leave(KErrNotFound);
       
    98 		}
       
    99 	__ASSERT_ALWAYS(tbl.CountL() == 1, Panic(ELogTooManyRows4));
       
   100 	tbl.GetL();
       
   101 	iConfig.iMaxEventAge = tbl.ColUint32(RLogConfigDbTable::iAgeColNo);
       
   102 	iConfig.iMaxLogSize = tbl.ColUint16(RLogConfigDbTable::iSizeColNo);
       
   103 	iConfig.iMaxRecentLogSize = tbl.ColUint8(RLogConfigDbTable::iRecentColNo);
       
   104 	CleanupStack::PopAndDestroy(&tbl);
       
   105 	}