ImagePrint/ImagePrintEngine/ImagePrintServer/src/server/cserverdiscoveryguard.cpp
branchRCL_3
changeset 27 159fc2f68139
parent 21 26673e532f65
child 28 d59c248c9d36
equal deleted inserted replaced
21:26673e532f65 27:159fc2f68139
     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 "cserverdiscoveryguard.h"
       
    20 #include "cimageprintbody.h"
       
    21 #include "clog.h"
       
    22 #include "tmessagewrp2.h"
       
    23 
       
    24 CServerDiscoveryGuard* CServerDiscoveryGuard::NewL( CImagePrintBody& aEngine )
       
    25     {
       
    26 	CServerDiscoveryGuard* self = new ( ELeave ) CServerDiscoveryGuard( aEngine );
       
    27     CleanupStack::PushL( self );
       
    28     self->ConstructL();
       
    29 	CleanupStack::Pop();    // self
       
    30     return self;
       
    31     }
       
    32 
       
    33 CServerDiscoveryGuard::CServerDiscoveryGuard( CImagePrintBody& aEngine ) : iEngine( aEngine ),
       
    34 													iRequestActive( EFalse )
       
    35     {
       
    36     }
       
    37 
       
    38 CServerDiscoveryGuard::~CServerDiscoveryGuard()
       
    39     {
       
    40     LOG("CServerDiscoveryGuard::~CServerDiscoveryGuard begin");
       
    41     iBuffer.Close();
       
    42     LOG("CServerDiscoveryGuard::~CServerDiscoveryGuard end");
       
    43     }
       
    44 
       
    45 void CServerDiscoveryGuard::ConstructL()
       
    46     {
       
    47     }
       
    48 
       
    49 TInt CServerDiscoveryGuard::StartL( TMessageWrp2& aMessage )
       
    50 	{
       
    51 	LOG("CServerDiscoveryGuard::StartL begin");
       
    52 	iRequestActive = EFalse;
       
    53 	iBuffer.Reset();
       
    54 	TInt protocols = aMessage.Int0();
       
    55 	TInt err = iEngine.StartDiscovery( *this, protocols );
       
    56 	LOG1("CServerDiscoveryGuard::StartL err: %d", err);
       
    57 	return err;
       
    58 	}
       
    59 
       
    60 void CServerDiscoveryGuard::ContinueL( TMessageWrp2& aMessage )
       
    61 	{
       
    62 	LOG("CServerDiscoveryGuard::ContinueL begin");
       
    63 	if( iMessage ) iMessage->SetDisposable( ETrue );
       
    64 	iMessage = &aMessage;
       
    65 	iRequestActive = ETrue;
       
    66 	if( iBuffer.Count() )
       
    67 		{
       
    68 		LOG("CServerDiscoveryGuard::ContinueL before ProcessL");
       
    69 		ProcessL();
       
    70 		LOG("CServerDiscoveryGuard::ContinueL after ProcessL");
       
    71 		}
       
    72 	LOG("CServerDiscoveryGuard::ContinueL end");
       
    73 	}
       
    74 
       
    75 void CServerDiscoveryGuard::Stop()
       
    76 	{
       
    77 	LOG("CServerDiscoveryGuard::Stop begin");
       
    78 	iBuffer.Reset();
       
    79 	if( iRequestActive )
       
    80 		{
       
    81 		LOG("CServerDiscoveryGuard::Stop cancelling...");
       
    82 		iMessage->Complete( KErrCancel );
       
    83 		iRequestActive = EFalse;
       
    84 		}
       
    85 	LOG("CServerDiscoveryGuard::Stop end");
       
    86 	}
       
    87 
       
    88 void CServerDiscoveryGuard::FoundPrinterL(const TPrinter& aPrinterInfo)
       
    89 	{
       
    90 	LOG("CServerDiscoveryGuard::FoundPrinterL begin");
       
    91 	LOG1("CServerDiscoveryGuard::FoundPrinterL aPrinterInfo.iProtocol: %d", aPrinterInfo.iProtocol);
       
    92 	LOG1("CServerDiscoveryGuard::FoundPrinterL aPrinterInfo.iProperties: %d", aPrinterInfo.iProperties);
       
    93 	LOG1("CServerDiscoveryGuard::FoundPrinterL aPrinterInfo.iPrinterID: %d", aPrinterInfo.iPrinterID);
       
    94 	LOG1("CServerDiscoveryGuard::FoundPrinterL aPrinterInfo.iDisplayName: %S", &(aPrinterInfo.iDisplayName));
       
    95 	LOG1("CServerDiscoveryGuard::FoundPrinterL aPrinterInfo.iVendor: %d", aPrinterInfo.iVendor);
       
    96 	TDiscoveryGuardData data;
       
    97 	data.iCb = TDiscoveryGuardData::EFoundCb;
       
    98 	data.iPrinterInfo = aPrinterInfo;
       
    99 	User::LeaveIfError( iBuffer.Append( data ) );
       
   100 	ProcessL();
       
   101 	LOG("CServerDiscoveryGuard::FoundPrinterL end");
       
   102 	}
       
   103 
       
   104 void CServerDiscoveryGuard::DiscoveryStatusL(TInt aStatus, TInt aErrorCode, TInt aErrorStringCode)
       
   105 	{
       
   106 	LOG("CServerDiscoveryGuard::DiscoveryStatusL begin");
       
   107 	LOG1("CServerDiscoveryGuard::DiscoveryStatusL aStatus: %d", aStatus);
       
   108 	LOG1("CServerDiscoveryGuard::DiscoveryStatusL aErrorCode: %d", aErrorCode);
       
   109 	LOG1("CServerDiscoveryGuard::DiscoveryStatusL aErrorStringCode: %d", aErrorStringCode);
       
   110 	TDiscoveryGuardData data;
       
   111 	data.iCb = TDiscoveryGuardData::EStatusCb;
       
   112 	data.iStatus = aStatus;
       
   113 	data.iErrorCode = aErrorCode;
       
   114 	data.iErrorStringCode = aErrorStringCode;
       
   115 	User::LeaveIfError( iBuffer.Append( data ) );
       
   116 	ProcessL();
       
   117 	LOG("CServerDiscoveryGuard::DiscoveryStatusL end");
       
   118 	}
       
   119 
       
   120 void CServerDiscoveryGuard::RemovePrinterL(const TPrinter& aPrinterInfo)
       
   121 	{
       
   122 	LOG("CServerDiscoveryGuard::RemovePrinterL begin");
       
   123 	LOG1("CServerDiscoveryGuard::RemovePrinterL aPrinterInfo.iProtocol: %d", aPrinterInfo.iProtocol);
       
   124 	LOG1("CServerDiscoveryGuard::RemovePrinterL aPrinterInfo.iProperties: %d", aPrinterInfo.iProperties);
       
   125 	LOG1("CServerDiscoveryGuard::RemovePrinterL aPrinterInfo.iPrinterID: %d", aPrinterInfo.iPrinterID);
       
   126 	LOG1("CServerDiscoveryGuard::RemovePrinterL aPrinterInfo.iDisplayName: %S", &(aPrinterInfo.iDisplayName));
       
   127 	TDiscoveryGuardData data;
       
   128 	data.iCb = TDiscoveryGuardData::ERemoveCb;
       
   129 	data.iPrinterInfo = aPrinterInfo;
       
   130 	User::LeaveIfError( iBuffer.Append( data ) );
       
   131 	ProcessL();
       
   132 	LOG("CServerDiscoveryGuard::RemovePrinterL end");
       
   133 	}
       
   134 
       
   135 void CServerDiscoveryGuard::ProcessL()
       
   136 	{
       
   137 	LOG("CServerDiscoveryGuard::ProcessL begin");
       
   138 	if( iBuffer.Count() && iRequestActive )
       
   139 		{
       
   140 		LOG("CServerDiscoveryGuard::ProcessL step 1");
       
   141 		TPtr8 ptr(reinterpret_cast<TUint8*>(&(iBuffer[0])), sizeof(iBuffer[0]), sizeof(iBuffer[0]));
       
   142 		LOG("CServerDiscoveryGuard::ProcessL step 2");
       
   143 		iMessage->WriteL( 0, ptr );
       
   144 		LOG("CServerDiscoveryGuard::ProcessL step 3");
       
   145 		iMessage->Complete( KErrNone );
       
   146 		LOG("CServerDiscoveryGuard::ProcessL step 4");
       
   147 		iRequestActive = EFalse;
       
   148 		LOG("CServerDiscoveryGuard::ProcessL step 5");
       
   149 		iBuffer.Remove( 0 );
       
   150 		LOG("CServerDiscoveryGuard::ProcessL step 6");
       
   151 		}
       
   152 	LOG("CServerDiscoveryGuard::ProcessL end");
       
   153 	}
       
   154 
       
   155 //  End of File