bluetoothapitest/bluetoothsvs/T_BTSdpAPI/src/T_DataSdpAttrValueInt.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "T_DataSdpAttrValueInt.h"
       
    19 #include "T_BTUtil.h"
       
    20 
       
    21 /*@{*/
       
    22 
       
    23 //Parameters
       
    24 _LIT(KInputInt,				"inputInt");
       
    25 _LIT(KSdpIntBufObj,			"sdpintbufobj");
       
    26 
       
    27 //Commands
       
    28 _LIT(KCmdNewIntL,		"NewIntL");
       
    29 _LIT(KCmdDestructor,	"~");
       
    30 /*@}*/
       
    31 
       
    32 // const TInt KInterval = 10000;
       
    33 //////////////////////////////////////////////////////////////////////
       
    34 // Construction/Destruction
       
    35 //////////////////////////////////////////////////////////////////////
       
    36 
       
    37 CT_DataSdpAttrValueInt* CT_DataSdpAttrValueInt::NewL()
       
    38 	{
       
    39 	CT_DataSdpAttrValueInt*	ret=new (ELeave) CT_DataSdpAttrValueInt();
       
    40 	CleanupStack::PushL(ret);
       
    41 	ret->ConstructL();
       
    42 	CleanupStack::Pop(ret);
       
    43 	return ret;
       
    44 	}
       
    45 
       
    46 CT_DataSdpAttrValueInt::CT_DataSdpAttrValueInt()
       
    47 :   iAttrValInt(NULL)
       
    48 	{
       
    49 	}
       
    50 
       
    51 void CT_DataSdpAttrValueInt::ConstructL()
       
    52 	{
       
    53 	}
       
    54 
       
    55 CSdpAttrValue* CT_DataSdpAttrValueInt::GetSdpAttrValue() const
       
    56 	{
       
    57 	return iAttrValInt;
       
    58 	}
       
    59 
       
    60 CT_DataSdpAttrValueInt::~CT_DataSdpAttrValueInt()
       
    61 	{
       
    62 	DestroyData();
       
    63 	}
       
    64 
       
    65 void CT_DataSdpAttrValueInt::SetObjectL(TAny* aAny)
       
    66 	{
       
    67 	DestroyData();
       
    68 	iAttrValInt = static_cast<CSdpAttrValueInt*> (aAny);
       
    69 	}
       
    70 
       
    71 void CT_DataSdpAttrValueInt::DisownObjectL()
       
    72 	{
       
    73 	iAttrValInt = NULL;
       
    74 	}
       
    75 
       
    76 void CT_DataSdpAttrValueInt::DestroyData()
       
    77 	{
       
    78 	delete iAttrValInt;
       
    79 	iAttrValInt=NULL;	
       
    80 	}
       
    81 
       
    82 inline TCleanupOperation CT_DataSdpAttrValueInt::CleanupOperation()
       
    83 	{
       
    84 	return CleanupOperation;
       
    85 	}
       
    86 
       
    87 void CT_DataSdpAttrValueInt::CleanupOperation(TAny* aAny)
       
    88 	{
       
    89 	CSdpAttrValueInt* arg=static_cast<CSdpAttrValueInt*>(aAny);
       
    90 	delete arg;
       
    91 	}
       
    92 
       
    93 /**
       
    94  * Process a command read from the ini file
       
    95  *
       
    96  * @param aCommand			The command to process
       
    97  * @param aSection			The section in the ini containing data for the command
       
    98  * @param aAsyncErrorIndex	Command index for async calls to return errors to
       
    99  *
       
   100  * @return					ETrue if the command is processed
       
   101  *
       
   102  * @leave					System wide error
       
   103  */
       
   104 TBool CT_DataSdpAttrValueInt::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   105 {
       
   106 	TBool	ret=ETrue;
       
   107 
       
   108 	if ( aCommand==KCmdNewIntL )
       
   109 		{
       
   110 		DoCmdNewIntL(aSection);         
       
   111 		}
       
   112 	else if ( aCommand==KCmdDestructor )
       
   113 		{
       
   114 		DoCmdDestructor();	  
       
   115 		}
       
   116 	else
       
   117 		{
       
   118 		ret=CT_DataSdpAttrValue::DoCommandL(aCommand, aSection, aAsyncErrorIndex);
       
   119 		}
       
   120 
       
   121 	return ret;
       
   122 }
       
   123 
       
   124 
       
   125 void CT_DataSdpAttrValueInt::DoCmdNewIntL(const TDesC& aSection)
       
   126 	{
       
   127 	DestroyData();
       
   128 	TPtrC	inputInt;
       
   129 	TPtrC	sdpIntBufName;
       
   130 	TBool	foundParameter=EFalse;
       
   131 	if ( GetStringFromConfig(aSection, KInputInt(), inputInt) )
       
   132 		{
       
   133 		foundParameter=ETrue;	
       
   134 		HBufC8*	buffer=HBufC8::NewLC(inputInt.Length());
       
   135 		TPtr8	bufferPtr=buffer->Des();
       
   136 		bufferPtr.Copy(inputInt);
       
   137        	TRAPD(err, iAttrValInt = CSdpAttrValueInt::NewIntL(bufferPtr));	
       
   138 	    if ( err!=KErrNone )
       
   139 			{
       
   140 			ERR_PRINTF2(_L("CSdpAttrValueInt::NewIntL failed with error %d"), err);
       
   141 			SetError(err);
       
   142 			}
       
   143 		CleanupStack::PopAndDestroy(buffer);
       
   144 		}
       
   145 		
       
   146 	if ( GetStringFromConfig(aSection, KSdpIntBufObj(), sdpIntBufName) )
       
   147 		{
       
   148 		foundParameter=ETrue;
       
   149 		TAny* object=GetDataObjectL(sdpIntBufName);
       
   150 		TSdpIntBuf<TUint8>*	sdpIntBuf = static_cast<TSdpIntBuf<TUint8>*>(object);
       
   151 		TSdpIntBuf<TUint8>	sdpIntObj = *sdpIntBuf;
       
   152 		const TUint8 *tmp=&sdpIntObj[0];			
       
   153 		TPtrC8 bufferPtr(tmp, sdpIntObj.Length());
       
   154 		TRAPD(err, iAttrValInt = CSdpAttrValueInt::NewIntL(bufferPtr));
       
   155 	    if ( err!=KErrNone )
       
   156 			{
       
   157 			ERR_PRINTF2(_L("CSdpAttrValueInt::NewIntL failed with error %d"), err);
       
   158 			SetError(err);
       
   159 			}		
       
   160 		}
       
   161 		
       
   162 	if (!foundParameter)
       
   163 		{
       
   164 		ERR_PRINTF2(_L("Missing parameter %S"), &KSdpIntBufObj());
       
   165 		SetBlockResult(EFail);
       
   166 		}
       
   167 	}
       
   168 
       
   169 void CT_DataSdpAttrValueInt::DoCmdDestructor()
       
   170 	{
       
   171     DestroyData();
       
   172 	}