|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * View activator - activates a tab view upon client request |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CxSPViewActivator.h" |
|
22 #include <CxSPViewData.h> |
|
23 #include "CxSPViewInfo.h" |
|
24 #include <Pbk2ViewId.hrh> |
|
25 |
|
26 |
|
27 // System includes |
|
28 #include <aknViewAppUi.h> |
|
29 |
|
30 // Unnamed namespace for local definitions |
|
31 namespace |
|
32 { |
|
33 const TInt KDesAddressParam = 2; // Des address is in param ix 2 |
|
34 _LIT( KPanicText, "xSPViewActivator" ); |
|
35 |
|
36 enum TPanicCode |
|
37 { |
|
38 EBadDescriptorLength, |
|
39 EBadDescriptor |
|
40 }; |
|
41 } // namespace |
|
42 |
|
43 // ================= MEMBER FUNCTIONS ======================= |
|
44 |
|
45 CxSPViewActivator* CxSPViewActivator::NewL(CxSPViewIdChanger* aViewIdChanger) |
|
46 { |
|
47 CxSPViewActivator* self = new(ELeave) CxSPViewActivator(aViewIdChanger); |
|
48 |
|
49 CleanupStack::PushL(self); |
|
50 self->ConstructL(); |
|
51 CleanupStack::Pop(); // self |
|
52 |
|
53 return self; |
|
54 } |
|
55 |
|
56 CxSPViewActivator::CxSPViewActivator(CxSPViewIdChanger* aViewIdChanger) : |
|
57 CServer2(EPriorityStandard) |
|
58 { |
|
59 iViewIdChanger = aViewIdChanger; |
|
60 } |
|
61 |
|
62 void CxSPViewActivator::ConstructL() |
|
63 { |
|
64 StartL(KxSPServer); |
|
65 } |
|
66 |
|
67 CxSPViewActivator::~CxSPViewActivator() |
|
68 { |
|
69 } |
|
70 |
|
71 CSession2* CxSPViewActivator::NewSessionL(const TVersion& aVersion, const RMessage2&) const |
|
72 { |
|
73 TBool supported = User::QueryVersionSupported(TVersion(KxSPViewServerMajor, |
|
74 KxSPViewServerMinor, |
|
75 KxSPViewServerBuild), |
|
76 aVersion); |
|
77 if(!supported) |
|
78 { |
|
79 User::Leave(KErrNotSupported); |
|
80 } |
|
81 |
|
82 return new (ELeave) CxSPViewActivatorSession(); |
|
83 } |
|
84 |
|
85 void CxSPViewActivator::ActivateView1L(const RMessage2 &aMessage) |
|
86 { |
|
87 TUint32 ecomID = aMessage.Int0(); |
|
88 TUint32 viewID = aMessage.Int1(); |
|
89 |
|
90 TInt err = KErrNone; |
|
91 TInt newViewId; |
|
92 if(ecomID) |
|
93 { |
|
94 err = iViewIdChanger->GetNewView(ecomID, viewID, newViewId); |
|
95 } |
|
96 else |
|
97 { |
|
98 newViewId = viewID; |
|
99 } |
|
100 |
|
101 aMessage.Complete(err); |
|
102 |
|
103 if(err == KErrNone) |
|
104 { |
|
105 // Activate the view |
|
106 static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi())->ActivateLocalViewL( |
|
107 TUid::Uid((TInt)newViewId)); |
|
108 } |
|
109 |
|
110 return; |
|
111 } |
|
112 |
|
113 void CxSPViewActivator::ActivateView2L(const RMessage2 &aMessage) |
|
114 { |
|
115 TInt err = KErrNone; |
|
116 |
|
117 TUint32 ecomID = aMessage.Int0(); |
|
118 TUint32 viewID = aMessage.Int1(); |
|
119 TInt desLen = aMessage.GetDesLength(KDesAddressParam); |
|
120 if( desLen <= 0 ) |
|
121 { |
|
122 aMessage.Panic( KPanicText, EBadDescriptorLength ); |
|
123 } |
|
124 else |
|
125 { |
|
126 HBufC8* paramBuf = HBufC8::NewL(desLen); |
|
127 CleanupStack::PushL(paramBuf); |
|
128 TPtr8 ptr = paramBuf->Des(); |
|
129 aMessage.ReadL(KDesAddressParam, ptr); |
|
130 |
|
131 TInt newViewId; |
|
132 if(ecomID) |
|
133 { |
|
134 err = iViewIdChanger->GetNewView(ecomID, viewID, newViewId); |
|
135 } |
|
136 else |
|
137 { |
|
138 newViewId = viewID; |
|
139 } |
|
140 |
|
141 // If err is KErrNone or KErrNotFound, complete client's request with KErrNone. |
|
142 // The reason is even if client passed an invalid view id to xsp server, |
|
143 // the server will launch phonebook namelist view instead. |
|
144 if ( KErrNone == err || KErrNotFound == err ) |
|
145 { |
|
146 aMessage.Complete( KErrNone ); |
|
147 } |
|
148 else |
|
149 { |
|
150 aMessage.Complete( err ); |
|
151 } |
|
152 |
|
153 if( err == KErrNone ) |
|
154 { |
|
155 // Make view id |
|
156 const TVwsViewId viewId( TUid::Uid( KUid ), TUid::Uid( newViewId ) ); |
|
157 // Activate the view |
|
158 static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi())->ActivateViewL( |
|
159 viewId, CPbk2ViewState::Uid(), *paramBuf); |
|
160 } |
|
161 else if ( err == KErrNotFound ) |
|
162 { |
|
163 // Activate phonebook namelist view if valid view id can't be found |
|
164 const TVwsViewId viewId( TUid::Uid( KUid ), TUid::Uid( EPbk2NamesListViewId ) ); |
|
165 static_cast<CAknViewAppUi*>( CCoeEnv::Static()->AppUi() )->ActivateViewL( |
|
166 viewId, CPbk2ViewState::Uid(), *paramBuf ); |
|
167 } |
|
168 |
|
169 CleanupStack::PopAndDestroy(); // paramBuf; |
|
170 } |
|
171 } |
|
172 |
|
173 void CxSPViewActivator::ActivateView2AsyncL(const RMessage2 &aMessage) |
|
174 { |
|
175 TInt err = KErrNone; |
|
176 |
|
177 TUint32 ecomID = aMessage.Int0(); |
|
178 TUint32 viewID = aMessage.Int1(); |
|
179 TInt desLen = aMessage.GetDesLength(KDesAddressParam); |
|
180 if( desLen <= 0 ) |
|
181 { |
|
182 aMessage.Panic( KPanicText, EBadDescriptorLength ); |
|
183 } |
|
184 else |
|
185 { |
|
186 HBufC8* paramBuf = HBufC8::NewL(desLen); |
|
187 CleanupStack::PushL(paramBuf); |
|
188 TPtr8 ptr = paramBuf->Des(); |
|
189 aMessage.ReadL(KDesAddressParam, ptr); |
|
190 |
|
191 TInt newViewId; |
|
192 if(ecomID) |
|
193 { |
|
194 err = iViewIdChanger->GetNewView(ecomID, viewID, newViewId); |
|
195 } |
|
196 else |
|
197 { |
|
198 newViewId = viewID; |
|
199 } |
|
200 |
|
201 aMessage.Complete(err); |
|
202 |
|
203 if(err == KErrNone) |
|
204 { |
|
205 // Make view id |
|
206 const TVwsViewId viewId(TUid::Uid(KUid), TUid::Uid(newViewId)); |
|
207 // Activate the view |
|
208 static_cast<CAknViewAppUi*>(CCoeEnv::Static()->AppUi())->ActivateViewL( |
|
209 viewId, CPbk2ViewState::Uid(), *paramBuf); |
|
210 } |
|
211 |
|
212 CleanupStack::PopAndDestroy(); // paramBuf; |
|
213 } |
|
214 |
|
215 } |
|
216 |
|
217 void CxSPViewActivator::GetViewCountL(const RMessage2 &aMessage) |
|
218 { |
|
219 TInt tabsCount; |
|
220 TInt dummy; |
|
221 iViewIdChanger->GetViewCount( tabsCount, dummy ); |
|
222 TPckgC<TInt> tabsCountDes( tabsCount ); |
|
223 TRAPD( err, aMessage.WriteL( 0, tabsCountDes ) ); |
|
224 if( err != KErrNone ) |
|
225 { |
|
226 aMessage.Panic( KPanicText, EBadDescriptor ); |
|
227 User::Leave( err ); |
|
228 } |
|
229 else |
|
230 { |
|
231 aMessage.Complete( KErrNone ); |
|
232 } |
|
233 } |
|
234 |
|
235 void CxSPViewActivator::GetViewDataPackLengthL(const RMessage2 &aMessage) |
|
236 { |
|
237 TInt index = aMessage.Int0(); |
|
238 TInt tabsCount; |
|
239 TInt dummy; |
|
240 iViewIdChanger->GetViewCount( tabsCount, dummy ); |
|
241 if( index < 0 ) |
|
242 { |
|
243 aMessage.Complete( KErrUnderflow ); |
|
244 } |
|
245 else if( index >= tabsCount ) |
|
246 { |
|
247 aMessage.Complete( KErrOverflow ); |
|
248 } |
|
249 else |
|
250 { |
|
251 RPointerArray<CxSPViewInfo> infoArray; |
|
252 CleanupClosePushL( infoArray ); |
|
253 iViewIdChanger->GetTabViewInfoL( infoArray ); |
|
254 const CxSPViewInfo& info = *infoArray[index]; |
|
255 CxSPViewData* viewData = CxSPViewData::NewL(); |
|
256 CleanupStack::PushL( viewData ); |
|
257 viewData->SetEComId( info.Id() ); |
|
258 viewData->SetOriginalViewId( info.OldViewId() ); |
|
259 viewData->SetIconId( info.SortIconId() ); |
|
260 viewData->SetMaskId( info.SortMaskId() ); |
|
261 viewData->SetIconFileL( info.SortIconFile() ); |
|
262 viewData->SetViewNameL( info.Name() ); |
|
263 HBufC8* packed = viewData->PackL(); |
|
264 TInt length = packed->Length(); |
|
265 delete packed; |
|
266 CleanupStack::PopAndDestroy(); // viewData |
|
267 CleanupStack::PopAndDestroy(); // infoArray |
|
268 TPckgC<TInt> lengthDes( length ); |
|
269 TRAPD( err, aMessage.WriteL( 1, lengthDes ) ); |
|
270 if( err != KErrNone ) |
|
271 { |
|
272 aMessage.Panic( KPanicText, EBadDescriptor ); |
|
273 User::Leave( err ); |
|
274 } |
|
275 else |
|
276 { |
|
277 aMessage.Complete( KErrNone ); |
|
278 } |
|
279 } |
|
280 } |
|
281 |
|
282 void CxSPViewActivator::GetViewDataL(const RMessage2 &aMessage) |
|
283 { |
|
284 TInt index = aMessage.Int0(); |
|
285 TInt tabsCount; |
|
286 TInt dummy; |
|
287 iViewIdChanger->GetViewCount( tabsCount, dummy ); |
|
288 if( index < 0 ) |
|
289 { |
|
290 aMessage.Complete( KErrUnderflow ); |
|
291 } |
|
292 else if( index >= tabsCount ) |
|
293 { |
|
294 aMessage.Complete( KErrOverflow ); |
|
295 } |
|
296 else |
|
297 { |
|
298 RPointerArray<CxSPViewInfo> infoArray; |
|
299 CleanupClosePushL( infoArray ); |
|
300 iViewIdChanger->GetTabViewInfoL( infoArray ); |
|
301 const CxSPViewInfo& info = *infoArray[index]; |
|
302 CxSPViewData* viewData = CxSPViewData::NewL(); |
|
303 CleanupStack::PushL( viewData ); |
|
304 viewData->SetEComId( info.Id() ); |
|
305 viewData->SetOriginalViewId( info.OldViewId() ); |
|
306 viewData->SetIconId( info.SortIconId() ); |
|
307 viewData->SetMaskId( info.SortMaskId() ); |
|
308 viewData->SetIconFileL( info.SortIconFile() ); |
|
309 viewData->SetViewNameL( info.Name() ); |
|
310 HBufC8* packed = viewData->PackL(); |
|
311 CleanupStack::PushL( packed ); |
|
312 TRAPD( err, aMessage.WriteL( 1, *packed ) ); |
|
313 if( err != KErrNone ) |
|
314 { |
|
315 aMessage.Panic( KPanicText, EBadDescriptor ); |
|
316 User::Leave( err ); |
|
317 } |
|
318 else |
|
319 { |
|
320 aMessage.Complete( KErrNone ); |
|
321 } |
|
322 CleanupStack::PopAndDestroy(); // packed |
|
323 CleanupStack::PopAndDestroy(); // viewData |
|
324 CleanupStack::PopAndDestroy(); // infoArray |
|
325 } |
|
326 } |
|
327 |
|
328 void CxSPViewActivator::StartL(const TDesC &aName) |
|
329 { |
|
330 CServer2::StartL(aName); |
|
331 |
|
332 RSemaphore semaphore; |
|
333 if(semaphore.OpenGlobal(KxSPServer) == KErrNone) |
|
334 { |
|
335 semaphore.Signal(); |
|
336 semaphore.Close(); |
|
337 } |
|
338 } |
|
339 |
|
340 void CxSPViewActivatorSession::ServiceL(const RMessage2 &aMessage) |
|
341 { |
|
342 // There are currently separate synchronous and asynchronous op codes for |
|
343 // some of the services. The server side implementation is however |
|
344 // synchronous and the opcodes are handled similarily whenever possible. |
|
345 // For example EGetViewCount and EGetViewCountAsync are treated identically |
|
346 // and the corresponding async cancel operation (ECancelGetViewCountAsync) |
|
347 // does nothing and completes immediately. |
|
348 |
|
349 switch(aMessage.Function()) |
|
350 { |
|
351 case EActivateView1: |
|
352 ((CxSPViewActivator*)Server())->ActivateView1L(aMessage); |
|
353 break; |
|
354 case EActivateView2: |
|
355 ((CxSPViewActivator*)Server())->ActivateView2L(aMessage); |
|
356 break; |
|
357 case EActivateView2Async: |
|
358 ((CxSPViewActivator*)Server())->ActivateView2AsyncL( aMessage ); |
|
359 break; |
|
360 case EGetViewCount: // FALLTHROUGH |
|
361 case EGetViewCountAsync: |
|
362 ((CxSPViewActivator*)Server())->GetViewCountL(aMessage); |
|
363 break; |
|
364 case ECancelGetViewCountAsync: |
|
365 aMessage.Complete( KErrNone ); |
|
366 break; |
|
367 case EGetViewDataPackLength: |
|
368 ((CxSPViewActivator*)Server())->GetViewDataPackLengthL(aMessage); |
|
369 break; |
|
370 case EGetViewDataPackLengthAsync: |
|
371 ((CxSPViewActivator*)Server())->GetViewDataPackLengthL( aMessage ); |
|
372 break; |
|
373 case ECancelGetViewDataPackLengthAsync: |
|
374 aMessage.Complete( KErrNone ); |
|
375 break; |
|
376 case EGetViewData: |
|
377 ((CxSPViewActivator*)Server())->GetViewDataL(aMessage); |
|
378 break; |
|
379 case EGetViewDataAsync: |
|
380 ((CxSPViewActivator*)Server())->GetViewDataL( aMessage ); |
|
381 break; |
|
382 case ECancelActivateView2Async: |
|
383 aMessage.Complete( KErrNone ); |
|
384 break; |
|
385 case ECancelGetViewDataAsync: |
|
386 aMessage.Complete( KErrNone ); |
|
387 break; |
|
388 default: |
|
389 aMessage.Complete(KErrNotSupported); |
|
390 } |
|
391 } |
|
392 |
|
393 // End of file. |