mtptransports/mtpptpiptransport/ptpipdatatypes/src/cptpipdatacontainer.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 "ptpipdatatypes.h"
       
    21 #include "cptpipdatacontainer.h"
       
    22 
       
    23 // Dataset constants
       
    24 const TUint CPTPIPDataContainer::KFlatChunkSize(12);
       
    25 
       
    26 // Dataset element metadata.
       
    27 const CMTPTypeCompoundBase::TElementInfo CPTPIPDataContainer::iElementMetaData[CPTPIPDataContainer::ENumElements] = 
       
    28     {
       
    29 		{EIdFlatChunk,      EMTPTypeFlat,       {EMTPTypeUINT32,    0,                  KMTPTypeUINT32Size}},   // EContainerLength
       
    30         {EIdFlatChunk,      EMTPTypeFlat,       {EMTPTypeUINT32,    4,                  KMTPTypeUINT32Size}},   // EContainerType
       
    31         {EIdFlatChunk,      EMTPTypeFlat,       {EMTPTypeUINT32,    8,                  KMTPTypeUINT32Size}},   // ETransactionId
       
    32 		{EIdPayloadChunk,   EMTPTypeUndefined,  {EMTPTypeUndefined, KMTPNotApplicable,  KMTPNotApplicable}}     // EPayload
       
    33     };
       
    34 
       
    35 /**
       
    36  Generic Container's factory method. 
       
    37  This is used to create an empty MTP PTPIP data container dataset type. 
       
    38  @return  Ownership IS transfered.
       
    39  @leave One of the system wide error codes, if unsuccessful.
       
    40  */
       
    41 EXPORT_C CPTPIPDataContainer* CPTPIPDataContainer::NewL()
       
    42 	{
       
    43 	CPTPIPDataContainer* self = new (ELeave) CPTPIPDataContainer();
       
    44 	CleanupStack::PushL(self);
       
    45 	self->ConstructL();
       
    46 	CleanupStack::Pop(self);
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 /**
       
    51  Destructor.
       
    52  */
       
    53 EXPORT_C CPTPIPDataContainer::~CPTPIPDataContainer()
       
    54 	{
       
    55 	iChunkHeader.Close();
       
    56 	}
       
    57 
       
    58 /**
       
    59  Constructor.
       
    60  */
       
    61 CPTPIPDataContainer::CPTPIPDataContainer( ) :
       
    62 	CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), iChunkHeader(
       
    63 			KFlatChunkSize, *this),
       
    64 			iElementInfo(iElementMetaData, ENumElements),iIsNextHeader(EFalse)
       
    65 	{
       
    66 	
       
    67 	}
       
    68 
       
    69 /**
       
    70  Second phase constructor.
       
    71  */
       
    72 void CPTPIPDataContainer::ConstructL( )
       
    73 	{
       
    74 	iChunkHeader.OpenL ( );
       
    75 	ChunkAppendL (iChunkHeader );
       
    76 	}
       
    77 
       
    78 /**
       
    79  Provides the bulk container payload.
       
    80  @return The bulk container payload.
       
    81  */
       
    82 EXPORT_C MMTPType* CPTPIPDataContainer::Payload() const
       
    83 	{
       
    84 	return iPayload;
       
    85 	}
       
    86 
       
    87 /**
       
    88  Sets the bulk container payload.
       
    89  @param aPayload The new bulk container payload.
       
    90  */
       
    91 EXPORT_C void CPTPIPDataContainer::SetPayloadL(MMTPType* aPayload)
       
    92 	{
       
    93 	if (iPayload)
       
    94 		{
       
    95 		// Remove the existing payload from the super class.
       
    96 		ChunkRemove(iElementMetaData[EPayload].iChunkId);
       
    97 		}
       
    98 
       
    99 	if (aPayload)
       
   100 		{
       
   101 		// Pass the payload to the super class for management.
       
   102 		ChunkAppendL(*aPayload);
       
   103 		}
       
   104 	iPayload = aPayload;
       
   105 	iIsNextHeader = EFalse; 
       
   106 	}
       
   107 
       
   108 EXPORT_C TUint CPTPIPDataContainer::Type() const
       
   109 	{
       
   110 	return EPTPIPTypeDataContainer;
       
   111 	}
       
   112 
       
   113 const CMTPTypeCompoundBase::TElementInfo& CPTPIPDataContainer::ElementInfo(
       
   114 		TInt aElementId ) const
       
   115 	{
       
   116 	__ASSERT_DEBUG((aElementId < ENumElements), User::Invariant());
       
   117 	return iElementInfo[aElementId];
       
   118 	}
       
   119 	
       
   120 /**
       
   121   Over-ridden implementation of FirstWriteChunk() derived from CMTPTypeCompoundBase.
       
   122   This sets the Write Sequence-State to EInProgressNext, forcing the headers, from the second 
       
   123   PTP/IP packet onwards,to be ignored
       
   124   @param aChunk The data that is currently given by Initiator
       
   125  **/
       
   126 EXPORT_C TInt CPTPIPDataContainer::FirstWriteChunk(TPtr8& aChunk)
       
   127 	        {
       
   128 	        TInt err(KErrNone);	        
       
   129 	        
       
   130 	        aChunk.Set(NULL, 0, 0);
       
   131 	        
       
   132 	        
       
   133 	        if (iChunks.Count() == 0)
       
   134 	            {
       
   135 	            err = KErrNotFound;            
       
   136 	            }
       
   137 	        else
       
   138 	            {
       
   139 	            iWriteChunk = 0;
       
   140 	            
       
   141 	            TInt iWriteErr = iChunks[iWriteChunk]->FirstWriteChunk(aChunk);
       
   142 	            
       
   143 	            if ((iIsNextHeader) && (iWriteErr == KMTPChunkSequenceCompletion))
       
   144 	            	iWriteErr = KErrNone;
       
   145 	            
       
   146 		        switch (iWriteErr)
       
   147 		            {
       
   148 		        case KMTPChunkSequenceCompletion:
       
   149 		            if ((iWriteChunk + 1) < iChunks.Count()) 
       
   150 		                {
       
   151 		                iWriteSequenceState = EInProgressFirst;
       
   152 		                err = KErrNone;
       
   153 		                }
       
   154 		            else
       
   155 		                {
       
   156 		                iWriteSequenceState = EIdle;                 
       
   157 		                }
       
   158 		            break;
       
   159 		            
       
   160 		        case KErrNone:
       
   161 		            iWriteSequenceState = EInProgressNext;
       
   162 		            break;
       
   163 		            
       
   164 		        default:
       
   165 		            break;                      
       
   166 	           } 
       
   167 	            } 
       
   168 	        
       
   169 	        iIsNextHeader = ETrue;
       
   170 	        
       
   171 	        return err;
       
   172 	        }
       
   173 
       
   174 /**
       
   175   Over-ridden implementation of CommitChunkL() derived from CMTPTypeCompoundBase.
       
   176   This increments the number of chunks read only after, the first header is read
       
   177   @param aChunk The data that is currently given by Initiator
       
   178  **/
       
   179 EXPORT_C MMTPType* CPTPIPDataContainer::CommitChunkL(TPtr8& aChunk)
       
   180 	    {       
       
   181 	    MMTPType *chunk(iChunks[iWriteChunk]);
       
   182 	    MMTPType* res = NULL;
       
   183 	    if (chunk->CommitRequired())
       
   184 	        {
       
   185 	        res = chunk->CommitChunkL(aChunk);
       
   186 	        }
       
   187 	        
       
   188 	    
       
   189 	    if (iWriteChunk == 0)
       
   190 	        {
       
   191 	        iWriteChunk++;            
       
   192 	        }
       
   193 
       
   194 	    return res;
       
   195 	    }
       
   196