|
1 /* |
|
2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Phonebook 2 database compression timeout timer. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbk2CompressPolicyTimer.h" |
|
22 |
|
23 // Phonebook 2 |
|
24 #include "MPbk2CompressPolicyManager.h" |
|
25 #include <MPbk2StoreObservationRegister.h> |
|
26 |
|
27 // Debugging headers |
|
28 #include <Pbk2Debug.h> |
|
29 |
|
30 /// Unnamed namespace for local definitions |
|
31 namespace { |
|
32 |
|
33 const TInt KOneSecond( 1000000 ); |
|
34 |
|
35 } /// namespace |
|
36 |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CPbk2CompressPolicyTimer::CPbk2CompressPolicyTimer |
|
40 // -------------------------------------------------------------------------- |
|
41 // |
|
42 CPbk2CompressPolicyTimer::CPbk2CompressPolicyTimer( |
|
43 MPbk2StoreObservationRegister& aStoreObservationRegister, |
|
44 MPbk2CompressPolicyManager& aManager, |
|
45 TTimeIntervalSeconds aTimeout) : |
|
46 CTimer(CActive::EPriorityIdle), |
|
47 iStoreObservationRegister(aStoreObservationRegister), |
|
48 iManager(aManager), |
|
49 iTimeout(KOneSecond * aTimeout.Int()) // 1 sec. timeout |
|
50 { |
|
51 CActiveScheduler::Add(this); |
|
52 } |
|
53 |
|
54 // -------------------------------------------------------------------------- |
|
55 // CPbk2CompressPolicyTimer::~CPbk2CompressPolicyTimer |
|
56 // -------------------------------------------------------------------------- |
|
57 // |
|
58 CPbk2CompressPolicyTimer::~CPbk2CompressPolicyTimer() |
|
59 { |
|
60 Cancel(); |
|
61 } |
|
62 |
|
63 // -------------------------------------------------------------------------- |
|
64 // CPbk2CompressPolicyTimer::NewL |
|
65 // -------------------------------------------------------------------------- |
|
66 // |
|
67 CPbk2CompressPolicyTimer* CPbk2CompressPolicyTimer::NewL |
|
68 ( MPbk2StoreObservationRegister& aStoreObservationRegister, |
|
69 MPbk2CompressPolicyManager& aManager, |
|
70 TTimeIntervalSeconds aTimeout) |
|
71 { |
|
72 CPbk2CompressPolicyTimer* self = new ( ELeave ) CPbk2CompressPolicyTimer |
|
73 ( aStoreObservationRegister, aManager, aTimeout ); |
|
74 CleanupStack::PushL(self); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop(self); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // -------------------------------------------------------------------------- |
|
81 // CPbk2CompressPolicyTimer::ConstructL |
|
82 // -------------------------------------------------------------------------- |
|
83 // |
|
84 inline void CPbk2CompressPolicyTimer::ConstructL() |
|
85 { |
|
86 CTimer::ConstructL(); |
|
87 } |
|
88 |
|
89 // -------------------------------------------------------------------------- |
|
90 // CPbk2CompressPolicyTimer::Start |
|
91 // -------------------------------------------------------------------------- |
|
92 // |
|
93 void CPbk2CompressPolicyTimer::Start() |
|
94 { |
|
95 RegisterToListenEventsSafely(); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // CPbk2CompressPolicyTimer::Stop |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 void CPbk2CompressPolicyTimer::Stop() |
|
103 { |
|
104 iStoreObservationRegister.DeregisterStoreEvents( *this ); |
|
105 Cancel(); |
|
106 } |
|
107 |
|
108 // -------------------------------------------------------------------------- |
|
109 // CPbk2CompressPolicyTimer::StoreReady |
|
110 // -------------------------------------------------------------------------- |
|
111 // |
|
112 void CPbk2CompressPolicyTimer::StoreReady |
|
113 ( MVPbkContactStore& /*aContactStore*/ ) |
|
114 { |
|
115 // Do nothing |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // CPbk2CompressPolicyTimer::StoreUnavailable |
|
120 // -------------------------------------------------------------------------- |
|
121 // |
|
122 void CPbk2CompressPolicyTimer::StoreUnavailable( |
|
123 MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/ ) |
|
124 { |
|
125 // Do nothing |
|
126 } |
|
127 |
|
128 // -------------------------------------------------------------------------- |
|
129 // CPbk2CompressPolicyTimer::HandleStoreEventL |
|
130 // -------------------------------------------------------------------------- |
|
131 // |
|
132 void CPbk2CompressPolicyTimer::HandleStoreEventL( |
|
133 MVPbkContactStore& /*aContactStore*/, |
|
134 TVPbkContactStoreEvent /*aStoreEvent*/) |
|
135 { |
|
136 StartTimer(); |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // CPbk2CompressPolicyTimer::RunL |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 void CPbk2CompressPolicyTimer::RunL() |
|
144 { |
|
145 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING("CPbk2CompressPolicyTimer::RunL(0x%x)"), |
|
146 this); |
|
147 |
|
148 if (iRestarted) |
|
149 { |
|
150 // If timer was restarted just renew it |
|
151 iRestarted = EFalse; |
|
152 After(iTimeout); |
|
153 } |
|
154 else |
|
155 { |
|
156 // Timer elapsed without restarting |
|
157 iManager.CompressStores(); |
|
158 } |
|
159 } |
|
160 |
|
161 // -------------------------------------------------------------------------- |
|
162 // CPbk2CompressPolicyTimer::RunError |
|
163 // -------------------------------------------------------------------------- |
|
164 // |
|
165 TInt CPbk2CompressPolicyTimer::RunError(TInt aError) |
|
166 { |
|
167 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING( |
|
168 "CPbk2CompressPolicyTimer::RunError(0x%x,%d)"), this, aError); |
|
169 |
|
170 // Compression is a silent background operation -> ignore all errors |
|
171 return KErrNone; |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // CPbk2CompressPolicyTimer::StartTimer |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 void CPbk2CompressPolicyTimer::StartTimer() |
|
179 { |
|
180 if (IsActive()) |
|
181 { |
|
182 // Timer already running -> set restarted flag |
|
183 iRestarted = ETrue; |
|
184 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING( |
|
185 "CPbk2CompressPolicyTimer::StartTimer(0x%x): restarted"), this); |
|
186 } |
|
187 else |
|
188 { |
|
189 // Start timer |
|
190 After(iTimeout); |
|
191 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING( |
|
192 "CPbk2CompressPolicyTimer::StartTimer(0x%x): started"), this); |
|
193 } |
|
194 } |
|
195 |
|
196 // -------------------------------------------------------------------------- |
|
197 // CPbk2CompressPolicyTimer::RegisterToListenEventsSafely |
|
198 // -------------------------------------------------------------------------- |
|
199 // |
|
200 void CPbk2CompressPolicyTimer::RegisterToListenEventsSafely() |
|
201 { |
|
202 // Make sure that you are not registered twice |
|
203 iStoreObservationRegister.DeregisterStoreEvents( *this ); |
|
204 TRAP_IGNORE( iStoreObservationRegister.RegisterStoreEventsL( *this ) ); |
|
205 } |
|
206 |
|
207 // End of File |