mtptransports/mtpptpiptransport/ptpipdatatypes/src/tptpipresponsepayload.cpp
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2008-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 //
       
    15 
       
    16 /**
       
    17  @internalComponent
       
    18 */
       
    19 
       
    20 #include <mtp/mtpprotocolconstants.h>
       
    21 #include "ptpipdatatypes.h"
       
    22 #include "tptpipresponsepayload.h"
       
    23 
       
    24 
       
    25 // Dataset element metadata.
       
    26 const TPTPIPTypeResponsePayload::TElementInfo TPTPIPTypeResponsePayload::iElementMetaData[ENumElements] = 
       
    27     {
       
    28         {EMTPTypeUINT16, 0,  KMTPTypeUINT16Size},   // EResponseCode
       
    29         {EMTPTypeUINT32, 2,  KMTPTypeUINT32Size},   // ETransactionId
       
    30         {EMTPTypeUINT32, 6,  KMTPTypeUINT32Size},   // EParameter1
       
    31         {EMTPTypeUINT32, 10,  KMTPTypeUINT32Size},  // EParameter2
       
    32         {EMTPTypeUINT32, 14,  KMTPTypeUINT32Size},  // EParameter3
       
    33         {EMTPTypeUINT32, 18,  KMTPTypeUINT32Size},  // EParameter4
       
    34         {EMTPTypeUINT32, 22,  KMTPTypeUINT32Size}   // EParameter5
       
    35     };
       
    36 
       
    37 /**
       
    38  Constructor.
       
    39  */
       
    40 EXPORT_C TPTPIPTypeResponsePayload::TPTPIPTypeResponsePayload() :
       
    41 	iElementInfo(iElementMetaData, ENumElements),
       
    42 	iBuffer(KSize),
       
    43 	//iNumParameters(0)
       
    44 	iMaxSetParam(0)
       
    45 	{
       
    46 	SetBuffer(iBuffer);
       
    47 	}
       
    48 
       
    49 /**
       
    50  Provides the number of parameters in the block which are set.
       
    51  @return the number of set parameters.
       
    52  */
       
    53 EXPORT_C TUint TPTPIPTypeResponsePayload::NumParameters() const
       
    54 	{
       
    55 	return (iMaxSetParam > 0 )? (iMaxSetParam - EParameter1 + 1) : 0;
       
    56 	//return iMaxSetParam - EParameter1 + 1;
       
    57 	}
       
    58 
       
    59 /**
       
    60  Copies up to five parameter values into the parameter block dataset from the specified dataset. 
       
    61  The paramters to be copied should be non null paramter or valid null paramter.
       
    62 
       
    63  @param aFrom The parameter values source dataset. This dataset should define three or five contiguous 32-bit parameter values starting at the specified offset.
       
    64  @param aParamStartOffset The element ID of the first in the set of contiguous 
       
    65  source dataset parameter values.
       
    66  @param aParamEndOffset The element ID of the last in the set of contiguous 
       
    67  source dataset parameter values.
       
    68  @param aIsNullParamValid a boolean value to check if a null parameter is valid. A value of ETrue means a null parameter is valid; EFalse means invalid.
       
    69  @param aNumOfNullParam the number of valid null parameters to be copied.
       
    70  */
       
    71 EXPORT_C void TPTPIPTypeResponsePayload::CopyIn ( 	const TMTPTypeFlatBase& aFrom,
       
    72 													TUint aParamStartOffset, TUint aParamEndOffset,
       
    73 													TBool aIsNullParamValid, TUint aNumOfNullParam)
       
    74 
       
    75 	{
       
    76 	__ASSERT_DEBUG((aParamEndOffset >= aParamStartOffset && (aParamEndOffset - aParamStartOffset + 1) <= ENumElements), User::Invariant());
       
    77 	TUint32 parameter = KMTPNotSpecified32;
       
    78 	TUint numberOfNullParam = 0;
       
    79 
       
    80 	for (TUint t(EParameter1), s(aParamStartOffset); s <= aParamEndOffset; t++, s++)	
       
    81 		{
       
    82 		parameter = aFrom.Uint32(s);
       
    83 		if (parameter != KMTPNotSpecified32)
       
    84 		    {
       
    85 		    SetUint32(t, parameter);
       
    86 		    }
       
    87 		else if(aIsNullParamValid && (numberOfNullParam < aNumOfNullParam))
       
    88 		    {
       
    89 		    SetUint32(t, parameter);
       
    90 		    numberOfNullParam++;
       
    91 		    }
       
    92 		}
       
    93 	}
       
    94 
       
    95 /**
       
    96  Copies the non-null parameter values from the parameter block dataset into the specified dataset. 
       
    97  Note: the number of parameters to be copied out depends on two conditions:
       
    98  1. The number of parameters contained in this parameter block dataset.
       
    99  2. The number of parameters to be copied out to the parameter values sink dataset, 
       
   100  which is (aParamEndOffset - aParamStartOffset + 1) by the caller.
       
   101 
       
   102  @param aTo The parameter values sink dataset. This dataset should define three or five contiguous 32-bit parameter values starting at the specified offset.
       
   103  @param aParamStartOffset the element ID of the first in the set of contiguous sink dataset parameter values.
       
   104  @param aParamEndOffset the element ID of the last in the set of contiguous sink dataset parameter values.
       
   105  */
       
   106 EXPORT_C void TPTPIPTypeResponsePayload::CopyOut( 	TMTPTypeFlatBase& aTo,
       
   107 													TUint aParamStartOffset, TUint aParamEndOffset)
       
   108 	{
       
   109 	__ASSERT_DEBUG((aParamEndOffset >= aParamStartOffset && (aParamEndOffset - aParamStartOffset + 1) <= ENumElements), User::Invariant());
       
   110 //	TUint loopCount = aParamEndOffset - aParamStartOffset;
       
   111 	for (TUint s(EParameter1), t(aParamStartOffset); (s <= iMaxSetParam && t <= aParamEndOffset); s++, t++)
       
   112 		{
       
   113 		aTo.SetUint32((t), Uint32(s));
       
   114 		}
       
   115 	}
       
   116 
       
   117 /**
       
   118  Resets the dataset.
       
   119  */
       
   120 EXPORT_C void TPTPIPTypeResponsePayload::Reset()
       
   121 	{
       
   122 	TMTPTypeFlatBase::Reset();
       
   123 	//iNumParameters = 0;
       
   124 	iMaxSetParam = 0;
       
   125 	}
       
   126 
       
   127 /**
       
   128  Setter for the response op code.
       
   129  */
       
   130 EXPORT_C void TPTPIPTypeResponsePayload::SetUint16(TInt aElementId, TUint16 aData)
       
   131 	{
       
   132 	__ASSERT_DEBUG((aElementId == EResponseCode), User::Invariant());
       
   133 	TMTPTypeFlatBase::SetUint16(aElementId, aData);
       
   134 	}
       
   135 
       
   136 /**
       
   137  Getter for the response op code. 
       
   138  */
       
   139 EXPORT_C TUint16 TPTPIPTypeResponsePayload::Uint16(TInt aElementId) const
       
   140 	{
       
   141 	__ASSERT_DEBUG((aElementId == EResponseCode), User::Invariant());
       
   142 	return TMTPTypeFlatBase::Uint16(aElementId);
       
   143 	}
       
   144 
       
   145 /**
       
   146  Setter for the parameters and tran id
       
   147  */
       
   148 EXPORT_C void TPTPIPTypeResponsePayload::SetUint32(TInt aElementId, TUint32 aData)
       
   149 	{
       
   150 	__ASSERT_DEBUG((aElementId != EResponseCode), User::Invariant());
       
   151 	if (aElementId >= EParameter1)
       
   152 		{
       
   153 		if (aElementId > iMaxSetParam)
       
   154 			iMaxSetParam = aElementId;		
       
   155 		
       
   156 		/**
       
   157 		// Recalculate iNumParameters.
       
   158 		TInt num((aElementId - EParameter1) + 1);
       
   159 
       
   160 		if (num > iNumParameters)
       
   161 			{
       
   162 			iNumParameters = num;
       
   163 			}
       
   164 			*/
       
   165 		}
       
   166 
       
   167 	//  Set the element value.
       
   168 	TMTPTypeFlatBase::SetUint32(aElementId, aData);
       
   169 	}
       
   170 
       
   171 /**
       
   172  Getter for the parameters and tran id. 
       
   173  */
       
   174 EXPORT_C TUint32 TPTPIPTypeResponsePayload::Uint32(TInt aElementId) const
       
   175 	{
       
   176 //	__ASSERT_DEBUG((aElementId < iMaxSetParam ), User::Invariant());
       
   177 //	__ASSERT_DEBUG((aElementId != EResponseCode), User::Invariant());
       
   178 	return TMTPTypeFlatBase::Uint32(aElementId);
       
   179 	}
       
   180 
       
   181 
       
   182 EXPORT_C TInt TPTPIPTypeResponsePayload::FirstReadChunk(TPtrC8& aChunk) const
       
   183 	{
       
   184 	TInt ret(TMTPTypeFlatBase::FirstReadChunk(aChunk));
       
   185 	TUint64 size(Size());
       
   186 
       
   187 	if (size < aChunk.Size())
       
   188 		{
       
   189 		// Truncate the buffer at the last set parameter.
       
   190 		aChunk.Set(aChunk.Left(size));
       
   191 		}
       
   192 
       
   193 	return ret;
       
   194 	}
       
   195 
       
   196 EXPORT_C TUint64 TPTPIPTypeResponsePayload::Size() const
       
   197 	{
       
   198 	return (NumParameters() * KMTPTypeUINT32Size + KHeaderElementsSize);
       
   199 	}
       
   200 
       
   201 EXPORT_C TUint TPTPIPTypeResponsePayload::Type() const
       
   202 	{
       
   203 	return EPTPIPTypeResponsePayload;
       
   204 	}
       
   205 
       
   206 EXPORT_C TBool TPTPIPTypeResponsePayload::CommitRequired() const
       
   207 	{
       
   208 	return ETrue;
       
   209 	}
       
   210 
       
   211 /**
       
   212  todo: optimise, start from 5, break on set. 
       
   213  */
       
   214 EXPORT_C MMTPType* TPTPIPTypeResponsePayload::CommitChunkL(TPtr8& /*aChunk*/)
       
   215 	{
       
   216 	//iNumParameters = 0;
       
   217 
       
   218 	// Recalculate iNumParameters.
       
   219 	for (TUint i(EParameter1); (i <= EParameter5); i++)
       
   220 		{
       
   221 		if (TMTPTypeFlatBase::Uint32(i) != KMTPNotSpecified32)
       
   222 			{
       
   223 			//iNumParameters = (i + 1);
       
   224 				iMaxSetParam = i;
       
   225 			}
       
   226 		}
       
   227 	return NULL;
       
   228 	}
       
   229 
       
   230 EXPORT_C const TMTPTypeFlatBase::TElementInfo& TPTPIPTypeResponsePayload::ElementInfo(TInt aElementId) const
       
   231 	{
       
   232 	return iElementInfo[aElementId];
       
   233 	}
       
   234