mtpfws/mtpfw/datatypes/interface/cmtptypearray.h
changeset 0 d0791faffa3f
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2006-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  @publishedPartner
       
    19  @released
       
    20 */
       
    21 
       
    22 #ifndef CMTPTYPEARRAY_H
       
    23 #define CMTPTYPEARRAY_H
       
    24 
       
    25 #include <e32std.h>
       
    26 #include <e32base.h>
       
    27 #include <mtp/mmtptype.h>
       
    28 
       
    29 /**
       
    30 Defines the MTP array data type. MTP arrays consist of a contiguous sequence
       
    31 of objects of the same fixed length type, and are zero based. MTP does not 
       
    32 define variable length arrays, e.g. of string objects. Arrays are prepended 
       
    33 with a single 32-bit unsigned integer that identifies the number of elements 
       
    34 to follow. An empty array would consist of a single 32-bit integer containing
       
    35 the value 0x00000000. 
       
    36 
       
    37 MTP arrays are stored in a flat buffer to optimize streaming performance 
       
    38 to/from the MTP transport connection. 
       
    39 @publishedPartner
       
    40 @released 
       
    41 */
       
    42 class CMTPTypeArray : public CBase, public MMTPType 
       
    43     {   
       
    44 public:
       
    45 
       
    46     IMPORT_C static CMTPTypeArray* NewL(TInt aElementType, TUint aElementSize);
       
    47     IMPORT_C static CMTPTypeArray* NewLC(TInt aElementType, TUint aElementSize); 
       
    48     IMPORT_C static CMTPTypeArray* NewL(TInt aArrayType, TInt aElementType, TUint aElementSize);
       
    49     IMPORT_C static CMTPTypeArray* NewLC(TInt aArrayType, TInt aElementType, TUint aElementSize); 
       
    50     IMPORT_C static CMTPTypeArray* NewL(TInt aArrayType);
       
    51     IMPORT_C static CMTPTypeArray* NewL(TInt aArrayType, const RArray<TInt>& aElements);
       
    52     IMPORT_C static CMTPTypeArray* NewL(TInt aArrayType, const RArray<TUint>& aElements);
       
    53     IMPORT_C static CMTPTypeArray* NewL(const RArray<TInt64>& aElements);
       
    54     IMPORT_C static CMTPTypeArray* NewL(const RArray<TUint64>& aElements);
       
    55     IMPORT_C static CMTPTypeArray* NewLC(TInt aArrayType);
       
    56     IMPORT_C static CMTPTypeArray* NewLC(TInt aArrayType, const RArray<TInt>& aElements);
       
    57     IMPORT_C static CMTPTypeArray* NewLC(TInt aArrayType, const RArray<TUint>& aElements);
       
    58     IMPORT_C static CMTPTypeArray* NewLC(const RArray<TInt64>& aElements);
       
    59     IMPORT_C static CMTPTypeArray* NewLC(const RArray<TUint64>& aElements);
       
    60     IMPORT_C ~CMTPTypeArray();
       
    61     
       
    62     IMPORT_C TInt ElementType() const;
       
    63     IMPORT_C TUint32 NumElements() const;
       
    64     
       
    65     IMPORT_C void AppendL(const MMTPType& aElement);
       
    66     IMPORT_C void AppendL(const RArray<TInt>& aElements);
       
    67     IMPORT_C void AppendL(const RArray<TUint>& aElements);
       
    68     IMPORT_C void AppendL(const RArray<TInt64>& aElements);
       
    69     IMPORT_C void AppendL(const RArray<TUint64>& aElements);
       
    70     
       
    71     IMPORT_C void AppendIntL(TInt aElement);
       
    72     IMPORT_C void AppendUintL(TUint aElement);
       
    73     IMPORT_C void AppendInt64L(TInt64 aElement);
       
    74     IMPORT_C void AppendUint64L(TUint64 aElement);
       
    75     
       
    76     IMPORT_C void ElementL(TUint aIndex, MMTPType& aElement) const;
       
    77     
       
    78     IMPORT_C TInt ElementInt(TUint aIndex) const;
       
    79     IMPORT_C TUint ElementUint(TUint aIndex) const;
       
    80     IMPORT_C TInt64 ElementInt64(TUint aIndex) const;
       
    81     IMPORT_C TUint64 ElementUint64(TUint aIndex) const;
       
    82     
       
    83     IMPORT_C void Array(RArray<TInt>& aElements) const;
       
    84     IMPORT_C void Array(RArray<TUint>& aElements) const;
       
    85     IMPORT_C void Array(RArray<TInt64>& aElements) const;
       
    86     IMPORT_C void Array(RArray<TUint64>& aElements) const;
       
    87     IMPORT_C void ToDes( TDes8& aRetDes ) const;
       
    88     IMPORT_C void SetByDesL( const TDesC8& aDesc );
       
    89     
       
    90 public: // From MMTPType
       
    91 
       
    92     IMPORT_C TInt FirstReadChunk(TPtrC8& aChunk) const;
       
    93     IMPORT_C TInt NextReadChunk(TPtrC8& aChunk) const;
       
    94     IMPORT_C TInt FirstWriteChunk(TPtr8& aChunk);
       
    95     IMPORT_C TInt NextWriteChunk(TPtr8& aChunk);
       
    96     IMPORT_C TUint64 Size() const;
       
    97     IMPORT_C virtual TUint Type() const;
       
    98     IMPORT_C TBool CommitRequired() const;
       
    99     IMPORT_C MMTPType* CommitChunkL(TPtr8& aChunk);
       
   100     IMPORT_C TInt Validate() const;
       
   101     
       
   102 private:
       
   103 
       
   104     CMTPTypeArray(TInt aArrayType, TInt aElementType, TUint aElementSize);
       
   105     void ConstructL(TUint32 aNumElements);
       
   106     void ConstructL(const RPointerArray<MMTPType>& aElements);
       
   107     
       
   108     void AppendL(const TAny* aElement);
       
   109     void Element(TUint aIndex, TAny* aElement) const;
       
   110     void ReAllocBufferL(TUint32 aNumElements);
       
   111     void SetNumElements(TUint32 aNumElements);
       
   112     TUint64 BufferSize(TUint32 aNumElements) const;
       
   113     TUint Offset(TUint aIndex) const;  
       
   114     void SetInvalidL();
       
   115      
       
   116     static void SimpleArrayTypeMetaDataL(TInt aArrayType, TInt& aElementType, TUint& aElementSize); 
       
   117     
       
   118 private:
       
   119 
       
   120     /**
       
   121     The write data stream states.
       
   122     */
       
   123     enum TWriteSequenceState
       
   124         {
       
   125         /**
       
   126         Write data stream is inactive.
       
   127         */
       
   128         EIdle,
       
   129         
       
   130         /**
       
   131         Streaming the NumElements data chunk.
       
   132         */
       
   133         ENumElements,
       
   134         
       
   135         /**
       
   136         Streaming the array Element chunks.
       
   137         */
       
   138         EElements            
       
   139         };
       
   140         
       
   141 	/**
       
   142 	The array type's MTP datatype code.
       
   143 	*/
       
   144     TInt    iArrayType;
       
   145     
       
   146     /**
       
   147     The data buffer.
       
   148     */
       
   149     RBuf8   iBuffer;
       
   150         
       
   151 	/**
       
   152 	The array element type's size in bytes.
       
   153 	*/
       
   154     TUint64 iElementSize;
       
   155         
       
   156 	/**
       
   157 	The array element type's MTP datatype code.
       
   158 	*/
       
   159     TInt    iElementType;
       
   160     
       
   161     /**
       
   162     The write data stream state variable.
       
   163     */
       
   164     TUint   iWriteSequenceState;
       
   165     
       
   166     /**
       
   167     The array type's validation state.
       
   168     */
       
   169     TInt    iValidationState;
       
   170     };
       
   171 
       
   172 #endif // CMTPTYPEARRAY_H