harvester/server/src/unmounthandlerao.cpp
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 */
       
    16 
       
    17 #include "unmounthandlerao.h"
       
    18 
       
    19 CUnmountHandlerAO::CUnmountHandlerAO( MUnmountObserver& aObserver ) : 
       
    20 		CActive( CActive::EPriorityHigh )
       
    21     {
       
    22 	iUnmountObserver = &aObserver;
       
    23     }
       
    24 
       
    25 CUnmountHandlerAO* CUnmountHandlerAO::NewLC( MUnmountObserver& aObserver )
       
    26     {
       
    27 	CUnmountHandlerAO* self = new ( ELeave ) CUnmountHandlerAO( aObserver );
       
    28 	CleanupStack::PushL( self );
       
    29 	self->ConstructL();
       
    30 	return self;
       
    31     }
       
    32 
       
    33 CUnmountHandlerAO* CUnmountHandlerAO::NewL( MUnmountObserver& aObserver )
       
    34     {
       
    35 	CUnmountHandlerAO* self = CUnmountHandlerAO::NewLC( aObserver );
       
    36 	CleanupStack::Pop(); // self;
       
    37 	return self;
       
    38     }
       
    39 
       
    40 void CUnmountHandlerAO::ConstructL()
       
    41     {
       
    42 	CActiveScheduler::Add( this );				// Add to scheduler
       
    43 	_LIT( KNote, "unmounthandlerao" );
       
    44 	User::LeaveIfError( iMsgQueue.CreateGlobal( KNote, 32) );
       
    45     }
       
    46 
       
    47 CUnmountHandlerAO::~CUnmountHandlerAO()
       
    48     {
       
    49 	Cancel(); // Cancel any request, if outstanding
       
    50 	iMsgQueue.Close();
       
    51     }
       
    52 
       
    53 void CUnmountHandlerAO::DoCancel()
       
    54     {
       
    55 	iMsgQueue.CancelDataAvailable();
       
    56     }
       
    57 
       
    58 void CUnmountHandlerAO::WaitForUnmountL()
       
    59     {
       
    60 	Cancel();							// Cancel any request, just to be sure
       
    61 	iMsgQueue.NotifyDataAvailable( iStatus );
       
    62 	SetActive();						// Tell scheduler a request is active
       
    63     }
       
    64 
       
    65 void CUnmountHandlerAO::RunL()
       
    66     {
       
    67 	User::LeaveIfError( iStatus.Int() );
       
    68 	if( iUnmountObserver )
       
    69 		{
       
    70 		TUint32 mediaId;
       
    71 		const TInt err = iMsgQueue.Receive( mediaId );
       
    72 		if( err == KErrNone )
       
    73 			{
       
    74 			iUnmountObserver->HandleUnmount( mediaId );
       
    75 			}
       
    76 		}
       
    77 	WaitForUnmountL();
       
    78     }
       
    79 
       
    80 TInt CUnmountHandlerAO::RunError( TInt /*aError*/ )
       
    81     {
       
    82 	return KErrNone;
       
    83     }