ImagePrint/ImagePrintEngine/DeviceProtocols/btprotocol/src/cbtsoapcodec.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:  Defines the CBtSoapCodec class to create and read SOAP-encoded messages.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "cxmlhandler.h"
       
    20 #include "cbtsoapcodec.h"
       
    21 #include "imageprint.h"
       
    22 #include "clog.h"
       
    23 #include "tbtmapper.h"
       
    24 #include "rsutils.h"
       
    25 
       
    26 //--------------------------------------------------------------------------------------------
       
    27 //
       
    28 // CBtSoapCodec::NewL
       
    29 //
       
    30 //--------------------------------------------------------------------------------------------
       
    31 CBtSoapCodec* CBtSoapCodec::NewL()
       
    32 	{
       
    33 		CBtSoapCodec *self = NewLC();
       
    34 		CleanupStack::Pop();	// self
       
    35 
       
    36 		return self;
       
    37 	}
       
    38 
       
    39 //--------------------------------------------------------------------------------------------
       
    40 //
       
    41 // CBtSoapCodec::NewLC
       
    42 //
       
    43 //--------------------------------------------------------------------------------------------
       
    44 CBtSoapCodec* CBtSoapCodec::NewLC()
       
    45 	{
       
    46 		CBtSoapCodec *self = new (ELeave) CBtSoapCodec();
       
    47 		CleanupStack::PushL(self);
       
    48 		self->ConstructL();
       
    49 		return self;
       
    50 	}
       
    51 
       
    52 //--------------------------------------------------------------------------------------------
       
    53 //
       
    54 // CBtSoapCodec::~CBtSoapCodec
       
    55 //
       
    56 //--------------------------------------------------------------------------------------------
       
    57 CBtSoapCodec::~CBtSoapCodec()
       
    58 {
       
    59 	if(iXmlHandler)
       
    60 		delete iXmlHandler;
       
    61 	iXmlHandler = NULL;
       
    62 
       
    63 	if(iActionBuffer)
       
    64 		delete iActionBuffer;
       
    65 	iActionBuffer = NULL;
       
    66 }
       
    67 
       
    68 //--------------------------------------------------------------------------------------------
       
    69 //
       
    70 // CBtSoapCodec::ConstructL
       
    71 //
       
    72 //--------------------------------------------------------------------------------------------
       
    73 void CBtSoapCodec::ConstructL()
       
    74 {
       
    75 	LOG("[CBtSoapCodec::ConstructL]\t");
       
    76 	iXmlHandler = CXmlHandler::NewL();
       
    77 }
       
    78 
       
    79 //--------------------------------------------------------------------------------------------
       
    80 //
       
    81 // CBtSoapCodec::Reset
       
    82 //
       
    83 //--------------------------------------------------------------------------------------------
       
    84 void CBtSoapCodec::Reset()
       
    85 {
       
    86 	LOG("[CBtSoapCodec::Reset]\t");
       
    87 
       
    88 	if(iXmlHandler)
       
    89 		delete iXmlHandler;
       
    90 	iXmlHandler = NULL;
       
    91 
       
    92 	if(iActionBuffer)
       
    93 		delete iActionBuffer;
       
    94 	iActionBuffer = NULL;
       
    95 
       
    96 }
       
    97 
       
    98 //--------------------------------------------------------------------------------------------
       
    99 //
       
   100 // CBtSoapCodec::CreateSoapL
       
   101 //
       
   102 //--------------------------------------------------------------------------------------------
       
   103 TPtrC8 CBtSoapCodec::CreateSoapL(const TInt aAction, const TInt aJobId)
       
   104 {
       
   105 	LOG1("[CBtSoapCodec::CreateSoapL]\t action: %d", aAction);
       
   106 	// Open the template file and read it into buffer
       
   107 
       
   108 	TPtrC8 soap(KNullDesC8);
       
   109 	TBtIntString8 jobId;
       
   110 	jobId.AppendNum(aJobId);
       
   111 
       
   112 	if(iActionBuffer)
       
   113 		delete iActionBuffer;
       
   114 	iActionBuffer = NULL;
       
   115 
       
   116 	switch(aAction)
       
   117 	{
       
   118 		case EBtCreateJob:
       
   119 			CreateJobSoapL(aJobId);
       
   120 			break;
       
   121 		case EBtGetPrinterAttributes:
       
   122 			GetPrinterAttributesSoapL();
       
   123 			break;
       
   124 		case EBtGetPrinterState:
       
   125 			GetPrinterStateSoapL();
       
   126 			break;
       
   127 		case EBtGetPrinterCapabilities:
       
   128 			GetCapabilitiesSoapL();
       
   129 			break;
       
   130 		case EBtCancelJob:
       
   131 			CancelJobSoapL(jobId);
       
   132 			break;
       
   133 		case EBtGetJobAttributes:
       
   134 			GetJobAttributesSoapL(jobId);
       
   135 			break;
       
   136 		case EBtGetEvent:
       
   137 			GetEventSoapL(jobId);
       
   138 			break;
       
   139 		default:
       
   140 			break;
       
   141 	}
       
   142 
       
   143 	TInt offset;
       
   144 	TPtrC8 ptr = iXmlHandler->GetDataL(KBtBodyStartTag, KBtBodyEndTag, offset);
       
   145 	iXmlHandler->ComposeDataL(ptr.Length(), KBtBytesInBody());
       
   146 
       
   147 	return iXmlHandler->FinalizeBufferL(KBtEnvelopeEndTag());
       
   148 
       
   149 }
       
   150 
       
   151 //--------------------------------------------------------------------------------------------
       
   152 //
       
   153 // CBtSoapCodec::ReadSoapL
       
   154 //
       
   155 //--------------------------------------------------------------------------------------------
       
   156 void CBtSoapCodec::ReadSoapL(const TDesC8& aSoapBuffer)
       
   157 {
       
   158 	LOG("[CBtSoapCodec::ReadSoapL(TDesC8&)]\t ");
       
   159 	// Open the template file and read it into buffer
       
   160 	
       
   161 	TInt action = 0;
       
   162 	ReadSoapL(action, aSoapBuffer);
       
   163 }
       
   164 
       
   165 //--------------------------------------------------------------------------------------------
       
   166 //
       
   167 // CBtSoapCodec::ReadSoapL
       
   168 //
       
   169 //--------------------------------------------------------------------------------------------
       
   170 void CBtSoapCodec::ReadSoapL(const CBufBase& aSoapBuffer)
       
   171 {
       
   172 	LOG("[CBtSoapCodec::ReadSoapL(CBufBase&)]\t ");
       
   173 	// Open the template file and read it into buffer
       
   174 	
       
   175 	TInt action = 0;
       
   176 	ReadSoapL(action, aSoapBuffer);
       
   177 }
       
   178 
       
   179 //--------------------------------------------------------------------------------------------
       
   180 //
       
   181 // CBtSoapCodec::ReadSoapL
       
   182 //
       
   183 //--------------------------------------------------------------------------------------------
       
   184 void CBtSoapCodec::ReadSoapL(TInt& aAction, const CBufBase& aSoapBuffer)
       
   185 {
       
   186 	LOG("[CBtSoapCodec::ReadSoapL(TInt&, CBufBase&)]\t ");
       
   187 	// Open the template file and read it into buffer
       
   188 
       
   189 	if(iActionBuffer)
       
   190 		delete iActionBuffer;
       
   191 	iActionBuffer = NULL;
       
   192 
       
   193 	iActionBuffer = static_cast<HBufC8*>(User::LeaveIfNull(HBufC8::NewL(aSoapBuffer.Size())));
       
   194 	TPtr8 ptr = iActionBuffer->Des();
       
   195 	aSoapBuffer.Read(0, ptr, aSoapBuffer.Size());
       
   196 
       
   197 	ReadSoapL(aAction, iActionBuffer->Des());
       
   198 }
       
   199 
       
   200 //--------------------------------------------------------------------------------------------
       
   201 //
       
   202 // CBtSoapCodec::ReadSoapL
       
   203 //
       
   204 //--------------------------------------------------------------------------------------------
       
   205 void CBtSoapCodec::ReadSoapL(TInt& aAction, const TDesC8& aSoapBuffer)
       
   206 {
       
   207 	LOG("[CBtSoapCodec::ReadSoapL(TInt&, TDesC8&)]\t ");
       
   208 	// Open the template file and read it into buffer
       
   209 
       
   210 #ifdef _DEBUG	
       
   211 	TInt len = aSoapBuffer.Length() < 50 ? aSoapBuffer.Length() : 50;
       
   212 	TPtrC8 p = aSoapBuffer.Mid(0, len);
       
   213 
       
   214 #endif
       
   215 
       
   216 	if(!iXmlHandler)
       
   217 		iXmlHandler = CXmlHandler::NewL();
       
   218 	iXmlHandler->InitFromBufferL(aSoapBuffer);
       
   219 
       
   220 	if(iActionBuffer)
       
   221 		delete iActionBuffer;
       
   222 	iActionBuffer = NULL;
       
   223 	
       
   224 	TInt offset = 0;
       
   225 
       
   226 	TPtrC8 ptr = iXmlHandler->GetDataL(KBtBodyStartTag, KBtBodyEndTag, offset);
       
   227 
       
   228 	iActionBuffer = static_cast<HBufC8*>(User::LeaveIfNull(ptr.AllocL()));
       
   229 
       
   230 	aAction = SoapAction();
       
   231 
       
   232 	iXmlHandler->Reset();
       
   233 	iXmlHandler->InitFromBufferL(iActionBuffer->Des(), aAction);
       
   234 }
       
   235 
       
   236 //------------------------------
       
   237 // Responses
       
   238 //------------------------------
       
   239 //--------------------------------------------------------------------------------------------
       
   240 //
       
   241 // CBtSoapCodec::CreateJobResponseL
       
   242 //
       
   243 //--------------------------------------------------------------------------------------------
       
   244 void CBtSoapCodec::CreateJobResponseL(TInt& aJobId, TInt& aErrorCode)
       
   245 {
       
   246 	LOG("[CBtSoapCodec::CreateJobResponseL]\t ");
       
   247 
       
   248 	if(EBtCreateJobResponse != SoapAction())
       
   249 	{
       
   250 		User::Leave(KErrInvalidSequence);
       
   251 	}
       
   252 
       
   253 	TBtIntString8 jobId;
       
   254 	jobId.Zero();
       
   255 	TInt status = OperationStatusL();
       
   256 
       
   257 	aErrorCode = KErrNotFound;
       
   258 	GetAttributeL(KBtJobId(), jobId, aErrorCode);
       
   259 	LOG82("[CBtSoapCodec::CreateJobResponseL]\t %S: %S",&KBtJobId(), &jobId);
       
   260 	LOG2("[CBtSoapCodec::CreateJobResponseL]\t opStatus: %d, err %d",status, aErrorCode);
       
   261 	if(aErrorCode == KErrNone)
       
   262 		aErrorCode = status;
       
   263 	
       
   264 	aJobId = TBtMapper::Int(jobId);
       
   265 }
       
   266 
       
   267 //--------------------------------------------------------------------------------------------
       
   268 //
       
   269 // CBtSoapCodec::GetPrinterAttributesResponseL
       
   270 //
       
   271 //--------------------------------------------------------------------------------------------
       
   272 void CBtSoapCodec::GetPrinterAttributesResponseL(TInt& aState, TInt& aStateReasons,
       
   273 								 			   RArray<TPrintCapability>& aCapabilities,
       
   274 								 			   TInt& aOperationStatus)
       
   275 {
       
   276 	LOG("[CBtSoapCodec::GetPrinterAttributesResponseL]\t");
       
   277 	
       
   278 	// same operationStatus got twce but no matter.
       
   279 	GetPrinterStateResponseL(aState, aStateReasons, aOperationStatus);
       
   280 	GetPrinterCapabilitiesResponseL(aCapabilities, aOperationStatus);
       
   281 }
       
   282 
       
   283 //--------------------------------------------------------------------------------------------
       
   284 //
       
   285 // CBtSoapCodec::GetPrinterStateResponseL
       
   286 //
       
   287 //--------------------------------------------------------------------------------------------
       
   288 void CBtSoapCodec::GetPrinterStateResponseL(TInt& aState, TInt& aStateReasons, TInt& aOperationStatus)
       
   289 {
       
   290 	LOG("[CBtSoapCodec::GetPrinterStateResponseL]\t");
       
   291 
       
   292 	if(EBtGetPrinterAttributesResponse != SoapAction())
       
   293 	{
       
   294 		User::Leave(KErrInvalidSequence);
       
   295 	}
       
   296 
       
   297 	aState = EBtStateUnknown;
       
   298 	aStateReasons = EPbCheckPrinter;
       
   299 	aOperationStatus = OperationStatusL();
       
   300 
       
   301 	/*get attribute*/
       
   302 	TBtAttrString8 value(KNullDesC8());
       
   303 
       
   304 	/* Get printer status and reason */
       
   305 	TInt err = KErrNotFound;
       
   306 	GetAttributeL(KBtPrinterState(), value, err);
       
   307 	LOG82("[CBtSoapCodec::GetPrinterStateResponseL]\t ** %S: %S",&KBtPrinterState(), &value);
       
   308 	if(KErrNone == err)
       
   309 	{
       
   310 		aState = TBtMapper::State(value);
       
   311 		GetAttributeL(KBtPrinterStateReasons(), value, err);
       
   312 		LOG82("[CBtSoapCodec::GetPrinterStateResponseL]\t ** %S: %S",&KBtPrinterStateReasons(), &value);
       
   313 		if(KErrNone == err)
       
   314 		{
       
   315 			aStateReasons = TBtMapper::PrintError(value);
       
   316 		}
       
   317 	}
       
   318 }
       
   319 
       
   320 
       
   321 
       
   322 //--------------------------------------------------------------------------------------------
       
   323 //
       
   324 // CBtSoapCodec::GetCapabilitiesResponseL
       
   325 //
       
   326 //--------------------------------------------------------------------------------------------
       
   327 void CBtSoapCodec::GetPrinterCapabilitiesResponseL(RArray<TPrintCapability>& aCapabilities,
       
   328 								 			   TInt& aOperationStatus)
       
   329 {
       
   330 	LOG("[CBtSoapCodec::GetPrinterCapabilitiesResponseL]\t");
       
   331 
       
   332 	if(EBtGetPrinterAttributesResponse != SoapAction())
       
   333 	{
       
   334 		User::Leave(KErrInvalidSequence);
       
   335 	}
       
   336 
       
   337 	aOperationStatus = OperationStatusL();
       
   338 	aCapabilities.Reset();
       
   339 
       
   340 	aCapabilities.Append(ParseLayoutL());
       
   341 	aCapabilities.Append(ParseQualityL());
       
   342 	aCapabilities.Append(ParsePaperSizeL());
       
   343 
       
   344 }
       
   345 
       
   346 //--------------------------------------------------------------------------------------------
       
   347 //
       
   348 // CBtSoapCodec::GetJobAttributesResponseL
       
   349 //
       
   350 //--------------------------------------------------------------------------------------------
       
   351 void CBtSoapCodec::GetJobAttributesResponseL(const TInt aJobId, TInt& aJobState, TBtAttrString8& aJobName,
       
   352 										   TBtAttrString8& aOriginator, TInt& aSheetsCompleted, 
       
   353 										   TInt& aPendingJobs, TInt& aErrorCode )
       
   354 
       
   355 {
       
   356 	LOG("[CBtSoapCodec::GetJobAttributesResponseL]\t");
       
   357 	if(EBtGetJobAttributesResponse != SoapAction())
       
   358 	{
       
   359 		User::Leave(KErrInvalidSequence);
       
   360 	}
       
   361 	
       
   362 	aJobState = EBtStateUnknown;
       
   363 	aJobName = KNullDesC8();
       
   364 	aOriginator = KNullDesC8();
       
   365 	aSheetsCompleted = KErrNotFound;
       
   366 	aPendingJobs = KErrNotFound;
       
   367 	aErrorCode = KErrNotFound;
       
   368 
       
   369 	TBtAttrString8 value(KNullDesC8());
       
   370 	TInt status = OperationStatusL();
       
   371 
       
   372 	GetAttributeL(KBtJobId(), value, aErrorCode);
       
   373 	LOG82("[CBtSoapCodec::GetJobAttributesResponseL]\t %S: %S",&KBtJobId(), &value);
       
   374 	LOG2("[CBtSoapCodec::GetJobAttributesResponseL]\t opStatus: %d, err %d",status, aErrorCode);
       
   375 	if(aErrorCode == KErrNone)
       
   376 	{
       
   377 		if(	TBtMapper::Int(value) != aJobId)
       
   378 			aErrorCode = KErrArgument;
       
   379 		else
       
   380 			aErrorCode = status;
       
   381 	}
       
   382 	
       
   383 	// then just get the rest of the arguments. Success or fails, just continue.
       
   384 	GetAttributeL(KBtJobState(), value, status);
       
   385 	if(KErrNone == status)
       
   386 		aJobState = TBtMapper::State(value);
       
   387 	else
       
   388 	{
       
   389 		LOG82("[CBtSoapCodec::GetJobAttributesResponseL]\t %S: %S",&KBtJobState(), &value);
       
   390 		LOG1("[CBtSoapCodec::GetJobAttributesResponseL]\t err %d",status);
       
   391 	}
       
   392 
       
   393 	GetAttributeL(KBtJobMediaSheetsCompleted(), value, status);
       
   394 	if(KErrNone == status)
       
   395 		aSheetsCompleted = TBtMapper::Int(value);
       
   396 	else
       
   397 	{
       
   398 		LOG82("[CBtSoapCodec::GetJobAttributesResponseL]\t %S: %S",&KBtJobMediaSheetsCompleted(), &value);
       
   399 		LOG1("[CBtSoapCodec::GetJobAttributesResponseL]\t err %d",status);
       
   400 	}
       
   401 
       
   402 	GetAttributeL(KBtJobPending(), value, status);
       
   403 	if(KErrNone == status)
       
   404 		aPendingJobs = TBtMapper::Int(value);
       
   405 	else
       
   406 	{
       
   407 		LOG82("[CBtSoapCodec::GetJobAttributesResponseL]\t %S: %S",&KBtJobPending(), &value);
       
   408 		LOG1("[CBtSoapCodec::GetJobAttributesResponseL]\t err %d",status);
       
   409 	}
       
   410 	
       
   411 	GetAttributeL(KBtJobName(), aJobName, status);
       
   412 	if(KErrNone != status)
       
   413 	{
       
   414 		LOG82("[CBtSoapCodec::GetJobAttributesResponseL]\t %S: %S",&KBtJobName(), &aJobName);
       
   415 		LOG1("[CBtSoapCodec::GetJobAttributesResponseL]\t err %d",status);
       
   416 	}
       
   417 
       
   418 	GetAttributeL(KBtJobOriginatingUserName(), aOriginator, status);
       
   419 	if(KErrNone != status)
       
   420 	{
       
   421 		LOG82("[CBtSoapCodec::GetJobAttributesResponseL]\t %S: %S",&KBtJobOriginatingUserName(), &aOriginator);
       
   422 		LOG1("[CBtSoapCodec::GetJobAttributesResponseL]\t err %d",status);
       
   423 	}
       
   424 }
       
   425 
       
   426 //--------------------------------------------------------------------------------------------
       
   427 //
       
   428 // CBtSoapCodec::CancelJobResponseL
       
   429 //
       
   430 //--------------------------------------------------------------------------------------------
       
   431 void CBtSoapCodec::CancelJobResponseL(const TInt aJobId, TInt& aErrorCode)
       
   432 {
       
   433 	LOG("[CBtSoapCodec::CancelJobResponseL]\t");
       
   434 	TBtIntString8 jobId;
       
   435 	jobId.Append(aJobId);
       
   436 
       
   437 	if(EBtCancelJobResponse != SoapAction())
       
   438 	{
       
   439 		User::Leave(KErrInvalidSequence);
       
   440 	}
       
   441 
       
   442 	TBuf8<KDefaultRealWidth> respJobId;
       
   443 	TInt status = OperationStatusL();
       
   444 
       
   445 	aErrorCode = KErrNotFound;
       
   446 	GetAttributeL(KBtJobId(), respJobId, aErrorCode);
       
   447 	LOG82("[CBtSoapCodec::CancelJobResponseL]\t %S: %S",&KBtJobId(), &respJobId);
       
   448 	LOG2("[CBtSoapCodec::CancelJobResponseL]\t opStatus: %d, err %d",status, aErrorCode);
       
   449 	if(aErrorCode == KErrNone)
       
   450 	{
       
   451 		if(TBtMapper::Int(respJobId) != aJobId)
       
   452 			aErrorCode = KErrArgument;
       
   453 		else
       
   454 			aErrorCode = status;
       
   455 	}
       
   456 }
       
   457 
       
   458 //--------------------------------------------------------------------------------------------
       
   459 //
       
   460 // CBtSoapCodec::GetEventResponseL
       
   461 //
       
   462 //--------------------------------------------------------------------------------------------
       
   463 void CBtSoapCodec::GetEventResponseL(const TInt aJobId,
       
   464 											  TInt& aJobState,
       
   465 											  TInt& aPrinterState,
       
   466 											  TInt& aStateReasons,
       
   467 											  TInt& aErrorCode)
       
   468 {
       
   469 	LOG("[CBtSoapCodec::GetEventResponseL]\t");
       
   470 	if(EBtGetEventResponse != SoapAction())
       
   471 	{
       
   472 		User::Leave(KErrInvalidSequence);
       
   473 	}
       
   474 
       
   475 	aJobState = EBtStateUnknown;
       
   476 	aPrinterState = KErrNotFound;
       
   477 	aStateReasons = KErrNotFound;
       
   478 	aErrorCode = KErrNotSupported;
       
   479 
       
   480 	TBtAttrString8 value(KNullDesC8());
       
   481 	TInt status = OperationStatusL();
       
   482 
       
   483 	GetAttributeL(KBtJobId(), value, aErrorCode);
       
   484 	LOG82("[CBtSoapCodec::GetEventResponseL]\t %S: %S",&KBtJobId(), &value);
       
   485 	LOG2("[CBtSoapCodec::GetEventResponseL]\t opStatus: %d, err %d",status, aErrorCode);
       
   486 	if(aErrorCode == KErrNone)
       
   487 	{
       
   488 		if(TBtMapper::Int(value) != aJobId)
       
   489 			aErrorCode = KErrArgument;
       
   490 		else
       
   491 			aErrorCode = status;
       
   492 	}
       
   493 	
       
   494 	// then just get the rest of the arguments. Success or fails, just continue.
       
   495 	GetAttributeL(KBtJobState(), value, status);
       
   496 	LOG82("[CBtSoapCodec::GetEventResponseL]\t %S: %S",&KBtJobState(), &value);
       
   497 	LOG1("[CBtSoapCodec::GetEventResponseL]\t err %d",status);
       
   498 	if(KErrNone == status)
       
   499 		aJobState = TBtMapper::Int(value);
       
   500 
       
   501 	GetAttributeL(KBtPrinterState(), value, status);
       
   502 	LOG82("[CBtSoapCodec::GetEventResponseL]\t %S: %S",&KBtPrinterState(), &value);
       
   503 	LOG1("[CBtSoapCodec::GetEventResponseL]\t err %d",status);
       
   504 	if(KErrNone == status)
       
   505 		aPrinterState = TBtMapper::Int(value);
       
   506 	
       
   507 	GetAttributeL(KBtPrinterStateReasons(), value, status);
       
   508 	LOG82("[CBtSoapCodec::GetEventResponseL]\t %S: %S",&KBtPrinterStateReasons(), &value);
       
   509 	LOG1("[CBtSoapCodec::GetEventResponseL]\t err %d",status);
       
   510 	if(KErrNone == status)
       
   511 		aStateReasons = TBtMapper::Int(value);
       
   512 }
       
   513 
       
   514 //--------------------------------------------------------------------------------------------
       
   515 //
       
   516 // CBtSoapCodec::OperationStatusL
       
   517 //
       
   518 //--------------------------------------------------------------------------------------------
       
   519 TInt CBtSoapCodec::OperationStatusL()
       
   520 {
       
   521 	LOG("[CBtSoapCodec::GetOperationStatus]\t");
       
   522 
       
   523 	/* Get operation status. If NOK or not found, no reason to continue */
       
   524 	TBtAttrString8 value(KNullDesC8());
       
   525 	TInt status = KErrNotFound;
       
   526 
       
   527 	GetAttributeL(KBtOperationStatus(), value, status);
       
   528 	LOG82("[CBtSoapCodec::GetOperationStatus]\t %S: %S",&KBtOperationStatus(), &value);
       
   529 
       
   530 	status = TBtMapper::OperationStatus(value);
       
   531 
       
   532 	LOG1("[CBtSoapCodec::GetOperationStatus]\t return status %d",status);
       
   533 	return status;
       
   534 }
       
   535 
       
   536 //------------------------------
       
   537 
       
   538 //--------------------------------------------------------------------------------------------
       
   539 //
       
   540 // CBtSoapCodec::GetAttributeL
       
   541 //
       
   542 //--------------------------------------------------------------------------------------------
       
   543 void CBtSoapCodec::GetAttributeL(const TDesC8& aName, TDes8& aValue, TInt& aError)
       
   544 {
       
   545 	LOG("[CBtSoapCodec::GetAttributeL()]\t ");
       
   546 
       
   547 	if(KErrNotFound == iXmlHandler->BufferId())
       
   548 		User::Leave(KErrInvalidSequence);
       
   549 
       
   550 	aError = KErrNotFound;
       
   551 
       
   552 	TBtAttrString8 startTag;
       
   553 	TBtAttrString8 endTag;
       
   554 
       
   555 	startTag.Format(KBtStartTag(), &aName);
       
   556 	endTag.Format(KBtEndTag(), &aName);
       
   557 
       
   558 	TInt offset = KErrNotFound;
       
   559 	TPtrC8 ptr = iXmlHandler->GetDataL(startTag, endTag, offset);
       
   560 
       
   561 	if(0 < ptr.Length())
       
   562 	{
       
   563 		aError = KErrNone;
       
   564 		aValue.Copy(ptr);
       
   565 	}
       
   566 	LOG("[CBtSoapCodec::GetAttributeL]\t end");
       
   567 }
       
   568 
       
   569 //--------------------------------------------------------------------------------------------
       
   570 //
       
   571 // CBtSoapCodec::GetAttributeListL
       
   572 //
       
   573 //--------------------------------------------------------------------------------------------
       
   574 void CBtSoapCodec::GetAttributeListL(const TDesC8& aName, CDesC8ArrayFlat& aList, TInt& aError)
       
   575 {
       
   576 	LOG("[CBtSoapCodec::GetAttributeL()]\t ");
       
   577 
       
   578 	if(KErrNotFound == iXmlHandler->BufferId())
       
   579 		User::Leave(KErrInvalidSequence);
       
   580 
       
   581 	aError = KErrNotFound;
       
   582 	aList.Reset();
       
   583 
       
   584 	// Read the list of tag aName
       
   585 	TInt offset = KErrNotFound;
       
   586 	HBufC8* listData = HBufC8::NewLC(iXmlHandler->Buffer().Length());
       
   587 	TPtr8 dataPtr = listData->Des();
       
   588 	GetAttributeL(aName, dataPtr, offset);
       
   589 	if(0 >= dataPtr.Length())
       
   590 	{
       
   591 		aError = KErrNotFound;
       
   592 		CleanupStack::PopAndDestroy(listData);
       
   593 		return;
       
   594 	}
       
   595 	
       
   596 	CXmlHandler* tmpHandler = CXmlHandler::NewLC();
       
   597 	tmpHandler->InitFromBufferL(dataPtr);
       
   598 	
       
   599 	// Now find the first tag data to identify the tag of the entry in the list
       
   600 	TPtrC8 newNamePtr = tmpHandler->GetDataL(KBtLessThan(), KBtGreaterThan(), offset);
       
   601 	
       
   602 	TBtAttrString8 startTag;
       
   603 	TBtAttrString8 endTag;
       
   604 
       
   605 	startTag.Format(KBtStartTag(), &newNamePtr);
       
   606 	endTag.Format(KBtEndTag(), &newNamePtr);
       
   607 
       
   608 	tmpHandler->GetDataListL(startTag, endTag, aList);
       
   609 	CleanupStack::PopAndDestroy(2); //listData, tmpHandler
       
   610 
       
   611 	if(0 < aList.Count())
       
   612 	{
       
   613 		aError = KErrNone;
       
   614 	}
       
   615 }
       
   616 
       
   617 
       
   618 // PRIVATE
       
   619 //--------------------------------------------------------------------------------------------
       
   620 //
       
   621 // CBtSoapCodec::CreateSoapTemplateL
       
   622 //
       
   623 //--------------------------------------------------------------------------------------------
       
   624 void CBtSoapCodec::CreateSoapTemplateL(const TDesC8& aStartTag, const TDesC8& aEndTag)
       
   625 {
       
   626 	LOG("[CBtSoapCodec::CreateSoapTemplateL]\t");
       
   627 
       
   628 	// Open the template file and read it into buffer
       
   629 	iXmlHandler->Reset();
       
   630 	iXmlHandler->InitFromFileL(KBtXmlTemplate());
       
   631 
       
   632 	// Separate the template element from the template buffer
       
   633 	if(iActionBuffer)
       
   634 		delete iActionBuffer;
       
   635 	iActionBuffer = NULL;
       
   636 	
       
   637 	TInt offset = 0;
       
   638 
       
   639 	TPtrC8 ptr = iXmlHandler->GetDataL(aStartTag, aEndTag, offset);
       
   640 
       
   641 	iActionBuffer = static_cast<HBufC8*>(User::LeaveIfNull(ptr.AllocL()));
       
   642 
       
   643 	iXmlHandler->DeleteBufferData(offset, iActionBuffer->Length()+aStartTag.Length()+aEndTag.Length());
       
   644 	iXmlHandler->ComposeDataL(iActionBuffer->Des(), KBtActionData());
       
   645 }
       
   646 
       
   647 //--------------------------------------------------------------------------------------------
       
   648 //
       
   649 // CBtSoapCodec::CreateJobSoapL
       
   650 //
       
   651 //--------------------------------------------------------------------------------------------
       
   652 void CBtSoapCodec::CreateJobSoapL(const TInt aJobId)
       
   653 {
       
   654 	LOG("[CBtSoapCodec::CreateJobSoapL]\t");
       
   655 	CreateSoapTemplateL(KBtCreateJobStart(), KBtCreateJobEnd());
       
   656 
       
   657 	TBuf8<KMaxFileName> filename;
       
   658 	filename.Format(KXHTMLFileName8(), aJobId);
       
   659 
       
   660 	TBtAttrString8 nameTempl, userNameTempl;
       
   661 	nameTempl.Format(KBtValueTemplate(), &KBtJobName());
       
   662 	userNameTempl.Format(KBtValueTemplate(), &KBtJobOriginatingUserName());
       
   663 	nameTempl.Format(KBtValueTemplate(), &KBtJobName());
       
   664 
       
   665 	iXmlHandler->ComposeDataL(KBtCreateJob(), KBtAction());
       
   666 	iXmlHandler->ComposeDataL(filename, nameTempl);
       
   667 	
       
   668 	TBuf8<0x100> name;
       
   669 	RsUtils::GetLocalBTNameL(name);
       
   670 	iXmlHandler->ComposeDataL(name, userNameTempl);
       
   671 }
       
   672 
       
   673 //--------------------------------------------------------------------------------------------
       
   674 //
       
   675 // CBtSoapCodec::GetCapabilitiesSoapL
       
   676 //
       
   677 //--------------------------------------------------------------------------------------------
       
   678 void CBtSoapCodec::GetCapabilitiesSoapL()
       
   679 {
       
   680 	LOG("[CBtSoapCodec::GetCapabilitiesSoapL]\t");
       
   681 	CreateSoapTemplateL(KBtGetPrinterCapabilitiesStart(), KBtGetPrinterCapabilitiesEnd());
       
   682 
       
   683 	iXmlHandler->ComposeDataL(KBtGetPrinterAttributes(), KBtAction());
       
   684 }
       
   685 
       
   686 //--------------------------------------------------------------------------------------------
       
   687 //
       
   688 // CBtSoapCodec::GetPrinterStateSoapL
       
   689 //
       
   690 //--------------------------------------------------------------------------------------------
       
   691 void CBtSoapCodec::GetPrinterStateSoapL()
       
   692 {
       
   693 	LOG("[CBtSoapCodec::GetPrinterStateSoapL]\t");
       
   694 	CreateSoapTemplateL(KBtGetPrinterStateStart(), KBtGetPrinterStateEnd());
       
   695 
       
   696 	iXmlHandler->ComposeDataL(KBtGetPrinterAttributes(), KBtAction());
       
   697 }
       
   698 
       
   699 //--------------------------------------------------------------------------------------------
       
   700 //
       
   701 // CBtSoapCodec::GetPrinterAttributesSoapL
       
   702 //
       
   703 //--------------------------------------------------------------------------------------------
       
   704 void CBtSoapCodec::GetPrinterAttributesSoapL()
       
   705 {
       
   706 	LOG("[CBtSoapCodec::GetPrinterAttributesSoapL]\t");
       
   707 	CreateSoapTemplateL(KBtGetPrinterAttributesAllStart(), KBtGetPrinterAttributesAllEnd());
       
   708 
       
   709 	iXmlHandler->ComposeDataL(KBtGetPrinterAttributes(), KBtAction());
       
   710 }
       
   711 
       
   712 //--------------------------------------------------------------------------------------------
       
   713 //
       
   714 // CBtSoapCodec::GetJobAttributesSoapL
       
   715 //
       
   716 //--------------------------------------------------------------------------------------------
       
   717 void CBtSoapCodec::GetJobAttributesSoapL(const TDesC8&  aJobId)
       
   718 {
       
   719 	LOG("[CBtSoapCodec::GetJobAttributesSoapL]\t");
       
   720 	CreateSoapTemplateL(KBtJobIdStart(), KBtJobIdEnd());
       
   721 
       
   722 	iXmlHandler->ComposeDataL(KBtGetJobAttributes(), KBtAction());
       
   723 
       
   724 	TBtAttrString8 templ;
       
   725 	templ.Format(KBtValueTemplate(), &KBtJobId());
       
   726 
       
   727 	iXmlHandler->ComposeDataL(aJobId, templ);
       
   728 }
       
   729 
       
   730 //--------------------------------------------------------------------------------------------
       
   731 //
       
   732 // CBtSoapCodec::CancelJobSoapL
       
   733 //
       
   734 //--------------------------------------------------------------------------------------------
       
   735 void CBtSoapCodec::CancelJobSoapL(const TDesC8&  aJobId)
       
   736 {
       
   737 	LOG("[CBtSoapCodec::CancelJobSoapL]\t");
       
   738 	CreateSoapTemplateL(KBtJobIdStart(), KBtJobIdEnd());
       
   739 
       
   740 	iXmlHandler->ComposeDataL(KBtCancelJob(), KBtAction());
       
   741 
       
   742 	TBtAttrString8 templ;
       
   743 	templ.Format(KBtValueTemplate(), &KBtJobId());
       
   744 
       
   745 	iXmlHandler->ComposeDataL(aJobId, templ);
       
   746 }
       
   747 
       
   748 //--------------------------------------------------------------------------------------------
       
   749 //
       
   750 // CBtSoapCodec::GetEventSoapL
       
   751 //
       
   752 //--------------------------------------------------------------------------------------------
       
   753 void CBtSoapCodec::GetEventSoapL(const TDesC8&  aJobId)
       
   754 {
       
   755 	LOG("[CBtSoapCodec::GetEventSoapL]\t");
       
   756 	CreateSoapTemplateL(KBtJobIdStart(), KBtJobIdEnd());
       
   757 
       
   758 	iXmlHandler->ComposeDataL(KBtGetEvent(), KBtAction());
       
   759 
       
   760 	TBtAttrString8 templ;
       
   761 	templ.Format(KBtValueTemplate(), &KBtJobId());
       
   762 
       
   763 	iXmlHandler->ComposeDataL(aJobId, templ);
       
   764 }
       
   765 
       
   766 //--------------------------------------------------------------------------------------------
       
   767 //
       
   768 // CBtSoapCodec::GetMarginsSoapL
       
   769 //
       
   770 //--------------------------------------------------------------------------------------------
       
   771 void CBtSoapCodec::GetMarginsSoapL()
       
   772 {
       
   773 	LOG("[CBtSoapCodec::GetMarginsSoapL]\t NOT SUPPORTED -> leave");
       
   774 	User::Leave(KErrNotSupported);
       
   775 	
       
   776 	CreateSoapTemplateL(KBtGetMarginsStart(), KBtGetMarginsEnd());
       
   777 
       
   778 	iXmlHandler->ComposeDataL(KBtGetMargins(), KBtAction());
       
   779 }
       
   780 
       
   781 //--------------------------------------------------------------------------------------------
       
   782 //
       
   783 // CBtSoapCodec::SoapAction
       
   784 //
       
   785 //--------------------------------------------------------------------------------------------
       
   786 TInt CBtSoapCodec::SoapAction()
       
   787 {
       
   788 	LOG1("[CBtSoapCodec::SoapAction()]\t iActionBuffer: %d", iActionBuffer);
       
   789 	if(!iActionBuffer || 0 >= iActionBuffer->Length())
       
   790 		return EBtUnknownAction;
       
   791 	
       
   792 	TInt len = iActionBuffer->Length() < 50 ? iActionBuffer->Length() : 50;
       
   793 	TPtrC8 ptr = iActionBuffer->Mid(0, len);
       
   794 	LOG81("[CBtSoapCodec::SoapAction()]\t ptr: \"%S\"", &ptr);
       
   795 
       
   796 	/* read action name - the order in list below matters: 
       
   797 	   be aware the substrings (as CreateJob is for CreateJobResponse) aren't found!*/
       
   798 	if(KErrNotFound < ptr.Find(KBtCreateJobResponse()))
       
   799 	{
       
   800 		return EBtCreateJobResponse;
       
   801 	}
       
   802 	else if(KErrNotFound < ptr.Find(KBtCreateJob()))
       
   803 	{
       
   804 		return EBtCreateJob;
       
   805 	}
       
   806 	else if(KErrNotFound < ptr.Find(KBtGetPrinterAttributesResponse()))
       
   807 	{
       
   808 		return EBtGetPrinterAttributesResponse;
       
   809 	}
       
   810 	else if(KErrNotFound < ptr.Find(KBtGetPrinterAttributes()))
       
   811 	{
       
   812 		return EBtGetPrinterAttributes;
       
   813 	}
       
   814 	else if(KErrNotFound < ptr.Find(KBtGetJobAttributesResponse()))
       
   815 	{
       
   816 		return EBtGetJobAttributesResponse;
       
   817 	}
       
   818 	else if(KErrNotFound < ptr.Find(KBtGetJobAttributes()))
       
   819 	{
       
   820 		return EBtGetJobAttributes;
       
   821 	}
       
   822 	else if(KErrNotFound < ptr.Find(KBtCancelJobResponse()))
       
   823 	{
       
   824 		return EBtCancelJobResponse;
       
   825 	}
       
   826 	else if(KErrNotFound < ptr.Find(KBtCancelJob()))
       
   827 	{
       
   828 		return EBtCancelJob;
       
   829 	}
       
   830 	else if(KErrNotFound < ptr.Find(KBtGetEventResponse()))
       
   831 	{
       
   832 		return EBtGetEventResponse;
       
   833 	}
       
   834 	else if(KErrNotFound < ptr.Find(KBtGetEvent()))
       
   835 	{
       
   836 		return EBtGetEvent;
       
   837 	}
       
   838 	else if(KErrNotFound < ptr.Find(KBtGetMarginsResponse()))
       
   839 	{
       
   840 		return EBtGetMarginsResponse;
       
   841 	}
       
   842 	else if(KErrNotFound < ptr.Find(KBtGetMargins()))
       
   843 	{
       
   844 		return EBtGetMargins;
       
   845 	}
       
   846 
       
   847 	return EBtUnknownAction;
       
   848 
       
   849 }
       
   850 
       
   851 //--------------------------------------------------------------------------------------------
       
   852 //
       
   853 // CBtSoapCodec::CBtSoapCodec
       
   854 //
       
   855 //--------------------------------------------------------------------------------------------
       
   856 CBtSoapCodec::CBtSoapCodec()
       
   857 {
       
   858 }
       
   859 
       
   860 //--------------------------------------------------------------------------------------------
       
   861 //
       
   862 // CBtSoapCodec::ParseLayout
       
   863 //
       
   864 //--------------------------------------------------------------------------------------------
       
   865 TPrintCapability CBtSoapCodec::ParseLayoutL()
       
   866 {
       
   867 	LOG("[CBtSoapCodec::ParseLayout]\t");
       
   868 
       
   869 	TPrintCapability layout;
       
   870 	layout.iCapabilityID = EPrintCapabLayout;
       
   871 	layout.iType = TPrintCapability::Enum;
       
   872 	layout.iLow = 0;
       
   873 	layout.iHigh = 0;
       
   874 	layout.iEnumCount = 0;
       
   875 
       
   876 	/* Get layout(s) */
       
   877 	TBtAttrString8 value(KNullDesC8());
       
   878 	TInt err = KErrNotFound;
       
   879 	GetAttributeL(KBtNumberUpSupported(), value, err);
       
   880 	LOG82("[CBtSoapCodec::ParseLayout]\t %S: %S",&KBtNumberUpSupported(), &value);
       
   881 	LOG1("[CBtSoapCodec::ParseLayout]\t error: %d",err);
       
   882 	if(KErrNone != err)
       
   883 	{
       
   884 		layout.iEnumCodes[0] = EPrintCapabLayout1UpBorderless;
       
   885 		layout.iEnumCount = 1;
       
   886 	}
       
   887 	else
       
   888 	{
       
   889 		LOG("[CBtSoapCodec::ParseLayout]\t get layout values...");
       
   890 		RArray<TInt> arr;
       
   891 		TBtMapper::Layout(value, arr);
       
   892 		LOG1("[CBtSoapCodec::ParseLayout]\t layout count: %d", arr.Count());
       
   893 		for(TInt i = 0; i < arr.Count(); ++i)
       
   894 		{
       
   895 			LOG2("[CBtSoapCodec::ParseLayout]\t arr[%d]: %d", i, arr[i]);
       
   896 			layout.iEnumCodes[i] = arr[i];
       
   897 		}
       
   898 		layout.iEnumCount = arr.Count();
       
   899 		arr.Close();
       
   900 	}
       
   901 
       
   902 	RArray<TInt> tmpArr;
       
   903 	tmpArr.Append(EPrintCapabLayout1UpBorderless);
       
   904 	tmpArr.Append(EPrintCapabLayout1UpBorder);
       
   905 	tmpArr.Append(EPrintCapabLayout2Up);
       
   906 	tmpArr.Append(EPrintCapabLayout4Up);
       
   907 	tmpArr.Append(EPrintCapabLayout6Up);
       
   908 	tmpArr.Append(EPrintCapabLayout9Up);
       
   909 	tmpArr.Append(EPrintCapabLayout12Up);
       
   910 	tmpArr.Append(EPrintCapabLayout16Up);
       
   911 
       
   912 	for(TInt i = 0; i < tmpArr.Count(); ++i)
       
   913 	{
       
   914 		TInt ix = ValuePosition(layout, tmpArr[i]);
       
   915 		if(KErrNotFound == ix)
       
   916 		{
       
   917 			layout.iEnumCodes[layout.iEnumCount] = tmpArr[i];
       
   918 			++layout.iEnumCount;
       
   919 		}
       
   920 	}
       
   921 	tmpArr.Close();
       
   922 
       
   923 	layout.iDefaultValue = layout.iEnumCodes[0];
       
   924 	
       
   925 	TInt ix = ValuePosition(layout, EPrintCapabLayout1UpBorderless);
       
   926 	if(KErrNotFound < ix)
       
   927 		layout.iDefaultValue = layout.iEnumCodes[ix];
       
   928 
       
   929 	LOG1("[CBtSoapCodec::ParseLayout]\t return default: %d", layout.iDefaultValue);
       
   930 	return layout;
       
   931 }
       
   932 
       
   933 //--------------------------------------------------------------------------------------------
       
   934 //
       
   935 // CBtSoapCodec::ParseQuality
       
   936 //
       
   937 //--------------------------------------------------------------------------------------------
       
   938 TPrintCapability CBtSoapCodec::ParseQualityL()
       
   939 {
       
   940 	LOG("[CBtSoapCodec::ParseQuality]\t");
       
   941 
       
   942 	TPrintCapability quality;
       
   943 	quality.iCapabilityID = EPrintCapabQuality;
       
   944 	quality.iType = TPrintCapability::Enum;
       
   945 	quality.iLow = 0;
       
   946 	quality.iHigh = 0;
       
   947 	quality.iDefaultValue = EPrintCapabQualityDefault;
       
   948 	quality.iEnumCodes[0] = EPrintCapabQualityDefault;
       
   949 	quality.iEnumCount = 1;
       
   950 
       
   951 	/* Get quality(s) */
       
   952 	CDesC8ArrayFlat *qualities = new (ELeave) CDesC8ArrayFlat(10);
       
   953 	CleanupStack::PushL(qualities);
       
   954 	
       
   955 	TInt err = KErrNotFound;
       
   956 	GetAttributeListL(KBtPrintQualitySupported(), *qualities, err);
       
   957 	LOG82("[CBtSoapCodec::ParseQuality]\t %S: count: %d",&KBtPrintQualitySupported(), qualities->MdcaCount());
       
   958 	if(KErrNone != err)
       
   959 	{
       
   960 		LOG1("[CBtSoapCodec::ParseQuality]\t return with error %d",err);
       
   961 		return quality;
       
   962 	}
       
   963 
       
   964 	for(TInt i = 0; i < qualities->MdcaCount(); ++i)
       
   965 	{
       
   966 		TInt tmp = TBtMapper::Quality( qualities->MdcaPoint(i) );
       
   967 		LOG2("[CBtSoapCodec::ParseQuality]\t qualities[%2d]: %d",i, tmp);
       
   968 		if(KErrNotSupported != tmp)
       
   969 		{
       
   970 			quality.iEnumCodes[quality.iEnumCount] = tmp;
       
   971 			++quality.iEnumCount;
       
   972 		}
       
   973 		if(KMaxEnumAmount < quality.iEnumCount)
       
   974 		{
       
   975 			LOG1("[CBtSoapCodec::ParseQuality]\t max enum count reached: %d",quality.iEnumCount);
       
   976 			--quality.iEnumCount;
       
   977 			break;
       
   978 		}
       
   979 	}
       
   980 	CleanupStack::PopAndDestroy(qualities);
       
   981 
       
   982 	LOG1("[CBtSoapCodec::ParseQuality]\t return default: %d", quality.iDefaultValue);
       
   983 	return quality;
       
   984 }
       
   985 
       
   986 //--------------------------------------------------------------------------------------------
       
   987 //
       
   988 // CBtSoapCodec::ParsePaperSize
       
   989 //
       
   990 //--------------------------------------------------------------------------------------------
       
   991 TPrintCapability CBtSoapCodec::ParsePaperSizeL()
       
   992 {
       
   993 	LOG("[CBtSoapCodec::ParsePaperSize]\t");
       
   994 
       
   995 	TPrintCapability size;
       
   996 	size.iCapabilityID = EPrintCapabPaperSize;
       
   997 	size.iType = TPrintCapability::Enum;
       
   998 	size.iLow = 0;
       
   999 	size.iHigh = 0;
       
  1000 	size.iDefaultValue = EPrintCapabPaperSize4x6;
       
  1001 
       
  1002 	/* Get size(s) */
       
  1003 	CDesC8ArrayFlat *sizes = new (ELeave) CDesC8ArrayFlat(10);
       
  1004 	CleanupStack::PushL(sizes);
       
  1005 
       
  1006 	TInt err = KErrNotFound;
       
  1007 	GetAttributeListL(KBtMediaSizesSupported(), *sizes, err);
       
  1008 	LOG82("[CBtSoapCodec::ParsePaperSize]\t %S: count %d",&KBtMediaSizesSupported(), sizes->MdcaCount());
       
  1009 	if(KErrNone != err)
       
  1010 	{
       
  1011 		size.iEnumCodes[0] = size.iDefaultValue;
       
  1012 		size.iEnumCount = 1;
       
  1013 		return size;
       
  1014 	}
       
  1015 
       
  1016 	TInt enumPos = 0;
       
  1017 	for(TInt i = 0; i < sizes->MdcaCount(); ++i)
       
  1018 	{
       
  1019 //		LOG82("[CBtSoapCodec::ParsePaperSize]\t sizes[%2d]: %S",i, &sizes[i]);
       
  1020 		TInt tmp = TBtMapper::Size(sizes->MdcaPoint(i));
       
  1021 		if(KErrNotSupported != tmp)
       
  1022 		{
       
  1023 			LOG2("[CBtSoapCodec::ParsePaperSize]\t sizes[%2d]: %d",i, tmp);
       
  1024 			size.iEnumCodes[enumPos] = tmp;
       
  1025 			size.iEnumCount = ++enumPos;
       
  1026 		}
       
  1027 		if(KMaxEnumAmount < enumPos)
       
  1028 		{
       
  1029 			LOG1("[CBtSoapCodec::ParsePaperSize]\t max enum count reached: %d",enumPos);
       
  1030 			break;
       
  1031 		}
       
  1032 	}
       
  1033 	CleanupStack::PopAndDestroy(sizes);
       
  1034 
       
  1035 	// Get default value from loaded media
       
  1036 	ParseDefaultSizeL(size, enumPos);
       
  1037 	
       
  1038 	// Sort the paper sizes in order 'smallest to biggest'
       
  1039 	RArray<TInt> tmpArr;
       
  1040 	tmpArr.Append(EPrintCapabPaperSizeAuto);
       
  1041 	tmpArr.Append(EPrintCapabPaperSize4x6);
       
  1042 	tmpArr.Append(EPrintCapabPaperSize5x7);
       
  1043 	tmpArr.Append(EPrintCapabPaperSizeA6);
       
  1044 	tmpArr.Append(EPrintCapabPaperSizeA4);
       
  1045 	tmpArr.Append(EPrintCapabPaperSizeLetter);	
       
  1046 	
       
  1047 	for(TInt s = 0; s < tmpArr.Count(); ++s)
       
  1048 	{
       
  1049 		TInt ix = ValuePosition(size,tmpArr[s]);
       
  1050 		if(KErrNotFound == ix)
       
  1051 			tmpArr.Remove(s);
       
  1052 	}
       
  1053 
       
  1054 	// Move back to enum array
       
  1055 	for(TInt s2 = 0; s2 < tmpArr.Count(); ++s2)
       
  1056 	{
       
  1057 		size.iEnumCodes[s2] = tmpArr[s2];
       
  1058 	}
       
  1059 	tmpArr.Close();
       
  1060 
       
  1061 #ifdef ENABLE_LOGGING
       
  1062 	_LIT(KTab, "|");
       
  1063 	TFileName tmp(KTab);
       
  1064 	
       
  1065 	for(TInt l = 0; l < size.iEnumCount; ++l)
       
  1066 	{
       
  1067 		tmp.AppendNum(size.iEnumCodes[l]);
       
  1068 		tmp.Append(KTab);
       
  1069 	}
       
  1070 	LOG1("[CBtSoapCodec::ParsePaperSizeL]\t order: %S", &tmp); 
       
  1071 #endif
       
  1072 
       
  1073 	return size;
       
  1074 }
       
  1075 
       
  1076 //--------------------------------------------------------------------------------------------
       
  1077 //
       
  1078 // CBtSoapCodec::ParseDefaultSizeL
       
  1079 //
       
  1080 //--------------------------------------------------------------------------------------------
       
  1081 void CBtSoapCodec::ParseDefaultSizeL(TPrintCapability& aSize, TInt& aPos)
       
  1082 {
       
  1083 	LOG("[CBtSoapCodec::ParseDefaultSizeL]\t");
       
  1084 
       
  1085 	//reserve more space for this: there are several long text lines
       
  1086 	TBuf8<KAttrStrLen*10> value(KNullDesC8());
       
  1087 	TInt err = KErrNotFound;
       
  1088 	
       
  1089 	GetAttributeL(KBtMediaLoaded(), value, err);
       
  1090 
       
  1091 #ifdef ENABLE_LOGGING
       
  1092 	TInt len = value.Length() < 50 ? value.Length() : 50;
       
  1093 	TPtrC8 p = value.Mid(0, len);
       
  1094 	LOG82("[CBtSoapCodec::ParseDefaultValues]\t %S: ptr: \"%S\"",&KBtMediaLoaded(), &p);
       
  1095 #endif
       
  1096 
       
  1097 	if(KErrNone != err)
       
  1098 	{
       
  1099 		LOG82("[CBtSoapCodec::ParseDefaultSizeL]\t %S not found. Error: %d. Return.",&KBtMediaLoaded(), err);
       
  1100 		return;
       
  1101 	}
       
  1102 
       
  1103 	CXmlHandler* tmpHandler = CXmlHandler::NewLC();
       
  1104 	tmpHandler->InitFromBufferL(value);
       
  1105 	TBtAttrString8 start;
       
  1106 	TBtAttrString8 end;
       
  1107 	start.Format(KBtStartTag(), &KBtLoadedMediumSize());
       
  1108 	end.Format(KBtEndTag(), &KBtLoadedMediumSize());
       
  1109 
       
  1110 	TPtrC8 defValue = tmpHandler->GetDataL(start, end, err);
       
  1111 	TInt tmpDefault = TBtMapper::Size(defValue);
       
  1112 
       
  1113 	CleanupStack::PopAndDestroy(tmpHandler);
       
  1114 
       
  1115 	if(KErrNotSupported != tmpDefault)
       
  1116 	{
       
  1117 		aSize.iDefaultValue = tmpDefault;
       
  1118 	}
       
  1119 
       
  1120 	// Check the default value exists...
       
  1121 	for(TInt i = 0; i < aSize.iEnumCount; ++i)
       
  1122 	{
       
  1123 		if(aSize.iDefaultValue == aSize.iEnumCodes[i])
       
  1124 		{
       
  1125 			return;
       
  1126 		}
       
  1127 	}
       
  1128 
       
  1129 	// ...if not, append it.
       
  1130 	if(KMaxEnumAmount < aPos)
       
  1131 	{
       
  1132 		--aPos;
       
  1133 	}
       
  1134 	aSize.iEnumCodes[aPos] = aSize.iDefaultValue;
       
  1135 	aSize.iEnumCount = ++aPos;
       
  1136 
       
  1137 	LOG1("[CBtSoapCodec::ParseDefaultSizeL]\t return default: %d", aSize.iDefaultValue);
       
  1138 }
       
  1139 
       
  1140 
       
  1141 //--------------------------------------------------------------------------------------------
       
  1142 //
       
  1143 // CBtSoapCodec::ValuePosition
       
  1144 //
       
  1145 //--------------------------------------------------------------------------------------------
       
  1146 TInt CBtSoapCodec::ValuePosition(TPrintCapability aCapab, TInt aValue)
       
  1147 {
       
  1148 	TInt pos = KErrNotFound;
       
  1149 	for(TInt i = 0; i < aCapab.iEnumCount; ++i)
       
  1150 		if(aValue == aCapab.iEnumCodes[i])
       
  1151 			pos = i;
       
  1152 		
       
  1153 	return pos;
       
  1154 }
       
  1155 
       
  1156 ////// TEST METHODS ///////////
       
  1157 //--------------------------------------------------------------------------------------------
       
  1158 void CBtSoapCodec::TestMeL()
       
  1159 {
       
  1160 
       
  1161     _LIT8(KSepar, "\n-------------------------\n");
       
  1162     _LIT8(KKErrNotFound, "KErrNotFound");
       
  1163     _LIT8(KLF, "\n%d\n");
       
  1164 
       
  1165 	RFs fs;
       
  1166 	CleanupClosePushL(fs);
       
  1167 	User::LeaveIfError(fs.Connect());
       
  1168 
       
  1169     /*create*/
       
  1170     CBtSoapCodec* codec = CBtSoapCodec::NewL();
       
  1171     TPtrC8 ptr = codec->CreateSoapL(EBtGetPrinterAttributes);
       
  1172 
       
  1173 	_LIT(KTstFile, "c:\\data\\tst.txt");
       
  1174 	RFile f;
       
  1175 	CleanupClosePushL(f);
       
  1176 	f.Replace(fs,KTstFile, EFileWrite);
       
  1177 	f.Write(ptr);
       
  1178 	f.Write(KSepar());
       
  1179 
       
  1180    	/*read*/
       
  1181 	TInt act;
       
  1182 	CBufFlat* data = CBufFlat::NewL(8);
       
  1183 	data->InsertL(0, GetPrinterAttributesResponseTestSoap());
       
  1184 
       
  1185 	codec->ReadSoapL(act, *data);
       
  1186 
       
  1187 	/*get attribute*/
       
  1188 	TBtAttrString8 val, errStr;
       
  1189 	_LIT8(KPrinterState,		"PrinterState");
       
  1190 	_LIT8(KPrinterStateReasons,	"PrinterStateReasons");
       
  1191 	TInt err = KErrNoMemory;
       
  1192 
       
  1193 	codec->GetAttributeL(KPrinterState(), val, err);
       
  1194 	TInt s;
       
  1195 	errStr.Format(KLF(), err);
       
  1196 	f.Size(s);
       
  1197 	f.Write(s+1, KPrinterState);
       
  1198 	f.Write(errStr);
       
  1199 	f.Write(val);
       
  1200 	f.Write(KSepar());
       
  1201 
       
  1202 	codec->GetAttributeL(KPrinterStateReasons(), val, err);
       
  1203 	errStr.Format(KLF(), err);
       
  1204 	f.Size(s);
       
  1205 	f.Write(s+1, KPrinterStateReasons);
       
  1206 	f.Write(errStr);
       
  1207 	f.Write(val);
       
  1208 	f.Write(KSepar());
       
  1209 
       
  1210 	codec->GetAttributeL(KKErrNotFound(), val, err);
       
  1211 	errStr.Format(KLF(), err);
       
  1212 	f.Size(s);
       
  1213 	f.Write(s+1, KKErrNotFound);
       
  1214 	f.Write(errStr);
       
  1215 	f.Write(val);
       
  1216 	f.Write(KSepar());
       
  1217 
       
  1218 	CleanupStack::PopAndDestroy(2);	// f, fs
       
  1219 
       
  1220 }
       
  1221 
       
  1222 
       
  1223 TPtrC8 CBtSoapCodec::CreateJobResponseTestSoap()
       
  1224 {
       
  1225     _LIT8(KTestSoap, "CONTENT-LENGTH:200\nCONTENT-TYPE:text/xml; charset=\"utf-8\""
       
  1226    				"<s:Envelope\nxmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
       
  1227    				"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       
  1228    				"<s:Body>"
       
  1229 				"<u:CreateJobResponse xmlns:u=\"urn:schemas-bluetooth-org:service:Printer:1\">"
       
  1230 					"<JobId>12345</JobId>"
       
  1231 					"<OperationStatus>0x0001</OperationStatus>"
       
  1232 				"</u:CreateJobResponse>"
       
  1233 				"</s:Body>"
       
  1234 				"</s:Envelope>");
       
  1235 				   				
       
  1236 	TPtrC8 response = KTestSoap();
       
  1237 	return response;
       
  1238 }
       
  1239 TPtrC8 CBtSoapCodec::CancelJobResponseTestSoap()
       
  1240 {
       
  1241     _LIT8(KTestSoap, "CONTENT-LENGTH:200\nCONTENT-TYPE:text/xml; charset=\"utf-8\""
       
  1242    				"<s:Envelope\nxmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
       
  1243    				"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       
  1244    				"<s:Body>"
       
  1245 				"<u:CancelJobResponse xmlns:u=\"urn:schemas-bluetooth-org:service:Printer:1\">"
       
  1246 					"<JobId>12345</JobId>"
       
  1247 					"<OperationStatus>0x0406</OperationStatus>"
       
  1248 				"</u:CancelJobResponse>"
       
  1249 				"</s:Body>"
       
  1250 				"</s:Envelope>");
       
  1251    				
       
  1252 	TPtrC8 response = KTestSoap();
       
  1253 	return response;
       
  1254 }
       
  1255 TPtrC8 CBtSoapCodec::GetPrinterAttributesResponseTestSoap()
       
  1256 {
       
  1257     _LIT8(KTestSoap, "CONTENT-LENGTH:200\nCONTENT-TYPE:text/xml; charset=\"utf-8\""
       
  1258    				"<s:Envelope\nxmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
       
  1259    				"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       
  1260    				"<s:Body>"
       
  1261    				"<u:GetPrinterAttributesResponse xmlns:u=\"urn:schemas-bluetooth-org:service:Printer:1\">"
       
  1262     				"<PrinterName>MyPrinter</PrinterName>"
       
  1263     				"<PrinterLocation>MyLocation</PrinterLocation>"
       
  1264     				"<PrinterState>idle</PrinterState>"
       
  1265     				"<PrinterStateReasons>none</PrinterStateReasons>"
       
  1266     				"<PrinterGeneralCurrentOperator></PrinterGeneralCurrentOperator>"
       
  1267     				"<DocumentFormatsSupported>"
       
  1268 	    				"<DocumentFormat> application/vnd.pwg-xhtml-print+xml:0.95 </DocumentFormat>"
       
  1269 	    				"<DocumentFormat> application/vnd.hp-PCL:5E</DocumentFormat>"
       
  1270 	    				"<DocumentFormat> text/plain</DocumentFormat>"
       
  1271 	    				"<DocumentFormat> application/PostScript:3</DocumentFormat>"
       
  1272     				"</DocumentFormatsSupported>"
       
  1273     				"<ImageFormatsSupported>"
       
  1274 	    				"<ImageFormat>image/jpeg</ImageFormat>"
       
  1275 	    				"<ImageFormat>image/gif</ImageFormat>"
       
  1276     				"</ImageFormatsSupported>"
       
  1277     				"<ColorSupported>true</ColorSupported>"
       
  1278     				"<MaxCopiesSupported>1</MaxCopiesSupported>"
       
  1279     				"<SidesSupported>"
       
  1280 	    				"<Sides> one-sided</Sides>"
       
  1281 	    				"<Sides> two-sided-long-edge</Sides>"
       
  1282 	    				"<Sides> two-sided-short-edge</Sides>"
       
  1283     				"</SidesSupported>"
       
  1284     				"<NumberUpSupported>4</NumberUpSupported>"
       
  1285     				"<OrientationsSupported>"
       
  1286 	    				"<Orientation>portrait</Orientation>"
       
  1287 	    				"<Orientation>landscape</Orientation>"
       
  1288     				"</OrientationsSupported>"
       
  1289     				"<MediaSizesSupported>"
       
  1290 	    				"<MediaSize>iso_a4_210x297mm</MediaSize>"
       
  1291 	    				"<MediaSize>iso_a3_297x420mm</MediaSize>"
       
  1292     				"</MediaSizesSupported>"
       
  1293     				"<MediaTypesSupported>"
       
  1294 	    				"<MediaType>stationery</MediaType>"
       
  1295 	    				"<MediaType>photographic</MediaType>"
       
  1296 	    				"<MediaType>cardstock</MediaType>"
       
  1297     				"</MediaTypesSupported>"
       
  1298     				"<MediaLoaded>"
       
  1299 	    				"<LoadedMediumDetails>"
       
  1300 		    				"<LoadedMediumSize> iso_a4_210x297mm</LoadedMediumSize>"
       
  1301 		    				"<LoadedMediumType>stationery</LoadedMediumType>"
       
  1302 	    				"</LoadedMediumDetails>"
       
  1303 	    				"<LoadedMediumDetails>"
       
  1304 		    				"<LoadedMediumSize> iso_a4_210x297mm</LoadedMediumSize>"
       
  1305 		    				"<LoadedMediumType>photographic</LoadedMediumType>"
       
  1306 	    				"</LoadedMediumDetails>"
       
  1307     				"</MediaLoaded>"
       
  1308     				"<PrintQualitySupported>"
       
  1309 	    				"<PrintQuality>draft</PrintQuality>"
       
  1310 	    				"<PrintQuality>normal</PrintQuality>"
       
  1311 	    				"<PrintQuality>fine</PrintQuality>"
       
  1312     				"</PrintQualitySupported>"
       
  1313     				"<QueuedJobCount>1</QueuedJobCount>"
       
  1314     				"<OperationStatus>0x0000</OperationStatus>"
       
  1315    				"</u:GetPrinterAttributesResponse></s:Body></s:Envelope>");
       
  1316 
       
  1317 	TPtrC8 response = KTestSoap();
       
  1318 	return response;
       
  1319 }
       
  1320 TPtrC8 CBtSoapCodec::GetJobAttributesResponseTestSoap()
       
  1321 {
       
  1322     _LIT8(KTestSoap, "CONTENT-LENGTH:200\nCONTENT-TYPE:text/xml; charset=\"utf-8\""
       
  1323    				"<s:Envelope\nxmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
       
  1324    				"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       
  1325    				"<s:Body>"
       
  1326 				"<u:GetJobAttributesResponse xmlns:u=\"urn:schemas-bluetooth-org:service:Printer:1\">"
       
  1327 					"<JobId>12345</JobId>"
       
  1328 					"<JobState>printing</JobState>"
       
  1329 					"<JobName>MyExpenseReport</JobName>"
       
  1330 					"<JobOriginatingUserName>mailto:MyEmail</JobOriginatingUserName>"
       
  1331 					"<JobMediaSheetsCompleted>2</JobMediaSheetsCompleted>"
       
  1332 					"<NumberOfInterveningJobs>0</NumberOfInterveningJobs>"
       
  1333 					"<OperationStatus>0x0000</OperationStatus>"
       
  1334 				"</u:GetJobAttributesResponse>"
       
  1335 				"</s:Body>"
       
  1336 				"</s:Envelope>");	
       
  1337 	
       
  1338 	TPtrC8 response = KTestSoap();
       
  1339 	return response;
       
  1340 }
       
  1341 TPtrC8 CBtSoapCodec::GetEventsResponseTestSoap()
       
  1342 {
       
  1343     _LIT8(KTestSoap, "CONTENT-LENGTH:200\nCONTENT-TYPE:text/xml; charset=\"utf-8\""
       
  1344    				"<s:Envelope\nxmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
       
  1345    				"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       
  1346    				"<s:Body>"
       
  1347 				"<u:GetEventResponse xmlns:u=\"urn:schemas-bluetooth-org:service:Printer:1\">"
       
  1348 					"<JobId>12345</JobId>"
       
  1349 					"<JobState>stopped</JobState>"
       
  1350 					"<PrinterState>stopped</PrinterState>"
       
  1351 					"<PrinterStateReasons>media-empty</PrinterStateReasons>"
       
  1352 					"<OperationStatus>0x0000</OperationStatus>"
       
  1353 				"</u:GetEventResponse>"
       
  1354 				"</s:Body>"
       
  1355 				"</s:Envelope>");
       
  1356    				
       
  1357 	TPtrC8 response = KTestSoap();
       
  1358 	return response;
       
  1359 }
       
  1360 TPtrC8 CBtSoapCodec::GetMarginsResponseTestSoap()
       
  1361 {
       
  1362     _LIT8(KTestSoap, "CONTENT-LENGTH:200\nCONTENT-TYPE:text/xml; charset=\"utf-8\""
       
  1363    				"<s:Envelope\nxmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
       
  1364    				"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
       
  1365    				"<s:Body>"
       
  1366 				"<u:GetMarginsResponse xmlns:u=\"urn:schemas-bluetooth-org:service:Printer:1\">"
       
  1367 				"	<Margins>.25in,.25in,0in,.25in</Margins>"
       
  1368 				"	<OperationStatus>0x0000</OperationStatus>"
       
  1369 				"</u:GetMarginsResponse>"
       
  1370 				"</s:Body>"
       
  1371 				"</s:Envelope>");
       
  1372    				
       
  1373 	TPtrC8 response = KTestSoap();
       
  1374 	return response;
       
  1375 }
       
  1376 
       
  1377 // End of file