|
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: factory class for Engine component |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "cvimpstenginefactory.h" |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <barsc.h> |
|
23 #include <gulutil.h> |
|
24 #include <coemain.h> |
|
25 |
|
26 #include "cvimpstengineservicetablefetcher.h" |
|
27 #include "cvimpstengine.h" |
|
28 #include "cvimpststoragemanagerfactory.h" |
|
29 |
|
30 #include <spnotifychange.h> |
|
31 #include <spsettings.h> |
|
32 |
|
33 #include "vimpstdebugtrace.h" |
|
34 #include "cvimpstenginecvlistener.h" |
|
35 |
|
36 // ================= MEMBER FUNCTIONS ======================= |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CVIMPSTEngineFactory::InstanceL |
|
40 // Create an instance of the ximp manager |
|
41 // behaving as singleton object already created then return same instance. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 EXPORT_C MVIMPSTEngineFactory* CVIMPSTEngineFactory::InstanceL() |
|
45 { |
|
46 CVIMPSTEngineFactory* singleton; |
|
47 singleton = static_cast<CVIMPSTEngineFactory*> (Dll::Tls()); |
|
48 if( !singleton ) |
|
49 { |
|
50 singleton = CVIMPSTEngineFactory::NewLC(); |
|
51 User::LeaveIfError( Dll::SetTls( static_cast<TAny*> (singleton ) )); |
|
52 CleanupStack::Pop(singleton); |
|
53 } |
|
54 singleton->IncreamentRefereneCount(); |
|
55 |
|
56 return (MVIMPSTEngineFactory*)singleton; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CVIMPSTEngineFactory::Release |
|
61 // Release the singelton |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C void CVIMPSTEngineFactory::Release() |
|
65 { |
|
66 CVIMPSTEngineFactory* singleton; |
|
67 singleton = static_cast<CVIMPSTEngineFactory*>(Dll::Tls()); |
|
68 if( singleton && !singleton->DecreamentRefereneCount()) |
|
69 { |
|
70 delete singleton; |
|
71 Dll::SetTls( NULL ) ; |
|
72 } |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CVIMPSTEngineFactory::NewLC |
|
77 // Object creation using two phase construction |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CVIMPSTEngineFactory* CVIMPSTEngineFactory::NewLC() |
|
81 { |
|
82 CVIMPSTEngineFactory* self = new (ELeave) CVIMPSTEngineFactory(); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL(); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CVIMPSTEngineFactory::ConstructL |
|
90 // Symbian OS default constructor can leave. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 void CVIMPSTEngineFactory::ConstructL() |
|
94 { |
|
95 |
|
96 CVIMPSTStorageManagerFactory::InitialiseLibraryL(); |
|
97 |
|
98 //only 1 instance of iServiceTableFetcher shared between services |
|
99 iServiceTableFetcher = CVIMPSTEngineServiceTableFetcher::NewL(); |
|
100 |
|
101 RArray<TUint32> serviceIdArray; |
|
102 CleanupClosePushL( serviceIdArray ); |
|
103 //Get the available services |
|
104 iServiceTableFetcher->GetMasterServiceIdsL(serviceIdArray); |
|
105 |
|
106 // iterate the service array |
|
107 for ( TInt index = 0; index < serviceIdArray.Count() ; index++ ) |
|
108 { |
|
109 //create seperate engine instance for each service |
|
110 //and provide the same to the UI |
|
111 CVIMPSTEngine* item = |
|
112 CVIMPSTEngine::NewL(serviceIdArray[ index ], |
|
113 *iServiceTableFetcher); |
|
114 |
|
115 iServiceItems.Append(item); |
|
116 } |
|
117 |
|
118 CleanupStack::PopAndDestroy(); //serviceIdArray |
|
119 |
|
120 //register for service table notifications |
|
121 RArray<TUint> serviceIds; |
|
122 CleanupClosePushL( serviceIds ); |
|
123 |
|
124 iSpNotifyChange = CSPNotifyChange::NewL( *this ); |
|
125 iSpNotifyChange->NotifyChangeL( serviceIds ); |
|
126 CleanupStack::PopAndDestroy( &serviceIds ) ; |
|
127 iCVlistener = CVIMPSTEngineCVListener::NewL( *iServiceTableFetcher ); |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CVIMPSTEngineFactory::IncreamentRefereneCount |
|
132 // Object creation using two phase construction |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CVIMPSTEngineFactory::IncreamentRefereneCount() |
|
136 { |
|
137 iReferenceCount++; |
|
138 } |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CVIMPSTEngineFactory::DecreamentRefereneCount |
|
141 // Object creation using two phase construction |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 TInt CVIMPSTEngineFactory::DecreamentRefereneCount() |
|
145 { |
|
146 iReferenceCount--; |
|
147 return iReferenceCount; |
|
148 } |
|
149 // --------------------------------------------------------- |
|
150 // CVIMPSTEngineFactory::CVIMPSTEngineFactory |
|
151 // --------------------------------------------------------- |
|
152 CVIMPSTEngineFactory::CVIMPSTEngineFactory() |
|
153 { |
|
154 |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------- |
|
158 // CVIMPSTEngineFactory::~CVIMPSTEngineFactory |
|
159 // --------------------------------------------------------- |
|
160 CVIMPSTEngineFactory::~CVIMPSTEngineFactory() |
|
161 { |
|
162 CVIMPSTStorageManagerFactory::Release(); |
|
163 |
|
164 delete iSpNotifyChange; |
|
165 iSpNotifyChange = NULL; |
|
166 |
|
167 delete iServiceTableFetcher; |
|
168 |
|
169 //delete all the create engine instances |
|
170 iServiceItems.ResetAndDestroy(); |
|
171 iServiceItems.Close(); |
|
172 delete iCVlistener; |
|
173 iCVlistener = NULL; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CVIMPSTEngineFactory::GetServiceEnginePtr |
|
178 // --------------------------------------------------------- |
|
179 void CVIMPSTEngineFactory::GetServiceEnginePtr |
|
180 (RPointerArray<MVIMPSTEngine>& serviceIdArray) const |
|
181 { |
|
182 |
|
183 TInt count = iServiceItems.Count() ; |
|
184 |
|
185 // iterate the service array |
|
186 for ( TInt index = 0; index < count ; index++ ) |
|
187 { |
|
188 //append the engines created for each service |
|
189 serviceIdArray.Append(iServiceItems[index]); |
|
190 } |
|
191 |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------- |
|
195 // CVIMPSTEngineFactory::GetServiceEnginePtr |
|
196 // --------------------------------------------------------- |
|
197 |
|
198 TInt CVIMPSTEngineFactory::FindService( |
|
199 TUint aServiceId ) const |
|
200 { |
|
201 TInt count = iServiceItems.Count() ; |
|
202 TInt ret = KErrNotFound; |
|
203 // iterate the service array |
|
204 for ( TInt index = 0; index < count ; index++ ) |
|
205 { |
|
206 //append the engines created for each service |
|
207 if(iServiceItems[index]->ServiceId() == aServiceId) |
|
208 { |
|
209 ret = index; |
|
210 break; |
|
211 } |
|
212 |
|
213 } |
|
214 return ret; |
|
215 } |
|
216 |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // CVIMPSTEngineFactory::HandleNotifyChange() |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 void CVIMPSTEngineFactory::HandleNotifyChange( |
|
223 TServiceId aServiceId ) |
|
224 { |
|
225 TRACE( T_LIT("CVIMPSTEngineFactory::HandleNotifyChange start")); |
|
226 TRACE( T_LIT("HandleNotifyChange() serviceid: %d"), aServiceId ); |
|
227 |
|
228 TBool newService = EFalse; |
|
229 |
|
230 if ( KErrNotFound == FindService(aServiceId) ) |
|
231 { |
|
232 newService = ETrue; |
|
233 } |
|
234 |
|
235 TRAP_IGNORE( iServiceTableFetcher->DoHandleNotifyChangeL( aServiceId, newService, GetEngine(aServiceId) ) ); |
|
236 |
|
237 TRACE( T_LIT("CVIMPSTEngineFactory::HandleNotifyChange end")); |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CVIMPSTEngineFactory::HandleError() |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CVIMPSTEngineFactory::HandleError( TInt /*aError*/ ) |
|
245 { |
|
246 TRACE( T_LIT("CVIMPSTEngineFactory::HandleError() start")); |
|
247 |
|
248 TRACE( T_LIT("CVIMPSTEngineFactory::HandleError() end")); |
|
249 |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // CVIMPSTEngineFactory::GetEngine() |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 MVIMPSTEngine* CVIMPSTEngineFactory::GetEngine( TServiceId aServiceId ) |
|
257 { |
|
258 TInt count = iServiceItems.Count(); |
|
259 MVIMPSTEngine* engine = NULL; |
|
260 for(int i=0 ; i<count ; i++) |
|
261 { |
|
262 if(iServiceItems[i]->ServiceId() == aServiceId) |
|
263 { |
|
264 engine = iServiceItems[i]; |
|
265 } |
|
266 } |
|
267 return engine; |
|
268 } |
|
269 |
|
270 |
|
271 |
|
272 // End of File |