mtpfws/mtpfw/datatypes/src/cmtptypeserviceinfo.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/cmtptypeservicesection.h>
       
    22 #include <mtp/cmtptypeserviceinfo.h>
       
    23 #include <mtp/cmtptypeserviceprop.h>
       
    24 #include <mtp/cmtptypeserviceformat.h>
       
    25 #include <mtp/cmtptypeservicemethod.h>
       
    26 #include <mtp/cmtptypeserviceevent.h>
       
    27 #include <mtp/cmtptypestring.h>
       
    28 
       
    29 #include "mtpdatatypespanic.h"
       
    30 
       
    31 const TUint CMTPTypeServiceInfo::KFlat1ChunkSize(44);
       
    32 const TUint CMTPTypeServiceInfo::KFlat2ChunkSize(8);
       
    33 
       
    34 const CMTPTypeCompoundBase::TElementInfo CMTPTypeServiceInfo::iElementMetaData[CMTPTypeServiceInfo::ENumElements] = 
       
    35     {
       
    36         {EIdFlat1Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT32,    0,                  KMTPTypeUINT32Size}},   // EMTPServiceID
       
    37         {EIdFlat1Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT32,    4,                  KMTPTypeUINT32Size}},   // EMTPServiceStorageID
       
    38         {EIdFlat1Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT128,   8,                  KMTPTypeUINT128Size}},  // EMTPServicePGUID
       
    39         {EIdFlat1Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT32,    24,                 KMTPTypeUINT32Size}},   // EMTPServiceVersion
       
    40         {EIdFlat1Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT128,   28,                 KMTPTypeUINT128Size}},  // EMTPServiceGUID
       
    41         {EIdServiceNameChunk,                 EMTPTypeString,    {EMTPTypeString,    KMTPNotApplicable,  KMTPNotApplicable}},    // EMTPServiceName        
       
    42         {EIdFlat2Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT32,    0,                  KMTPTypeUINT32Size}},   // EMTPServiceType
       
    43         {EIdFlat2Chunk,                       EMTPTypeFlat,      {EMTPTypeUINT32,    4,                  KMTPTypeUINT32Size}},   // EMTPBaseServiceID
       
    44    };
       
    45 
       
    46 EXPORT_C CMTPTypeServiceInfo* CMTPTypeServiceInfo::NewL()
       
    47     {
       
    48     CMTPTypeServiceInfo* self = CMTPTypeServiceInfo::NewLC(); 
       
    49     CleanupStack::Pop(self);
       
    50     return self; 
       
    51     }
       
    52 
       
    53 EXPORT_C CMTPTypeServiceInfo* CMTPTypeServiceInfo::NewLC()
       
    54     {
       
    55     CMTPTypeServiceInfo* self = new (ELeave) CMTPTypeServiceInfo(); 
       
    56     CleanupStack::PushL(self); 
       
    57     self->ConstructL();
       
    58     return self;    
       
    59     }
       
    60 
       
    61 EXPORT_C CMTPTypeServiceInfo::~CMTPTypeServiceInfo()
       
    62     {   
       
    63     iChunkFlat1.Close();
       
    64     iChunkFlat2.Close();
       
    65     delete iChunkString;
       
    66     
       
    67     delete iChunkUsedServices;
       
    68     delete iChunkServiceDataBlock;
       
    69     
       
    70     delete iServicePropList;
       
    71     delete iServiceFormatList;
       
    72     delete iServiceMethodList;
       
    73     delete iServiceEventList;
       
    74     }
       
    75 
       
    76 EXPORT_C TUint32 CMTPTypeServiceInfo::NumberOfUsedServices() const
       
    77     {
       
    78     return iChunkUsedServices->NumElements();
       
    79     }
       
    80 
       
    81 EXPORT_C void CMTPTypeServiceInfo::UsedServiceL( const TUint aIndex, TMTPTypeGuid& aUsedServiceGUID ) const
       
    82     {
       
    83     iChunkUsedServices->ElementL(aIndex, aUsedServiceGUID);
       
    84     }
       
    85 
       
    86 EXPORT_C void CMTPTypeServiceInfo::AppendUsedServiceL( const TMTPTypeGuid& aElement )
       
    87     {
       
    88     iChunkUsedServices->AppendL( aElement );
       
    89     }
       
    90 
       
    91 EXPORT_C TUint32 CMTPTypeServiceInfo::NumberOfServiceDataBlock() const
       
    92     {
       
    93     return iChunkServiceDataBlock->NumElements();
       
    94     }
       
    95 
       
    96 EXPORT_C void CMTPTypeServiceInfo::SerivceDataBlockL( const TUint aIndex, TMTPTypeGuid& aGUID ) const
       
    97     {
       
    98     iChunkServiceDataBlock->ElementL(aIndex, aGUID);
       
    99     }
       
   100 
       
   101 EXPORT_C void CMTPTypeServiceInfo::AppendServiceDataBlockL( const TMTPTypeGuid& aElement )
       
   102     {
       
   103     iChunkServiceDataBlock->AppendL( aElement );
       
   104     }
       
   105 
       
   106 EXPORT_C TUint CMTPTypeServiceInfo::Type() const
       
   107     {
       
   108     return EMTPTypeServiceInfoDataset;
       
   109     }
       
   110 
       
   111 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeServiceInfo::ElementInfo(TInt aElementId) const
       
   112     {
       
   113     return iElementInfo[aElementId];
       
   114     }
       
   115 
       
   116 TBool CMTPTypeServiceInfo::WriteableElementL(TInt aElementId) const
       
   117     {
       
   118     TBool ret(EFalse);
       
   119     if(aElementId <= EBaseServiceID )
       
   120         ret = ETrue;
       
   121     
       
   122     return ret;
       
   123     }
       
   124 
       
   125 TBool CMTPTypeServiceInfo::ReadableElementL(TInt aElementId) const
       
   126     {
       
   127     TBool ret(EFalse);
       
   128         if(aElementId <= EBaseServiceID )
       
   129             ret = ETrue;
       
   130         
       
   131         return ret;
       
   132     }
       
   133 
       
   134 CMTPTypeServiceInfo::CMTPTypeServiceInfo() : 
       
   135     CMTPTypeCompoundBase((!KJustInTimeConstruction), EIdNumChunks), 
       
   136     iElementInfo(iElementMetaData, ENumElements),
       
   137     iChunkFlat1(KFlat1ChunkSize, *this),
       
   138     iChunkFlat2(KFlat2ChunkSize, *this)
       
   139     {
       
   140     
       
   141     }
       
   142 
       
   143 void CMTPTypeServiceInfo::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     iChunkUsedServices = CMTPTypeArray::NewL(EMTPTypeAUINT128, EMTPTypeUINT128,  KMTPTypeUINT128Size );
       
   171     ChunkAppendL( *iChunkUsedServices );
       
   172     
       
   173     iServicePropList = CMTPTypeServicePropertyList::NewL();
       
   174     iServiceFormatList = CMTPTypeServiceFormatList::NewL();
       
   175     iServiceMethodList = CMTPTypeServiceMethodList::NewL();
       
   176     iServiceEventList = CMTPTypeServiceEventList::NewL();
       
   177     
       
   178     ChunkAppendL(*iServicePropList);
       
   179     ChunkAppendL(*iServiceFormatList);
       
   180     ChunkAppendL(*iServiceMethodList);
       
   181     ChunkAppendL(*iServiceEventList);
       
   182     
       
   183     iChunkServiceDataBlock = CMTPTypeArray::NewL(EMTPTypeAUINT128, EMTPTypeUINT128,  KMTPTypeUINT128Size );
       
   184     ChunkAppendL( *iChunkServiceDataBlock );
       
   185     
       
   186     }
       
   187 
       
   188 
       
   189 MMTPType* CMTPTypeServiceInfo::NewFlatChunkL(const TElementInfo& aElementInfo)
       
   190     {
       
   191     MMTPType* chunk(NULL);
       
   192     if (aElementInfo.iChunkId == EIdFlat1Chunk)
       
   193         {
       
   194         iChunkFlat1.OpenL();
       
   195         chunk = &iChunkFlat1;
       
   196         }
       
   197     else if ( aElementInfo.iChunkId == EIdFlat2Chunk )
       
   198         {
       
   199         iChunkFlat2.OpenL();
       
   200         chunk = &iChunkFlat2;
       
   201         }
       
   202     else
       
   203         {}
       
   204     __ASSERT_DEBUG(chunk, User::Invariant());
       
   205     return chunk;
       
   206     }
       
   207 
       
   208 EXPORT_C CMTPTypeServicePropertyList& CMTPTypeServiceInfo::ServicePropList()
       
   209     {
       
   210     return *iServicePropList;
       
   211     }
       
   212 
       
   213 EXPORT_C CMTPTypeServiceFormatList& CMTPTypeServiceInfo::ServiceFormatList()
       
   214     {
       
   215     return *iServiceFormatList;
       
   216     }
       
   217 
       
   218 EXPORT_C CMTPTypeServiceMethodList& CMTPTypeServiceInfo::ServiceMethodList()
       
   219     {
       
   220     return *iServiceMethodList;
       
   221     }
       
   222 
       
   223 EXPORT_C CMTPTypeServiceEventList& CMTPTypeServiceInfo::ServiceEventList()
       
   224     {
       
   225     return *iServiceEventList;
       
   226     }
       
   227