mtpfws/mtpfw/datatypes/src/cmtptypeserviceprop.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 
       
    21 #include <mtp/tmtptypeflatbase.h>
       
    22 #include <mtp/cmtptypestring.h>
       
    23 #include <mtp/cmtptypeserviceprop.h>
       
    24 
       
    25 #include "mtpdatatypespanic.h"
       
    26 
       
    27 // Dataset constants
       
    28 
       
    29 
       
    30 const TUint KMTPChunk0Size = 22;
       
    31 
       
    32 
       
    33 const CMTPTypeCompoundBase::TElementInfo CMTPTypeServicePropertyElement::iElementMetaData[CMTPTypeServicePropertyElement::ENumElements] = 
       
    34     {
       
    35         {EIdFlatChunk,                      EMTPTypeFlat,   {EMTPTypeUINT16,    0,                  KMTPTypeUINT16Size}},   // EMTPServicePropCode
       
    36         {EIdFlatChunk,                      EMTPTypeFlat,   {EMTPTypeUINT128,   2,                  KMTPTypeUINT128Size}},  // EMTPServicePropNamespace
       
    37         {EIdFlatChunk,						EMTPTypeFlat,	{EMTPTypeUINT32,	18,					KMTPTypeUINT32Size}},	// EMTPServicePropPKID
       
    38         {EIdServicePropNameChunk,         	EMTPTypeString, {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // EMTPServicePropName
       
    39    };
       
    40 
       
    41 EXPORT_C CMTPTypeServicePropertyList* CMTPTypeServicePropertyList::NewL()
       
    42     {
       
    43     CMTPTypeServicePropertyList* self = CMTPTypeServicePropertyList::NewLC(); 
       
    44     CleanupStack::Pop(self);
       
    45     return self;  
       
    46     }
       
    47 
       
    48 EXPORT_C CMTPTypeServicePropertyList* CMTPTypeServicePropertyList::NewLC()
       
    49     {
       
    50     CMTPTypeServicePropertyList* self = new(ELeave) CMTPTypeServicePropertyList();
       
    51     CleanupStack::PushL(self);
       
    52     self->ConstructL();
       
    53     return self;
       
    54     }
       
    55 
       
    56 EXPORT_C CMTPTypeServicePropertyList::~CMTPTypeServicePropertyList()
       
    57     {
       
    58 
       
    59     }
       
    60 
       
    61 EXPORT_C void CMTPTypeServicePropertyList::AppendL(CMTPTypeServicePropertyElement* aElement)
       
    62     {
       
    63     CMTPTypeList::AppendL(aElement);
       
    64     }
       
    65 
       
    66 CMTPTypeServicePropertyList::CMTPTypeServicePropertyList() :
       
    67 CMTPTypeList(EMTPTypeServicePropertyListDataset,EMTPTypeServicePropertyElementDataset)
       
    68     {
       
    69     }
       
    70 
       
    71 void CMTPTypeServicePropertyList::ConstructL()
       
    72     {
       
    73     InitListL();
       
    74     }
       
    75 
       
    76 EXPORT_C CMTPTypeServicePropertyElement& CMTPTypeServicePropertyList::ElementL(TUint aIndex) const
       
    77     {
       
    78     return static_cast<CMTPTypeServicePropertyElement&>( CMTPTypeList::ElementL(aIndex) );
       
    79     }   
       
    80 
       
    81 EXPORT_C CMTPTypeServicePropertyElement* CMTPTypeServicePropertyElement::NewL()
       
    82     {
       
    83     CMTPTypeServicePropertyElement* self = NewLC();
       
    84     CleanupStack::Pop(self);
       
    85     return self;  
       
    86     }
       
    87 
       
    88 EXPORT_C CMTPTypeServicePropertyElement* CMTPTypeServicePropertyElement::NewLC()
       
    89     {
       
    90     CMTPTypeServicePropertyElement* self = new(ELeave) CMTPTypeServicePropertyElement();
       
    91     CleanupStack::PushL(self);
       
    92     self->ConstructL();
       
    93     return self;
       
    94     }
       
    95 
       
    96 EXPORT_C CMTPTypeServicePropertyElement* CMTPTypeServicePropertyElement::NewL(const TUint16 aPropertyCode, const TMTPTypeGuid& aNameSpace,const TUint32 aPKeyID, const TDesC& aPropertyName)
       
    97     {
       
    98     CMTPTypeServicePropertyElement* self = NewLC(aPropertyCode, aNameSpace,aPKeyID, aPropertyName);
       
    99     CleanupStack::Pop(self);
       
   100     return self;  
       
   101     }
       
   102 
       
   103 EXPORT_C CMTPTypeServicePropertyElement* CMTPTypeServicePropertyElement::NewLC(const TUint16 aPropertyCode, const TMTPTypeGuid& aNameSpace,const TUint32 aPKeyID, const TDesC& aPropertyName)
       
   104     {
       
   105     CMTPTypeServicePropertyElement* self = new (ELeave) CMTPTypeServicePropertyElement(); 
       
   106 	CleanupStack::PushL(self); 
       
   107     self->ConstructL(aPropertyCode, aNameSpace,aPKeyID, aPropertyName);
       
   108 	return self;    
       
   109     }
       
   110 
       
   111 /**
       
   112 Destructor.
       
   113 */    
       
   114 EXPORT_C CMTPTypeServicePropertyElement::~CMTPTypeServicePropertyElement()
       
   115     {    
       
   116     iChunkFlat.Close();
       
   117     delete iChunkString;
       
   118     }
       
   119 
       
   120 EXPORT_C TUint CMTPTypeServicePropertyElement::Type() const
       
   121     {
       
   122     return EMTPTypeServicePropertyElementDataset;
       
   123     }
       
   124 
       
   125 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeServicePropertyElement::ElementInfo(TInt aElementId) const
       
   126     {
       
   127     return iElementInfo[aElementId];
       
   128     }
       
   129 
       
   130 CMTPTypeServicePropertyElement::CMTPTypeServicePropertyElement() : 
       
   131     CMTPTypeCompoundBase((KJustInTimeConstruction), EIdNumChunks), 
       
   132     iElementInfo(iElementMetaData, ENumElements),
       
   133     iChunkFlat(KMTPChunk0Size, *this)
       
   134     {
       
   135     
       
   136     }
       
   137 
       
   138 void CMTPTypeServicePropertyElement::ConstructL()
       
   139     {
       
   140     for (TUint i(0); (i < ENumElements); i++)
       
   141         {
       
   142         const TElementInfo& info(iElementInfo[i]);
       
   143         if (ChunkCount() <= info.iChunkId)
       
   144             {
       
   145             MMTPType* chunk(NULL);
       
   146             
       
   147             switch (info.iType)
       
   148                 {
       
   149             	case EMTPTypeFlat:
       
   150             		chunk = NewFlatChunkL();
       
   151             	break;  
       
   152             	case EMTPTypeString:
       
   153             		 iChunkString = CMTPTypeString::NewL();
       
   154             		 chunk = iChunkString ;
       
   155                 break;
       
   156             	default:
       
   157                 break;
       
   158                 }    
       
   159                 __ASSERT_DEBUG(chunk, User::Invariant());
       
   160                 ChunkAppendL(*chunk);
       
   161                 
       
   162             }
       
   163         }
       
   164     }
       
   165 
       
   166 
       
   167 MMTPType* CMTPTypeServicePropertyElement::NewFlatChunkL()
       
   168     {
       
   169     MMTPType* chunk(NULL);
       
   170 
       
   171     iChunkFlat.OpenL();
       
   172     chunk = &iChunkFlat;
       
   173 
       
   174     __ASSERT_DEBUG(chunk, User::Invariant());
       
   175     return chunk;
       
   176     }
       
   177 
       
   178 void CMTPTypeServicePropertyElement::ConstructL(const TUint16 aPropertyCode, const TMTPTypeGuid& aNameSpace,const TUint32 aPKeyID, const TDesC& aPropertyName)
       
   179     {
       
   180 
       
   181     ConstructL();
       
   182 
       
   183     // Set mandatory construction values.
       
   184     SetUint16L(EPropertyCode, aPropertyCode);
       
   185     SetL(ENameSpace, aNameSpace);
       
   186 
       
   187     SetUint32L(EPkeyID,aPKeyID);
       
   188     SetStringL(EPorpertyName,aPropertyName);
       
   189 
       
   190     }