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