1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
1 // Copyright (c) 2008-2010 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 "SqlPanic.h" |
17 #include "SqlAssert.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" |
19 |
24 |
20 /** |
25 /** |
21 Creates new CSqlCompactTimer instance. |
26 Creates new CSqlCompactTimer instance. |
22 |
27 |
23 @param aIntervalMs The timer intrerval (ms). |
28 @param aIntervalMs The timer intrerval (ms). |
24 |
29 |
25 @panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs. |
30 @panic SqlDb 4 In _DEBUG mode. Zero or negative aIntervalMs. |
26 */ |
31 */ |
27 CSqlCompactTimer* CSqlCompactTimer::NewL(TInt aIntervalMs) |
32 CSqlCompactTimer* CSqlCompactTimer::NewL(TInt aIntervalMs) |
28 { |
33 { |
29 __SQLASSERT(aIntervalMs > 0, ESqlPanicBadArgument); |
34 SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_ENTRY, "Entry;0;CSqlCompactTimer::NewL;aIntervalMs=%d", aIntervalMs)); |
|
35 __ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC2(ESqlPanicBadArgument)); |
30 CSqlCompactTimer* self = new (ELeave) CSqlCompactTimer(aIntervalMs); |
36 CSqlCompactTimer* self = new (ELeave) CSqlCompactTimer(aIntervalMs); |
31 CleanupStack::PushL(self); |
37 CleanupStack::PushL(self); |
32 self->ConstructL(); |
38 self->ConstructL(); |
33 CleanupStack::Pop(self); |
39 CleanupStack::Pop(self); |
|
40 SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_NEWL_EXIT, "Exit;0x%X;CSqlCompactTimer::NewL;aIntervalMs=%d", (TUint)self, aIntervalMs)); |
34 return self; |
41 return self; |
35 } |
42 } |
36 |
43 |
37 /** |
44 /** |
38 Destroys the object. |
45 Destroys the object. |
39 */ |
46 */ |
40 CSqlCompactTimer::~CSqlCompactTimer() |
47 CSqlCompactTimer::~CSqlCompactTimer() |
41 { |
48 { |
|
49 SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_CSQLCOMPACTTIMER2, "0x%X;CSqlCompactTimer::~CSqlCompactTimer", (TUint)this)); |
42 Cancel(); |
50 Cancel(); |
43 } |
51 } |
44 |
52 |
45 /** |
53 /** |
46 If the queue is not empty, the timer will be restarted. |
54 If the queue is not empty, the timer will be restarted. |
63 |
71 |
64 @see CSqlCompactEntry |
72 @see CSqlCompactEntry |
65 */ |
73 */ |
66 void CSqlCompactTimer::Queue(CSqlCompactEntry& aEntry) |
74 void CSqlCompactTimer::Queue(CSqlCompactEntry& aEntry) |
67 { |
75 { |
|
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()))); |
68 SQLCOMPACTTIMER_INVARIANT(); |
77 SQLCOMPACTTIMER_INVARIANT(); |
69 iQueue.AddFirst(aEntry); |
78 iQueue.AddFirst(aEntry); |
70 if(!IsActive()) |
79 if(!IsActive()) |
71 { |
80 { |
72 After(iIntervalMicroSec); |
81 After(iIntervalMicroSec); |
81 |
90 |
82 @see CSqlCompactEntry |
91 @see CSqlCompactEntry |
83 */ |
92 */ |
84 void CSqlCompactTimer::DeQueue(CSqlCompactEntry& aEntry) |
93 void CSqlCompactTimer::DeQueue(CSqlCompactEntry& aEntry) |
85 { |
94 { |
|
95 SQL_TRACE_COMPACT(OstTraceExt2(TRACE_INTERNALS, CSQLCOMPACTTIMER_DEQUEUE, "0x%X;CSqlCompactTimer::DeQueue;aEntry=0x%X", (TUint)this, (TUint)&aEntry)); |
86 SQLCOMPACTTIMER_INVARIANT(); |
96 SQLCOMPACTTIMER_INVARIANT(); |
87 iQueue.Remove(aEntry); |
97 iQueue.Remove(aEntry); |
88 if(iQueue.IsEmpty()) |
98 if(iQueue.IsEmpty()) |
89 { |
99 { |
90 Cancel(); |
100 Cancel(); |
102 CSqlCompactTimer::CSqlCompactTimer(TInt aIntervalMs) : |
112 CSqlCompactTimer::CSqlCompactTimer(TInt aIntervalMs) : |
103 CTimer(CActive::EPriorityIdle), |
113 CTimer(CActive::EPriorityIdle), |
104 iIntervalMicroSec(aIntervalMs * 1000), |
114 iIntervalMicroSec(aIntervalMs * 1000), |
105 iQueue(_FOFF(CSqlCompactEntry, iLink)) |
115 iQueue(_FOFF(CSqlCompactEntry, iLink)) |
106 { |
116 { |
107 __SQLASSERT(aIntervalMs > 0, ESqlPanicBadArgument); |
117 __ASSERT_DEBUG(aIntervalMs > 0, __SQLPANIC(ESqlPanicBadArgument)); |
108 } |
118 } |
109 |
119 |
110 /** |
120 /** |
111 Initializes the created CSqlCompactTimer instance. |
121 Initializes the created CSqlCompactTimer instance. |
112 */ |
122 */ |
126 @panic SqlDb 7 The queue is empty. |
136 @panic SqlDb 7 The queue is empty. |
127 @panic SqlDb 7 In _DEBUG mode. The last entry in the queue is NULL. |
137 @panic SqlDb 7 In _DEBUG mode. The last entry in the queue is NULL. |
128 */ |
138 */ |
129 void CSqlCompactTimer::RunL() |
139 void CSqlCompactTimer::RunL() |
130 { |
140 { |
|
141 SQL_TRACE_COMPACT(OstTrace1(TRACE_INTERNALS, CSQLCOMPACTTIMER_RUNL, "0x%X;CSqlCompactTimer::RunL", (TUint)this)); |
131 SQLCOMPACTTIMER_INVARIANT(); |
142 SQLCOMPACTTIMER_INVARIANT(); |
132 __SQLASSERT_ALWAYS(!iQueue.IsEmpty(), ESqlPanicInternalError); |
143 __ASSERT_ALWAYS(!iQueue.IsEmpty(), __SQLPANIC(ESqlPanicInternalError)); |
133 CSqlCompactEntry* entry = iQueue.Last(); |
144 CSqlCompactEntry* entry = iQueue.Last(); |
134 __SQLASSERT(entry, ESqlPanicInternalError); |
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())); |
|
146 __ASSERT_DEBUG(entry, __SQLPANIC(ESqlPanicInternalError)); |
135 (void)entry->Compact(); |
147 (void)entry->Compact(); |
136 if(!iQueue.IsEmpty()) |
148 if(!iQueue.IsEmpty()) |
137 { |
149 { |
138 After(iIntervalMicroSec); |
150 After(iIntervalMicroSec); |
139 } |
151 } |
144 /** |
156 /** |
145 CSqlCompactTimer invariant. |
157 CSqlCompactTimer invariant. |
146 */ |
158 */ |
147 void CSqlCompactTimer::Invariant() const |
159 void CSqlCompactTimer::Invariant() const |
148 { |
160 { |
149 __SQLASSERT(iIntervalMicroSec > 0, ESqlPanicInternalError); |
161 __ASSERT_DEBUG(iIntervalMicroSec > 0, __SQLPANIC(ESqlPanicInternalError)); |
150 if(!iQueue.IsEmpty()) |
162 if(!iQueue.IsEmpty()) |
151 { |
163 { |
152 CSqlCompactEntry* entry = iQueue.Last(); |
164 CSqlCompactEntry* entry = iQueue.Last(); |
153 __SQLASSERT(entry != NULL, ESqlPanicInternalError); |
165 __ASSERT_DEBUG(entry != NULL, __SQLPANIC(ESqlPanicInternalError)); |
154 } |
166 } |
155 } |
167 } |
156 #endif//_DEBUG |
168 #endif//_DEBUG |