mtpfws/mtpfw/datatypes/src/cmtptypeservicecapabilitylist.cpp
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 */
       
    20 #include <mtp/tmtptypeflatbase.h>
       
    21 #include <mtp/cmtptypeobjectpropdesc.h>
       
    22 #include <mtp/cmtptypeinterdependentpropdesc.h>
       
    23 #include <mtp/cmtptypeservicecapabilitylist.h>
       
    24 
       
    25 
       
    26 #include "mtpdatatypespanic.h"
       
    27 
       
    28 // Dataset constants
       
    29 const TUint KMTPChunk0Size = 2;
       
    30 
       
    31 // Dataset element metadata.
       
    32 const CMTPTypeCompoundBase::TElementInfo CMTPTypeFormatCapability::iElementMetaData[CMTPTypeFormatCapability::ENumElements] = 
       
    33     {
       
    34         {EIdFlatChunk,                          EMTPTypeFlat,                          {EMTPTypeUINT16,    0,                  KMTPTypeUINT16Size}},   // EFormatCode
       
    35    };
       
    36 
       
    37 
       
    38 EXPORT_C CMTPTypeServiceCapabilityList* CMTPTypeServiceCapabilityList::NewL()
       
    39     {
       
    40     CMTPTypeServiceCapabilityList* self = CMTPTypeServiceCapabilityList::NewLC(); 
       
    41     CleanupStack::Pop(self);
       
    42     return self;  
       
    43     }
       
    44 
       
    45 EXPORT_C CMTPTypeServiceCapabilityList* CMTPTypeServiceCapabilityList::NewLC()
       
    46     {
       
    47     CMTPTypeServiceCapabilityList* self = new(ELeave) CMTPTypeServiceCapabilityList();
       
    48     CleanupStack::PushL(self);
       
    49     self->ConstructL();
       
    50     return self;
       
    51     }
       
    52 
       
    53 EXPORT_C CMTPTypeServiceCapabilityList::~CMTPTypeServiceCapabilityList()
       
    54     {
       
    55 
       
    56     }
       
    57 
       
    58 EXPORT_C void CMTPTypeServiceCapabilityList::AppendL(CMTPTypeFormatCapability* aElement)
       
    59     {
       
    60     CMTPTypeList::AppendL(aElement);
       
    61     }
       
    62 
       
    63 EXPORT_C CMTPTypeFormatCapability& CMTPTypeServiceCapabilityList::ElementL(TUint aIndex) const
       
    64 	{
       
    65 	return static_cast<CMTPTypeFormatCapability&>( CMTPTypeList::ElementL(aIndex) );
       
    66 	}
       
    67 
       
    68 CMTPTypeServiceCapabilityList::CMTPTypeServiceCapabilityList():
       
    69 	CMTPTypeList(EMTPTypeServiceCapabilityListDataset,EMTPTypeFormatCapabilityDataset)
       
    70     {
       
    71 
       
    72     }
       
    73 
       
    74 void CMTPTypeServiceCapabilityList::ConstructL()
       
    75     {
       
    76     InitListL();
       
    77     }
       
    78     
       
    79 
       
    80 EXPORT_C CMTPTypeFormatCapability* CMTPTypeFormatCapability::NewL()
       
    81     {
       
    82     CMTPTypeFormatCapability* self = CMTPTypeFormatCapability::NewLC(); 
       
    83     CleanupStack::Pop(self);
       
    84     return self; 
       
    85     }
       
    86 
       
    87 EXPORT_C CMTPTypeFormatCapability* CMTPTypeFormatCapability::NewLC()
       
    88     {
       
    89     CMTPTypeFormatCapability* self = new (ELeave) CMTPTypeFormatCapability( NULL ); 
       
    90     CleanupStack::PushL(self); 
       
    91     self->ConstructL();
       
    92     return self;    
       
    93     }
       
    94 
       
    95 EXPORT_C CMTPTypeFormatCapability* CMTPTypeFormatCapability::NewL(const TUint16 aFormatCode, CMTPTypeInterdependentPropDesc* aInterDependentPropDesc )
       
    96     {
       
    97     CMTPTypeFormatCapability* self = CMTPTypeFormatCapability::NewLC( aFormatCode, aInterDependentPropDesc ); 
       
    98     CleanupStack::Pop(self);
       
    99     return self; 
       
   100     }
       
   101 
       
   102 EXPORT_C CMTPTypeFormatCapability* CMTPTypeFormatCapability::NewLC(const TUint16 aFormatCode, CMTPTypeInterdependentPropDesc* aInterDependentPropDesc )
       
   103     {
       
   104     CMTPTypeFormatCapability* self = new (ELeave) CMTPTypeFormatCapability( aInterDependentPropDesc ); 
       
   105     CleanupStack::PushL(self); 
       
   106     self->ConstructL( aFormatCode );
       
   107     return self;    
       
   108     }
       
   109 
       
   110 EXPORT_C CMTPTypeFormatCapability::~CMTPTypeFormatCapability()
       
   111     {    
       
   112     iChunkFlat.Close();
       
   113     delete iObjectPropDescList;
       
   114     delete iInterdependentPropDesc;
       
   115     }
       
   116 
       
   117 EXPORT_C void CMTPTypeFormatCapability::AppendL(CMTPTypeObjectPropDesc* aElement)
       
   118     {
       
   119     __ASSERT_DEBUG(aElement, User::Invariant());
       
   120     
       
   121     iObjectPropDescList->AppendL( static_cast<MMTPType*>(aElement));
       
   122     }
       
   123 
       
   124 EXPORT_C TUint32 CMTPTypeFormatCapability::NumberOfPropDescs() const
       
   125     {
       
   126     return iObjectPropDescList->NumberOfElements();
       
   127     }
       
   128 
       
   129 EXPORT_C CMTPTypeObjectPropDesc& CMTPTypeFormatCapability::ObjectPropDescL(TUint aIndex) const
       
   130     {
       
   131      return static_cast<CMTPTypeObjectPropDesc&>(iObjectPropDescList->ElementL( aIndex ));
       
   132     }
       
   133 
       
   134 EXPORT_C CMTPTypeInterdependentPropDesc& CMTPTypeFormatCapability::InterdependentPropDesc() const
       
   135     {
       
   136     return *iInterdependentPropDesc;
       
   137     }
       
   138 
       
   139 EXPORT_C TUint CMTPTypeFormatCapability::Type() const
       
   140     {
       
   141     return EMTPTypeFormatCapabilityDataset;
       
   142     }
       
   143 
       
   144 EXPORT_C TBool CMTPTypeFormatCapability::ReadableElementL(TInt aElementId) const
       
   145     {
       
   146     if( aElementId == EFormatCode)
       
   147         {
       
   148         return ETrue;
       
   149         }
       
   150     else
       
   151         {
       
   152         return EFalse;
       
   153         }
       
   154     }
       
   155 
       
   156 EXPORT_C TBool CMTPTypeFormatCapability::WriteableElementL(TInt aElementId ) const
       
   157     {
       
   158     if( aElementId == EFormatCode)
       
   159            {
       
   160            return ETrue;
       
   161            }
       
   162        else
       
   163            {
       
   164            return EFalse;
       
   165            } 
       
   166     }
       
   167 
       
   168 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeFormatCapability::ElementInfo(TInt aElementId) const
       
   169     {
       
   170     return iElementInfo[aElementId];
       
   171     }
       
   172 
       
   173 
       
   174 CMTPTypeFormatCapability::CMTPTypeFormatCapability( CMTPTypeInterdependentPropDesc* aInterDependentPropDesc) : 
       
   175     CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), 
       
   176     iElementInfo(iElementMetaData, ENumElements),
       
   177     iChunkFlat(KMTPChunk0Size, *this),
       
   178     iInterdependentPropDesc(aInterDependentPropDesc)
       
   179     {
       
   180     
       
   181     }
       
   182 
       
   183 void CMTPTypeFormatCapability::ConstructL()
       
   184     {
       
   185     for (TUint i(0); (i < ENumElements); i++)
       
   186         {
       
   187         const TElementInfo& info(iElementInfo[i]);
       
   188         if (ChunkCount() <= info.iChunkId)
       
   189             {
       
   190             MMTPType* chunk(NULL);
       
   191             
       
   192             switch (info.iType)
       
   193                 {
       
   194             case EMTPTypeFlat:
       
   195                 chunk = NewFlatChunkL();
       
   196                 break;  
       
   197             default:
       
   198                 break;
       
   199                 }
       
   200                 
       
   201             __ASSERT_DEBUG(chunk, User::Invariant());
       
   202             ChunkAppendL(*chunk);
       
   203             }
       
   204         }
       
   205     
       
   206     iObjectPropDescList = CMTPTypeList::NewL(EMTPTypeFormatCapabilityDataset,EMTPTypeObjectPropDescDataset);
       
   207     if( NULL == iInterdependentPropDesc )
       
   208         {
       
   209         iInterdependentPropDesc = CMTPTypeInterdependentPropDesc::NewL();
       
   210         }
       
   211     ChunkAppendL(*iObjectPropDescList);
       
   212     ChunkAppendL(*iInterdependentPropDesc);
       
   213     }
       
   214 
       
   215 MMTPType* CMTPTypeFormatCapability::NewFlatChunkL()
       
   216     {
       
   217     MMTPType* chunk(NULL);
       
   218 
       
   219     iChunkFlat.OpenL();
       
   220     chunk = &iChunkFlat;
       
   221     
       
   222     __ASSERT_DEBUG(chunk, User::Invariant());
       
   223     return chunk;
       
   224     }
       
   225 
       
   226 void CMTPTypeFormatCapability::ConstructL(const TUint16 aFormatCode)
       
   227     {
       
   228     ConstructL();
       
   229 
       
   230     // Set mandatory construction values.
       
   231     SetUint16L(EFormatCode, aFormatCode);
       
   232     }