|
1 /* |
|
2 * Copyright (c) 2006 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: Implements CNcdNodeCacheCleanerManager class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdnodecachecleanermanager.h" |
|
20 #include "ncdnodecachecleaner.h" |
|
21 #include "ncdnodemanager.h" |
|
22 #include "ncdnodedbmanager.h" |
|
23 #include "ncdnodefactory.h" |
|
24 #include "catalogsconstants.h" |
|
25 #include "ncdproviderdefines.h" |
|
26 #include "catalogsutils.h" |
|
27 #include "ncdgeneralmanager.h" |
|
28 |
|
29 #include "catalogsdebug.h" |
|
30 |
|
31 |
|
32 CNcdNodeCacheCleanerManager* |
|
33 CNcdNodeCacheCleanerManager::NewL( CNcdGeneralManager& aGeneralManager, |
|
34 CNcdNodeDbManager& aNodeDbManager, |
|
35 TInt aDbDefaultMaxSize, |
|
36 CNcdNodeFactory& aNodeFactory ) |
|
37 { |
|
38 CNcdNodeCacheCleanerManager* self = |
|
39 CNcdNodeCacheCleanerManager::NewLC( aGeneralManager, |
|
40 aNodeDbManager, |
|
41 aDbDefaultMaxSize, |
|
42 aNodeFactory ); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CNcdNodeCacheCleanerManager* |
|
48 CNcdNodeCacheCleanerManager::NewLC( CNcdGeneralManager& aGeneralManager, |
|
49 CNcdNodeDbManager& aNodeDbManager, |
|
50 TInt aDbDefaultMaxSize, |
|
51 CNcdNodeFactory& aNodeFactory ) |
|
52 { |
|
53 CNcdNodeCacheCleanerManager* self = |
|
54 new( ELeave ) CNcdNodeCacheCleanerManager( aGeneralManager, |
|
55 aNodeDbManager, |
|
56 aDbDefaultMaxSize, |
|
57 aNodeFactory ); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(); |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 |
|
65 CNcdNodeCacheCleanerManager::CNcdNodeCacheCleanerManager( CNcdGeneralManager& aGeneralManager, |
|
66 CNcdNodeDbManager& aNodeDbManager, |
|
67 TInt aDbDefaultMaxSize, |
|
68 CNcdNodeFactory& aNodeFactory ) |
|
69 : CBase(), |
|
70 iGeneralManager( aGeneralManager ), |
|
71 iNodeManager( aGeneralManager.NodeManager() ), |
|
72 iNodeDbManager( aNodeDbManager ), |
|
73 iDbMaxSize( aDbDefaultMaxSize ), |
|
74 iNodeFactory( aNodeFactory ) |
|
75 { |
|
76 } |
|
77 |
|
78 |
|
79 void CNcdNodeCacheCleanerManager::ConstructL() |
|
80 { |
|
81 // These values have to be set. |
|
82 } |
|
83 |
|
84 |
|
85 CNcdNodeCacheCleanerManager::~CNcdNodeCacheCleanerManager() |
|
86 { |
|
87 DLTRACEIN(("")); |
|
88 |
|
89 // Before deleting cache cleaners make sure that db cleaner |
|
90 // has finished its job. |
|
91 // Reload the node list just in case. Also, reset the list |
|
92 // when everything is done. |
|
93 DLINFO(("Cache cleaner force clean")); |
|
94 for ( TInt i = 0; i < iCleaners.Count(); ++i ) |
|
95 { |
|
96 // Be sure to trap here, because destructor can not leave. |
|
97 TRAP_IGNORE( iCleaners[ i ]->ForceCleanupL() ); |
|
98 } |
|
99 |
|
100 // This manager owns the cleaners. |
|
101 // So, delete them. |
|
102 iCleaners.ResetAndDestroy(); |
|
103 |
|
104 DLTRACEOUT(("")); |
|
105 } |
|
106 |
|
107 |
|
108 CNcdNodeCacheCleaner& CNcdNodeCacheCleanerManager::CacheCleanerL( const TUid& aClientUid ) |
|
109 { |
|
110 DLTRACEIN(("")); |
|
111 |
|
112 for ( TInt i = 0; i < iCleaners.Count(); ++i ) |
|
113 { |
|
114 if ( aClientUid == iCleaners[ i ]->ClientUid() ) |
|
115 { |
|
116 DLTRACEOUT(("Cleaner was in the array")); |
|
117 return *iCleaners[ i ]; |
|
118 } |
|
119 } |
|
120 |
|
121 DLINFO(("Cleaner was not in the array. So, create new.")); |
|
122 CNcdNodeCacheCleaner* cleaner( |
|
123 CNcdNodeCacheCleaner::NewLC( iGeneralManager, NodeDbManager(), |
|
124 DbMaxSize(), NodeFactory() ) ); |
|
125 // Array takes the ownership. |
|
126 iCleaners.AppendL( cleaner ); |
|
127 CleanupStack::Pop( cleaner ); |
|
128 |
|
129 DLTRACEOUT(("")); |
|
130 |
|
131 return *cleaner; |
|
132 } |
|
133 |
|
134 |
|
135 TInt CNcdNodeCacheCleanerManager::DbMaxSize() const |
|
136 { |
|
137 DLTRACEIN(("")); |
|
138 return iDbMaxSize; |
|
139 } |
|
140 |
|
141 |
|
142 void CNcdNodeCacheCleanerManager::SetDbMaxSize( const TInt aDbMaxSize ) |
|
143 { |
|
144 DLTRACEIN(("")); |
|
145 iDbMaxSize = aDbMaxSize; |
|
146 } |
|
147 |
|
148 |
|
149 void CNcdNodeCacheCleanerManager::CheckAllL() const |
|
150 { |
|
151 DLTRACEIN(("")); |
|
152 |
|
153 for ( TInt i = 0; i < iCleaners.Count(); ++i ) |
|
154 { |
|
155 iCleaners[ i ]->CheckDbSizeL(); |
|
156 } |
|
157 |
|
158 DLTRACEOUT(("")); |
|
159 } |
|
160 |
|
161 |
|
162 CNcdNodeManager& CNcdNodeCacheCleanerManager::NodeManager() const |
|
163 { |
|
164 return iNodeManager; |
|
165 } |
|
166 |
|
167 |
|
168 CNcdNodeDbManager& CNcdNodeCacheCleanerManager::NodeDbManager() const |
|
169 { |
|
170 return iNodeDbManager; |
|
171 } |
|
172 |
|
173 |
|
174 CNcdNodeFactory& CNcdNodeCacheCleanerManager::NodeFactory() const |
|
175 { |
|
176 return iNodeFactory; |
|
177 } |
|
178 |
|
179 |