ImagePrint/ImagePrintEngine/ImagePrintServer/src/client/cdiscoveryguard.cpp
branchGCC_SURGE
changeset 25 59ea2209bb67
parent 23 08cc4cc059d4
parent 15 a92d00fca574
equal deleted inserted replaced
23:08cc4cc059d4 25:59ea2209bb67
     1 /*
       
     2 * Copyright (c) 2004-2007 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 
       
    18 
       
    19 #include "cdiscoveryguard.h"
       
    20 #include "rimageprintclient.h"
       
    21 #include "imageprint.h"
       
    22 #include "tdiscoveryguarddata.h"
       
    23 
       
    24 EXPORT_C CDiscoveryGuard* CDiscoveryGuard::NewL( RImagePrintClient& aClient )
       
    25     {	
       
    26 	CDiscoveryGuard* self = new ( ELeave ) CDiscoveryGuard( aClient );
       
    27     CleanupStack::PushL( self );
       
    28     self->ConstructL();
       
    29 	CleanupStack::Pop();    // self
       
    30     return self;
       
    31     }
       
    32 
       
    33 CDiscoveryGuard::CDiscoveryGuard( RImagePrintClient& aClient ) : 
       
    34 							CActive( CActive::EPriorityStandard ),
       
    35 							iClient( aClient )
       
    36     {
       
    37     CActiveScheduler::Add( this );
       
    38     }
       
    39 
       
    40 EXPORT_C CDiscoveryGuard::~CDiscoveryGuard()
       
    41     {  
       
    42     Cancel();
       
    43     delete iData;
       
    44     }
       
    45 
       
    46 void CDiscoveryGuard::ConstructL()
       
    47     {
       
    48     iData = new (ELeave) TDiscoveryGuardData;
       
    49     }
       
    50 	
       
    51 EXPORT_C TInt CDiscoveryGuard::Guard( MPrinterDiscoveryObserver& aObserver, TUint aProtocols )
       
    52 	{
       
    53 	Cancel();	
       
    54 	iObserver = &aObserver;
       
    55 	TInt err = iClient.StartDiscovery( *iData, aProtocols, iStatus );
       
    56 	if( !err )
       
    57 		{
       
    58 		SetActive();	
       
    59 		}	
       
    60 	return err;
       
    61 	}	
       
    62 	
       
    63 void CDiscoveryGuard::RunL()
       
    64 	{
       
    65 	if( iStatus == KErrNone && iObserver )
       
    66 		{
       
    67 		switch( iData->iCb )
       
    68 			{
       
    69 			case TDiscoveryGuardData::EFoundCb:
       
    70 				iObserver->FoundPrinterL( iData->iPrinterInfo );
       
    71 				break;			
       
    72 			case TDiscoveryGuardData::EStatusCb:
       
    73 				iObserver->DiscoveryStatusL( iData->iStatus, iData->iErrorCode, iData->iErrorStringCode );
       
    74 				break;				
       
    75 			case TDiscoveryGuardData::ERemoveCb:
       
    76 				iObserver->RemovePrinterL( iData->iPrinterInfo );
       
    77 				break;				
       
    78 			default:
       
    79 				break;
       
    80 			}
       
    81 			
       
    82 		iClient.ContinueDiscovery( *iData, iStatus );
       
    83 		SetActive();
       
    84 		}		
       
    85 	}
       
    86 
       
    87 void CDiscoveryGuard::DoCancel()
       
    88 	{
       
    89 	iClient.CancelStartDiscovery();		
       
    90 	}
       
    91 
       
    92 //  End of File