persistentstorage/sql/SRC/Server/Compact/SqlCompactTimer.cpp
branchRCL_3
changeset 24 cc28652e0254
parent 23 26645d81f48d
equal deleted inserted replaced
23:26645d81f48d 24:cc28652e0254
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "SqlCompactTimer.h"
    16 #include "SqlCompactTimer.h"
    17 #include "SqlAssert.h"
    17 #include "SqlPanic.h"
    18 #include "SqlCompactEntry.h"
    18 #include "SqlCompactEntry.h"
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "SqlCompactTimerTraces.h"
       
    22 #endif
       
    23 #include "SqlTraceDef.h"
       
    24 
    19 
    25 /**
    20 /**
    26 Creates new CSqlCompactTimer instance.
    21 Creates new CSqlCompactTimer instance.
    27 
    22 
    28 @param aIntervalMs The timer intrerval (ms).
    23 @param aIntervalMs The timer intrerval (ms).
    29 
    24 
    30 @panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs.
    25 @panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs.
    31 */
    26 */
    32 CSqlCompactTimer* CSqlCompactTimer::NewL(TInt aIntervalMs)
    27 CSqlCompactTimer* CSqlCompactTimer::NewL(TInt aIntervalMs)
    33 	{
    28 	{
    34 	SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_ENTRY, "Entry;0;CSqlCompactTimer::NewL;aIntervalMs=%d", aIntervalMs));
    29 	__SQLASSERT(aIntervalMs > 0, ESqlPanicBadArgument);
    35 	__ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC2(ESqlPanicBadArgument));
       
    36 	CSqlCompactTimer* self = new (ELeave) CSqlCompactTimer(aIntervalMs);
    30 	CSqlCompactTimer* self = new (ELeave) CSqlCompactTimer(aIntervalMs);
    37 	CleanupStack::PushL(self);
    31 	CleanupStack::PushL(self);
    38 	self->ConstructL();
    32 	self->ConstructL();
    39 	CleanupStack::Pop(self);
    33 	CleanupStack::Pop(self);
    40 	SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_EXIT, "Exit;0x%X;CSqlCompactTimer::NewL;aIntervalMs=%d", (TUint)self, aIntervalMs));
       
    41 	return self;
    34 	return self;
    42 	}
    35 	}
    43 
    36 
    44 /**
    37 /**
    45 Destroys the object.
    38 Destroys the object.
    46 */
    39 */
    47 CSqlCompactTimer::~CSqlCompactTimer()
    40 CSqlCompactTimer::~CSqlCompactTimer()
    48 	{
    41 	{
    49 	SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_CSQLCOMPACTTIMER2, "0x%X;CSqlCompactTimer::~CSqlCompactTimer", (TUint)this));
       
    50 	Cancel();
    42 	Cancel();
    51 	}
    43 	}
    52 
    44 
    53 /**
    45 /**
    54 If the queue is not empty, the timer will be restarted.
    46 If the queue is not empty, the timer will be restarted.
    71 
    63 
    72 @see CSqlCompactEntry
    64 @see CSqlCompactEntry
    73 */
    65 */
    74 void CSqlCompactTimer::Queue(CSqlCompactEntry& aEntry)
    66 void CSqlCompactTimer::Queue(CSqlCompactEntry& aEntry)
    75 	{
    67 	{
    76 	SQL_TRACE_COMPACT(OstTraceExt3(TRACE_INTERNALS, CSQLCOMPACTTIMER_QUEUE, "0x%X;CSqlCompactTimer::Queue;aEntry=0x%X;Name=%S", (TUint)this, (TUint)&aEntry,__SQLPRNSTR(aEntry.FullName())));
       
    77 	SQLCOMPACTTIMER_INVARIANT();
    68 	SQLCOMPACTTIMER_INVARIANT();
    78 	iQueue.AddFirst(aEntry);
    69 	iQueue.AddFirst(aEntry);
    79 	if(!IsActive())
    70 	if(!IsActive())
    80 		{
    71 		{
    81 		After(iIntervalMicroSec);
    72 		After(iIntervalMicroSec);
    90 
    81 
    91 @see CSqlCompactEntry
    82 @see CSqlCompactEntry
    92 */
    83 */
    93 void CSqlCompactTimer::DeQueue(CSqlCompactEntry& aEntry)
    84 void CSqlCompactTimer::DeQueue(CSqlCompactEntry& aEntry)
    94 	{
    85 	{
    95 	SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_DEQUEUE, "0x%X;CSqlCompactTimer::DeQueue;aEntry=0x%X", (TUint)this, (TUint)&aEntry));
       
    96 	SQLCOMPACTTIMER_INVARIANT();
    86 	SQLCOMPACTTIMER_INVARIANT();
    97 	iQueue.Remove(aEntry);
    87 	iQueue.Remove(aEntry);
    98 	if(iQueue.IsEmpty())
    88 	if(iQueue.IsEmpty())
    99 		{
    89 		{
   100 		Cancel();
    90 		Cancel();
   112 CSqlCompactTimer::CSqlCompactTimer(TInt aIntervalMs) :
   102 CSqlCompactTimer::CSqlCompactTimer(TInt aIntervalMs) :
   113 	CTimer(CActive::EPriorityIdle),
   103 	CTimer(CActive::EPriorityIdle),
   114 	iIntervalMicroSec(aIntervalMs * 1000),
   104 	iIntervalMicroSec(aIntervalMs * 1000),
   115 	iQueue(_FOFF(CSqlCompactEntry, iLink))
   105 	iQueue(_FOFF(CSqlCompactEntry, iLink))
   116 	{
   106 	{
   117 	__ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC(ESqlPanicBadArgument));
   107 	__SQLASSERT(aIntervalMs > 0, ESqlPanicBadArgument);
   118 	}
   108 	}
   119 
   109 
   120 /**
   110 /**
   121 Initializes the created CSqlCompactTimer instance.
   111 Initializes the created CSqlCompactTimer instance.
   122 */
   112 */
   136 @panic SqlDb 7 The queue is empty.
   126 @panic SqlDb 7 The queue is empty.
   137 @panic SqlDb 7 In _DEBUG mode. The last entry in the queue is NULL.
   127 @panic SqlDb 7 In _DEBUG mode. The last entry in the queue is NULL.
   138 */
   128 */
   139 void CSqlCompactTimer::RunL()
   129 void CSqlCompactTimer::RunL()
   140 	{
   130 	{
   141 	SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_RUNL, "0x%X;CSqlCompactTimer::RunL", (TUint)this));
       
   142 	SQLCOMPACTTIMER_INVARIANT();
   131 	SQLCOMPACTTIMER_INVARIANT();
   143 	__ASSERT_ALWAYS(!iQueue.IsEmpty(), __SQLPANIC(ESqlPanicInternalError));	
   132 	__SQLASSERT_ALWAYS(!iQueue.IsEmpty(), ESqlPanicInternalError);	
   144 	CSqlCompactEntry* entry = iQueue.Last();
   133 	CSqlCompactEntry* entry = iQueue.Last();
   145 	SQL_TRACE_COMPACT(OstTraceExt4(TRACE_INTERNALS, CSQLCOMPACTTIMER_RUNL2, "0x%X;CSqlCompactTimer::RunL;Compact;entry=0x%X;Name=%S;iQueue.IsEmpty()=%d", (TUint)this, (TUint)entry,__SQLPRNSTR(entry->FullName()), (TInt)iQueue.IsEmpty()));
   134 	__SQLASSERT(entry, ESqlPanicInternalError);	
   146 	__ASSERT_DEBUG(entry, __SQLPANIC(ESqlPanicInternalError));	
       
   147 	(void)entry->Compact();
   135 	(void)entry->Compact();
   148 	if(!iQueue.IsEmpty())
   136 	if(!iQueue.IsEmpty())
   149 		{
   137 		{
   150 		After(iIntervalMicroSec);
   138 		After(iIntervalMicroSec);
   151 		}
   139 		}
   156 /**
   144 /**
   157 CSqlCompactTimer invariant.
   145 CSqlCompactTimer invariant.
   158 */
   146 */
   159 void CSqlCompactTimer::Invariant() const
   147 void CSqlCompactTimer::Invariant() const
   160 	{
   148 	{
   161 	__ASSERT_DEBUG(iIntervalMicroSec > 0, __SQLPANIC(ESqlPanicInternalError));
   149 	__SQLASSERT(iIntervalMicroSec > 0, ESqlPanicInternalError);
   162 	if(!iQueue.IsEmpty())
   150 	if(!iQueue.IsEmpty())
   163 		{
   151 		{
   164 		CSqlCompactEntry* entry = iQueue.Last();
   152 		CSqlCompactEntry* entry = iQueue.Last();
   165 		__ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError));
   153 		__SQLASSERT(entry != NULL, ESqlPanicInternalError);
   166 		}
   154 		}
   167 	}
   155 	}
   168 #endif//_DEBUG
   156 #endif//_DEBUG