// ---------------------------------------------------------------------------
// CSensorDataCompensatorAxisDataHandler::Compensate
// ---------------------------------------------------------------------------
//
TInt CSensorDataCompensatorAxisDataHandler::Compensate( TDes8& aData )
    {
	FUNC_LOG;
	TInt err( KErrNone );
    TInt x( 0 );
    TInt y( 0 );
    TInt z( 0 );

    TRACE_MATRIX( "Axis data compensation matrix", iMatrix );

    if ( KSensrvChannelTypeIdMagnetometerXYZAxisData == iDataType )
        {
        INFO( "Compensating magnetometer data" );
        TPckgBuf<TSensrvMagnetometerAxisData> pckg;
        if ( aData.MaxSize() == pckg.MaxSize() )
            {
            pckg.Copy( aData );
            iMatrix.Transform( x, y, z, pckg().iAxisXRaw, pckg().iAxisYRaw,  pckg().iAxisZRaw );
            INFO_3( "Compensated data Magnetometer raw [X: %d], [Y: %d], [Z: %d]", x, y, z );

            pckg().iAxisXRaw = x;
            pckg().iAxisYRaw = y;
            pckg().iAxisZRaw = z;                
            iMatrix.Transform( x, y, z, pckg().iAxisXCalibrated, pckg().iAxisYCalibrated, pckg().iAxisZCalibrated );
            INFO_3( "Compensated data Magnetometer calib [X: %d], [Y: %d], [Z: %d]", x, y, z );

            pckg().iAxisXCalibrated = x;
            pckg().iAxisYCalibrated = y;
            pckg().iAxisZCalibrated = z;
            aData.Copy( pckg );    
            }
        else
            {
            err = KErrArgument;
            }
        }
    else
        {        
        INFO( "Compensating accelerometer data" );
        TPckgBuf<TSensrvAccelerometerAxisData> pckg;
        if ( aData.MaxSize() == pckg.MaxSize() )
            {
            pckg.Copy( aData );
            iMatrix.Transform( x, y, z, pckg().iAxisX, pckg().iAxisY, pckg().iAxisZ );
            INFO_3( "Compensated data accelerometer[X: %d], [Y: %d], [Z: %d]", x, y, z  );
            pckg().iAxisX = x;
            pckg().iAxisY = y;
            pckg().iAxisZ = z;
            aData.Copy( pckg );
            }
        else
            {
            err = KErrArgument;
            }
        }

    ERROR( err, "Axis data compensation error" );
    return err;
    }
LOCAL_C void TestDeleteStoreOperationL()
	{
	CMsgsTestUtils::SetDriveL(EDriveC);

	CSessionObserver* ob = new(ELeave)CSessionObserver;
	CleanupStack::PushL(ob);

	// Set session in observer
	CMsvSession* session = CMsvSession::OpenAsyncL(*ob);
	ob->iSession = session; 
	CleanupStack::PushL(session);
	
	CActiveScheduler::Start();
	test(ob->iType==MMsvSessionObserver::EMsvServerReady);

	CTestActive* active = new(ELeave)CTestActive;
	CleanupStack::PushL(active);
	
	// Test Delete MailStore 
	active->StartL();
	CMsvOperation* operation = NULL;
	TDriveUnit unit =(EDriveD);
	operation = session->DeleteStoreL(unit, active->iStatus);
	test(operation->Mtm() == KUidMsvServerMtm);
	CleanupStack::PushL(operation);
	
    CActiveScheduler::Start();
    
    //Retrieve progress 
	TPckgBuf<TMsvCopyProgress> package;
	package.Copy(operation->ProgressL());
	test((package().iError == KErrNone) || (package().iError == KErrPathNotFound)) ;
	
	CleanupStack::PopAndDestroy(4);	
	}
// ---------------------------------------------------------------------------
// CNATFWTraversalAdapter::SaveL
//
// ---------------------------------------------------------------------------
//
void CNATFWTraversalAdapter::SaveL( TInt aIndex )
    {
    DBG_PRINT( "CNATFWTraversalAdapter::SaveL - begin" );
    CWPNATFWItem* cNATFWItem = iDatas[aIndex];
    const TInt iapItemCount( iDatas[aIndex]->IAPItems().Count() );
    for ( TInt counter = 0; counter < iapItemCount; counter++ )
        {
        // Set access point ID to current IAP item (access point is always
        // stored before NAT/FW settings).
        CNATFWIAPSpecificItem* cIapItem = iDatas[aIndex]->IAPItems()[counter];
        if ( cIapItem->NapDef() )
            {
            // Get WAP ID.
            TPckgBuf<TUint32> uid;
            uid.Copy( cIapItem->NapDef()->Data( 0 ) );
            
            TUint32 wapId( uid() );
            // Get corresponding IAP ID.
            TUint32 iapId = IapIdFromWapIdL( wapId );
            cIapItem->SetIAPId( iapId );
            }// if 
        cIapItem = NULL;    
        }
    cNATFWItem->StoreL();
    cNATFWItem = NULL;
    DBG_PRINT( "CNATFWTraversalAdapter::SaveL - end" );
    }
// -----------------------------------------------------------------------------
// CMceComAvSink::SetParameterL
// -----------------------------------------------------------------------------
//    
TBool CMceComAvSink::SetParameterL( 
    const CMceComEndpoint& aClient, 
    TUint32 aParam,
    const TDesC8& aValue )
    {
    // At the moment, only supported parameter is volume for speaker
    //
    if ( aClient.iType != KMceSpeakerSink || aParam != KMccSpeakerVolume )
        {
        return KMceSrvStreamDefaultSequence;
        }
    
    __ASSERT_ALWAYS( ServesProxyClient( aClient ), User::Leave( KErrNotFound ) );
    
    __ASSERT_ALWAYS( aClient.MediaStream() && aClient.MediaStream()->Session(),
                     User::Leave( KErrNotFound ) );
   
    CMceMediaManager& manager = 
        aClient.MediaStream()->Session()->SdpSession().Manager();
    
    TPckgBuf<TInt> volBuf;
    volBuf.Copy( aValue );
    
    iVolume = volBuf();
    
    if ( aClient.IsEnabled() )
        {
        manager.SetMccParameterL( 
            static_cast<const CMceComMediaSink&>( aClient ), aParam, aValue );
        }
        
    return KMceSrvStreamAlternativeSequence;
    }
// -----------------------------------------------------------------------------
// CNSmlDsProvisioningAdapter::DeleteL
// -----------------------------------------------------------------------------
void CNSmlDsProvisioningAdapter::DeleteL( const TDesC8& aSaveData)
	{
	_DBG_FILE("CNSmlDsProvisioningAdapter::DeleteL(): begin");
	TPckgBuf<TInt> uid;
	uid.Copy( aSaveData );
	iSession.DeleteProfileL( uid() );
	_DBG_FILE("CNSmlDsProvisioningAdapter::DeleteL(): end");
	}
/**
Extracts the artist from the 'get artist' response data and calls 
the relevant mixin function on the observer.	
	
@param The data passed with the response.
*/	
void CRemConTrackInfoController::HandleGetArtistResponse(TInt aError, const TDesC8& aData)
	{
	LOG_FUNC

	TPckgBuf<TName> buf;
	buf.Copy((aData.Mid(KRemConExtApi1ResultDataLength)));
	iObserver.MrcticoGetArtistResponse(aError, buf());
	}
Exemple #7
0
CMsvOperation* CTextMtmClient::ForwardL(TMsvId aForwardEntryId, TMsvPartList aPartList, 
										TRequestStatus& aCompletionStatus)
// Create forwarded message 
// Destination folder is aForwardEntryL
//
	{
	__ASSERT_DEBUG(iMsvEntry!=NULL,gPanic(ETxtcNoCMsvEntrySet));
	__ASSERT_DEBUG(iMsvEntry->Entry().iType.iUid == KUidMsvMessageEntryValue, gPanic(ETxtcEntryTypeNotSupported));
	__ASSERT_DEBUG(iMsvEntry->Entry().iServiceId == KMsvLocalServiceIndexEntryId, gPanic(ETxtcInvalidServiceId));
	
	// Create the forwarded index entry
	TMsvEntry forwardEntry;
	forwardEntry.iMtm = KUidMsgTypeText;
	forwardEntry.iServiceId = Entry().Entry().iServiceId;
	forwardEntry.iType = KUidMsvMessageEntry;
	forwardEntry.iDetails.Set(iMsvEntry->Entry().iDetails);				
	forwardEntry.iSize = iMsvEntry->Entry().iSize;	
	if(aPartList&KMsvMessagePartDate)
		forwardEntry.iDate.HomeTime();
	if(aPartList&KMsvMessagePartDescription)
		forwardEntry.iDescription.Set(iMsvEntry->Entry().iDescription);		

	// Get CMsvEntry for destination (parent)
	CMsvEntry* cEntry = CMsvEntry::NewL(Session(), aForwardEntryId, TMsvSelectionOrdering());
	CleanupStack::PushL(cEntry);
	// Synchronously create new child
	CMsvOperationActiveSchedulerWait* wait = CMsvOperationActiveSchedulerWait::NewLC();
	CMsvOperation* opert = cEntry->CreateL(forwardEntry, wait->iStatus);
	CleanupStack::PushL(opert);
	wait->Start();
	User::LeaveIfError(opert->iStatus.Int());
	// Check result
	TPckgBuf<TMsvLocalOperationProgress> progressPack;
    progressPack.Copy(opert->ProgressL());
	TMsvLocalOperationProgress progress = progressPack();
	User::LeaveIfError(progress.iError);
	CleanupStack::PopAndDestroy(2);	// opert, wait

	// Get CMsvEntry for new entry
	TMsvId forwardId=progress.iId;
	cEntry->SetEntryL(forwardId);
	
	// Populate new forwarded message with Body text
	if(aPartList&KMsvMessagePartBody)
		{
		CMsvStore* store=cEntry->EditStoreL();
		CleanupStack::PushL(store);
		StoreBodyL(*store);				// Current context is original message
		store->CommitL();
		CleanupStack::PopAndDestroy();	// store
		}

	CleanupStack::PopAndDestroy(); // cEntry
		
	// Request was performed synchronously, so return a completed operation object
	return CMsvCompletedOperation::NewL(Session(), KUidMsgTypeText, progressPack, 
		KMsvNullIndexEntryId, aCompletionStatus);
	}
/**
Extracts the track duration from the 'get track duration' response data and calls 
the relevant mixin function on the observer.	
	
@param The data passed with the response.
*/	
void CRemConTrackInfoController::HandleGetTrackDurationResponse(TInt aError, const TDesC8& aData)
	{
	LOG_FUNC	
	
	TPckgBuf<TInt64> buf;
	buf.Copy((aData.Mid(KRemConExtApi1ResultDataLength)));
	TTime duration(buf());
	iObserver.MrcticoGetTrackDurationResponse(aError, duration);
	}
// -----------------------------------------------------------------------------
// CMccFileSource::ConstructSourceL
// -----------------------------------------------------------------------------
//
void CMccFileSource::ConstructSourceL( const TDesC8& aInitData )
    {    	
	iSourceImpl = CMccFileSourceImpl::NewL( 
        MCC_ENDPOINT_ID( static_cast<MDataSource*>( this ) ) );
  
    TPckgBuf<TFileName> initData;
    initData.Copy( aInitData );
    
    OpenFileL( initData() );
    }
// ---------------------------------------------------------------------------
// CSensorDataCompensatorAxisDataHandler::Update
// ---------------------------------------------------------------------------
//
TInt CSensorDataCompensatorAxisDataHandler::Update()
    {
	
	FUNC_LOG;
    TInt err( KErrNone );
    TInt count = iPlugin.GetCompensationItemCount();
    INFO_1( "Axis compensation item count %d", count );
    iMatrix.SetIdentity(); // Reset compensation
    if ( count >= 0 )
        {
        // Calculate final compensation angles and create compensation matrix
        TPckgBuf<TCompensationTypeAxisData> pckg;
        TInt x( 0 );
        TInt y( 0 );
        TInt z( 0 );
        TSensorDataCompensatorMatrix m;
        TSensorDataCompensatorMatrix m2;
        for ( TInt i( 0 ) ; i < count; i++ )
            {
            TPtrC8 data( iPlugin.GetCompensationItem( i ) );
            if ( data.Size() == pckg.MaxSize() )
                {
                pckg.Copy( data );
                x = pckg().iAxisX;
                y = pckg().iAxisY;
                z = pckg().iAxisZ;
                }
            else
                {
                err = KErrCorrupt;
                break;
                }
            m.SetRotateX( x );
            m2.SetRotateY( y );
            m *= m2; // xy
            m2.SetRotateZ( z );
            m *= m2; // xy * z
            iMatrix *= m;
            }
        if ( err != KErrNone )
            {
            iMatrix.SetIdentity();
            }
        }
    else
        {
        // Error occured in plugin
        err = count;
        }
    iCompensate = ( count > 0 ) && ( err == KErrNone ); // Ready to compensate
    ERROR( err, "Axis update error" );
    return err;
    }
void CWin32Socket::Listen(TWin32Message& aMessage)
	{
	TPckgBuf<TUint> queueSizeBuf;
	queueSizeBuf.Copy(aMessage.ReadBuffer());
	TUint& queueSize = queueSizeBuf();
	if (listen(iSocket, queueSize))
		{
		aMessage.Complete(MapWinSockError(WSAGetLastError()));
		}
	else
		{
		aMessage.Complete(KErrNone);
		}
	}
void CWin32Socket::Accept(TWin32Message& aMessage)
	{
	__ASSERT_DEBUG(iAcceptMessage == NULL, Panic(EWinSockPrtCWin32SocketMultipleAcceptRequests));
	__ASSERT_DEBUG(iBlankAcceptSocket == NULL, Panic(EWinSockPrtCWin32SocketAcceptBlankSocketNotNull));
	iAcceptMessage = &aMessage;
	WSP_LOG(WspLog::Printf(_L("CWin32Socket::Accept: this: 0x%x"), this));
	if (WSAEventSelect(iSocket, iEvent, FD_ACCEPT) == SOCKET_ERROR)
		{
		Complete(iAcceptMessage, MapWinSockError(WSAGetLastError()));
		}
	TPckgBuf<TInt> newSocketHandleBuf;
	newSocketHandleBuf.Copy(iAcceptMessage->ReadBuffer());
	iBlankAcceptSocket = (CWin32Socket*)newSocketHandleBuf();
	}
// -----------------------------------------------------------------------------
// CResultCollector::VisitL
// -----------------------------------------------------------------------------
// 
void CResultCollector::VisitL( CNSPTest& aTest )
	{
	CBufFlat* buffer = CBufFlat::NewL( 300 );
	CleanupStack::PushL( buffer );
	RBufWriteStream stream;
	stream.Open( *buffer );
	CleanupClosePushL( stream );
	aTest.ExternalizeL( stream );
	
	TPckgBuf<TResult> pkgIn;
	pkgIn.Copy( buffer->Ptr(0) );
	PrintResult( pkgIn() );
	
	CleanupStack::PopAndDestroy();
	CleanupStack::PopAndDestroy( buffer );
	}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------    
// 
TInt CIpsPlgPop3ConnectOp::GetOperationErrorCodeL( )
    {
    FUNC_LOG;
    if ( !iSubOperation )
        {
        return KErrNotFound;
        }
    if ( !iSubOperation->IsActive() && iSubOperation->iStatus.Int() != KErrNone )
        {
        return iSubOperation->iStatus.Int();
        }
    
    TPckgBuf<TPop3Progress> paramPack;
    paramPack.Copy( iSubOperation->ProgressL() );
    const TPop3Progress& progress = paramPack();
    
    return progress.iErrorCode;
    }
EXPORT_C CMemSpyApiHeap* RMemSpySession::GetHeapL()
	{
	CMemSpyApiHeap* aHeap;
	
	HBufC8* buffer = HBufC8::NewLC( sizeof(TMemSpyHeapData) );
	TPtr8 bufferPtr(buffer->Des());
	TIpcArgs args( &bufferPtr );
	
	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetHeap, args ));
	
	TPckgBuf<TMemSpyHeapData> data;
	data.Copy(bufferPtr.Ptr(), sizeof(TMemSpyHeapData));		
	aHeap = CMemSpyApiHeap::NewL( data() );
	
	CleanupStack::PopAndDestroy(buffer);
		
	return aHeap;
	}
EXPORT_C void RMemSpySession::GetThreadInfoItemsL( RArray<CMemSpyApiThreadInfoItem*> &aInfoItems, TThreadId aId, TMemSpyThreadInfoItemType aType )
	{
	TPckgBuf<TThreadId> id( aId );	
	TPckgBuf<TMemSpyThreadInfoItemType> type( aType );
	TPckgBuf<TInt> count;	
	
	TInt error = SendReceive( EMemSpyClientServerOpGetThreadInfoItemsCount, TIpcArgs( &id, &type, &count ) );
	TInt itemCount = count();
	
	if( error == KErrNone )
		{		
		if( itemCount == 0 )
			{
			aInfoItems.Reset();
			}
		else
			{
			HBufC8* buffer = HBufC8::NewLC( itemCount * sizeof(TMemSpyThreadInfoItemData) );
			TPtr8 bufferPtr(buffer->Des());
			
			TPckgBuf<TInt> requestedCount( itemCount );
			
			TIpcArgs args( &requestedCount, &id, &type, &bufferPtr );
			TInt error = SendReceive( EMemSpyClientServerOpGetThreadInfoItems, args ); // TODO check error
			
			aInfoItems.Reset();
		
			for(TInt i=0, offset = 0; i < itemCount; i++, offset+=sizeof(TMemSpyThreadInfoItemData))
				{
				TPckgBuf<TMemSpyThreadInfoItemData> data;
				data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyThreadInfoItemData));
				aInfoItems.AppendL(CMemSpyApiThreadInfoItem::NewLC(data()));
				}
			
			CleanupStack::Pop(aInfoItems.Count());
			CleanupStack::PopAndDestroy(buffer);
			}
		}
	
	User::LeaveIfError(error);
	}
LOCAL_C void TestStoreExistsL()
	{
	CMsgsTestUtils::SetDriveL(EDriveC);
	
	//Check that message store exists on the drive at this stage
	CSessionObserver* ob = new(ELeave)CSessionObserver;
	CleanupStack::PushL(ob);
       
	// Set session in observer
	CMsvSession* session = CMsvSession::OpenAsyncL(*ob);
	ob->iSession = session; 
	CleanupStack::PushL(session);
    
	CActiveScheduler::Start();
	test(ob->iType==MMsvSessionObserver::EMsvServerReady);
	
	CTestActive* active = new(ELeave)CTestActive;
	CleanupStack::PushL(active);
     
	// Test Copy MailStore 
	active->StartL();
	CMsvOperation* operation = NULL;
	TDriveUnit unit = EDriveD;
	operation = session->CopyStoreL(unit, active->iStatus);
	test(operation->Mtm() == KUidMsvServerMtm);
	CleanupStack::PushL(operation);
	
	CActiveScheduler::Start();
	
	//Retrieve progress 
	//Should retrun KErrAlreadyExists
	TPckgBuf<TMsvCopyProgress> package;
	package.Copy(operation->ProgressL());
	test(package().iError == KErrAlreadyExists);
		
	//delete session;
	CleanupStack::PopAndDestroy(4, ob);
	
	CMsgsTestUtils::WaitForServerClose();
		
  	}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
//
TInt CIpsSosAOImapPopLogic::QueryMailboxStatus( TDesC8& aParameter )
    {
    FUNC_LOG;
    TPckgBuf<RMessage2> param;
    param.Copy( aParameter );
    // get ipc message from param
    RMessage2 msg = param();
    TPckgBuf<TMsvId> mboxBuf;
    msg.Read(0, mboxBuf);
    
    TMsvId mbox = mboxBuf();
    
    TInt error = KErrNone;
    
    TInt index = GetMailboxLogicIndex( mbox );


    if ( index != KErrNotFound )
        {
        TInt state = iMailboxLogics[index]->GetCurrentState(); // faulty CS warning

        if ( state == CIpsSosAOMBoxLogic::EStateSyncOngoing
          || state == CIpsSosAOMBoxLogic::EStateFetchOngoing )
            {
            TPckgBuf<TInt> event( EIpsAOPluginStatusSyncStarted );
            msg.Write(1, event );
            }
        else
            {
            TPckgBuf<TInt> event( EIpsAOPluginStatusSyncCompleted );
            msg.Write(1, event );
            }
        }
    else
        {
        error = KErrNotFound;
        }
    
    return error;
    }
/**
Log command data
*/
void CMockPowerEngine::DoLogCommandData(TInt aCmdId, const TMockHwrmPluginData& aCmdData, const TDesC& aComment)
	{
	TBuf<KMaxLogLineSize> buffer;

    if (aCmdId == HWRMPowerCommand::EStartAverageBatteryPowerReportingCmdId)
        {
        TPckgBuf<TUint> intervalMultipleData;
		intervalMultipleData.Copy(aCmdData.CommandData());
		buffer.Format(_L("%S: Power intervalMultipleData=%d"), & aComment,
				intervalMultipleData());
        }
#ifdef SYMBIAN_HWRM_EXTPOWERINFO
    else if (aCmdId == HWRMPowerCommand::EStartAverageBatteryChargingCurrentReportingCmdId)
		{
		HWRMPowerCommand::TChrgCurrentIntervalMultiplePackage intervalMultipleData;
		intervalMultipleData.Copy(aCmdData.CommandData());
		buffer.Format(_L("%S: intervalMultipleData=%d"), & aComment,
				intervalMultipleData());			
		}		
#endif //SYMBIAN_HWRM_EXTPOWERINFO
	Log(buffer);
	}
// Servers
EXPORT_C void RMemSpySession::GetServersL(RArray<CMemSpyApiServer*> &aServers)
    {
    TPckgBuf<TInt> count;
    User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetServerCount, TIpcArgs(&count)));
    
    TInt requestedCount = count();
    HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyServerData));
    TPtr8 bufferPtr(buffer->Des());
    
    User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetServers, TIpcArgs(&count, &bufferPtr)));
    aServers.Reset();
    
    TInt receivedCount = Min(count(), requestedCount);
    for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyServerData))
        {
        TPckgBuf<TMemSpyServerData> data;
        data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyServerData));
        aServers.AppendL(CMemSpyApiServer::NewLC(data()));
        }
    CleanupStack::Pop(aServers.Count());
    CleanupStack::PopAndDestroy(buffer);
    }
EXPORT_C void RMemSpySession::GetEComImplementationsL(TUid aInterface, RArray<CMemSpyApiEComImplementation*> &aImplementations)
    {
    TPckgBuf<TInt> count;
    TPckgBuf<TUid> interface(aInterface);
    User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetEComImplementationCount, TIpcArgs(&count, &interface)));
    
    TInt requestedCount = count();
    HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyEComImplementationData));
    TPtr8 bufferPtr(buffer->Des());
    
    User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetEComImplementations, TIpcArgs(&count, &interface, &bufferPtr)));
    aImplementations.Reset();
    
    TInt receivedCount = Min(count(), requestedCount);
    for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyEComImplementationData))
        {
        TPckgBuf<TMemSpyEComImplementationData> data;
        data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyEComImplementationData));
        aImplementations.AppendL(CMemSpyApiEComImplementation::NewLC(data()));
        }
    CleanupStack::Pop(aImplementations.Count());
    CleanupStack::PopAndDestroy(buffer);
    }
// Threads related methods
EXPORT_C void RMemSpySession::GetThreadsL(TProcessId aProcessId, RArray<CMemSpyApiThread*> &aThreads, TSortType aSortType)
	{
	TPckgBuf<TInt> count;
	TPckgBuf<TProcessId> pid(aProcessId);
	User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetThreadCount, TIpcArgs(&count, &pid)));
	
	TInt requestedCount = count();
	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyThreadData));
	TPtr8 bufferPtr(buffer->Des());
	
	User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetThreads, TIpcArgs(&count, &bufferPtr, &pid)));
	aThreads.Reset();
	
	TInt receivedCount = Min(count(), requestedCount);
	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyThreadData))
		{
		TPckgBuf<TMemSpyThreadData> data;
		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyThreadData));
		aThreads.AppendL(CMemSpyApiThread::NewLC(data()));
		}
	CleanupStack::Pop(aThreads.Count());
	CleanupStack::PopAndDestroy(buffer);
	}
EXPORT_C void RMemSpySession::GetKernelObjectItemsL( RArray<CMemSpyApiKernelObjectItem*> &aKernelObjectItems, TMemSpyDriverContainerType aForContainer )
	{
	TPckgBuf<TInt> count;
	TPckgBuf<TMemSpyDriverContainerType> type(aForContainer);
	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectItemCount, TIpcArgs(&count, &type) ));

	TInt requestedCount = count();
	HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyDriverHandleInfoGeneric));
	TPtr8 bufferPtr(buffer->Des());
	
	TIpcArgs args( &count, &type, &bufferPtr );
	User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectItems, args ));
	
	aKernelObjectItems.Reset();
	
	for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyDriverHandleInfoGeneric))
		{
		TPckgBuf<TMemSpyDriverHandleInfoGeneric> data;
		data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyDriverHandleInfoGeneric));
		aKernelObjectItems.AppendL( CMemSpyApiKernelObjectItem::NewLC( data() ) );
		}
	CleanupStack::Pop(aKernelObjectItems.Count());
	CleanupStack::PopAndDestroy(buffer);
	}
// -----------------------------------------------------------------------------
// CWPWAPBrowserAdapter::DeleteL
// -----------------------------------------------------------------------------
//
void CWPWAPBrowserAdapter::DeleteL( const TDesC8& aSaveData )
    {
    CreateDbL();

    TPckgBuf<MWPWAPItemBase::TWPWAPSaveItem> item;
    item.Copy( aSaveData );

    switch( item().iSaveItemType )
        {
        case KWPWAPItemTypeAccesspoint:
            {
            // Access point deletion is handled by the base class
            CWPWAPAdapterBase::DeleteL( aSaveData );
            break;
            }

        case KWPWAPItemTypeBookmark:
            {
            DVA( "DeleteL: Deleting bookmark %08x", item().iUID );
            TInt err = iFavouritesDb.Begin( ETrue );
            iFavouritesDb.CleanupRollbackPushL();  // push a rollback
            
            DVA( "DeleteL: Transaction, %d", err );
            if( err == KErrNone )
                {
                err = iFavouritesDb.Delete( item().iUID );
                DVA( "DeleteL: Deleted, %d", err );
                iFavouritesDb.Commit();
                DEBUG( "DeleteL: Committed" );
                }
            CleanupStack::Pop();    // pop the rollback

            switch( err )
                {
                case KErrNotFound:
                    {
                    // Item not existing is what we want, so this error is ok
                    break;
                    }
                    
                case KErrLocked:
                    {
                    User::Leave( EWPBookmarksLocked );
                    break;
                    }
                    
                default:
                    {
                    User::LeaveIfError( err );
                    break;
                    }
                }
            break;
            }

        default:
            {
            // Don't know how to delete an item of this type. Better
            // just ignore it.
            break;
            }
        }
    }
void CMockPowerEngine::FurtherProcessEventL(const TInt aCommandId, TDesC8& aData)
	{
	switch (aCommandId)
		{

        case HWRMPowerCommand::EStartAverageBatteryPowerReportingCmdId:
			{
			// starting the measurements. Set flag ETrue and the counter to 0.
			iPowerReporting = ETrue;
			iPowerVoltageNotificationCounter = 0;
            iPowerCurrentNotificationCounter = 0;
			
			// Setting the interval multiple to the requested valuue
			TPckgBuf<TUint> requestedIntervalMultiplePckg;
			requestedIntervalMultiplePckg.Copy(aData);			    
			iPowerNotificationPeriod = requestedIntervalMultiplePckg();
			}
		break;

        case HWRMPowerCommand::ESetPowerReportingIntervalMultipleCmdId:
			{
			// Setting the interval multiple to the requested valuue
			TPckgBuf<TUint> requestedIntervalMultiplePckg;
			requestedIntervalMultiplePckg.Copy(aData);
			iPowerNotificationPeriod = requestedIntervalMultiplePckg();
			}
		break;
    	case HWRMPowerCommand::EStopAverageBatteryPowerReportingCmdId:
    		{
    		iPowerReporting = EFalse;
    		}
		break;
#ifdef SYMBIAN_HWRM_EXTPOWERINFO
        case HWRMPowerCommand::EStartAverageBatteryChargingCurrentReportingCmdId:
			{
			// starting the measurements. Set flag ETrue and the counter to 0.
			iChargingCurrentReporting = ETrue;
			iChargingCurrentCounter = 0;
			
			// Setting the interval multiple to the requested valuue
			HWRMPowerCommand::TChrgCurrentIntervalMultiplePackage requestedIntervalMultiplePckg;
			requestedIntervalMultiplePckg.Copy(aData);			    
			iChargingCurrentNotificationPeriod = requestedIntervalMultiplePckg();
			}
		break;

        case HWRMPowerCommand::EStartBatteryFullChargingTimeReportingCmdId:
			{
			// starting the measurements. Set flag ETrue and the counter to 0.
			iChargingTimeReporting = ETrue;
			iChargeTimeCounter = 0;
			
			//Notification time is decided by plugin
			iChargeTimeNotificationPeriod = 1;
			}
		break;
		
        case HWRMPowerCommand::ESetChargeCurrentIntervalMultipleCmdId:
			{
			// Setting the interval multiple to the requested valuue
			HWRMPowerCommand::TChrgCurrentIntervalMultiplePackage requestedIntervalMultiplePckg;
			requestedIntervalMultiplePckg.Copy(aData);
			iChargingCurrentNotificationPeriod = requestedIntervalMultiplePckg();
			}
		break;
		
		case HWRMPowerCommand::EStopAverageBatteryChargingCurrentReportingCmdId:
			{
			iChargingCurrentReporting = EFalse;
			}
		break;

        case HWRMPowerCommand::EStopBatteryFullChargingTimeReportingCmdId:
			{
			iChargingTimeReporting = EFalse;
			}
		break;
#endif //SYMBIAN_HWRM_EXTPOWERINFO
        
		default:
		break;		
		}
	}
/**
Called when the INIT property is changed and once on the construction of the object. Extracts 
the message from the INIT property, notifies both the observer by calling the 
MLbsSuplPushRecObserver::OnSuplInit function and the sender by setting the ACK property.
Then it resubscribes for the INIT property to listen for next messages.

@see CSuplPushImpl
@see MLbsSuplPushRecObserver::OnSuplInit
@see CActive::RunL
*/
void CLbsSuplPushRecChannel::RunL()
	{
	LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() Begin\n");
	if(iStatus==KErrNone)
		{
		iInitProperty.Subscribe(iStatus);
		SetActive();
		
		TPckgBuf<TInt> length;
		TInt err = RProperty::Get(iPropOwnerSecureId, iInitPropKey, length);
		
		//The INIT propery has been defined but not set yet.
		if(err==KErrNone && length.Length()==0)
			{
			LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - err==KErrNone && length.Length()==0 End\n");
			return;
			}
		
		//Can't do anything here, just resubscribe
		if(err!=KErrOverflow || length()<=0)
			{
			//The property must be set in the correct value.
			__ASSERT_DEBUG(0, User::Invariant());
			LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - err!=KErrOverflow || length()<=0 End\n");
			return;
			}

		TInt len = length() + 2*sizeof(TInt);
		
		HBufC8* msg = HBufC8::New(len);
		
		//Not enough memory to handle the message, just resubscribe 
		if(msg==0)
			{
			LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - msg==0 End\n");
			return;
			}
		
		TPtr8 ptr = msg->Des();
		err = RProperty::Get(iPropOwnerSecureId, iInitPropKey, ptr);
		if(err!=KErrNone || ptr.Length()!=len)
			{
			delete msg;
			//Unexpected environment error or the length of the message is not equal the length declared in
			//the header.
			__ASSERT_DEBUG(0, User::Invariant());
			LBSLOG(ELogP1, 
				"CLbsSuplPushRecChannel::RunL() RProperty::Get(iPropOwnerSecureId, iInitPropKey, ptr)|| ptr.Length()!=len End\n");
			return;
			}
		
		TPckgBuf<TInt> reqId;
		reqId.Copy(msg->Mid(sizeof(TInt), sizeof(TInt))); 
		
		if(reqId()<=0)
			{
			delete msg;
			//Message is corrupted, the reqId must be > 0. 
			__ASSERT_DEBUG(0, User::Invariant());
			LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() - reqId()<=0 End\n");
			return;
			}

			
		TInt ackId = 0;
		err = RProperty::Get(iPropOwnerSecureId, iAckPropKey, ackId);

		if(err!=KErrNone || ackId<0)
			{
			delete msg;
			if(ackId<0)
				{
				RProperty::Set(iPropOwnerSecureId, iAckPropKey, 0);
				}
			//Unexpected environment error or wrong ackId, it must be > 0.
			__ASSERT_DEBUG(0, User::Invariant());
			LBSLOG(ELogP1, 
					"CLbsSuplPushRecChannel::RunL() - RProperty::Get(iPropOwnerSecureId, iAckPropKey, ackId)!=KErrNone || ackId<0 End\n");
			return;
			}
		

		//We notify the observer only if message was not delivered before
		if(ackId!=reqId())
			{
			TLbsSuplPushRequestId reqIdUnsgn = reqId(); 
			TPtrC8 msgPtr = msg->Right(length());
			err = RProperty::Set(iPropOwnerSecureId, iAckPropKey, reqId());
			//Unexpected environment error.
			__ASSERT_DEBUG(err==KErrNone, User::Invariant());
			iObserver.OnSuplInit(iChannel, reqIdUnsgn , msgPtr);
			LBSLOG(ELogP9, "<-S MLbsSuplPushRecObserver::OnSuplInit() SuplPush\n");
			LBSLOG2(ELogP9, "  > TLbsSuplPushChannel aChannel = %d\n", iChannel);
			LBSLOG2(ELogP9, "  > TLbsSuplPushRequestId aReqId = %d\n", reqIdUnsgn);
			
			}
						
		delete msg;
		}
	else
		{
		iInitProperty.Subscribe(iStatus);
		SetActive();
		}
	LBSLOG(ELogP1, "CLbsSuplPushRecChannel::RunL() End\n");
	}
// -----------------------------------------------------------------------------
// CNSmlDsProvisioningAdapter::SaveL
// -----------------------------------------------------------------------------
void CNSmlDsProvisioningAdapter::SaveL(TInt aItem)
	{
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): begin");
	TPckgBuf<TUint32> uid;
	
	RSyncMLDataSyncProfile profile;
	TBool ret = EFalse;
	
	if(iProfiles[aItem]->iServerId != NULL)
	{
	RSyncMLDataSyncProfile ProfileToSearch;
	RArray<TSmlProfileId> arr;
    iSession.ListProfilesL( arr, ESmlDataSync );
    
    TInt ProfileId = KErrNotFound;
    CleanupClosePushL(arr);   	
	for ( TInt index = 0; index < arr.Count(); index++ )
		{
	    TRAPD( error, ProfileToSearch.OpenL(iSession, arr[index], ESmlOpenRead ) );
	    if ( error == KErrNone )
	        {	            	            	        
    	        if ( ( iProfiles[aItem]->iServerId->Des()).Compare(ProfileToSearch.ServerId() ) == 0 )
    	            {
    	            
                    ret = ETrue;                    
                    ProfileId = (TInt)arr[index];
                    ProfileToSearch.Close();
                    break;
                    }	            		    
	        }
	      ProfileToSearch.Close();  
		}
    CleanupStack::PopAndDestroy( &arr );
	
	if( ret )
		{
		profile.OpenL(iSession, ProfileId , ESmlOpenReadWrite );	
		}
	else
		{
	profile.CreateL( iSession );
		}
	CleanupClosePushL( profile );	
	}
	else
	{
		
		profile.CreateL( iSession );
		CleanupClosePushL( profile );	
	}
	
	// ui needs this to be set 0
	profile.SetCreatorId(0);//iProfiles[aItem]->iProfile.SetCreatorId(0);
	profile.SetSanUserInteractionL( iProfiles[aItem]->iServerAlertedAction );
	
	if ( iProfiles[aItem]->iDisplayName )
	    {
	    profile.SetDisplayNameL( iProfiles[aItem]->iDisplayName->Des() );    
	    }
	
	if ( iProfiles[aItem]->iServerId )
	    {
	    profile.SetServerIdL( iProfiles[aItem]->iServerId->Des() );    
	    }
	    
	if ( iProfiles[aItem]->iUsername )   
	    {
	    profile.SetUserNameL( iProfiles[aItem]->iUsername->Des() );    
	    }
	
	if ( iProfiles[aItem]->iPassword )
	    {
	    profile.SetPasswordL( iProfiles[aItem]->iPassword->Des() );    
	    }
	    
	// creates profile -> must be done before opening the connection
	profile.UpdateL();
		
	RSyncMLConnection connection;
	connection.OpenL( profile, KUidNSmlMediumTypeInternet.iUid );
	CleanupClosePushL( connection );
		
    if ( (iProfiles[aItem]->iVisitParameter
            && iProfiles[aItem]->iVisitParameter->Data().Length() == uid.MaxLength() )
            || iToNapIDInternetIndicator)
		{
        TUint apId = 0;
        TInt ERROR = KErrNone;
        TInt err1 = KErrNone;

        if (iToNapIDInternetIndicator)
            {
            //Get Access Point from DB or SNAP
            TRAP(err1, apId = WPAdapterUtil::GetAPIDL());
            }

        else
            {
            uid.Copy(iProfiles[aItem]->iVisitParameter->Data() );

            RCmManagerExt  cmmanagerExt;
		    cmmanagerExt.OpenL();
		    CleanupClosePushL(cmmanagerExt);
		    RCmConnectionMethodExt cm;
		    cm = cmmanagerExt.ConnectionMethodL( uid());
		    CleanupClosePushL( cm );

            TRAP( ERROR, apId = cm.GetIntAttributeL(CMManager::ECmIapId) );
            CleanupStack::PopAndDestroy(2); //cmmanager,cm
            }

        //Get default access point in failure of getting AP
        if (ERROR != KErrNone || err1 != KErrNone)
			{
			apId = GetDefaultIAPL();
			}
		
		HBufC8* iapBuf = HBufC8::NewLC( 8 );
		TPtr8 ptrBuf = iapBuf->Des();
		ptrBuf.Num( apId );
		
		connection.SetPropertyL( KNSmlIAPId, *iapBuf );
			
        CleanupStack::PopAndDestroy(); //iapBuf	
		}
		
	if( iProfiles[aItem]->iHostAddress )
		{
		// see if address contains also port
		TBool portFound = EFalse;
		TInt startPos(0);
		if(iProfiles[aItem]->iHostAddress->Find(KNSmlDsProvisioningHTTP)==0)
		    {
		    startPos=KNSmlDsProvisioningHTTP().Length();		    		    
		    }
		else if(iProfiles[aItem]->iHostAddress->Find(KNSmlDsProvisioningHTTPS)==0)
		    {
		    startPos=KNSmlDsProvisioningHTTPS().Length();		    		    
		    }
		TPtrC uriPtr = iProfiles[aItem]->iHostAddress->Mid(startPos);
		
		if(uriPtr.Locate(KNSmlDMColon)!=KErrNotFound)
		    {
			portFound = ETrue;
		    }
	
		if( portFound == EFalse )
			{
			HBufC *uri = 0;
			// port not found from URI -> see if it is given separately				
			if( iProfiles[aItem]->iPort )
				{
				// parse address and port into URI
			
				if( CombineURILC( iProfiles[aItem]->iHostAddress->Des(),
							  iProfiles[aItem]->iPort->Des(), uri ) == KErrNone )
					{
					if(iProfiles[aItem]->iHostAddress)
					{
						delete iProfiles[aItem]->iHostAddress;
						iProfiles[aItem]->iHostAddress = NULL;
					}
					iProfiles[aItem]->iHostAddress = uri->Des().AllocL();
					}
				CleanupStack::PopAndDestroy(); // uri		  
				}
			else
				{
				// use default port
				if( CombineURILC( iProfiles[aItem]->iHostAddress->Des(),
							  KNSmlDsDefaultPort(), uri ) == KErrNone )
					{
					if(iProfiles[aItem]->iHostAddress)
					{
						delete iProfiles[aItem]->iHostAddress;
						iProfiles[aItem]->iHostAddress = NULL;
					}
					iProfiles[aItem]->iHostAddress = uri->Des().AllocL();
					}
				CleanupStack::PopAndDestroy(); // uri		  
				}
			}
		

		connection.SetServerURIL( ConvertTo8LC( iProfiles[aItem]->iHostAddress->Des() ) );
		CleanupStack::PopAndDestroy(); // ConvertTo8LC
		}
		
	// set authtype, HTTPUserName, HTTPPassword
	if( iProfiles[aItem]->iHTTPUserName ||
	    iProfiles[aItem]->iHTTPPassword )
		{
		connection.SetPropertyL( KNSmlHTTPAuth, KNSmlTrueVal );
		
		if( iProfiles[aItem]->iHTTPUserName )
			{
			connection.SetPropertyL( KNSmlHTTPUsername, iProfiles[aItem]->iHTTPUserName->Des() );
			}
		if( iProfiles[aItem]->iHTTPPassword )
			{
			connection.SetPropertyL( KNSmlHTTPPassword, iProfiles[aItem]->iHTTPPassword->Des() );
			}
		}
	else
		{
		connection.SetPropertyL( KNSmlHTTPAuth, KNSmlFalseVal );
		}
		
	connection.UpdateL();
	CleanupStack::PopAndDestroy(); // connection
	
	
		
	
	
	if(iProfiles[aItem]->iProtocolVersion == ESmlVersion1_1_2 || 
			iProfiles[aItem]->iProtocolVersion == ESmlVersion1_2 )
	{
		profile.SetProtocolVersionL(iProfiles[aItem]->iProtocolVersion);
	}

	
	
	
	
		
	TInt iDataProvElementCount = iProfiles[aItem]->iDataProvElement.Count();
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): Resource For loop: before Start");
	for ( TInt i = 0; i < iDataProvElementCount; i++ )
		{
        _DBG_FILE(
                "CNSmlDsProvisioningAdapter::SaveL(): Resource For loop: In");
		RSyncMLDataProvider dataProvider;

        TRAPD(error, dataProvider.OpenL(iSession,
                iProfiles[aItem]->iDataProvElement[i]->iUid));
		if (!error)
		    {
		    CleanupClosePushL(dataProvider);
            if (ret)
                {
                RArray<TSmlTaskId> providers;
                profile.ListTasksL(providers);
                TInt dataprovcount = providers.Count();

                for (TInt i = 0; i < dataprovcount; i++)
                    {
                    TSmlTaskId taskID = providers[i];
                    RSyncMLTask task;
                    task.OpenL(profile, taskID);
                    CleanupClosePushL(task);

                    if (dataProvider.Identifier() == task.DataProvider())
                        {
                        profile.DeleteTaskL(taskID);
                        CleanupStack::PopAndDestroy();
                        break;
                        }

                    CleanupStack::PopAndDestroy();

                    }
                providers.Reset();
                providers.Close();

                }
            HBufC* localDB = dataProvider.DefaultDataStoreName().AllocLC();
            _DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): DB value");
            DBG_ARGS(
                    iProfiles[aItem]->iDataProvElement[i]->iRemoteDBUri->Des().Ptr());

            RSyncMLTask task;
            task.CreateL(
                    profile,
                    iProfiles[aItem]->iDataProvElement[i]->iUid,
                    iProfiles[aItem]->iDataProvElement[i]->iRemoteDBUri->Des(),
                    localDB->Des());
            CleanupClosePushL(task);
            TRAPD(err, task.UpdateL());
            if (err != KErrAlreadyExists && err != KErrNone)
                {
                User::Leave(err);
                }
            CleanupStack::PopAndDestroy(3); // task, localDB, dataProvider
		    }
		
		}
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): Resource For loop: after End");
				
	profile.UpdateL();
	iProfiles[aItem]->iProfileId = profile.Identifier();
	CleanupStack::PopAndDestroy( &profile );
	_DBG_FILE("CNSmlDsProvisioningAdapter::SaveL(): end");
	}
EXPORT_C void CSchSendTestUtils::DisplayAllSchedulesL(TInt& rSchCount, TInt& rSchSize)
	{
	Printf(_L("Displaying all Schedules:\n"));
	rSchCount = 0;
	rSchSize = 0;

	TParse parse;
	TFileName fileName(_L("\\system\\schedules\\")); 
	_LIT(KCDrive, "C:");
	parse.Set(fileName, &KCDrive, NULL);

	CDir* entryList;
	TPtrC drive(parse.DriveAndPath());
	TInt err = iFs.GetDir(drive, KEntryAttNormal, ESortNone, entryList);
	
	if (err)
		{
		Printf(_L("\tiFs.GetDir(%S) returned %d\n"), &drive, err);
		return;
		}

	CleanupStack::PushL(entryList);
	
	TInt count = entryList->Count();

	while (count--)
		{
		TEntry entry((*entryList)[count]);
		rSchSize += entry.iSize;
		}

	Printf(_L("\tFiles in %S have total size %d\n"), &drive, rSchSize);

	CleanupStack::PopAndDestroy(entryList);

	RScheduler sch;
	err = sch.Connect();

	if (err)
		{
		Printf(_L("\tRScheduler::Connect() returned %d\n"), err);
		return;
		}
	
	CleanupClosePushL(sch);

	IMPORT_C TInt GetScheduleL(const TInt aScheduleHandle, TScheduleState& aState, 
			CArrayFixFlat<TScheduleEntryInfo>& aEntries, CArrayFixFlat<TTaskInfo>& aTasks, TTime& aDueTime);

	CArrayFixFlat<TSchedulerItemRef>* schRefArray = new (ELeave) CArrayFixFlat<TSchedulerItemRef>(10);
	CleanupStack::PushL(schRefArray);

	CArrayFixFlat<TScheduleEntryInfo>* schEntries = new (ELeave) CArrayFixFlat<TScheduleEntryInfo>(10);
	CleanupStack::PushL(schEntries);

	CArrayFixFlat<TTaskInfo>* schTasks = new (ELeave) CArrayFixFlat<TTaskInfo>(10);
	CleanupStack::PushL(schTasks);

	err = sch.GetScheduleRefsL(*schRefArray, EAllSchedules);

	if (!err)
		{
		TScheduleState schState;
		TTime schDueTime;
		count = schRefArray->Count();
		rSchCount = count;
		Printf(_L("\t%d schedules in the task scheduler\n"), count);

		while (count--)
			{
			err = sch.GetScheduleL((*schRefArray)[count].iHandle, schState, *schEntries, *schTasks, schDueTime);

			if (!err)
				{
				TInt taskCount = schTasks->Count();
				Printf(_L("\tSchedule %d (\"%S\") has %d tasks\n"), (*schRefArray)[count].iHandle, &(*schRefArray)[count].iName, taskCount);

				while (taskCount--)
					{
					TTaskInfo taskInfo((*schTasks)[taskCount]);
					TInt size;
					err = sch.GetTaskDataSize(taskInfo.iTaskId, size);

					if (!err)
						{
						HBufC* hBuf = HBufC::NewLC(size);
						TPtr ptr(hBuf->Des());
						TSchedulerItemRef schRef;

						err = sch.GetTaskInfoL(taskInfo.iTaskId, taskInfo, ptr, schRef, schDueTime);

						if (!err)
							{
							TPckgBuf<TMsvSchedulePackage> mtmBuf;
							mtmBuf.Copy(*hBuf);
							Printf(_L("\t\tTask %d: msvId %d, commandId %d, pollProgress %d\n"), taskInfo.iTaskId, mtmBuf().iId, mtmBuf().iCommandId, mtmBuf().iPollProgress.Int());
							}
						else
							{
							Printf(_L("\t\tRScheduler::GetTaskInfoL(%d) returned %d\n"), taskInfo.iTaskId, err);
							}

						CleanupStack::PopAndDestroy(hBuf);
						}
					else
						{
						Printf(_L("\t\tRScheduler::GetTaskDataSize(%d) returned %d\n"), taskInfo.iTaskId, err);
						}
					}
				}
			else
				{
				Printf(_L("\tRScheduler::GetScheduleL(%d (\"%S\")) returned %d\n"), (*schRefArray)[count].iHandle, &(*schRefArray)[count].iName, err);
				}
			}
		}
	else
		{
		Printf(_L("RScheduler::GetScheduleRefsL() returned %d"), err);
		}

	CleanupStack::PopAndDestroy(3); //schRefArray, schEntries, schTasks
	CleanupStack::PopAndDestroy(); //sch
	}
/* Test to check the new API
** CopyStoreL(TInt aDrive, TMsvOp aOperationId, TRequestStatus& aStatus) 
*/
LOCAL_C void TestCopyStoreOperationL()
	{
	CMsgsTestUtils::SetDriveL(EDriveC);
    
	CSessionObserver* ob = new(ELeave)CSessionObserver;
	CleanupStack::PushL(ob);
       
	// Set session in observer
	CMsvSession* session = CMsvSession::OpenAsyncL(*ob);
	ob->iSession = session; 
	CleanupStack::PushL(session);
    
	CActiveScheduler::Start();
	test(ob->iType==MMsvSessionObserver::EMsvServerReady);
	
	//Create an entry in the mail
	
	CMsvEntry* entry=session->GetEntryL(KMsvDraftEntryId);
	CleanupStack::PushL(entry);
	// create entry to work under
	TMsvEntry folder;
	folder.iType = KUidMsvFolderEntry;
	folder.iMtm = KUidMsvLocalServiceMtm;
	folder.iServiceId = KMsvLocalServiceIndexEntryId;
	_LIT(KTestDescription,"A Description");
	_LIT(KTestDetails,"A Details");
	folder.iDescription.Set(KTestDescription);
	folder.iDetails.Set(KTestDetails);
	entry->CreateL(folder);
	entry->SetEntryL(folder.Id());
	CMsvStore* store=entry->EditStoreL();
	CleanupStack::PushL(store);
	RMsvWriteStream stream;
	stream.AssignLC(*store,TUid::Uid(0x1000));
	stream.WriteL(KTestDescription);
	stream.CommitL();
	store->CommitL();
	CleanupStack::PopAndDestroy(3);
            
	CTestActive* active = new(ELeave)CTestActive;
	CleanupStack::PushL(active);
     
	// Test Copy MailStore 
	active->StartL();
	CMsvOperation* operation = NULL;
	TDriveUnit unit =(EDriveD);
	operation = session->CopyStoreL(unit, active->iStatus);
	test(operation->Mtm() == KUidMsvServerMtm);
	CleanupStack::PushL(operation);
	
	CActiveScheduler::Start();
	
	//Retrieve progress 
	TPckgBuf<TMsvCopyProgress> package;
	package.Copy(operation->ProgressL());
	test(package().iError == KErrNone);
		
	//delete session;
	CleanupStack::PopAndDestroy(4);
		
	//Check that both the source and destination
	//MailStore directory structure is same
	
	CMsgsTestUtils::WaitForServerClose();
	
	CDir 		 *srcDir;
	CDir 	     *destDir;
	_LIT(intro, "Testing the directory structure");
	_LIT(KEntryname,"%S");
	
	theUtils->Printf(intro);
	
	TFileName dest = unit.Name();
	dest.Append(KMsvDefaultFolder2);

	User::LeaveIfError(theUtils->FileSession().GetDir(dest, KEntryAttDir|KEntryAttNormal, ESortByName, destDir));
	
	unit =EDriveC;
	TFileName src = unit.Name();
	src.Append(KMsvDefaultFolder2);

	User::LeaveIfError(theUtils->FileSession().GetDir(src, KEntryAttDir|KEntryAttNormal, ESortByName, srcDir));
	
	TInt counter=0;
	TEntry srcEntry;
	TEntry destEntry;

	while (counter<srcDir->Count())
		{
		srcEntry = (*srcDir)[counter];
		destEntry = (*destDir)[counter];
		//Check the sizes 
		test(srcEntry.iSize == destEntry.iSize);
		//Check the names
		test(srcEntry.iName == destEntry.iName);
		//Print out the names on the log
		theUtils->Printf(KEntryname,&(srcEntry.iName));
		counter++;
		}
		
	delete srcDir;
	delete destDir;
	
	}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
//
TInt CIpsSosAOImapPopLogic::HandleAOServerCommandL( 
    TInt aCommand, TDesC8* aParameters )
    
    {
    
    FUNC_LOG;
    TInt result = KErrNone;

    TInt mailboxId = KErrNotFound;
            
    // Make sure that the parameter length matches Id length
    if ( aParameters && aParameters->Length() == sizeof( TMsvId ) )
        {
        TPckgBuf<TMsvId> paramPack;
        paramPack.Copy( *aParameters );
        
        // Get the mailbox id from the packet
        mailboxId = paramPack();
        }
    
    switch ( aCommand )
        {
        case EAOManagerPluginStart:
            RefreshMailboxListL( );
            if ( !iNoNWOpsAllowed )
                {
                SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStart );
                }
            break;
            
        case EAOManagerPluginStop:
            SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStop );
            // Return value does not matter, plugin will be stopped anyway.
            break;

        case EAOManagerNWOpsNotAllowed:
            iNoNWOpsAllowed = ETrue;
            SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStop );
            break;
            
        case EAOManagerNWOpsAllowed:
            iNoNWOpsAllowed = EFalse;
            SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStart );
            break;
            
        case EAOManagerStartedRoaming:
            SendCommandToMailboxesL( 
                    CIpsSosAOMBoxLogic::ECommandStartedRoaming );
            break;
            
        case EAOManagerStoppedRoaming:
            SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStoppedRoaming );
            break;
            
        case EAOManagerDiskSpaceAboveCritical:
            if ( !iNoNWOpsAllowed )
                {
                SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStart );
                }
            break;
            
        case EAOManagerDiskSpaceBelowCritical:
            SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStop );
            break;
        case EAOManagerSuicideQuery:
            // Always tell to server, that we don't 
            // want to make a suicide.
            result = EFalse;
            break;
        // Mailbox handling
        case EAOManagerMailboxAgentSuspend:
            SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandStop );
            break;
        case EAOManagerMailboxAgentResume:
            RefreshMailboxListL( );
            if ( !iNoNWOpsAllowed )
                {
                SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandStart );
                }
            break;
        case EAOManagerMailboxAgentRemove:
            StopAndRemoveMailboxL( mailboxId );
            //cancel all
            break;
        case EAOManagerEMNReceived:
            if ( aParameters )
                {
                HandleEMNMessageL( *aParameters );
                }
            break;
        case EAOManagerMailboxAgentUpdateMailWhileConnected:
            // Not supported atm, was in old plugin Imap-idle
            break;
        case EAOManagerQueryState:
            result = QueryMailboxStatus( *aParameters );
            break;
        case EAOManagerCancelAllAndDisconnect:
            SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandCancelAndDisconnect );
            break;
        case EAOManagerCancelAllAndDoNotDisconnect:
            SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandCancelDoNotDiconnect );
            break;
        case EAOManagerSuspend:
            SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandSuspend );
            break;
        case EAOManagerContinue:
            SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandContinue );
            break;
        case EAOManagerDoNotDisconnect:
            SendCommandToSpecificMailboxL( mailboxId, 
                    CIpsSosAOMBoxLogic::ECommandDoNotDisconnect );
            break;
        // error in CActiveScheduler
        // EAOManagerAOSchdulerError not handled because 
        // there's no badly behaving active objects
        case EAOManagerAOSchdulerError:
        default:    
            result = KErrNotSupported;
            break;
        }
    return result;
    }