ImagePrint/ImagePrintEngine/ImagePrintServer/src/server/cimageprintbody.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:  Contains the CImagePrintBody class definition.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bluetooth/hci/hcierrors.h>
       
    20 
       
    21 #include "cimageprintbody.h"
       
    22 #include "crsimageparser.h"
       
    23 #include "clog.h"
       
    24 
       
    25 CImagePrintBody* CImagePrintBody::NewL()
       
    26     {
       
    27 	CImagePrintBody* self = new (ELeave) CImagePrintBody();
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL();
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32     }
       
    33 
       
    34 CImagePrintBody::~CImagePrintBody()
       
    35 	{
       
    36 	LOG("CImagePrintBody::~CImagePrintBody begin");			
       
    37 	delete iClassLoader;
       
    38 	iImageFileNames.ResetAndDestroy();
       
    39 	delete iIdleDiscovery;
       
    40 	LOG("CImagePrintBody::~CImagePrintBody end");
       
    41 	}
       
    42 
       
    43 TInt CImagePrintBody::StartDiscovery(MPrinterDiscoveryObserver& aObserver, TUint aProtocols)
       
    44 	{
       
    45 	LOG1("CImagePrintBody::StartDiscovery aProtocols: %d", aProtocols);
       
    46 	iPrinterDiscoveryObserver = &aObserver;
       
    47 
       
    48 	if( iCurrentProtocol )
       
    49 		{
       
    50 		iCurrentProtocol->CancelDiscovery( EFalse );
       
    51 		}
       
    52 
       
    53 	iCurrentProtocol = NULL;
       
    54 	iClassLoader->Reset();
       
    55 	iProtocolsRequested = aProtocols;
       
    56 	iDiscoveryCancelled = EFalse;
       
    57 	TryNextDiscovery();		
       
    58 	
       
    59 	LOG("CImagePrintBody::StartDiscovery end");
       
    60 	return KErrNone;
       
    61 	}
       
    62 
       
    63 void CImagePrintBody::CancelDiscovery()
       
    64 	{
       
    65 	LOG("CImagePrintBody::CancelDiscovery begin");
       
    66 	iDiscoveryCancelled = ETrue;
       
    67 	if( iCurrentProtocol )
       
    68 		{
       
    69 		iCurrentProtocol->CancelDiscovery();
       
    70 		}
       
    71 	LOG("CImagePrintBody::CancelDiscovery end");		
       
    72 	}
       
    73 
       
    74 
       
    75 TInt CImagePrintBody::CreatePrintJobL(TInt aPrinterID, RPointerArray<TDesC>& aImages, MPrintEventObserver& aObserver)
       
    76 	{
       
    77 	LOG("CImagePrintBody::CreatePrintJobL begin");		
       
    78 	iPrinterPrintEventObserver = &aObserver;
       
    79 	iCurrentPrintJobProtocol = NULL;
       
    80 
       
    81 	if( iCurrentProtocol )
       
    82 		{		
       
    83 		iCurrentProtocol->CancelDiscovery( EFalse );
       
    84 		}
       
    85 
       
    86 	TInt DeviceID;
       
    87 	TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, iCurrentPrintJobProtocol );
       
    88 	if( !err )
       
    89 		{
       
    90 		TInt count = aImages.Count();				
       
    91 		if( count )
       
    92 			{
       
    93 			iImageFileNames.ResetAndDestroy();
       
    94 			for( TInt i = 0; i < count; ++i )
       
    95 				{
       
    96 				HBufC* fileName = aImages[i]->AllocLC();
       
    97 				iImageFileNames.AppendL( fileName );
       
    98 				CleanupStack::Pop(); // fileName
       
    99 				}
       
   100 							
       
   101 			ActiveScheduler().SetCurrentProtocol( iCurrentPrintJobProtocol->SupportedProtocols() );
       
   102 			err = iCurrentPrintJobProtocol->CreatePrintJobL( DeviceID, aImages, *this );	
       
   103 			}
       
   104 		else
       
   105 			{
       
   106 			err = KErrInvalidData;
       
   107 			}
       
   108 		}
       
   109 	
       
   110 	LOG1("CImagePrintBody::CreatePrintJobL return: %d", err);	
       
   111 	return err;
       
   112 	}
       
   113 
       
   114 
       
   115 void CImagePrintBody::SubmitPrintJobL()
       
   116 	{	
       
   117 	LOG1("CImagePrintBody::SubmitPrintJobL iCurrentPrintJobProtocol: %d", iCurrentPrintJobProtocol);
       
   118 	TInt err( KErrNone );
       
   119 			
       
   120 	if( !iCurrentPrintJobProtocol )
       
   121 		{
       
   122 		err = KErrInvalidSequence;		
       
   123 		}		
       
   124 	if( !err )		
       
   125 		{
       
   126 		TInt invalidImages;
       
   127 		err = ValidateImagesL( iImageFileNames, invalidImages );
       
   128 		LOG1("CImagePrintBody::SubmitPrintJobL ValidateImagesL returns: %d", err);	
       
   129 		}
       
   130 		
       
   131 	User::LeaveIfError( err );		
       
   132 	
       
   133 	iCurrentPrintJobProtocol->SubmitPrintJobL();
       
   134 		
       
   135 	LOG("CImagePrintBody::SubmitPrintJobL end");
       
   136 	}
       
   137 
       
   138 
       
   139 TInt CImagePrintBody::CancelPrintJob()
       
   140 	{
       
   141 	LOG("CImagePrintBody::CancelPrintJob begin");
       
   142 	TInt err( KErrNone );		
       
   143 	if( !iCurrentPrintJobProtocol )
       
   144 		{
       
   145 		err = KErrInvalidSequence;
       
   146 		}
       
   147 	if( !err )
       
   148 		{
       
   149 		err = iCurrentPrintJobProtocol->CancelPrintJob();	
       
   150 		}		
       
   151 	LOG1("CImagePrintBody::CancelPrintJob return: %d", err);		
       
   152 	return err;
       
   153 	}
       
   154 
       
   155 
       
   156 TInt CImagePrintBody::ContinuePrintJobL()
       
   157 	{
       
   158 	LOG("CImagePrintBody::ContinuePrintJobL begin");
       
   159 	TInt err( KErrInvalidSequence );
       
   160 	if( iCurrentPrintJobProtocol )
       
   161 		{
       
   162 		err = iCurrentPrintJobProtocol->ContinuePrintJobL();
       
   163 		}	
       
   164 	LOG1("CImagePrintBody::ContinuePrintJobL return: %d", err);
       
   165 	return err;
       
   166 	}
       
   167 
       
   168 
       
   169 TInt CImagePrintBody::GetNumPrintPages()
       
   170 	{
       
   171 	LOG("CImagePrintBody::GetNumPrintPages begin");
       
   172 	TInt err( KErrInvalidSequence );
       
   173 	if( iCurrentPrintJobProtocol )
       
   174 		{
       
   175 		err = iCurrentPrintJobProtocol->GetNumPrintPages();
       
   176 		}
       
   177 	LOG1("CImagePrintBody::GetNumPrintPages return: %d", err);
       
   178 	return err;
       
   179 	}
       
   180 
       
   181 TInt CImagePrintBody::GetJobStatus()
       
   182 	{
       
   183 	LOG("CImagePrintBody::GetJobStatus begin");
       
   184 	TInt err( KErrInvalidSequence );
       
   185 	if( iCurrentPrintJobProtocol )
       
   186 		{
       
   187 		err = iCurrentPrintJobProtocol->GetPrintJobStatus();
       
   188 		}
       
   189 	LOG1("CImagePrintBody::GetJobStatus return: %d", err);
       
   190 	return err;
       
   191 	}
       
   192 
       
   193 TInt CImagePrintBody::GetPrinterStatus(TInt aPrinterID)
       
   194 	{
       
   195 	LOG1("CImagePrintBody::GetPrinterStatus aPrinterID: %d", aPrinterID);
       
   196 	TInt DeviceID;
       
   197 	MProtPrintingDevice* theProtToQuery = NULL;
       
   198 	TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery );
       
   199 	if( !err )
       
   200 		{
       
   201 		err = theProtToQuery->GetPrinterStatus( DeviceID );
       
   202 		}
       
   203 	LOG1("CImagePrintBody::GetPrinterStatus return: %d", err);
       
   204 	return err;
       
   205 	}
       
   206 
       
   207 TInt CImagePrintBody::GetPrinterCapabilityIDsL(TInt aPrinterID, RArray<TInt>& aCapabilityIDs)
       
   208 	{
       
   209 	LOG1("CImagePrintBody::GetPrinterCapabilityIDsL aPrinterID: %d", aPrinterID);		
       
   210 	TInt DeviceID;
       
   211 	MProtPrintingDevice* theProtToQuery = NULL;
       
   212 
       
   213 	TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery );
       
   214 	if( !err )
       
   215 		{
       
   216 		err = theProtToQuery->GetDeviceCapabilityIDsL( DeviceID, aCapabilityIDs );
       
   217 		}
       
   218 	else if( err == KErrNotFound )
       
   219 		{
       
   220 		err = KErrInvalidData;
       
   221 		}
       
   222 
       
   223 	LOG1("CImagePrintBody::GetPrinterCapabilityIDsL return: %d", err);
       
   224 	return err;
       
   225 	}
       
   226 
       
   227 TInt CImagePrintBody::GetPrinterCapabilityL(TInt aPrinterID, TInt aCapabilityID, TPrintCapability& aCapability)
       
   228 	{
       
   229 	LOG1("CImagePrintBody::GetPrinterCapabilityL aPrinterID: %d", aPrinterID);
       
   230 	LOG1("CImagePrintBody::GetPrinterCapabilityL aCapabilityID: %d", aCapabilityID);
       
   231 	TInt DeviceID;
       
   232 	MProtPrintingDevice* theProtToQuery = NULL;
       
   233 	
       
   234 	TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery );
       
   235 	if( !err )
       
   236 		{
       
   237 		err = theProtToQuery->GetDeviceCapabilityL( DeviceID, aCapabilityID, aCapability );
       
   238 		}
       
   239 	else if( err == KErrNotFound )
       
   240 		{
       
   241 		err = KErrInvalidData;
       
   242 		}
       
   243 	
       
   244 	LOG1("CImagePrintBody::GetPrinterCapabilityL return: %d", err);	
       
   245 	return err;
       
   246 	}
       
   247 
       
   248 TInt CImagePrintBody::GetJobSetting(TInt aCapabilityID, TInt& aValue)
       
   249 	{
       
   250 	LOG1("CImagePrintBody::GetJobSetting aCapabilityID: %d", aCapabilityID);
       
   251 	TInt err( KErrInvalidSequence );
       
   252 	if( iCurrentPrintJobProtocol )
       
   253 		{
       
   254 		err = iCurrentPrintJobProtocol->GetJobSetting( aCapabilityID, aValue );
       
   255 		}
       
   256 	LOG1("CImagePrintBody::GetJobSetting return: %d", err);
       
   257 	return err;
       
   258 	}
       
   259 
       
   260 TInt CImagePrintBody::SetJobSettingL(TInt aCapabilityID, TInt aValue, TInt& aAffectedCapability)
       
   261 	{
       
   262 	LOG1("CImagePrintBody::SetJobSettingL aCapabilityID: %d", aCapabilityID);
       
   263 	LOG1("CImagePrintBody::SetJobSettingL aValue: %d", aValue);
       
   264 	TInt err( KErrInvalidSequence );		
       
   265 	if( iCurrentPrintJobProtocol )
       
   266 		{
       
   267 		err = iCurrentPrintJobProtocol->SetJobSettingL( aCapabilityID, aValue, aAffectedCapability );
       
   268 		}
       
   269 	LOG1("CImagePrintBody::SetJobSettingL return: %d", err);
       
   270 	return err;		
       
   271 	}
       
   272 
       
   273 TInt CImagePrintBody::GetNumPreviewPages()
       
   274 	{
       
   275 	LOG("CImagePrintBody::GetNumPreviewPages");
       
   276 	TInt err( KErrInvalidSequence );		
       
   277 	if( iCurrentPrintJobProtocol )
       
   278 		{
       
   279 		err = iCurrentPrintJobProtocol->GetNumPreviewPages();
       
   280 		}
       
   281 	LOG1("CImagePrintBody::GetNumPreviewPages return: %d", err);
       
   282 	return err;	
       
   283 	}
       
   284 
       
   285 TInt CImagePrintBody::GetJobTemplateIconL( TInt aTemplateID, TInt& aFbsBitmapHandle )
       
   286 	{
       
   287 	LOG1("CImagePrintBody::GetJobTemplateIconL aTemplateID: %d", aTemplateID);
       
   288 	TInt err( KErrInvalidSequence );
       
   289 	if( iCurrentPrintJobProtocol )
       
   290 		{
       
   291 		err = iCurrentPrintJobProtocol->GetJobTemplateIconL( aTemplateID, aFbsBitmapHandle );
       
   292 		}
       
   293 	LOG1("CImagePrintBody::GetJobTemplateIconL return: %d", err);
       
   294 	return err;
       
   295 	}
       
   296 
       
   297 TInt CImagePrintBody::CreatePreviewImage(TInt aPageNumber)
       
   298 	{
       
   299 	LOG1("CImagePrintBody::CreatePreviewImage aPageNumber: %d", aPageNumber);
       
   300 	TInt err( KErrInvalidSequence );
       
   301 	if( iCurrentPrintJobProtocol )
       
   302 		{
       
   303 		err = iCurrentPrintJobProtocol->CreatePreviewImage(aPageNumber);
       
   304 		}
       
   305 	LOG1("CImagePrintBody::CreatePreviewImage return: %d", err);
       
   306 	return err;
       
   307 	}
       
   308 
       
   309 TInt CImagePrintBody::RemoveCachedPrinterL(TInt aPrinterID)
       
   310 	{
       
   311 	LOG1("CImagePrintBody::RemoveCachedPrinterL aPrinterID: %d", aPrinterID);
       
   312 	TInt DeviceID;
       
   313 	MProtPrintingDevice* theProtToQuery = NULL;
       
   314 	TInt err = FindInternalDeviceReference( aPrinterID, DeviceID, theProtToQuery );
       
   315 	if( !err )
       
   316 		{
       
   317 		err = theProtToQuery->RemoveCachedDeviceL( DeviceID );
       
   318 		}
       
   319 	LOG1("CImagePrintBody::RemoveCachedPrinterL return: %d", err);
       
   320 	return err;
       
   321 	}
       
   322 
       
   323 TUint CImagePrintBody::SupportedProtocols()
       
   324 	{
       
   325 	LOG("CImagePrintBody::SupportedProtocols begin");
       
   326 	TUint prots = iClassLoader->SupportedProtocols();
       
   327 	LOG1("CImagePrintBody::SupportedProtocols return: %d", prots);
       
   328 	return prots;
       
   329 	}
       
   330 
       
   331 void CImagePrintBody::RegisterIdleObserver(MIdleObserver *aObserver)
       
   332 	{
       
   333 	LOG("CImagePrintBody::RegisterIdleObserver begin");
       
   334 	iPrinterIdleObserver = aObserver;
       
   335 	LOG("CImagePrintBody::RegisterIdleObserver end");
       
   336 	}
       
   337 
       
   338 // From MProtDiscoveryObserver.
       
   339 void CImagePrintBody::FoundDeviceL(TPrinter& aDeviceInfo)
       
   340 	{
       
   341 	LOG("CImagePrintBody::FoundDeviceL begin");		
       
   342 	if( iPrinterDiscoveryObserver )
       
   343 		{	
       
   344 		//Check that device id is valid, there can't be any bits in the protocol field (higher bits)
       
   345 		if( !( PROTOCOL_ID_FIELD_MASK & aDeviceInfo.iPrinterID ) )			
       
   346 			{
       
   347 			// Get the protocol index number
       
   348 			TInt protocolIndex = iClassLoader->GetProtocolIndex();		
       
   349 
       
   350 			// Left shift this number so that it occupies the higher X bits (the PROTOCOL_ID_BIT_COUNT highest bits)
       
   351 			protocolIndex <<= sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT;
       
   352 
       
   353 			// Add the protocol index number to the device id
       
   354 			aDeviceInfo.iPrinterID |= protocolIndex;
       
   355 
       
   356 			// Forward the FoundPrinterL callback to the observer
       
   357 			iPrinterDiscoveryObserver->FoundPrinterL( aDeviceInfo );			
       
   358 			}
       
   359 		}
       
   360 	LOG("CImagePrintBody::FoundDeviceL end");	
       
   361 	}
       
   362 
       
   363 void CImagePrintBody::DiscoveryStatusL( TInt aStatus, TInt aErrorCode, TInt aErrorStringCode )
       
   364 	{
       
   365 	LOG1("CImagePrintBody::DiscoveryStatusL aStatus: %d", aStatus);
       
   366 	LOG1("CImagePrintBody::DiscoveryStatusL aErrorCode: %d", aErrorCode);
       
   367 	LOG1("CImagePrintBody::DiscoveryStatusL aErrorStringCode: %d", aErrorStringCode);
       
   368 	if( iPrinterDiscoveryObserver )
       
   369 		{
       
   370 		switch( aStatus )
       
   371 			{
       
   372 			case EDiscoveryFinished: // Done with 1 protocol.
       
   373 			{
       
   374 				// When Bluetooth discovery is finished, but Bluetooth is not enabled pass error code to UI. 
       
   375 				if ( aErrorCode == ENoConnection )
       
   376 					{
       
   377 					iPrinterDiscoveryObserver->DiscoveryStatusL( aStatus, aErrorCode, aErrorStringCode );
       
   378 					}
       
   379 				iCurrentProtocol = NULL;
       
   380 				TUint doDiscovery = iProtocolsRequested & iClassLoader->SupportedProtocols();
       
   381 				LOG1("CImagePrintBody::DiscoveryStatusL doDiscovery: %d", doDiscovery);
       
   382 				LOG1("CImagePrintBody::DiscoveryStatusL iDiscoveryCancelled: %d", iDiscoveryCancelled);
       
   383 				if( ( !doDiscovery && aErrorCode == KErrCancel ) || iDiscoveryCancelled )
       
   384 					{
       
   385 					iPrinterDiscoveryObserver->DiscoveryStatusL( aStatus, aErrorCode, aErrorStringCode );
       
   386 					}
       
   387 				else
       
   388 					{
       
   389 					TryNextDiscovery();
       
   390 					}
       
   391 			}
       
   392 				break;
       
   393 			default: // Discovering, Cancelling.
       
   394 				iCurrentProtocol = NULL;
       
   395 				iPrinterDiscoveryObserver->DiscoveryStatusL( aStatus, aErrorCode, aErrorStringCode );
       
   396 			break;
       
   397 			}
       
   398 		}
       
   399 	LOG("CImagePrintBody::DiscoveryStatusL end");
       
   400 	}
       
   401 
       
   402 
       
   403 void CImagePrintBody::RemoveDeviceL(TPrinter& aDeviceInfo)
       
   404 	{	
       
   405 	LOG("CImagePrintBody::RemoveDeviceL begin");
       
   406 	if( iPrinterDiscoveryObserver )
       
   407 		{
       
   408 		if (PROTOCOL_ID_FIELD_MASK & aDeviceInfo.iPrinterID)
       
   409 			{	//Invalid id, reject printer
       
   410 			}
       
   411 		else
       
   412 			{	// Get the protocol index number
       
   413 			TInt protocolIndex = iClassLoader->GetProtocolIndex();
       
   414 			
       
   415 			// Left shift this number so that it occupies the higher X bits (the PROTOCOL_ID_BIT_COUNT highest bits)
       
   416 			protocolIndex <<= sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT;
       
   417 
       
   418 			// Add the protocol index number to the device id
       
   419 			aDeviceInfo.iPrinterID |= protocolIndex;
       
   420 
       
   421 			// Forward the RemovePrinterL callback to the observer
       
   422 			iPrinterDiscoveryObserver->RemovePrinterL( aDeviceInfo );			
       
   423 			}
       
   424 		}
       
   425 	LOG("CImagePrintBody::RemoveDeviceL end");	
       
   426 	}
       
   427 
       
   428 // From MProtPrintEventObserver.
       
   429 void CImagePrintBody::PrintJobProgressEvent(TInt aStatus, TInt aPercent, TInt aJobStateCode)
       
   430 	{
       
   431 	LOG1("CImagePrintBody::PrintJobProgressEvent aStatus: %d", aStatus);
       
   432 	LOG1("CImagePrintBody::PrintJobProgressEvent aPercent: %d", aPercent);
       
   433 	LOG1("CImagePrintBody::PrintJobProgressEvent aJobStateCode: %d", aJobStateCode);
       
   434 	if( iPrinterPrintEventObserver )
       
   435 		iPrinterPrintEventObserver->PrintJobProgressEvent(aStatus, aPercent, aJobStateCode);
       
   436 	LOG("CImagePrintBody::PrintJobProgressEvent end");
       
   437 	}
       
   438 
       
   439 void CImagePrintBody::PrintJobErrorEvent(TInt aErrorCode, TInt aErrorStringCode)
       
   440 	{
       
   441 	LOG1("CImagePrintBody::PrintJobErrorEvent aErrorCode: %d", aErrorCode);
       
   442 	LOG1("CImagePrintBody::PrintJobErrorEvent aErrorStringCode: %d", aErrorStringCode);
       
   443 	if( iPrinterPrintEventObserver )
       
   444 		iPrinterPrintEventObserver->PrintJobErrorEvent(aErrorCode, aErrorStringCode);
       
   445 	LOG("CImagePrintBody::PrintJobErrorEvent end");
       
   446 	}
       
   447 
       
   448 void CImagePrintBody::PrinterStatusEvent(TInt aErrorCode, TInt aErrorStringCode)
       
   449 	{
       
   450 	LOG1("CImagePrintBody::PrinterStatusEvent aErrorCode: %d", aErrorCode);
       
   451 	LOG1("CImagePrintBody::PrinterStatusEvent aErrorStringCode: %d", aErrorStringCode);
       
   452 	if( iPrinterPrintEventObserver )
       
   453 		iPrinterPrintEventObserver->PrinterStatusEvent(aErrorCode, aErrorStringCode);
       
   454 	LOG("CImagePrintBody::PrinterStatusEvent end");
       
   455 	}
       
   456 
       
   457 void CImagePrintBody::PreviewImageEvent(TInt aFsBitmapHandle)
       
   458 	{
       
   459 	LOG1("CImagePrintBody::PreviewImageEvent aFsBitmapHandle: %d", aFsBitmapHandle);
       
   460 	if( iPrinterPrintEventObserver )
       
   461 		iPrinterPrintEventObserver->PreviewImageEvent(aFsBitmapHandle);
       
   462 	LOG("CImagePrintBody::PreviewImageEvent end");
       
   463 	}
       
   464 
       
   465 void CImagePrintBody::ShowMessageL(TInt aMsgLine1Code, TInt aMsgLine2Code)
       
   466 	{
       
   467 	LOG1("CImagePrintBody::ShowMessageL aMsgLine1Code: %d", aMsgLine1Code);
       
   468 	LOG1("CImagePrintBody::ShowMessageL aMsgLine2Code: %d", aMsgLine2Code);
       
   469 	if( iPrinterPrintEventObserver )
       
   470 		iPrinterPrintEventObserver->ShowMessageL(aMsgLine1Code, aMsgLine2Code);
       
   471 	LOG("CImagePrintBody::ShowMessageL end");
       
   472 	}
       
   473 
       
   474 TBool CImagePrintBody::AskYesNoQuestionL(TInt aMsgLine1Code, TInt aMsgLine2Code)
       
   475 	{
       
   476 	LOG1("CImagePrintBody::AskYesNoQuestionL aMsgLine1Code: %d", aMsgLine1Code);
       
   477 	LOG1("CImagePrintBody::AskYesNoQuestionL aMsgLine2Code: %d", aMsgLine2Code);
       
   478 	TBool res( EFalse );
       
   479 	if( iPrinterPrintEventObserver )
       
   480 		{
       
   481 		res = iPrinterPrintEventObserver->AskYesNoQuestionL(aMsgLine1Code, aMsgLine2Code);	
       
   482 		}
       
   483 	LOG1("CImagePrintBody::AskYesNoQuestionL return: %d", res);	
       
   484 	return res;
       
   485 	}
       
   486 
       
   487 const TDesC& CImagePrintBody::AskForInputL(TInt aMsgLine1Code, TInt aMsgLine2Code)
       
   488 	{
       
   489 	LOG1("CImagePrintBody::ShowMessageL aMsgLine1Code: %d", aMsgLine1Code);
       
   490 	LOG1("CImagePrintBody::ShowMessageL aMsgLine2Code: %d", aMsgLine2Code);
       
   491 	if( iPrinterPrintEventObserver )
       
   492 		{
       
   493 		return iPrinterPrintEventObserver->AskForInputL(aMsgLine1Code, aMsgLine2Code);	
       
   494 		}
       
   495 	else
       
   496 		{
       
   497 		return KNullDesC;	
       
   498 		}				
       
   499 	}
       
   500 
       
   501 void CImagePrintBody::StatusEvent(const TEvent& aEvent, TInt aError, TInt aMsgCode)
       
   502 	{
       
   503 	LOG1("CImagePrintBody::StatusEvent aError: %d", aError);
       
   504 	LOG1("CImagePrintBody::StatusEvent aMsgCode: %d", aMsgCode);
       
   505 	LOG1("CImagePrintBody::StatusEvent aEvent.iProtocol: %d", aEvent.iProtocol);
       
   506 	LOG1("CImagePrintBody::StatusEvent aEvent.iSeverity: %d", aEvent.iSeverity);
       
   507 	LOG1("CImagePrintBody::StatusEvent aEvent.iEventType: %d", aEvent.iEventType);
       
   508 	
       
   509 	if( iPrinterIdleObserver )
       
   510 		{
       
   511 		iPrinterIdleObserver->StatusEvent( aEvent, aError, aMsgCode );
       
   512 		}
       
   513 	
       
   514 	if( aEvent.iEventType == EAsynchronousLeave )
       
   515 		{
       
   516 		// a protocol threw an async leave
       
   517 		// we continue with other protocols
       
   518 		TUint doDiscovery = iProtocolsRequested & iClassLoader->SupportedProtocols();
       
   519 		if( doDiscovery ) TryNextDiscovery();					
       
   520 		}
       
   521 	LOG("CImagePrintBody::StatusEvent end");
       
   522 	}
       
   523 
       
   524 CImagePrintBody::CImagePrintBody() :
       
   525 							iCurrentProtocol( NULL ),
       
   526 							iCurrentPrintJobProtocol( NULL ) 
       
   527 	{
       
   528 	LOG("CImagePrintBody::CImagePrintBody begin");	
       
   529 	LOG("CImagePrintBody::CImagePrintBody end");
       
   530 	}
       
   531 
       
   532 void CImagePrintBody::ConstructL()
       
   533 	{
       
   534 	LOG("CImagePrintBody::ConstructL begin");	
       
   535 	iClassLoader = CProtocolsLoader::NewL();
       
   536 	iClassLoader->Reset();
       
   537 	for( TInt x=0; x < iClassLoader->GetNumberOfProtocolsAvailable(); ++x )
       
   538 		{
       
   539 		iClassLoader->GetNextProtocol()->RegisterIdleObserver( this );
       
   540 		}
       
   541 	
       
   542 	iIdleDiscovery = CIdle::NewL( CActive::EPriorityIdle );
       
   543 	ActiveScheduler().SetIdleObserver( *this );
       
   544 	LOG("CImagePrintBody::ConstructL end");
       
   545 	}
       
   546 	
       
   547 CImagePrintScheduler& CImagePrintBody::ActiveScheduler() const
       
   548 	{
       
   549 	LOG("CImagePrintBody::ActiveScheduler begin");
       
   550 	CImagePrintScheduler* scheduler = static_cast<CImagePrintScheduler*>( CActiveScheduler::Current() );
       
   551 	LOG("CImagePrintBody::ActiveScheduler end");
       
   552 	return *scheduler;
       
   553 	}
       
   554 
       
   555 TInt CImagePrintBody::FindInternalDeviceReference(TInt aExternalDeviceID, TInt& aInternalDeviceID, MProtPrintingDevice*& aProtToUse)
       
   556 	{
       
   557 	LOG1("CImagePrintBody::FindInternalDeviceReference aExternalDeviceID: %d", aExternalDeviceID);
       
   558 	TInt err( KErrNotFound );
       
   559 	
       
   560 	aProtToUse = NULL;	
       
   561 		
       
   562 	// Separate the external id into the corresponding fields
       
   563 	TInt protId = aExternalDeviceID & PROTOCOL_ID_FIELD_MASK;
       
   564 	
       
   565 	TInt deviceId = aExternalDeviceID & DEVICE_ID_FIELD_MASK;
       
   566 	protId >>= (sizeof(TInt)*8 - PROTOCOL_ID_BIT_COUNT);
       
   567 	// If TInt is more than 4 bytes the mask should clear everything but the 6 least significant bits
       
   568 	protId &= PROTOCOL_ID_CLEAR_MASK;	//remove 1's if the original protId was negative
       
   569 		
       
   570 	// Check that the external ID does indeed belong to one of the currently
       
   571 	// loaded protocols
       
   572 	if( protId >= 0 && protId < iClassLoader->GetNumberOfProtocolsAvailable() )
       
   573 		{
       
   574 		aInternalDeviceID = deviceId;
       
   575 		aProtToUse = iClassLoader->GetProtocolAt(protId);
       
   576 		if( aProtToUse ) err = KErrNone;				
       
   577 		}
       
   578 	
       
   579 	LOG1("CImagePrintBody::FindInternalDeviceReference return: %d", err);	
       
   580 	return err;
       
   581 	}
       
   582 
       
   583 TInt CImagePrintBody::ValidateImagesL(const RPointerArray<HBufC>& aImageList, TInt &aInvalidCount)
       
   584 	{
       
   585 	LOG1("CImagePrintBody::ValidateImagesL aImageList.Count(): %d", aImageList.Count());
       
   586 	aInvalidCount = 0;
       
   587 	TInt lastError = KErrNone;
       
   588 	CRsImageParser *imageParser = CRsImageParser::NewLC();
       
   589 
       
   590 	for( TInt nCnt=0; nCnt < aImageList.Count(); ++nCnt )
       
   591 		{
       
   592 		LOG1("CImagePrintBody::ValidateImagesL nCnt: %d", nCnt);
       
   593 		LOG1("CImagePrintBody::ValidateImagesL image: %S", aImageList[nCnt]);
       
   594 		TBool valid;
       
   595 		imageParser->ValidateL(*(aImageList[nCnt]), valid, lastError);
       
   596 		LOG1("CImagePrintBody::ValidateImagesL valid: %d", valid);
       
   597 		LOG1("CImagePrintBody::ValidateImagesL lastError: %d", lastError);
       
   598 		if( !valid )
       
   599 			{
       
   600 			++aInvalidCount;
       
   601 			}	
       
   602 		}
       
   603 		
       
   604 	CleanupStack::PopAndDestroy(imageParser);
       
   605 	LOG1("CImagePrintBody::ValidateImagesL aInvalidCount: %d", aInvalidCount);
       
   606 	LOG1("CImagePrintBody::ValidateImagesL ends with: %d", lastError);
       
   607 	return lastError;
       
   608 	}
       
   609 	
       
   610 void CImagePrintBody::TryNextDiscovery()
       
   611 	{
       
   612 	LOG("CImagePrintBody::TryNextDiscovery begin");
       
   613 	iIdleDiscovery->Cancel();
       
   614 	iIdleDiscovery->Start(TCallBack(TryNextDiscoveryL, this));
       
   615 	LOG("CImagePrintBody::TryNextDiscovery end");	
       
   616 	}
       
   617 
       
   618 void CImagePrintBody::DoTryNextDiscoveryL()
       
   619 	{
       
   620 	LOG("CImagePrintBody::DoTryNextDiscoveryL begin");	
       
   621 	TUint doDiscovery = iProtocolsRequested & iClassLoader->SupportedProtocols();
       
   622 	LOG1("CImagePrintBody::DoTryNextDiscoveryL doDiscovery: %d", doDiscovery);	
       
   623 	if( doDiscovery )
       
   624 		{
       
   625 		TBool found( EFalse );
       
   626 		TInt protId( 0 );
       
   627     	TInt count = iClassLoader->GetNumberOfProtocolsAvailable();
       
   628     	LOG1("CImagePrintBody::DoTryNextDiscoveryL count: %d", count);
       
   629     	for( TInt i = 0; i < count && !found; i++ )
       
   630 	        {
       
   631 	        iCurrentProtocol = iClassLoader->GetNextProtocol();
       
   632 	        protId = iCurrentProtocol->SupportedProtocols();
       
   633 	        if( iProtocolsRequested & protId ) found = ETrue;
       
   634 	        }
       
   635 		LOG1("CImagePrintBody::DoTryNextDiscoveryL found: %d", found);
       
   636 		LOG1("CImagePrintBody::DoTryNextDiscoveryL protId: %d", protId);
       
   637 		if( found )
       
   638 	        {
       
   639 	        TUint temp = KMaxTUint ^ protId;
       
   640 	        iProtocolsRequested &= temp;
       
   641 	        LOG1("CImagePrintBody::DoTryNextDiscoveryL iProtocolsRequested: %d", iProtocolsRequested);
       
   642 	        ActiveScheduler().SetCurrentProtocol( protId );
       
   643 	        iCurrentProtocol->StartDiscoveryL( *this, protId );
       
   644 	        }	        
       
   645 		}
       
   646 	else
       
   647 		{
       
   648 		iPrinterDiscoveryObserver->DiscoveryStatusL( EDiscoveryFinished, 0, 0 );
       
   649 		}			
       
   650 	LOG("CImagePrintBody::DoTryNextDiscoveryL end");
       
   651 	}
       
   652 	
       
   653 TInt CImagePrintBody::TryNextDiscoveryL(TAny* aObj)	
       
   654 	{
       
   655 	LOG("CImagePrintBody::TryNextDiscoveryL begin");
       
   656 	CImagePrintBody* obj = static_cast<CImagePrintBody*>(aObj);
       
   657 	obj->DoTryNextDiscoveryL();		
       
   658 	LOG("CImagePrintBody::TryNextDiscoveryL end");
       
   659 	return EFalse;
       
   660 	}
       
   661 
       
   662 void CImagePrintBody::SetNumsOfCopiesL( const RArray<TInt>& aNumsOfCopies, TInt& aErr )
       
   663 	{	
       
   664 	LOG1("CImagePrintBody::SetNumberOfCopiesL aNumsOfCopies.Count(): %d", aNumsOfCopies.Count());
       
   665 
       
   666 	if( iCurrentPrintJobProtocol )
       
   667 		{
       
   668 		iCurrentPrintJobProtocol->SetNumsOfCopiesL( aNumsOfCopies, aErr );
       
   669 		LOG1("CImagePrintBody::SetNumberOfCopiesL aErr: %d", aErr);	
       
   670 		}
       
   671 		
       
   672 	LOG("CImagePrintBody::SetNumberOfCopiesL end");	
       
   673 	}
       
   674 
       
   675 void CImagePrintBody::HandleSessionDisconnect( const MIdleObserver* aIdleObserver,
       
   676 											const MPrinterDiscoveryObserver* aDiscoveryObserver,
       
   677 											const MPrintEventObserver* aEventObserver )
       
   678 	{
       
   679 	LOG1("CImagePrintBody::HandleSessionDisconnect aIdleObserver address: %d", aIdleObserver);
       
   680 	LOG1("CImagePrintBody::HandleSessionDisconnect iPrinterIdleObserver address: %d", iPrinterIdleObserver);	
       
   681 	LOG1("CImagePrintBody::HandleSessionDisconnect aDiscoveryObserver address: %d", aDiscoveryObserver);
       
   682 	LOG1("CImagePrintBody::HandleSessionDisconnect iPrinterDiscoveryObserver address: %d", iPrinterDiscoveryObserver);	
       
   683 	LOG1("CImagePrintBody::HandleSessionDisconnect aEventObserver address: %d", aEventObserver);	
       
   684 	LOG1("CImagePrintBody::HandleSessionDisconnect iPrinterPrintEventObserver address: %d", iPrinterPrintEventObserver);	
       
   685 	if( aIdleObserver == iPrinterIdleObserver )	iPrinterIdleObserver = NULL;
       
   686 	if( aEventObserver == iPrinterPrintEventObserver ) iPrinterPrintEventObserver = NULL;
       
   687 	if( aDiscoveryObserver == iPrinterDiscoveryObserver ) iPrinterDiscoveryObserver = NULL;
       
   688 	LOG("CImagePrintBody::HandleSessionDisconnect end");
       
   689 	}
       
   690 
       
   691 //  End of File