userlibandfileserver/domainmgr/src/domaincli.cpp
branchRCL_3
changeset 42 a179b74831c9
parent 0 a41df078684a
equal deleted inserted replaced
41:0ffb4e86fcc9 42:a179b74831c9
     1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    17 
    17 
    18 #include <e32base.h>
    18 #include <e32base.h>
    19 #include <e32base_private.h>
    19 #include <e32base_private.h>
    20 #include <e32property.h>
    20 #include <e32property.h>
    21 
    21 
       
    22 
    22 #include <domainmember.h>
    23 #include <domainmember.h>
    23 #include <domainmanager.h>
    24 #include <domainmanager.h>
    24 #include "domainobserver.h"
    25 #include "domainobserver.h"
    25 #include "domainsrv.h"
    26 #include "domainsrv.h"
    26 
    27 
   378 
   379 
   379 TInt RDmManagerSession::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
   380 TInt RDmManagerSession::GetTransitionFailures(RArray<const TTransitionFailure>& aTransitionFailures)
   380 	{
   381 	{
   381 	__DM_ASSERT(Handle() != KNullHandle);
   382 	__DM_ASSERT(Handle() != KNullHandle);
   382 
   383 
       
   384 	
   383 	aTransitionFailures.Reset();
   385 	aTransitionFailures.Reset();
   384 
   386 
   385 	TInt err = KErrNone;
   387 	TInt err = KErrNone;
   386 
   388 		
   387 	TInt failureCount = GetTransitionFailureCount();
   389 	TInt failureCount = GetTransitionFailureCount();
   388 	if (failureCount <= 0)
   390 	if (failureCount <= 0)
   389 		return failureCount;
   391 		return failureCount;
   390 
   392 	
       
   393 	// Pre-allocate array with a known size which for this case is the value in failureCount 
       
   394 	// in order to guarantee that future append operations to the array aTransitionFailures would
       
   395 	// not fail. This is assuming that the pre-allocated size is not exceeded.
       
   396 	err=aTransitionFailures.Reserve(failureCount); 
       
   397 	if (err != KErrNone)
       
   398 		return err;
       
   399 		
   391 	TTransitionFailure* failures = new TTransitionFailure[failureCount];
   400 	TTransitionFailure* failures = new TTransitionFailure[failureCount];
   392 	if(failures == NULL)
   401 	if(failures == NULL)
       
   402 		{		
       
   403 		aTransitionFailures.Reset();
   393 		return(KErrNoMemory);
   404 		return(KErrNoMemory);
       
   405 		}
       
   406 	
   394 	TPtr8 dataPtr(reinterpret_cast<TUint8*>(failures), failureCount * sizeof(TTransitionFailure));
   407 	TPtr8 dataPtr(reinterpret_cast<TUint8*>(failures), failureCount * sizeof(TTransitionFailure));
   395 
   408 
   396 	TIpcArgs a(&dataPtr);
   409 	TIpcArgs a(&dataPtr);
   397 	err = RSessionBase::SendReceive(EDmGetTransitionFailures, a);
   410 	err = RSessionBase::SendReceive(EDmGetTransitionFailures, a);
   398 	
   411 
   399 	if (err == KErrNone)
   412 	if (err == KErrNone)
   400 		{
   413 		{
   401 		for (TInt i=0; i<failureCount; i++)
   414 		for (TInt i=0; i<failureCount; i++)	
   402 			aTransitionFailures.Append(failures[i]);
   415 			{
       
   416 			err = aTransitionFailures.Append(failures[i]);		
       
   417 			//The pre-allocation made above for the array aTransitionFailures should guarantee
       
   418 			//that append operations complete succesfully.			
       
   419 			__DM_ASSERT(err == KErrNone);	
       
   420 			}
   403 		}
   421 		}
   404 
   422 
   405 	delete [] failures;
   423 	delete [] failures;
   406 
   424 
   407 	return err;
   425 	return err;
   437 	TInt count = GetEventCount();
   455 	TInt count = GetEventCount();
   438 	// This shouldn't happen unless something gone terribly wrong
   456 	// This shouldn't happen unless something gone terribly wrong
   439 	if (count <= 0)
   457 	if (count <= 0)
   440 		return KErrGeneral;
   458 		return KErrGeneral;
   441 
   459 
       
   460 	// Pre-allocate array with a known size which for this case is the value in count 
       
   461 	// in order to guarantee that future append operations to the array aTransitionFailures 
       
   462 	// would not fail. This is assuming that the pre-allocated size is not exceeded.
       
   463 	TInt ret=aTransitions.Reserve(count); 
       
   464 	if (ret != KErrNone)
       
   465 		return ret;
       
   466 
   442 	TTransInfo* trans = new TTransInfo[count];
   467 	TTransInfo* trans = new TTransInfo[count];
   443 	if(trans == NULL)
   468 	if(trans == NULL)
       
   469 		{
       
   470 		aTransitions.Reset();
   444 		return(KErrNoMemory);
   471 		return(KErrNoMemory);
       
   472 		}
   445 	
   473 	
   446 	TPtr8 dataPtr(reinterpret_cast<TUint8*>(trans), count * sizeof(TTransInfo));
   474 	TPtr8 dataPtr(reinterpret_cast<TUint8*>(trans), count * sizeof(TTransInfo));
   447 
   475 
   448 	TIpcArgs a(&dataPtr);
   476 	TIpcArgs a(&dataPtr);
   449 	TInt ret=RSessionBase::SendReceive(EDmObserverGetEvent, a);
   477 	ret=RSessionBase::SendReceive(EDmObserverGetEvent, a);
   450 	
   478 	
   451 	if(ret==KErrNone)
   479 	if(ret==KErrNone)
   452 		{
   480 		{
   453 		for (TInt i=0; i<count; i++)
   481 		for (TInt i=0; i<count; i++)
   454 			aTransitions.Append(trans[i]);
   482 			{
       
   483 			ret = aTransitions.Append(trans[i]);					
       
   484 			//The pre-allocation made above for the array aTransitions should guarantee
       
   485 			//that append operations complete succesfully.
       
   486 			__DM_ASSERT(ret == KErrNone);					
       
   487 			}
   455 		}
   488 		}
   456 	
   489 	
   457 	delete [] trans;
   490 	delete [] trans;
   458 	return ret;
   491 	return ret;
   459 	
   492