mtpfws/mtpfw/datatypes/src/cmtptypecomplexbuffer.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  @file
       
    18  @InternalTechnology
       
    19 */
       
    20 
       
    21 #include "cmtptypecomplexbuffer.h"
       
    22 #include <mtp/mtpdatatypeconstants.h>
       
    23 
       
    24 // File type constants.
       
    25 const TInt KMTPBufferChunkSize(0x00019000); // 100KB
       
    26 
       
    27 /**
       
    28 MTP string data type factory method. This method is used to create a 
       
    29 zero-length MTP string.
       
    30 @return A pointer to a zero-length MTP string data type. Ownership IS 
       
    31 transfered.
       
    32 @leave One of the system wide error codes, if unsuccessful.
       
    33 */   
       
    34 EXPORT_C CMTPTypeComplexBuffer* CMTPTypeComplexBuffer::NewL()
       
    35     {
       
    36 	CMTPTypeComplexBuffer* self = NewLC(); 
       
    37 	CleanupStack::Pop(self);
       
    38 	return self; 
       
    39     }
       
    40 
       
    41 /**
       
    42 MTP string data type factory method. This method is used to create an 
       
    43 MTP string with the specified value.
       
    44 @param aString The initial string value.
       
    45 @return A pointer to the MTP string data type. Ownership IS transfered.
       
    46 @leave One of the system wide error codes, if unsuccessful.
       
    47 */     
       
    48 EXPORT_C CMTPTypeComplexBuffer* CMTPTypeComplexBuffer::NewL(const TDesC8& aData)
       
    49     {
       
    50 	CMTPTypeComplexBuffer* self = NewLC(aData);
       
    51 	CleanupStack::Pop(self);
       
    52 	return self;
       
    53     }
       
    54 
       
    55 /**
       
    56 MTP file object data type factory method. 
       
    57 @param aFs The handle of an active file server session.
       
    58 @param aName The name of the file. Any path components (i.e. drive letter
       
    59 or directory), which are not specified, are taken from the session path. 
       
    60 @param aMode The mode in which the file is opened (@see TFileMode).
       
    61 @return A pointer to the MTP file object data type. Ownership IS transfered.
       
    62 @leave One of the system wide error codes, if a processing failure occurs.
       
    63 @see TFileMode
       
    64 */   
       
    65 EXPORT_C CMTPTypeComplexBuffer* CMTPTypeComplexBuffer::NewLC()
       
    66     {
       
    67     CMTPTypeComplexBuffer* self = NewLC(KNullDesC8);
       
    68     return self;
       
    69     }
       
    70 
       
    71 /**
       
    72 MTP file object data type factory method. A pointer to the MTP file object data
       
    73 type is placed on the cleanup stack.
       
    74 @param aFs The handle of an active file server session.
       
    75 @param aName The name of the file. Any path components (i.e. drive letter
       
    76 or directory), which are not specified, are taken from the session path. 
       
    77 @param aMode The mode in which the file is opened (@see TFileMode).
       
    78 @return A pointer to the MTP file object data type. Ownership IS transfered.
       
    79 @leave One of the system wide error codes, if a processing failure occurs.
       
    80 @see TFileMode
       
    81 */   
       
    82 EXPORT_C CMTPTypeComplexBuffer* CMTPTypeComplexBuffer::NewLC(const TDesC8& aData)
       
    83     {
       
    84     CMTPTypeComplexBuffer* self = new(ELeave) CMTPTypeComplexBuffer;
       
    85     CleanupStack::PushL(self);
       
    86     self->ConstructL(aData);
       
    87     return self;
       
    88     }
       
    89 
       
    90 /**
       
    91 Destructor
       
    92 */
       
    93 EXPORT_C CMTPTypeComplexBuffer::~CMTPTypeComplexBuffer()
       
    94     {
       
    95     iBuffer.Close();
       
    96     }
       
    97 
       
    98 /**
       
    99 Provides a reference to the native file object encapsulate by the MTP file 
       
   100 object data type.
       
   101 @return The native file object reference.
       
   102 */
       
   103 EXPORT_C const TDesC8& CMTPTypeComplexBuffer::Buffer()
       
   104     {
       
   105     return iBuffer;
       
   106     }    
       
   107     
       
   108 EXPORT_C void CMTPTypeComplexBuffer::SetBuffer(const TDesC8& aData )
       
   109 	{
       
   110     iBuffer.Zero();
       
   111     if(aData == KNullDesC8)
       
   112         {
       
   113     	return;
       
   114         }
       
   115 
       
   116 	iBuffer.Copy(aData);   	
       
   117 	}
       
   118 
       
   119 EXPORT_C TInt CMTPTypeComplexBuffer::FirstReadChunk(TPtrC8& aChunk) const
       
   120     {
       
   121 	aChunk.Set(iBuffer.Ptr(), iBuffer.Length());
       
   122     return KMTPChunkSequenceCompletion;
       
   123     }
       
   124 
       
   125 EXPORT_C TInt CMTPTypeComplexBuffer::NextReadChunk(TPtrC8& aChunk) const
       
   126     {
       
   127     aChunk.Set(NULL, 0);
       
   128     return KErrNotReady;
       
   129     }
       
   130 
       
   131 EXPORT_C TInt CMTPTypeComplexBuffer::FirstWriteChunk(TPtr8& aChunk)
       
   132     {
       
   133     TInt err(KErrNone);
       
   134 	aChunk.Set(NULL, 0, 0);
       
   135     iWriteSequenceState = EIdle;
       
   136     aChunk.Set(&iBuffer[0], 0, iBuffer.MaxLength());
       
   137     iWriteSequenceState = EInProgress;
       
   138     return err;
       
   139     }
       
   140     
       
   141 EXPORT_C TInt CMTPTypeComplexBuffer::NextWriteChunk(TPtr8& aChunk)
       
   142     {
       
   143     TInt err(KErrNone);
       
   144 	aChunk.Set(NULL, 0, 0);
       
   145     
       
   146     if (iWriteSequenceState != EInProgress)
       
   147         {
       
   148         err = KErrNotReady;            
       
   149         }
       
   150     else
       
   151         {
       
   152     	aChunk.Set(&iBuffer[0], 0, iBuffer.MaxLength());
       
   153         }
       
   154        
       
   155     return err;
       
   156     }
       
   157 
       
   158 EXPORT_C TUint64 CMTPTypeComplexBuffer::Size() const
       
   159     {
       
   160     return iBuffer.Size();
       
   161     }
       
   162 
       
   163 EXPORT_C TUint CMTPTypeComplexBuffer::Type() const
       
   164     {
       
   165     return EMTPTypeString;
       
   166     }
       
   167 
       
   168 EXPORT_C TBool CMTPTypeComplexBuffer::CommitRequired() const
       
   169     {
       
   170     return ETrue;
       
   171     }
       
   172 
       
   173 EXPORT_C MMTPType* CMTPTypeComplexBuffer::CommitChunkL(TPtr8& aChunk)
       
   174     {
       
   175     iBuffer.Zero(); 
       
   176     iBuffer.Copy(aChunk);
       
   177     return NULL;
       
   178     }
       
   179     
       
   180 CMTPTypeComplexBuffer::CMTPTypeComplexBuffer()
       
   181     {
       
   182         
       
   183     }
       
   184 
       
   185 void CMTPTypeComplexBuffer::ConstructL(const TDesC8& aData)
       
   186     {    
       
   187     iBuffer.CreateMaxL(KMTPBufferChunkSize);
       
   188     if(aData != KNullDesC8)
       
   189     	{
       
   190     	iBuffer.Zero();
       
   191     	iBuffer.Copy(aData);
       
   192     	}
       
   193     }
       
   194