Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include "T_EComSessionData.h"
21 #include "T_ImplementationInformationData.h"
22 #include "TestEComInterface.h"
27 _LIT(KResolver, "resolver");
28 _LIT(KExpectedResult, "expected");
29 _LIT(KResolverUid, "resolver_uid");
30 _LIT(KOffset, "offset");
31 _LIT(KInteger, "integer");
32 _LIT(KDescriptor, "descriptor");
33 _LIT(KEmpty, "empty");
34 _LIT(KSaveTo, "saveto");
35 _LIT(KSaveIndex, "saveindex");
38 _LIT(KCmdOpenL, "OpenL");
39 _LIT(KCmdClose, "Close");
40 _LIT(KCmdFinalClose, "FinalClose");
41 _LIT(KCmdNotifyOnChange, "NotifyOnChange");
42 _LIT(KCmdCancelNotifyOnChange, "CancelNotifyOnChange");
43 _LIT(KCmdListImplementationsL, "ListImplementationsL");
44 _LIT(KCmdCreateImplementationL, "CreateImplementationL");
45 _LIT(KCmdDestroyedImplementation, "DestroyedImplementation");
48 _LIT(KEmptyString, "");
49 _LIT(KDefault, "default");
52 //////////////////////////////////////////////////////////////////////
53 // Construction/Destruction
54 //////////////////////////////////////////////////////////////////////
57 * Two phase constructor
59 CT_EComSessionData* CT_EComSessionData::NewL()
61 CT_EComSessionData* ret=new (ELeave) CT_EComSessionData();
62 CleanupStack::PushL(ret);
64 CleanupStack::Pop(ret);
69 * Constructor. First phase construction
71 CT_EComSessionData::CT_EComSessionData()
72 : iActiveNotifyOnChange(NULL)
73 , iImplementationInterface(NULL)
75 iInitParams.iInteger=0;
76 iInitParams.iDescriptor=&iInterfaceDesc;
80 * Second phase construction
82 void CT_EComSessionData::ConstructL()
84 iInterfaceDesc=KEmptyString;
85 iDTorKey=TUid::Uid(0);
86 iActiveNotifyOnChange=CActiveCallback::NewL(*this);
92 CT_EComSessionData::~CT_EComSessionData()
95 iInfoArray.ResetAndDestroy();
97 delete iActiveNotifyOnChange;
98 iActiveNotifyOnChange=NULL;
101 TAny* CT_EComSessionData::GetObject()
103 * Return a pointer to the object that the data wraps
105 * @return Pointer to the object that the data wraps
111 void CT_EComSessionData::DestroyData()
113 if (iImplementationInterface)
115 delete static_cast<CBase*>(iImplementationInterface);
116 iImplementationInterface=NULL;
120 //////////////////////////////////////////////////////////////////////
121 // Read data from INI file
122 //////////////////////////////////////////////////////////////////////
124 void CT_EComSessionData::GetUid(const TDesC& aSection, TUid& aUid)
128 GetHexFromConfig(aSection, KUid(), uidValue );
129 aUid = TUid::Uid(uidValue);
132 TBool CT_EComSessionData::GetResolver(const TDesC& aSection, TPtrC& aResolver)
134 return GetStringFromConfig(aSection, KResolver(), aResolver);
137 TBool CT_EComSessionData::GetResolverUid(const TDesC& aSection, TUid& aUid)
140 TBool ret=GetHexFromConfig(aSection, KResolverUid(), uidValue );
141 aUid = TUid::Uid(uidValue);
145 TBool CT_EComSessionData::GetEmpty(const TDesC& aSection, TBool& aEmpty)
148 return GetBoolFromConfig(aSection, KEmpty(), aEmpty );
151 TBool CT_EComSessionData::GetExpectedResult(const TDesC& aSection, TInt& aExpectedResult)
154 return GetIntFromConfig(aSection, KExpectedResult(), aExpectedResult );
157 TBool CT_EComSessionData::GetOffset(const TDesC& aSection, TInt& aOffset)
159 aOffset=_FOFF(CTestEComInterface, iDtor_ID_Key);
162 TBool ret=GetStringFromConfig(aSection, KOffset(), offset);
165 if ( offset == KDefault )
167 INFO_PRINTF2(_L("Default offset %d"), aOffset);
171 ret=GetIntFromConfig(aSection, KOffset(), aOffset);
178 TBool CT_EComSessionData::GetDescriptor(const TDesC& aSection, TPtrC& aDescriptor)
180 aDescriptor.Set(KEmptyString);
181 return GetStringFromConfig(aSection, KDescriptor(), aDescriptor );
184 TBool CT_EComSessionData::GetInteger(const TDesC& aSection, TInt& aInt)
186 return GetIntFromConfig(aSection, KInteger(), aInt );
190 TBool CT_EComSessionData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
192 * Process a command read from the ini file
194 * @param aCommand The command to process
195 * @param aSection The section in the ini containing data for the command
196 * @param aAsyncErrorIndex Command index for async calls to return errors to
198 * @return ETrue if the command is processed
202 * @leave System wide error
207 if ( aCommand==KCmdOpenL )
211 else if ( aCommand==KCmdClose )
215 else if ( aCommand==KCmdFinalClose )
219 else if ( aCommand==KCmdNotifyOnChange )
221 DoCmdNotifyOnChange(aAsyncErrorIndex);
223 else if ( aCommand==KCmdCancelNotifyOnChange )
225 DoCmdCancelNotifyOnChange();
227 else if ( aCommand==KCmdListImplementationsL )
229 DoCmdListImplementationsL(aSection);
231 else if ( aCommand==KCmdCreateImplementationL )
233 DoCmdCreateImplementationL(aSection);
235 else if ( aCommand==KCmdDestroyedImplementation )
237 DoCmdDestroyedImplementation(aSection);
239 else if ( aCommand==KCmdClean )
250 void CT_EComSessionData::DoCmdOpenL()
252 INFO_PRINTF1(_L("OpenL Call"));
253 TRAPD ( err, iSession = REComSession::OpenL() );
256 ERR_PRINTF2(_L("OpenL Error %d"), err);
261 INFO_PRINTF1(_L("Session opened"));
265 void CT_EComSessionData::DoCmdClose()
267 INFO_PRINTF1(_L("Close"));
271 void CT_EComSessionData::DoCmdFinalClose()
273 INFO_PRINTF1(_L("Final Close"));
274 REComSession::FinalClose();
277 void CT_EComSessionData::DoCmdNotifyOnChange(const TInt aIndex)
279 INFO_PRINTF1(_L("NotifyOnChange"));
280 iSession.NotifyOnChange(iActiveNotifyOnChange->iStatus);
281 iActiveNotifyOnChange->Activate(aIndex);
285 void CT_EComSessionData::DoCmdCancelNotifyOnChange()
287 INFO_PRINTF1(_L("CancelNotifyOnChange"));
288 iSession.CancelNotifyOnChange(iActiveNotifyOnChange->iStatus);
292 // 1. ListImplementationsL with impossible aResolutionParameters argument don't leave
293 // Status: possible defect
294 void CT_EComSessionData::DoCmdListImplementationsL(const TDesC& aSection)
296 INFO_PRINTF1(_L("Getting Implementnation List"));
299 GetUid(aSection, impUid);
302 TBool hasResolverUid=GetResolverUid(aSection, resolverUid);
307 TBool hasResolver=GetResolver(aSection, resolver);
310 TEComResolverParams* resolverParams=static_cast<TEComResolverParams*>(GetDataObjectL(resolver));
311 if ( hasResolverUid )
313 INFO_PRINTF1(_L("Getting Implementnation List(3) by Uid, ResolverParams as a filter params && Resolver Uid as a filter"));
314 TRAP(err, REComSession::ListImplementationsL(impUid, *resolverParams, resolverUid, iInfoArray));
318 INFO_PRINTF1(_L("Getting Implementnation List(1) by Uid && ResolverParams as a filter"));
319 TRAP(err, REComSession::ListImplementationsL(impUid, *resolverParams, iInfoArray));
324 INFO_PRINTF1(_L("Getting Implementnation List(2) by Uid"));
325 TRAP(err, REComSession::ListImplementationsL(impUid, iInfoArray));
330 // Check to see if we the data object has to be set in a CT_ImplementationInformationData
332 if ( GetStringFromConfig(aSection, KSaveTo(), saveTo) )
335 GetIntFromConfig(aSection, KSaveIndex(), index);
336 CDataWrapper* wrapper=static_cast<CDataWrapper*>(GetDataWrapperL(saveTo));
337 wrapper->SetObjectL(iInfoArray[index]);
341 if( err != KErrNone )
343 ERR_PRINTF2(_L("Failed to get implementation list with error %d"), err);
349 if ( GetExpectedResult(aSection, expectedResult) )
351 if (iInfoArray.Count() != expectedResult)
353 ERR_PRINTF3(_L("List retrieved. Found %d imlementations, expected %d"),
354 iInfoArray.Count(), expectedResult );
355 SetBlockResult(EFail);
359 for (TInt i = 0; i < iInfoArray.Count(); i++)
361 const TDesC8& name8=iInfoArray[i]->DataType();
362 TBuf<KMaxTestExecuteCommandLength> name16;
364 INFO_PRINTF3(_L("Implementation UID %d: - \"%S\""), iInfoArray[i]->ImplementationUid().iUid, &(iInfoArray[i]->DisplayName()));
365 INFO_PRINTF2(_L("Data Type is \"%S\""), &name16);
371 // 1. CreateImplementationL with any aKeyOffset argument - aKeyOffset can have any value (-1, 0, 10000, ...)
372 // but CreateImplementationL returns no error and generates memory leak.
373 // Status: possible defects
374 // 2. CreateImplementationL with impossible aResolutionParameters argument - returns KErrnotFound, but in documentation
375 // CreateImplementationL levaes only with KErrNoMemory, KErrNotConnected, KErrArgument or KErrPermissionDenied error
376 // Status: documentation defect
377 void CT_EComSessionData::DoCmdCreateImplementationL(const TDesC& aSection)
382 GetUid(aSection,impUid);
385 TBool hasOffset=GetOffset(aSection,offset);
388 TBool hasResolverUid=GetResolverUid(aSection, resolverUid);
390 TBool hasIntegerValue=GetInteger(aSection, iInitParams.iInteger);
393 TBool hasEmptyArgs=GetEmpty(aSection, emptyArgs);
395 TBool hasInitParams=hasIntegerValue || hasEmptyArgs;
396 TAny* initParamsPtr=NULL;
401 initParamsPtr=&iInitParams;
406 TBool getKeyFromOffset=EFalse;
409 if ( GetResolver(aSection, resolver) )
411 TEComResolverParams* resolverParams=static_cast<TEComResolverParams*>(GetDataObjectL(resolver));
412 if (hasResolverUid && hasInitParams && hasOffset)
414 INFO_PRINTF1(_L("Creating Implementnation(12) by Interface Uid, Offset, Init Params, ResolverParams as a filter params && Resolver Uid as a filter"));
416 TRAP( err, iImplementationInterface =
417 REComSession::CreateImplementationL(impUid, offset, initParamsPtr, *resolverParams, resolverUid));
418 getKeyFromOffset=(err==KErrNone);
420 else if (hasResolverUid && hasInitParams)
422 INFO_PRINTF1(_L("Creating Implementnation(11) by Interface Uid, Init Params, ResolverParams as a filter params && Resolver Uid as a filter"));
423 TRAP( err, iImplementationInterface =
424 REComSession::CreateImplementationL(impUid, iDTorKey, initParamsPtr, *resolverParams, resolverUid));
426 else if (hasResolverUid && hasOffset)
428 INFO_PRINTF1(_L("Creating Implementnation(10) by Interface Uid, Offset, ResolverParams as a filter params && Resolver Uid as a filter"));
429 TRAP( err, iImplementationInterface =
430 REComSession::CreateImplementationL(impUid, offset, *resolverParams, resolverUid));
431 getKeyFromOffset=(err==KErrNone);
433 else if (hasResolverUid)
435 INFO_PRINTF1(_L("Creating Implementnation(9) by Interface Uid, ResolverParams as a filter params && Resolver Uid as a filter"));
436 TRAP( err, iImplementationInterface =
437 REComSession::CreateImplementationL(impUid, iDTorKey, *resolverParams, resolverUid));
439 else if (hasInitParams && hasOffset)
441 INFO_PRINTF1(_L("Creating Implementnation(8) by Interface Uid, Offset, Init Params && Resolver Parameters as a filter"));
442 TRAP( err, iImplementationInterface =
443 REComSession::CreateImplementationL(impUid, offset, initParamsPtr, *resolverParams));
445 getKeyFromOffset=(err==KErrNone);
447 else if (hasInitParams)
449 INFO_PRINTF1(_L("Creating Implementnation(7) by Interface Uid, Init Params && Resolver Parameters as a filter"));
450 TRAP( err, iImplementationInterface =
451 REComSession::CreateImplementationL(impUid, iDTorKey, initParamsPtr, *resolverParams));
455 INFO_PRINTF1(_L("Creating Implementnation(6) by Interface Uid, Offset && Resolver Parameters as a filter"));
457 TRAP( err, iImplementationInterface =
458 REComSession::CreateImplementationL(impUid, offset, *resolverParams));
460 getKeyFromOffset=(err==KErrNone);
464 INFO_PRINTF1(_L("Creating Implementnation(5) by Interface Uid && Resolver Parameters as a filter"));
466 TRAP( err, iImplementationInterface =
467 REComSession::CreateImplementationL(impUid, iDTorKey, *resolverParams));
473 if (hasInitParams && hasOffset)
475 INFO_PRINTF1(_L("Creating Implementnation(4) by Uid, Offset && Construction Parameters"));
477 TRAP( err, iImplementationInterface =
478 REComSession::CreateImplementationL(impUid, offset, initParamsPtr));
480 getKeyFromOffset=(err==KErrNone);
482 else if (hasInitParams)
484 INFO_PRINTF1(_L("Creating Implementnation(3) by Uid && Construction Parameters"));
486 TRAP( err, iImplementationInterface =
487 REComSession::CreateImplementationL(impUid, iDTorKey, initParamsPtr));
492 INFO_PRINTF1(_L("Creating Implementnation(2) by Uid && offset defined by interface"));
494 TRAP( err, iImplementationInterface =
495 REComSession::CreateImplementationL(impUid, offset));
497 getKeyFromOffset=(err==KErrNone);
501 INFO_PRINTF1(_L("Creating Implementnation(1) by Uid"));
503 TRAP( err, iImplementationInterface =
504 REComSession::CreateImplementationL(impUid, iDTorKey ));
509 if ( getKeyFromOffset )
511 TUint8* uidPtr=REINTERPRET_CAST(TUint8*, iImplementationInterface) + offset;
512 TUid* uid=REINTERPRET_CAST(TUid*, uidPtr);
517 INFO_PRINTF2(_L("Implementation created successfully. iDTorKey is %d"), iDTorKey.iUid);
518 if (BlockResult()==EPass)
520 if( err != KErrNone )
522 ERR_PRINTF2(_L("Failed to create implementation with error %d"), err);
524 if (iImplementationInterface != NULL)
526 SetBlockResult(EFail);
527 ERR_PRINTF1(_L("Data verification failed: CreateImplementationL returns an error, but implementation was created"));
531 INFO_PRINTF1(_L("Data verification succcess: CreateImplementationL returns an error and implementation was not created as expected"));
537 void CT_EComSessionData::DoCmdDestroyedImplementation(const TDesC& aSection)
540 if ( GetIntFromConfig(aSection, KUid(), uidValue) )
542 iDTorKey = TUid::Uid(uidValue);
545 INFO_PRINTF2(_L("Destroy Interface Implementation. UID is %d"), iDTorKey.iUid);
546 REComSession::DestroyedImplementation(iDTorKey);
547 INFO_PRINTF1(_L("REComSession::DestroyedImplementation(iDTorKey) completed"));
549 INFO_PRINTF1(_L("Interface implementation destroyed"));
553 Virtual RunL - Called on completion of an asynchronous command
555 @see MTPActiveCallback
556 @param aActive Active Object that RunL has been called on
559 @leave system wide error code
561 void CT_EComSessionData::RunL(CActive* aActive, const TInt aIndex)
563 if ( aActive==iActiveNotifyOnChange )
565 RunNotifyOnChangeL( aIndex );
569 ERR_PRINTF1(_L("Stray signal"));
570 SetBlockResult(EFail);
575 RunNotifyOnChangeL - Process RunL for iActiveNotifyOnChange
579 @leave system wide error code
581 void CT_EComSessionData::RunNotifyOnChangeL(const TInt aIndex)
583 TInt err=iActiveNotifyOnChange->iStatus.Int();
586 ERR_PRINTF2(_L("RunL Error %d"), err);
587 SetAsyncError(aIndex, err);
591 INFO_PRINTF1(_L("RunNotifyOnChangeL OK"));