|
1 /* |
|
2 * Copyright (c) 2008 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: Implementation of CNcdProviderManager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdprovidermanager.h" |
|
20 |
|
21 #include <bautils.h> |
|
22 |
|
23 #include "ncdproviderimpl.h" |
|
24 #include "catalogsconstants.h" |
|
25 #include "catalogstransportimpl.h" |
|
26 #include "ncdproviderutils.h" |
|
27 #include "ncdstoragemanagerimpl.h" |
|
28 #include "catalogsutils.h" |
|
29 |
|
30 #include "catalogsdebug.h" |
|
31 |
|
32 // ======== MEMBER FUNCTIONS ======== |
|
33 |
|
34 CNcdProviderManager* CNcdProviderManager::NewL() |
|
35 { |
|
36 CNcdProviderManager* self = new (ELeave) CNcdProviderManager; |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CNcdProviderManager::CNcdProviderManager() |
|
48 { |
|
49 } |
|
50 |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CNcdProviderManager::~CNcdProviderManager() |
|
57 { |
|
58 // Providers are not owned by the array |
|
59 iProviders.Close(); |
|
60 delete iEngineRootPath; |
|
61 delete iTransport; |
|
62 delete iStorageManager; |
|
63 delete iProviderUtils; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CNcdProviderManager::ConstructL() |
|
72 { |
|
73 DLTRACEIN(("")); |
|
74 // create provider utils, fs is used as the global fs returned by |
|
75 // CNcdProviderUtils::FileSession so it must not be closed here |
|
76 iProviderUtils = CNcdProviderUtils::NewL( |
|
77 KCatalogsConfigFile ); |
|
78 |
|
79 iEngineRootPath = WritableEnginePathL( CNcdProviderUtils::FileSession() ); |
|
80 |
|
81 // Create transport |
|
82 iTransport = CCatalogsTransport::NewL( |
|
83 CNcdProviderUtils::InstallationServiceL().DocumentHandler() ); |
|
84 |
|
85 iStorageManager = CNcdStorageManager::NewL( |
|
86 CNcdProviderUtils::FileSession(), *iEngineRootPath ); |
|
87 DLTRACE(("iStorageManager ok")); |
|
88 |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 CNcdProvider& CNcdProviderManager::ProviderL( |
|
97 const MCatalogsContext& aContext, |
|
98 TBool& aCreated ) |
|
99 { |
|
100 DLTRACEIN(("")); |
|
101 TInt index = FindFamily( aContext ); |
|
102 aCreated = EFalse; |
|
103 |
|
104 if ( index == KErrNotFound ) |
|
105 { |
|
106 DLTRACE(("Creating new provider")); |
|
107 CNcdProvider* provider = CNcdProvider::NewLC( |
|
108 aContext.FamilyId(), |
|
109 *this, |
|
110 *iEngineRootPath, |
|
111 *iTransport, |
|
112 *iStorageManager ); |
|
113 |
|
114 iProviders.AppendL( provider ); |
|
115 |
|
116 CleanupStack::Pop( provider ); |
|
117 index = iProviders.Count() - 1; |
|
118 aCreated = ETrue; |
|
119 } |
|
120 |
|
121 return *iProviders[ index ]; |
|
122 } |
|
123 |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 CNcdProvider* CNcdProviderManager::Provider( |
|
130 const MCatalogsContext& aContext ) const |
|
131 { |
|
132 TInt index = FindFamily( aContext ); |
|
133 CNcdProvider* provider = NULL; |
|
134 if ( index != KErrNotFound ) |
|
135 { |
|
136 provider = iProviders[ index ]; |
|
137 } |
|
138 return provider; |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CNcdProviderManager::ProviderClosed( CNcdProvider& aProvider ) |
|
147 { |
|
148 DLTRACEIN(("")); |
|
149 |
|
150 TInt index = iProviders.Find( &aProvider ); |
|
151 if ( index != KErrNotFound ) |
|
152 { |
|
153 DLTRACE(("Removing provider: %x", &aProvider)); |
|
154 iProviders.Remove( index ); |
|
155 } |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 TInt CNcdProviderManager::FindFamily( const MCatalogsContext& aContext ) const |
|
163 { |
|
164 TInt count = iProviders.Count(); |
|
165 TInt index = KErrNotFound; |
|
166 while( count-- ) |
|
167 { |
|
168 if ( aContext.FamilyId() == iProviders[ count ]->FamilyId() ) |
|
169 { |
|
170 index = count; |
|
171 break; |
|
172 } |
|
173 } |
|
174 return index; |
|
175 } |
|
176 |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 HBufC* CNcdProviderManager::WritableEnginePathL( RFs& aFs ) |
|
183 { |
|
184 DLTRACEIN( ( "" ) ); |
|
185 // Determine the installation path from the location of the |
|
186 // engine's config file |
|
187 HBufC* fullPath = FindEngineFileL( aFs, KCatalogsConfigFile ); |
|
188 TParsePtrC parse( *fullPath ); |
|
189 TPath path( parse.DriveAndPath() ); |
|
190 delete fullPath; |
|
191 |
|
192 if ( path.Length() < 1 ) |
|
193 { |
|
194 DLERROR(("No path")); |
|
195 User::Leave( KErrArgument ); |
|
196 } |
|
197 |
|
198 // If it is in ROM, default to C. |
|
199 if ( IsRomDriveL( aFs, path[0] ) ) |
|
200 { |
|
201 DLTRACE(("Config on ROM, use C:")); |
|
202 path[0] = DriveToCharL( EDriveC ); |
|
203 } |
|
204 |
|
205 TDriveName drive; |
|
206 drive.Append( path[0] ); |
|
207 drive.Append( KDriveDelimiter ); |
|
208 |
|
209 CreatePrivatePathL( aFs, drive, path ); |
|
210 BaflUtils::EnsurePathExistsL( aFs, path ); |
|
211 |
|
212 DLTRACEOUT( ( _L("Path: %S"), &path ) ); |
|
213 return path.AllocL(); |
|
214 } |