mtptransports/mtpptpiptransport/ptpipdatatypes/src/cptpipgenericcontainer.cpp
changeset 0 d0791faffa3f
child 47 63cf70d3ecd8
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 "ptpipdatatypes.h"
       
    21 #include "cptpipgenericcontainer.h"
       
    22 
       
    23 // Dataset constants
       
    24 const TUint CPTPIPGenericContainer::KFlatChunkSize(8);
       
    25 
       
    26 // Dataset element metadata.
       
    27 const CMTPTypeCompoundBase::TElementInfo CPTPIPGenericContainer::iElementMetaData[CPTPIPGenericContainer::ENumElements] = 
       
    28     {
       
    29         {EIdFlatChunk,      EMTPTypeFlat,       {EMTPTypeUINT32,    0,                  KMTPTypeUINT32Size}},   // EContainerLength
       
    30         {EIdFlatChunk,      EMTPTypeFlat,       {EMTPTypeUINT32,    4,                  KMTPTypeUINT32Size}},   // EContainerType
       
    31 		{EIdPayloadChunk,   EMTPTypeUndefined,  {EMTPTypeUndefined, KMTPNotApplicable,  KMTPNotApplicable}}     // EPayload
       
    32     };
       
    33 
       
    34 /**
       
    35  Generic Container's factory method. 
       
    36  This is used to create an empty MTP PTPIP generic container dataset type. 
       
    37  @return  Ownership IS transfered.
       
    38  @leave One of the system wide error codes, if unsuccessful.
       
    39  */
       
    40 EXPORT_C CPTPIPGenericContainer* CPTPIPGenericContainer::NewL()
       
    41 	{
       
    42 	CPTPIPGenericContainer* self = new (ELeave) CPTPIPGenericContainer();
       
    43 	CleanupStack::PushL(self);
       
    44 	self->ConstructL();
       
    45 	CleanupStack::Pop(self);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 /**
       
    50  Destructor.
       
    51  */
       
    52 EXPORT_C CPTPIPGenericContainer::~CPTPIPGenericContainer()
       
    53 	{
       
    54 	iChunkHeader.Close();
       
    55 	}
       
    56 
       
    57 /**
       
    58  Constructor.
       
    59  */
       
    60 CPTPIPGenericContainer::CPTPIPGenericContainer( ) :
       
    61 	CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), iChunkHeader(
       
    62 			KFlatChunkSize, *this),
       
    63 			iElementInfo(iElementMetaData, ENumElements)
       
    64 	{
       
    65 
       
    66 	}
       
    67 
       
    68 /**
       
    69  Second phase constructor.
       
    70  */
       
    71 void CPTPIPGenericContainer::ConstructL( )
       
    72 	{
       
    73 	iChunkHeader.OpenL ( );
       
    74 	ChunkAppendL (iChunkHeader );
       
    75 	}
       
    76 /**
       
    77  Provides the container payload.
       
    78  @return The container payload.
       
    79  */
       
    80 EXPORT_C MMTPType* CPTPIPGenericContainer::Payload() const
       
    81 	{
       
    82 	return iPayload;
       
    83 	}
       
    84 
       
    85 /**
       
    86  Sets the container payload.
       
    87  @param aPayload The new container payload.
       
    88  */
       
    89 EXPORT_C void CPTPIPGenericContainer::SetPayloadL(MMTPType* aPayload)
       
    90 	{
       
    91 	if (iPayload)
       
    92 		{
       
    93 		// Remove the existing payload from the super class.
       
    94 		ChunkRemove(iElementMetaData[EPayload].iChunkId);
       
    95 		}
       
    96 
       
    97 	if (aPayload)
       
    98 		{
       
    99 		// Pass the payload to the super class for management.
       
   100 		ChunkAppendL(*aPayload);
       
   101 		}
       
   102 	iPayload = aPayload;
       
   103 	}
       
   104 
       
   105 EXPORT_C TUint CPTPIPGenericContainer::Type() const
       
   106 	{
       
   107 	return EPTPIPTypeGenericContainer;
       
   108 	}
       
   109 
       
   110 const CMTPTypeCompoundBase::TElementInfo& CPTPIPGenericContainer::ElementInfo(
       
   111 		TInt aElementId ) const
       
   112 	{
       
   113 	__ASSERT_DEBUG((aElementId < ENumElements), User::Invariant());
       
   114 	return iElementInfo[aElementId];
       
   115 	}
       
   116