|
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: Manages the call bubble extension plugins. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <badesca.h> |
|
20 #include <ecom.h> |
|
21 #include <telbubbleextension.h> |
|
22 |
|
23 #include "phonebubbleextension.h" |
|
24 #include "phonebubbleextensionmanager.h" |
|
25 #include "phonebubbleextensiondata.h" |
|
26 |
|
27 const TUint8 KDefaultPriority(255); |
|
28 |
|
29 /** |
|
30 * This is a support class that is used to carry relation of plugin UId and the |
|
31 * assigned priority. Used inside an ordered array only. |
|
32 */ |
|
33 class TPriorityItem |
|
34 { |
|
35 public: |
|
36 TPriorityItem( const TUid aUid, const TUint8 aPriority ) |
|
37 : iUid(aUid),iPriority(aPriority){}; |
|
38 const TUid Uid() const |
|
39 { return iUid; }; |
|
40 TUint8 Priority() const |
|
41 { return iPriority; }; |
|
42 TBool operator==( const TPriorityItem& aOther ) const |
|
43 { return iUid == aOther.Uid(); }; |
|
44 TBool operator<( const TPriorityItem& aOther ) const |
|
45 { return iUid.iUid < aOther.Uid().iUid; }; |
|
46 static TInt Compare( const TPriorityItem& aFirst, |
|
47 const TPriorityItem& aSecond ) |
|
48 { |
|
49 if( aFirst < aSecond ) |
|
50 { |
|
51 return -1; |
|
52 } |
|
53 if( aFirst == aSecond ) |
|
54 { |
|
55 return 0; |
|
56 } |
|
57 return 1; |
|
58 }; |
|
59 private: |
|
60 TPriorityItem(); |
|
61 |
|
62 private: |
|
63 const TUid iUid; |
|
64 const TUint8 iPriority; |
|
65 }; |
|
66 |
|
67 |
|
68 // ======== LOCAL FUNCTIONS ======== |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // ECOM array cleanupstack support function |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CleanupEComArray(TAny* aArray) |
|
75 { |
|
76 (static_cast<RImplInfoPtrArray*> (aArray))->ResetAndDestroy(); |
|
77 (static_cast<RImplInfoPtrArray*> (aArray))->Close(); |
|
78 } |
|
79 |
|
80 // ======== MEMBER FUNCTIONS ======== |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Two-phase constructor |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CPhoneBubbleExtensionManager* CPhoneBubbleExtensionManager::NewL( |
|
87 CBubbleManager& aBubbleManager ) |
|
88 { |
|
89 CPhoneBubbleExtensionManager* self = |
|
90 CPhoneBubbleExtensionManager::NewLC( aBubbleManager ); |
|
91 CleanupStack::Pop( self ); |
|
92 return self; |
|
93 } |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // Two-phase constructor |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 CPhoneBubbleExtensionManager* CPhoneBubbleExtensionManager::NewLC( |
|
101 CBubbleManager& aBubbleManager ) |
|
102 { |
|
103 CPhoneBubbleExtensionManager* self = |
|
104 new( ELeave ) CPhoneBubbleExtensionManager( aBubbleManager ); |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL(); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // destructor |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 CPhoneBubbleExtensionManager::~CPhoneBubbleExtensionManager() |
|
115 { |
|
116 Reset(); |
|
117 iPriorityArray.Close(); |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // Notifies the plugin framework about a new call. |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CPhoneBubbleExtensionManager::StartCallL( |
|
125 TInt aBubbleId, |
|
126 TPhoneCmdParamCallHeaderData* aParams ) |
|
127 { |
|
128 if ( !iInitialized ) |
|
129 { |
|
130 // Load plugins (happens on first call) |
|
131 InitializeL(); |
|
132 } |
|
133 if ( iPlugins.Count() > 0 ) // Call added only if any plugins |
|
134 { |
|
135 // create call data |
|
136 CPhoneBubbleExtensionData* callData = CPhoneBubbleExtensionData::NewLC( |
|
137 aBubbleId, |
|
138 aParams, |
|
139 ( iCalls.Count() == 0 ) ); |
|
140 |
|
141 // insert to array |
|
142 iCalls.AppendL( callData ); // ownership transferred |
|
143 CleanupStack::Pop( callData ); |
|
144 |
|
145 // notify all plugins |
|
146 const TUint pluginCount = iPlugins.Count(); |
|
147 for ( TUint index(0); index < pluginCount; index++ ) |
|
148 { |
|
149 iPlugins[index]->StartCustomizedBubble( *callData ); |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Notifies the plugin framework about cleared call. |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CPhoneBubbleExtensionManager::StopCall( TInt aBubbleId) |
|
159 { |
|
160 // find call data |
|
161 TBool found(EFalse); |
|
162 TUint callIndex(0); |
|
163 const TUint callCount = iCalls.Count(); |
|
164 while ( callIndex < callCount && !found ) |
|
165 { |
|
166 found = ( iCalls[callIndex]->BubbleId() == aBubbleId ); |
|
167 if ( !found ) |
|
168 { |
|
169 callIndex++; |
|
170 } |
|
171 } |
|
172 if ( found ) |
|
173 { |
|
174 // notify all plugins |
|
175 const TUint pluginCount = iPlugins.Count(); |
|
176 for ( TUint index(0); index < pluginCount; index++ ) |
|
177 { |
|
178 iPlugins[index]->StopCustomizedBubble( *iCalls[callIndex] ); |
|
179 } |
|
180 // destroy call data |
|
181 delete iCalls[callIndex]; |
|
182 iCalls.Remove( callIndex ); |
|
183 } |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // Notifies the plugin framework about changed call state. |
|
188 // --------------------------------------------------------------------------- |
|
189 // |
|
190 void CPhoneBubbleExtensionManager::UpdateCallState( |
|
191 TInt aBubbleId, |
|
192 TInt aNewState ) |
|
193 { |
|
194 // find call data |
|
195 TBool found(EFalse); |
|
196 TUint callIndex(0); |
|
197 const TUint callCount = iCalls.Count(); |
|
198 while ( callIndex < callCount && !found ) |
|
199 { |
|
200 found = ( iCalls[callIndex]->BubbleId() == aBubbleId ); |
|
201 if ( !found ) |
|
202 { |
|
203 callIndex++; |
|
204 } |
|
205 } |
|
206 if ( found ) |
|
207 { |
|
208 // modify call data |
|
209 iCalls[callIndex]->SetState( aNewState, ( iCalls.Count() == 0 ) ); |
|
210 // notify all plugins |
|
211 const TUint pluginCount = iPlugins.Count(); |
|
212 for ( TUint index(0); index < pluginCount; index++ ) |
|
213 { |
|
214 iPlugins[index]->BubbleUpdating(); |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // Loads all plugins |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 void CPhoneBubbleExtensionManager::InitializeL() |
|
224 { |
|
225 if ( !iInitialized ) |
|
226 { |
|
227 // load list of plugins |
|
228 RImplInfoPtrArray pluginArray; |
|
229 TCleanupItem cleanup( CleanupEComArray, &pluginArray ); |
|
230 CleanupStack::PushL( cleanup ); |
|
231 REComSession::ListImplementationsL( |
|
232 KTelBubbleExtensionInterfaceUid, |
|
233 pluginArray); |
|
234 |
|
235 // loop through the list, load plugin and insert to array |
|
236 CPhoneBubbleExtension* plugin; |
|
237 const TUint count( pluginArray.Count() ); |
|
238 for ( TUint index(0); index < count; index++ ) |
|
239 { |
|
240 // Plugin UID |
|
241 TUid uid = pluginArray[index]->ImplementationUid(); |
|
242 // Plugin priority |
|
243 TUint8 priority( KDefaultPriority ); // for unknown plugins |
|
244 TInt priorityIndex = iPriorityArray.FindInOrder( |
|
245 TPriorityItem( uid, 0 ), |
|
246 TLinearOrder<TPriorityItem>( TPriorityItem::Compare )); |
|
247 if ( priorityIndex >= 0) |
|
248 { |
|
249 // Priority for this plugin found. |
|
250 priority = iPriorityArray[priorityIndex].Priority(); |
|
251 } |
|
252 |
|
253 // Load plugin: |
|
254 TRAP_IGNORE( |
|
255 plugin = CPhoneBubbleExtension::NewLC( iBubbleManager, |
|
256 uid, |
|
257 priority ); |
|
258 |
|
259 // Plugin was loaded successfully |
|
260 iPlugins.AppendL( plugin ); // ownership trasferred |
|
261 CleanupStack::Pop( plugin ); |
|
262 ); |
|
263 } |
|
264 |
|
265 // Clean up |
|
266 CleanupStack::PopAndDestroy(); // pluginArray |
|
267 iInitialized = ETrue; |
|
268 } |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // First phase constructor |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 CPhoneBubbleExtensionManager::CPhoneBubbleExtensionManager( |
|
276 CBubbleManager& aBubbleManager ) |
|
277 :iBubbleManager( aBubbleManager ), iInitialized(EFalse) |
|
278 { |
|
279 // no implementation needed |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // Second phase constructor |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void CPhoneBubbleExtensionManager::ConstructL() |
|
287 { |
|
288 // Load priorities |
|
289 LoadPrioritiesL(); |
|
290 |
|
291 // Currently, the plugins are loaded when the first call happens, |
|
292 // not during construction. This avoids the situation where phone might |
|
293 // panic during boot up if there's a bad plugin which panics when loaded. |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // Loads plugin priorities. |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CPhoneBubbleExtensionManager::LoadPrioritiesL() |
|
301 { |
|
302 // Currently plugin priorities are not in use. No array is loaded, |
|
303 // therefore all plugins get default priority as the priority is not |
|
304 // found during the loading. |
|
305 // Here's an example implementation how to insert loaded priority data |
|
306 // (UID + priority pairs) into the array: |
|
307 // iPriorityArray.InsertInOrderL( |
|
308 // TPriorityItem( TUid::Uid(0x12345789), 5 ), |
|
309 // TLinearOrder<TPriorityItem>( TPriorityItem::Compare )); |
|
310 |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // Unloads all plugins, closes all calls |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CPhoneBubbleExtensionManager::Reset() |
|
318 { |
|
319 // Close all calls |
|
320 for ( TInt callIndex(0); callIndex < iCalls.Count(); callIndex++ ) |
|
321 { |
|
322 // notify all plugins |
|
323 const TUint pluginCount = iPlugins.Count(); |
|
324 for ( TUint index(0); index < pluginCount; index++ ) |
|
325 { |
|
326 iPlugins[index]->StopCustomizedBubble( *iCalls[callIndex] ); |
|
327 } |
|
328 // destroy call data |
|
329 delete iCalls[callIndex]; |
|
330 } |
|
331 iCalls.Close(); |
|
332 |
|
333 // Unload plugins |
|
334 for ( TInt index(0); index < iPlugins.Count(); index++ ) |
|
335 { |
|
336 delete iPlugins[index]; |
|
337 } |
|
338 iPlugins.Close(); |
|
339 |
|
340 iInitialized = EFalse; |
|
341 } |
|
342 |