|
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: mpx user helper classes |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <s32mem.h> |
|
19 #include <f32file.h> |
|
20 #include <e32property.h> |
|
21 #include <ctsydomainpskeys.h> |
|
22 #include <mpxmediageneraldefs.h> |
|
23 #include <mpxmedia.h> |
|
24 #include <mpxattribute.h> |
|
25 #include <mpxlog.h> |
|
26 #include "mpxuser.h" |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // Recreate a buffer |
|
30 // ---------------------------------------------------------------------------- |
|
31 // |
|
32 EXPORT_C void MPXUser::RecreateBufferL(TInt aSize, CBufBase*& aBuf) |
|
33 { |
|
34 delete aBuf; |
|
35 aBuf=NULL; |
|
36 CBufBase* buf=CBufFlat::NewL(aSize); |
|
37 CleanupStack::PushL(buf); |
|
38 buf->ResizeL(aSize); |
|
39 CleanupStack::Pop(buf); |
|
40 aBuf = buf; |
|
41 } |
|
42 |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // Helper funciton to create descriptor array from buffer |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C void MPXUser::CreateFromBufferL( |
|
49 const CBufBase &aBuf, |
|
50 CDesCArray*& aArray) |
|
51 { |
|
52 delete aArray; |
|
53 aArray = NULL; |
|
54 RBufReadStream rs(aBuf); |
|
55 CleanupClosePushL(rs); |
|
56 InternalizeL(aArray, rs); |
|
57 CleanupStack::PopAndDestroy(&rs); |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // Helper funciton to create a buffer |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C CBufBase* MPXUser::CreateBufferLC(TInt aSize) |
|
65 { |
|
66 CBufBase* buf=CBufFlat::NewL(aSize); |
|
67 CleanupStack::PushL(buf); |
|
68 buf->ResizeL(aSize); |
|
69 return buf; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // Create a buffer from an array |
|
74 // aBuf replaced with the contents of the descriptor array and its sizes. |
|
75 // The size of the buffer is the size of data in the buffer |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C void MPXUser::CreateBufferL(const MDesCArray* aArray, CBufBase*& aBuf) |
|
79 { |
|
80 delete aBuf; |
|
81 aBuf = NULL; |
|
82 |
|
83 CBufBase* buffer=CreateBufferLC(KMPXBufGranularity); |
|
84 RBufWriteStream ws(*buffer); |
|
85 CleanupClosePushL(ws); |
|
86 ExternalizeL(aArray, ws); |
|
87 ws.CommitL(); |
|
88 CleanupStack::PopAndDestroy(&ws); |
|
89 buffer->Compress(); |
|
90 CleanupStack::Pop(buffer); |
|
91 aBuf = buffer; |
|
92 } |
|
93 |
|
94 // ---------------------------------------------------------------------------- |
|
95 // Create buffer from message |
|
96 // ---------------------------------------------------------------------------- |
|
97 // |
|
98 EXPORT_C void MPXUser::CreateBufferL( |
|
99 const RMessage2& aMessage, |
|
100 TInt aMsgSlot, |
|
101 CBufBase*& aBuffer) |
|
102 { |
|
103 TInt s=aMessage.GetDesLengthL(aMsgSlot); |
|
104 if ( s <= 0 ) |
|
105 { |
|
106 User::Leave( KErrArgument ); |
|
107 } |
|
108 RecreateBufferL(s, aBuffer); |
|
109 TPtr8 p(aBuffer->Ptr(0)); |
|
110 aMessage.Read(aMsgSlot,p); |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // Create buffer from a descriptor |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 EXPORT_C void MPXUser::CreateBufferL(const TDesC& aDes, CBufBase*& aBuffer) |
|
118 { |
|
119 TPtrC8 ptr8 = MPXUser::Ptr(aDes); |
|
120 RecreateBufferL(ptr8.Length(), aBuffer); |
|
121 aBuffer->Write(0, ptr8); |
|
122 aBuffer->Compress(); |
|
123 } |
|
124 |
|
125 // ---------------------------------------------------------------------------- |
|
126 // Creates a narrow heap descriptor from a unicode descriptor. |
|
127 // No character conversion |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C HBufC8* MPXUser::Alloc8L(const TDesC& aDes) |
|
131 { |
|
132 HBufC8* des8=HBufC8::NewL(aDes.Length()); |
|
133 des8->Des().Copy(aDes); |
|
134 return des8; |
|
135 } |
|
136 |
|
137 // ---------------------------------------------------------------------------- |
|
138 // Creates a zero-terminated narrow heap descriptor from a unicode descriptor. |
|
139 // No character conversion |
|
140 // ---------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C HBufC8* MPXUser::Alloc8ZL(const TDesC& aDes) |
|
143 { |
|
144 HBufC8* des8=HBufC8::NewL(aDes.Length()+1); |
|
145 des8->Des().Copy(aDes); |
|
146 des8->Des().ZeroTerminate(); |
|
147 return des8; |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // Creates a heap descriptor from a narrow descriptor. |
|
152 // No character conversion |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C HBufC* MPXUser::AllocL(const TDesC8& aDes) |
|
156 { |
|
157 HBufC* item = HBufC::NewL(aDes.Length()); |
|
158 item->Des().Copy(aDes); |
|
159 return item; |
|
160 } |
|
161 |
|
162 // ---------------------------------------------------------------------------- |
|
163 // Creates a narrow ptr descriptor on a unicode descriptor |
|
164 // ---------------------------------------------------------------------------- |
|
165 // |
|
166 EXPORT_C TPtrC8 MPXUser::Ptr(const TDesC& aDes) |
|
167 { |
|
168 #ifdef _UNICODE |
|
169 TInt len=aDes.Length()*2; // Unicode->Narrow |
|
170 return TPtrC8((TUint8*)(&aDes[0]),len); |
|
171 #else |
|
172 return TPtrC8(aDes); |
|
173 #endif |
|
174 } |
|
175 |
|
176 // ---------------------------------------------------------------------------- |
|
177 // Creates a wide ptr descriptor on a narrow descriptor |
|
178 // ---------------------------------------------------------------------------- |
|
179 // |
|
180 EXPORT_C TPtrC MPXUser::Ptr(const TDesC8& aDes) |
|
181 { |
|
182 #ifdef _UNICODE |
|
183 TInt len=aDes.Length()/2; // Narrrow->Unicode |
|
184 return TPtrC((TUint16*)(&aDes[0]),len); |
|
185 #else |
|
186 return TPtrC(aDes); |
|
187 #endif |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // Helper internalize a descriptor array from a stream |
|
192 // ---------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C void MPXUser::InternalizeL( |
|
195 CDesCArray*& aArray, |
|
196 RReadStream& aStream) |
|
197 { |
|
198 delete aArray; |
|
199 aArray = NULL; |
|
200 TInt n=aStream.ReadInt32L(); |
|
201 if( n ) |
|
202 { |
|
203 CDesCArray* array=new(ELeave)CDesCArrayFlat(n); |
|
204 CleanupStack::PushL(array); |
|
205 TInt len; |
|
206 for (TInt i=0;i<n;++i) |
|
207 { |
|
208 len=aStream.ReadInt32L(); |
|
209 HBufC* item=HBufC::NewLC(len); |
|
210 TPtr bp = item->Des(); |
|
211 aStream.ReadL(bp,len); |
|
212 array->AppendL(*item); |
|
213 CleanupStack::PopAndDestroy(item); |
|
214 } |
|
215 CleanupStack::Pop(array); |
|
216 aArray = array; |
|
217 } |
|
218 else |
|
219 { |
|
220 // Dummy |
|
221 aArray = new(ELeave)CDesCArrayFlat(1); |
|
222 } |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // Helper externalize a descriptor array to a stream |
|
227 // ---------------------------------------------------------------------------- |
|
228 // |
|
229 EXPORT_C void MPXUser::ExternalizeL( |
|
230 const MDesCArray* aArray, |
|
231 RWriteStream& aStream) |
|
232 { |
|
233 if (aArray) |
|
234 { |
|
235 TInt n = aArray->MdcaCount(); |
|
236 aStream.WriteInt32L(n); |
|
237 for (TInt i=0;i<n;++i) |
|
238 { |
|
239 TPtrC item=aArray->MdcaPoint(i); |
|
240 aStream.WriteInt32L( item.Length() ); |
|
241 aStream.WriteL(item, item.Length()); |
|
242 } |
|
243 } |
|
244 else |
|
245 { |
|
246 // Nothing to externalize |
|
247 aStream.WriteInt32L(0); |
|
248 } |
|
249 } |
|
250 |
|
251 // ---------------------------------------------------------------------------- |
|
252 // Group attributes belonging to one content into an item in the array |
|
253 // ---------------------------------------------------------------------------- |
|
254 // |
|
255 EXPORT_C void MPXUser::MergeAttributeL( |
|
256 const TArray<TMPXAttribute>& aSrc, |
|
257 RArray<TMPXAttribute>& aDest) |
|
258 { |
|
259 aDest.Reset(); |
|
260 for (TInt i = 0; i < aSrc.Count(); i++) |
|
261 { |
|
262 const TMPXAttribute& s = aSrc[i]; |
|
263 TInt index = aDest.Find(s, TMPXAttribute::MatchContentId); |
|
264 if ( KErrNotFound == index ) |
|
265 { |
|
266 aDest.AppendL(s); |
|
267 } |
|
268 else |
|
269 { |
|
270 TMPXAttribute& d = aDest[index]; |
|
271 d = TMPXAttribute(d.ContentId(), d.AttributeId() | s.AttributeId()); |
|
272 } |
|
273 } |
|
274 } |
|
275 |
|
276 // ---------------------------------------------------------------------------- |
|
277 // Determines the owning process id of the thread |
|
278 // ---------------------------------------------------------------------------- |
|
279 // |
|
280 EXPORT_C TProcessId MPXUser::ProcessIdL(TThreadId aId) |
|
281 { |
|
282 RThread t; |
|
283 User::LeaveIfError(t.Open(aId)); |
|
284 CleanupClosePushL(t); |
|
285 RProcess p; |
|
286 User::LeaveIfError(t.Process(p)); |
|
287 TProcessId pid=p.Id(); |
|
288 p.Close(); |
|
289 CleanupStack::PopAndDestroy(&t); |
|
290 return pid; |
|
291 } |
|
292 |
|
293 // ---------------------------------------------------------------------------- |
|
294 // Add array items in aSrc into sorted array aDest if the item is not in |
|
295 // the aDest yet |
|
296 // ---------------------------------------------------------------------------- |
|
297 // |
|
298 EXPORT_C void MPXUser::MergeArray(const MDesCArray& aSrc, CDesCArray& aDest) |
|
299 { |
|
300 for (TInt i=aSrc.MdcaCount(); --i>=0 ;) |
|
301 { |
|
302 ////ignore leave when insert the same item |
|
303 TRAP_IGNORE(aDest.InsertIsqL(aSrc.MdcaPoint(i))); |
|
304 } |
|
305 } |
|
306 |
|
307 // ---------------------------------------------------------------------------- |
|
308 // Copies elements from one array of descriptors to another |
|
309 // ---------------------------------------------------------------------------- |
|
310 // |
|
311 EXPORT_C void MPXUser::CopyArrayL(const MDesCArray& aSrc, CDesCArray& aDest) |
|
312 { |
|
313 aDest.Reset(); |
|
314 for (TInt i=0; i < aSrc.MdcaCount(); ++i) |
|
315 { |
|
316 aDest.AppendL(aSrc.MdcaPoint(i)); |
|
317 } |
|
318 } |
|
319 |
|
320 // ---------------------------------------------------------------------------- |
|
321 // Compare two uids |
|
322 // ---------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C TInt MPXUser::CompareUids(const TUid& aId1, const TUid& aId2) |
|
325 { |
|
326 TInt ret(0); |
|
327 if (aId1.iUid > aId2.iUid) |
|
328 { |
|
329 ret=1; |
|
330 } |
|
331 else if (aId1.iUid < aId2.iUid) |
|
332 { |
|
333 ret=-1; |
|
334 } |
|
335 return ret; |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // Compare two sorted arrays of uids |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 EXPORT_C TInt MPXUser::CompareOrderedUidArrays( |
|
343 const TArray<TUid>& aArray1, |
|
344 const TArray<TUid>& aArray2) |
|
345 { |
|
346 TInt ret(-1); |
|
347 TInt count1 = aArray1.Count(); |
|
348 TInt count2 = aArray2.Count(); |
|
349 if (count1 >= count2) |
|
350 { |
|
351 TInt s1(0); // start point of array 1 |
|
352 TBool found(ETrue); |
|
353 for (TInt i=0; i<count2 && found; ++i) |
|
354 { |
|
355 found = EFalse; |
|
356 for (TInt j=s1; j<count1; ++j) |
|
357 { |
|
358 if (aArray1[j].iUid == aArray2[i].iUid) |
|
359 { |
|
360 s1=j+1; // compare from next item |
|
361 found = ETrue; |
|
362 break; |
|
363 } |
|
364 } |
|
365 } |
|
366 if (found) |
|
367 { |
|
368 if (count1==count2) |
|
369 { |
|
370 ret=0; |
|
371 } |
|
372 else |
|
373 { |
|
374 ret=1; |
|
375 } |
|
376 } |
|
377 } |
|
378 return ret; |
|
379 } |
|
380 |
|
381 // ---------------------------------------------------------------------------- |
|
382 // Internalize an array of item ids from stream |
|
383 // ---------------------------------------------------------------------------- |
|
384 // |
|
385 EXPORT_C void MPXUser::InternalizeL(RArray<TMPXItemId>& aArray, RReadStream& aStream) |
|
386 { |
|
387 TInt n=aStream.ReadInt32L(); |
|
388 for (TInt i=0;i<n;++i) |
|
389 { |
|
390 TUint32 id1(aStream.ReadUint32L()); |
|
391 TUint32 id2(aStream.ReadUint32L()); |
|
392 aArray.AppendL(TMPXItemId(id1,id2)); |
|
393 } |
|
394 } |
|
395 |
|
396 // ---------------------------------------------------------------------------- |
|
397 // Externalize an array of itemids to stream |
|
398 // ---------------------------------------------------------------------------- |
|
399 // |
|
400 EXPORT_C void MPXUser::ExternalizeL(const TArray<TMPXItemId>& aArray, RWriteStream& aStream) |
|
401 { |
|
402 TInt n=aArray.Count(); |
|
403 aStream.WriteInt32L(n); |
|
404 for (TInt i=0;i<n;++i) |
|
405 { |
|
406 aStream.WriteUint32L(aArray[i].iId1); |
|
407 aStream.WriteUint32L(aArray[i].iId2); |
|
408 } |
|
409 } |
|
410 |
|
411 // ---------------------------------------------------------------------------- |
|
412 // Helper to get the window group ID associated with a process |
|
413 // ---------------------------------------------------------------------------- |
|
414 // |
|
415 EXPORT_C TInt MPXUser::FindWindowGroupIdL( |
|
416 TProcessId aProcId, |
|
417 RWsSession& aWsSession ) |
|
418 { |
|
419 TInt wgId( KErrNotFound ); |
|
420 RArray<RWsSession::TWindowGroupChainInfo> windowArray; |
|
421 CleanupClosePushL( windowArray ); |
|
422 aWsSession.WindowGroupList( &windowArray ); |
|
423 TInt wgCount( windowArray.Count() ); |
|
424 |
|
425 for ( TInt i = 0; i < wgCount && wgId == KErrNotFound; i++ ) |
|
426 { |
|
427 TThreadId threadId; |
|
428 User::LeaveIfError( |
|
429 aWsSession.GetWindowGroupClientThreadId( |
|
430 windowArray[i].iId, threadId ) ); |
|
431 RThread thread; |
|
432 CleanupClosePushL( thread ); |
|
433 User::LeaveIfError( thread.Open( threadId )); |
|
434 RProcess proc; |
|
435 CleanupClosePushL( proc ); |
|
436 User::LeaveIfError( thread.Process( proc )); |
|
437 if ( proc.Id() == aProcId ) |
|
438 { |
|
439 wgId = windowArray[i].iId; |
|
440 } |
|
441 CleanupStack::PopAndDestroy( &proc ); |
|
442 CleanupStack::PopAndDestroy( &thread ); |
|
443 } |
|
444 CleanupStack::PopAndDestroy( &windowArray ); |
|
445 return wgId; |
|
446 } |
|
447 |
|
448 // ----------------------------------------------------------------------------- |
|
449 // Check if there is the given type call ongoing. |
|
450 // ----------------------------------------------------------------------------- |
|
451 // |
|
452 EXPORT_C TBool MPXUser::IsCallOngoing( TInt aCallType ) |
|
453 { |
|
454 MPX_FUNC( "MPXUser::IsCallOngoing" ); |
|
455 // In case call info not fully received (err != KErrNone), |
|
456 // assume no call exists. |
|
457 TBool ret( EFalse ); |
|
458 |
|
459 // Get call status and type. |
|
460 TInt callState( EPSCTsyCallStateUninitialized ); |
|
461 |
|
462 TInt err( RProperty::Get( |
|
463 KPSUidCtsyCallInformation, |
|
464 KCTsyCallState, |
|
465 callState ) ); |
|
466 |
|
467 MPX_DEBUG3("MPXUser::IsCallOngoing() call state: %d , error (%d)", callState, err ); |
|
468 |
|
469 if ( !err && |
|
470 ( callState != EPSCTsyCallStateUninitialized && |
|
471 callState != EPSCTsyCallStateNone ) ) |
|
472 { |
|
473 TInt callType( EPSCTsyCallTypeUninitialized ); |
|
474 |
|
475 // There is call ongoing, check it's type. |
|
476 err = RProperty::Get( |
|
477 KPSUidCtsyCallInformation, |
|
478 KCTsyCallType, |
|
479 callType ); |
|
480 |
|
481 MPX_DEBUG3("MPXUser::IsCallOngoing() call type: %d, error (%d)", callType, err ); |
|
482 |
|
483 if ( !err ) |
|
484 { |
|
485 if ( aCallType == KMPXCallTypeGenericVoice ) |
|
486 { |
|
487 // Return true for CSVoice/Video/VOIP calls |
|
488 ret = ( callType == EPSCTsyCallTypeCSVoice || |
|
489 callType == EPSCTsyCallTypeH324Multimedia || |
|
490 callType == EPSCTsyCallTypeVoIP ); |
|
491 MPX_DEBUG2("MPXUser::IsCallOngoing KMPlayerCallTypeGenericVoice return (%d) ", ret ); |
|
492 } |
|
493 else |
|
494 { |
|
495 // Check the requested type call. |
|
496 ret = ( callType == aCallType ); |
|
497 MPX_DEBUG2("MPXUser::IsCallOngoing return (%d) ", ret ); |
|
498 } |
|
499 } |
|
500 } |
|
501 MPX_DEBUG2("MPXUser::IsCallOngoing return (%d) ", ret ); |
|
502 return ret; |
|
503 } |
|
504 |
|
505 // ----------------------------------------------------------------------------- |
|
506 // Compelete file name with file path of the dll |
|
507 // ----------------------------------------------------------------------------- |
|
508 // |
|
509 EXPORT_C TInt MPXUser::CompleteWithDllPath(const TDesC& aDllName, TDes& aFileName) |
|
510 { |
|
511 MPX_DEBUG2("==>MPXUser::CompleteWithDllPath aFileName %S", &aFileName); |
|
512 TInt error(KErrNotSupported); |
|
513 MPX_DEBUG2("MPX Dll file path: %S", &aDllName); |
|
514 TPtrC driveAndPath = TParsePtrC(aDllName).DriveAndPath(); |
|
515 TParse parse; |
|
516 error = parse.Set(aFileName, &driveAndPath, NULL); |
|
517 if (!error) |
|
518 { |
|
519 aFileName.Zero(); |
|
520 aFileName.Append(parse.FullName()); |
|
521 } |
|
522 MPX_DEBUG2("<==MPXUser::CompleteWithDllPath aFileName %S", &aFileName); |
|
523 return error; |
|
524 } |
|
525 |
|
526 // End of file |