|
1 /* |
|
2 * Copyright (c) 2005-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: Device status plugin interface. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom/ecom.h> |
|
20 #include <ecom/implementationproxy.h> |
|
21 #include <coemain.h> |
|
22 #include <data_caging_path_literals.hrh> |
|
23 #include <bautils.h> |
|
24 #include <aiutility.h> |
|
25 #include <featmgr.h> |
|
26 #include "aidevicestatusplugin.h" |
|
27 #include "aidevicestatuspluginengine.h" |
|
28 #include "aipublishprioritizer.h" |
|
29 #include "aidevicestatuscontentmodel.h" |
|
30 #include "aimulticontentobserver.h" |
|
31 #include "aipluginsettings.h" |
|
32 #include "ainetworkinfolistener.h" |
|
33 |
|
34 _LIT( KResourceDrive, "Z:" ); |
|
35 _LIT( KResourceFile, "aidevstaplgres.rsc" ); |
|
36 #define KResourcePath KDC_APP_RESOURCE_DIR |
|
37 |
|
38 // ECOM implementation table |
|
39 const TImplementationProxy KImplementationTable[] = |
|
40 { |
|
41 IMPLEMENTATION_PROXY_ENTRY(KImplUidDevStaPlugin, CAiDeviceStatusPlugin::NewL) |
|
42 }; |
|
43 |
|
44 |
|
45 // ======== MEMBER FUNCTIONS ======== |
|
46 |
|
47 CAiDeviceStatusPlugin::CAiDeviceStatusPlugin() : |
|
48 iResourceOffset( KErrNotFound ) |
|
49 { |
|
50 } |
|
51 |
|
52 |
|
53 void CAiDeviceStatusPlugin::ConstructL() |
|
54 { |
|
55 iInfo.iUid.iUid = AI_UID_ECOM_IMPLEMENTATION_CONTENTPUBLISHER_DEVSTAPLUGIN; |
|
56 |
|
57 FeatureManager::InitializeLibL(); |
|
58 |
|
59 // Create master instance to prevent deletion on Stop() |
|
60 iListener = CAiNetworkInfoListener::InstanceL(); |
|
61 |
|
62 //Create content here since this is needed in optimization phase. |
|
63 iContent = AiUtility::CreateContentItemArrayIteratorL( KAiDeviceStatusContent ); |
|
64 iResources = AiUtility::CreateContentItemArrayIteratorL( KAiDeviceStatusResources ); |
|
65 iContentObservers = CAiMultiContentObserver::NewL(); |
|
66 iPrioritizer = CAiPublishPrioritizer::NewL( *iContentObservers, *this ); |
|
67 } |
|
68 |
|
69 |
|
70 CAiDeviceStatusPlugin* CAiDeviceStatusPlugin::NewL() |
|
71 { |
|
72 CAiDeviceStatusPlugin* self = CAiDeviceStatusPlugin::NewLC(); |
|
73 CleanupStack::Pop( self ); |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 CAiDeviceStatusPlugin* CAiDeviceStatusPlugin::NewLC() |
|
79 { |
|
80 CAiDeviceStatusPlugin* self = new( ELeave ) CAiDeviceStatusPlugin; |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 return self; |
|
84 } |
|
85 |
|
86 |
|
87 CAiDeviceStatusPlugin::~CAiDeviceStatusPlugin() |
|
88 { |
|
89 delete iPrioritizer; |
|
90 FreeResources(); |
|
91 delete iContentObservers; |
|
92 Release( iResources ); |
|
93 Release( iContent ); |
|
94 FeatureManager::UnInitializeLib(); |
|
95 if( iListener ) |
|
96 { |
|
97 iListener->Release(); |
|
98 } |
|
99 } |
|
100 |
|
101 |
|
102 /** |
|
103 * Allocates all resourcers required for plug-in operation. |
|
104 */ |
|
105 void CAiDeviceStatusPlugin::AllocateResourcesL() |
|
106 { |
|
107 //create engine |
|
108 if( !iEngine ) |
|
109 { |
|
110 iEngine = CAiDeviceStatusPluginEngine::NewL( *iContentObservers, |
|
111 *this, |
|
112 *iPrioritizer); |
|
113 } |
|
114 |
|
115 if( iResourceOffset < 0 ) |
|
116 { |
|
117 CCoeEnv* coe = CCoeEnv::Static(); |
|
118 |
|
119 if( !coe ) |
|
120 { |
|
121 User::Leave( KErrNotReady ); |
|
122 } |
|
123 |
|
124 //Add resource file to cone |
|
125 TFullName resourceFile( KResourceDrive ); |
|
126 resourceFile.Append( KResourcePath ); |
|
127 resourceFile.Append( KResourceFile ); |
|
128 BaflUtils::NearestLanguageFile( CCoeEnv::Static()->FsSession(), resourceFile ); |
|
129 iResourceOffset = coe->AddResourceFileL( resourceFile ); |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 /** |
|
135 * Frees all allocated resources. |
|
136 */ |
|
137 void CAiDeviceStatusPlugin::FreeResources() |
|
138 { |
|
139 if( iResourceOffset >= 0 ) |
|
140 { |
|
141 CCoeEnv* coe = CCoeEnv::Static(); |
|
142 //If device status plugin is created when CCoeEnv is available and |
|
143 //destroyed when it is not anymore available, cone will inform about |
|
144 //resource leak. |
|
145 if ( coe ) |
|
146 { |
|
147 coe->DeleteResourceFile( iResourceOffset ); |
|
148 iResourceOffset = KErrNotFound; |
|
149 } |
|
150 } |
|
151 |
|
152 delete iEngine; |
|
153 iEngine = NULL; |
|
154 } |
|
155 |
|
156 |
|
157 void CAiDeviceStatusPlugin::Resume(TAiTransitionReason aReason) |
|
158 { |
|
159 if( IgnoreReason( aReason ) ) |
|
160 { |
|
161 return; |
|
162 } |
|
163 // resume all publishers only in startup |
|
164 if( iEngine ) |
|
165 { |
|
166 if ( aReason == EAiIdleForeground || aReason == EAiKeylockDisabled ) |
|
167 { |
|
168 // not much can be done if some publisher cannot be refreshed |
|
169 TRAP_IGNORE( iEngine->RefreshPublishersL( |
|
170 EAiDeviceStatusContentNetworkIdentity, ETrue ) ); |
|
171 |
|
172 TRAP_IGNORE( iEngine->RefreshPublishersL( |
|
173 EAiDeviceStatusContentCUGMCNIndicator, ETrue ) ); |
|
174 } |
|
175 // if layout changed republish some information |
|
176 else if ( aReason == EAiScreenLayoutChanged ) |
|
177 { |
|
178 TRAP_IGNORE( iEngine->RefreshPublishersL( EAiDeviceStatusContentDate, ETrue )); |
|
179 TRAP_IGNORE( iEngine->RefreshPublishersL( EAiDeviceStatusContentCUGMCNIndicator, ETrue )); |
|
180 TRAP_IGNORE( iEngine->RefreshPublishersL( EAiDeviceStatusContentVHZText, ETrue )); |
|
181 TRAP_IGNORE( iEngine->RefreshPublishersL( EAiDeviceStatusContentNetworkIdentity, ETrue )); |
|
182 } |
|
183 return; |
|
184 } |
|
185 // If engine has been deleted. create it again. |
|
186 else |
|
187 { |
|
188 iContentObservers->StartTransaction( KImplUidDevStaPlugin ); |
|
189 |
|
190 TRAPD( err, DoResumeL(aReason) ); |
|
191 |
|
192 if( err == KErrNone ) |
|
193 { |
|
194 iContentObservers->Commit( KImplUidDevStaPlugin ); |
|
195 } |
|
196 else |
|
197 { |
|
198 iContentObservers->CancelTransaction( KImplUidDevStaPlugin ); |
|
199 } |
|
200 } |
|
201 } |
|
202 |
|
203 |
|
204 void CAiDeviceStatusPlugin::DoResumeL(TAiTransitionReason /*aReason*/) |
|
205 { |
|
206 AllocateResourcesL( ); |
|
207 iEngine->ResumePublishersL(); |
|
208 iEngine->RefreshPublishersL( EFalse ); |
|
209 } |
|
210 |
|
211 |
|
212 TBool CAiDeviceStatusPlugin::IgnoreReason( TAiTransitionReason aReason ) |
|
213 { |
|
214 switch( aReason ) |
|
215 { |
|
216 case EAiBacklightOff: |
|
217 return ETrue; |
|
218 } |
|
219 return EFalse; |
|
220 } |
|
221 |
|
222 |
|
223 void CAiDeviceStatusPlugin::Stop(TAiTransitionReason /*aReason*/) |
|
224 { |
|
225 FreeResources(); |
|
226 } |
|
227 |
|
228 |
|
229 void CAiDeviceStatusPlugin::Suspend(TAiTransitionReason /*aReason*/) |
|
230 { |
|
231 } |
|
232 |
|
233 |
|
234 void CAiDeviceStatusPlugin::SubscribeL(MAiContentObserver& aObserver) |
|
235 { |
|
236 iContentObservers->AddObserverL( aObserver ); |
|
237 } |
|
238 |
|
239 |
|
240 TAny* CAiDeviceStatusPlugin::Extension(TUid aUid) |
|
241 { |
|
242 //Access to extensions |
|
243 if( aUid == KExtensionUidProperty ) |
|
244 { |
|
245 return static_cast<MAiPropertyExtension*>(this); |
|
246 } |
|
247 |
|
248 return NULL; |
|
249 } |
|
250 |
|
251 |
|
252 void CAiDeviceStatusPlugin::ConfigureL(RAiSettingsItemArray& aSettings) |
|
253 { |
|
254 aSettings.ResetAndDestroy(); |
|
255 } |
|
256 |
|
257 TAny* CAiDeviceStatusPlugin::GetPropertyL(TInt aProperty) |
|
258 { |
|
259 //Return properties. |
|
260 switch (aProperty) |
|
261 { |
|
262 case EAiPublisherInfo: |
|
263 return &iInfo; |
|
264 |
|
265 case EAiPublisherContent: |
|
266 return static_cast<MAiContentItemIterator*>(iContent); |
|
267 |
|
268 case EAiPublisherResources: |
|
269 return static_cast<MAiContentItemIterator*>(iResources); |
|
270 |
|
271 case EAiContentRequest: |
|
272 return static_cast<MAiContentRequest*>(this); |
|
273 } |
|
274 |
|
275 return NULL; |
|
276 } |
|
277 |
|
278 void CAiDeviceStatusPlugin::SetPropertyL(TInt aProperty, TAny* aValue) |
|
279 { |
|
280 if( aProperty == EAiPublisherInfo ) |
|
281 { |
|
282 ASSERT( aValue ); |
|
283 |
|
284 const TAiPublisherInfo* info( |
|
285 static_cast<const TAiPublisherInfo*>( aValue ) ); |
|
286 |
|
287 iInfo = *info; |
|
288 } |
|
289 } |
|
290 |
|
291 TBool CAiDeviceStatusPlugin::RefreshContent( TInt aContentId ) |
|
292 { |
|
293 TBool result = EFalse; |
|
294 |
|
295 TRAP_IGNORE( result = iEngine->RefreshPublishersL( aContentId, EFalse ) ); |
|
296 return result; |
|
297 } |
|
298 |
|
299 |
|
300 /** |
|
301 * ECom component entry point. |
|
302 */ |
|
303 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
304 { |
|
305 aTableCount = sizeof(KImplementationTable) / sizeof(TImplementationProxy); |
|
306 return KImplementationTable; |
|
307 } |