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