messagingappbase/obexmtms/TObexMTM/SRC/AddHeadersState.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // $Workfile: AddHeadersState.cpp $
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "AddHeadersState.h"
       
    19 
       
    20 #include "obexharness.h"
       
    21 #include "obextestutils.h"
       
    22 
       
    23 #include <obexheaderlist.h>
       
    24 
       
    25 
       
    26 CAddHeadersState::CAddHeadersState(const CObexHeader::THeaderType aHeaderType, const TUint8 aHeaderHI, const TDesC& aHeaderHV, CObexClientTest& aClientTest) :
       
    27 iClientTest(aClientTest),
       
    28 iHeaderType(aHeaderType),
       
    29 iHeaderHI(aHeaderHI)
       
    30 	{
       
    31 	// Setup the header data buffer.
       
    32 	iHeaderHV = HBufC::NewL(aHeaderHV.Length());
       
    33 	iHeaderHV->Des().Copy(aHeaderHV);
       
    34 	}
       
    35 //
       
    36 
       
    37 CAddHeadersState::~CAddHeadersState()
       
    38 	{
       
    39 	delete iHeaderHV;
       
    40 	}
       
    41 //
       
    42 
       
    43 void CAddHeadersState::StartL(TRequestStatus& aStatus)
       
    44 	{
       
    45 
       
    46 	// Create a new obex header.
       
    47 	CObexHeader* header = CObexHeader::NewL();
       
    48 	CleanupStack::PushL(header);
       
    49 
       
    50 	// Process the header data type depending on type.
       
    51 	switch (iHeaderType)
       
    52 		{
       
    53 		case CObexHeader::EUnicode:
       
    54 			{
       
    55 			header->SetUnicodeL(iHeaderHI, iHeaderHV->Des());
       
    56 
       
    57 			break;
       
    58 			}
       
    59 
       
    60 		case CObexHeader::EByteSeq:
       
    61 			{
       
    62 			// Convert the 16 bit string to 8 bit string.
       
    63 
       
    64 			// Src
       
    65 			TPtrC ptrHeaderHV(iHeaderHV->Des());
       
    66 
       
    67 			// Dst
       
    68 			HBufC8* byteSeqHV = HBufC8::NewMaxLC(iHeaderHV->Length());
       
    69 			TPtr8 ptrByteSeqHV(byteSeqHV->Des()); 
       
    70 
       
    71 			TInt	i = 0;
       
    72 			while (i < iHeaderHV->Length())
       
    73 				{
       
    74 				ptrByteSeqHV[i] = (TUint8)ptrHeaderHV[i];
       
    75 				i++;
       
    76 				}
       
    77 			header->SetByteSeqL(iHeaderHI, byteSeqHV->Des());
       
    78 
       
    79 			CleanupStack::PopAndDestroy(byteSeqHV);
       
    80 			break;
       
    81 			}
       
    82 
       
    83 		case CObexHeader::EByte:
       
    84 			{
       
    85 			TUint8 byteHV = 0;
       
    86 			TLex lex(iHeaderHV->Des());
       
    87 
       
    88 			lex.Inc(2); // Jump '0x'.
       
    89 			User::LeaveIfError(lex.Val(byteHV, EHex));
       
    90 			header->SetByte(iHeaderHI, byteHV);
       
    91 			break;
       
    92 			}
       
    93 
       
    94 		case CObexHeader::EFourByte:
       
    95 			{
       
    96 			TUint32 fourByteHV = 0;
       
    97 			TLex lex(iHeaderHV->Des());
       
    98 
       
    99 			lex.Inc(2); // Jump '0x'.
       
   100 			User::LeaveIfError(lex.Val(fourByteHV, EHex));
       
   101 			header->SetFourByte(iHeaderHI, fourByteHV);
       
   102 			break;
       
   103 			}
       
   104 
       
   105 		default:
       
   106 			User::Leave(KErrUnknown);
       
   107 		}
       
   108 
       
   109 	// Add header to the current headers list.
       
   110 	CObexHeaderList* currentHeaders = iClientTest.CurrentHeaders();
       
   111 	User::LeaveIfError(currentHeaders->AddHeader(header));
       
   112 
       
   113 	// Make a dupilcate header and add to the verify headers list.
       
   114 	CObexHeader* dupHeader = CObexHeader::NewL();
       
   115 	CleanupStack::PushL(dupHeader);
       
   116 	
       
   117 	dupHeader->Set(header);
       
   118 
       
   119 	CObexTestHeaderList* verifyHeaders = iClientTest.VerifyHeaders();
       
   120 	User::LeaveIfError(verifyHeaders->AddHeader(dupHeader));
       
   121 
       
   122 	CleanupStack::Pop(dupHeader);
       
   123 	CleanupStack::Pop(header);
       
   124 
       
   125 	// Complete the state.
       
   126 	TRequestStatus* status = &aStatus;
       
   127 	User::RequestComplete(status, KErrNone);
       
   128 	}