mtpfws/mtpfw/dataproviders/devdp/src/cmtptypedeviceinfo.cpp
changeset 0 d0791faffa3f
child 18 453dfc402455
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 #include <mtp/mtpdatatypeconstants.h>
       
    17 #include <mtp/mtptypescomplex.h>
       
    18 
       
    19 #include "cmtptypedeviceinfo.h"
       
    20 
       
    21 // Dataset constants
       
    22 const TUint KMTPChunk0Size = 8;
       
    23 
       
    24 // Dataset element metadata.
       
    25 const CMTPTypeCompoundBase::TElementInfo CMTPTypeDeviceInfo::iElementMetaData[CMTPTypeDeviceInfo::ENumElements] = 
       
    26     {
       
    27         {EIdFlatChunk,                      EMTPTypeFlat,   {EMTPTypeUINT16,    0,                  KMTPTypeUINT16Size}},   // EStandardVersion
       
    28         {EIdFlatChunk,                      EMTPTypeFlat,   {EMTPTypeUINT32,    2,                  KMTPTypeUINT32Size}},   // EMTPVendorExtensionID
       
    29         {EIdFlatChunk,                      EMTPTypeFlat,   {EMTPTypeUINT16,    6,                  KMTPTypeUINT16Size}},   // EMTPVersion
       
    30         {EIdMTPExtensionsChunk,             EMTPTypeString, {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // EMTPExtensions
       
    31         {EIdFunctionalModeChunk,            EMTPTypeUINT16, {EMTPTypeUINT16,    KMTPNotApplicable,  KMTPNotApplicable}},    // EFunctionalMode
       
    32         {EIdOperationsSupportedChunk,       EMTPTypeArray,  {EMTPTypeAUINT16,   KMTPNotApplicable,  KMTPNotApplicable}},    // EOperationsSupported
       
    33         {EIdEventsSupportedChunk,           EMTPTypeArray,  {EMTPTypeAUINT16,   KMTPNotApplicable,  KMTPNotApplicable}},    // EventsSupported
       
    34         {EIdDevicePropertiesSupportedChunk, EMTPTypeArray,  {EMTPTypeAUINT16,   KMTPNotApplicable,  KMTPNotApplicable}},    // EDevicePropertiesSupported
       
    35         {EIdCaptureFormatsChunk,            EMTPTypeArray,  {EMTPTypeAUINT16,   KMTPNotApplicable,  KMTPNotApplicable}},    // ECaptureFormats
       
    36         {EIdPlaybackFormatsChunk,           EMTPTypeArray,  {EMTPTypeAUINT16,   KMTPNotApplicable,  KMTPNotApplicable}},    // EPlaybackFormats
       
    37         {EIdManufacturerChunk,              EMTPTypeString, {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // EManufacturer
       
    38         {EIdModelChunk,                     EMTPTypeString, {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // EModel  
       
    39         {EIdDeviceVersionChunk,             EMTPTypeString, {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // EDeviceVersion
       
    40         {EIdSerialNumberChunk,              EMTPTypeString, {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // ESerialNumber
       
    41     };
       
    42 
       
    43 /**
       
    44 MTP DeviceInfo dataset factory method. This method is used to create an empty 
       
    45 MTP DeviceInfo dataset type. A pointer to the MTP array data type is placed on 
       
    46 the cleanup stack.
       
    47 @return A pointer to an empty MTP DeviceInfo dataset type. Ownership IS 
       
    48 transfered.
       
    49 @leave One of the system wide error codes, if unsuccessful.
       
    50 */    
       
    51 CMTPTypeDeviceInfo* CMTPTypeDeviceInfo::NewL()
       
    52     {
       
    53 	CMTPTypeDeviceInfo* self = CMTPTypeDeviceInfo::NewLC(); 
       
    54 	CleanupStack::Pop(self);
       
    55 	return self; 
       
    56     }
       
    57 
       
    58 /**
       
    59 MTP DeviceInfo dataset factory method. This method is used to create an empty 
       
    60 MTP DeviceInfo dataset type.
       
    61 @return A pointer to an empty MTP DeviceInfo dataset type. Ownership IS 
       
    62 transfered.
       
    63 @leave One of the system wide error codes, if unsuccessful.
       
    64 */    
       
    65 CMTPTypeDeviceInfo* CMTPTypeDeviceInfo::NewLC()
       
    66     {
       
    67 	CMTPTypeDeviceInfo* self = new (ELeave) CMTPTypeDeviceInfo(); 
       
    68 	CleanupStack::PushL(self); 
       
    69     self->ConstructL();
       
    70 	return self;    
       
    71     }
       
    72 
       
    73 /**
       
    74 Destructor.
       
    75 */    
       
    76 CMTPTypeDeviceInfo::~CMTPTypeDeviceInfo()
       
    77     {    
       
    78     iChunkFlat.Close();
       
    79     iArrayChunks.ResetAndDestroy();
       
    80     iStringChunks.ResetAndDestroy();
       
    81     }
       
    82  
       
    83 TUint CMTPTypeDeviceInfo::Type() const
       
    84     {
       
    85     return EMTPTypeDeviceInfoDataset;
       
    86     }
       
    87     
       
    88 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeDeviceInfo::ElementInfo(TInt aElementId) const
       
    89     {
       
    90     return iElementInfo[aElementId];
       
    91     }
       
    92 
       
    93 CMTPTypeDeviceInfo::CMTPTypeDeviceInfo() : 
       
    94     CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), 
       
    95     iElementInfo(iElementMetaData, ENumElements),
       
    96     iChunkFlat(KMTPChunk0Size, *this)
       
    97     {
       
    98     
       
    99     }
       
   100     
       
   101 void CMTPTypeDeviceInfo::ConstructL()
       
   102     {
       
   103     for (TUint i(0); (i < ENumElements); i++)
       
   104         {
       
   105         const TElementInfo& info(iElementInfo[i]);
       
   106         if (ChunkCount() <= info.iChunkId)
       
   107             {
       
   108             MMTPType* chunk(NULL);
       
   109             
       
   110             switch (info.iType)
       
   111                 {
       
   112             case EMTPTypeArray:
       
   113                 chunk = NewArrayChunkL(info);
       
   114                 break;
       
   115                 
       
   116             case EMTPTypeFlat:
       
   117                 chunk = NewFlatChunkL(info);
       
   118                 break;
       
   119                 
       
   120             case EMTPTypeString:
       
   121                 chunk = NewStringChunkL(info);
       
   122                 break;
       
   123                 
       
   124             case EMTPTypeUINT16:
       
   125                 chunk = NewUInt16Chunk(info);
       
   126                 break;
       
   127                 
       
   128             default:
       
   129                 break;
       
   130                 }
       
   131                 
       
   132             __ASSERT_DEBUG(chunk, User::Invariant());
       
   133             ChunkAppendL(*chunk);
       
   134             }
       
   135         }
       
   136     }
       
   137 
       
   138 MMTPType* CMTPTypeDeviceInfo::NewArrayChunkL(const TElementInfo& aElementInfo)
       
   139     {
       
   140     CMTPTypeArray* chunk(NULL);
       
   141     if (aElementInfo.iFlatChunkInfo.iType)
       
   142         {
       
   143         chunk = CMTPTypeArray::NewLC(EMTPTypeAUINT16);
       
   144         }
       
   145     __ASSERT_DEBUG(chunk, User::Invariant());
       
   146     iArrayChunks.AppendL(chunk);
       
   147     CleanupStack::Pop(chunk);
       
   148     return chunk;
       
   149     }
       
   150 
       
   151 MMTPType* CMTPTypeDeviceInfo::NewFlatChunkL(const TElementInfo& aElementInfo)
       
   152     {
       
   153     MMTPType* chunk(NULL);
       
   154     if (aElementInfo.iChunkId == EIdFlatChunk)
       
   155         {
       
   156         iChunkFlat.OpenL();
       
   157         chunk = &iChunkFlat;
       
   158         }
       
   159     __ASSERT_DEBUG(chunk, User::Invariant());
       
   160     return chunk;
       
   161     }
       
   162 
       
   163 MMTPType* CMTPTypeDeviceInfo::NewStringChunkL(const TElementInfo& /*aElementInfo*/)
       
   164     {
       
   165     CMTPTypeString* chunk(CMTPTypeString::NewLC());
       
   166     iStringChunks.AppendL(chunk);
       
   167     CleanupStack::Pop(chunk);
       
   168     return chunk;
       
   169     }
       
   170 
       
   171 MMTPType* CMTPTypeDeviceInfo::NewUInt16Chunk(const TElementInfo& aElementInfo)
       
   172     {
       
   173     MMTPType* chunk(NULL);
       
   174     if (aElementInfo.iChunkId == EIdFunctionalModeChunk)
       
   175         {
       
   176         chunk = &iChunkFunctionalMode;
       
   177         }
       
   178     __ASSERT_DEBUG(chunk, User::Invariant());
       
   179     return chunk; 
       
   180     }