mtpfws/mtpfw/datatypes/src/cmtptypeservicemethodparamextnform.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 @internalComponent
       
    19 */
       
    20 
       
    21 #include <mtp/cmtptypeservicemethodparamextnform.h>
       
    22 #include <mtp/mtpdatatypeconstants.h>
       
    23 #include <mtp/mtpprotocolconstants.h>
       
    24 #include <mtp/cmtptypestring.h>
       
    25 
       
    26 #include "mtpdatatypespanic.h"
       
    27 
       
    28 // Dataset constants
       
    29 const TUint CMTPTypeServiceMethodParamExtnForm::KFlat1ChunkSize(20);
       
    30 const TUint CMTPTypeServiceMethodParamExtnForm::KFlat2ChunkSize(3);
       
    31 const TUint CMTPTypeServiceMethodParamExtnForm::KNumChunksWithoutForm(EIdFlat2Chunk + 1);
       
    32 const TUint CMTPTypeServiceMethodParamExtnForm::KNumChunksWithForm(EIdFormChunk + 1);
       
    33 
       
    34 //Dataset element metadata    
       
    35 const CMTPTypeCompoundBase::TElementInfo CMTPTypeServiceMethodParamExtnForm::iElementMetaData[CMTPTypeServiceMethodParamExtnForm::ENumElements] = 
       
    36     {
       
    37         {EIdFlat1Chunk,       EMTPTypeFlat,       {EMTPTypeUINT128,    0,                 KMTPTypeUINT128Size}},   // EPKNamespace
       
    38         {EIdFlat1Chunk,       EMTPTypeFlat,       {EMTPTypeUINT32,    16,                 KMTPTypeUINT32Size}},    // EPKeyID
       
    39         {EIdNameChunk,        EMTPTypeString,     {EMTPTypeString,  KMTPNotApplicable,    KMTPNotApplicable}},     // EPropertyName
       
    40         {EIdFlat2Chunk,       EMTPTypeFlat,       {EMTPTypeUINT8,     0,                  KMTPTypeUINT8Size}},     // EParameterType
       
    41         {EIdFlat2Chunk,       EMTPTypeFlat,       {EMTPTypeUINT8,     1,                  KMTPTypeUINT8Size}},     // EParameterNumber
       
    42         {EIdFlat2Chunk,       EMTPTypeFlat,       {EMTPTypeUINT8,     2,                  KMTPTypeUINT8Size}},     // EFormFlag
       
    43         {EIdFormChunk,        EMTPTypeReference,  {EMTPTypeUndefined, KMTPNotApplicable,  KMTPNotApplicable}},     // EForm
       
    44     };
       
    45 
       
    46 
       
    47 /**
       
    48 MTP Service Method Parameter Extension FORM dataset factory method. This method is used to 
       
    49 create an empty MTP Service Method Parameter Extension FORM  of the specified Datatype. 
       
    50 @param aDataType The data type identifier datacode of the object property.
       
    51 @return A pointer to the form type. Ownership IS 
       
    52 transfered.
       
    53 @leave One of the system wide error codes, if unsuccessful.
       
    54 */ 
       
    55 EXPORT_C  CMTPTypeServiceMethodParamExtnForm* CMTPTypeServiceMethodParamExtnForm::NewL( const TUint aDataType )
       
    56     {
       
    57     CMTPTypeServiceMethodParamExtnForm* self = CMTPTypeServiceMethodParamExtnForm::NewLC( aDataType );
       
    58     CleanupStack::Pop(self); 
       
    59     return self;
       
    60     }
       
    61 /**
       
    62 MTP DevicePropDesc  Service Method Parameter Extension FORM  factory method. This method is used to 
       
    63 create an empty MTP Service Method Parameter Extension FORM  of the specified Datatype. 
       
    64 @param aDataType The data type identifier datacode of the the object property.
       
    65 @return A pointer to the form type. Ownership IS 
       
    66 transfered.
       
    67 @leave One of the system wide error codes, if unsuccessful.
       
    68 */
       
    69 EXPORT_C  CMTPTypeServiceMethodParamExtnForm* CMTPTypeServiceMethodParamExtnForm::NewLC( const TUint aDataType )
       
    70     {
       
    71     CMTPTypeServiceMethodParamExtnForm* self = new(ELeave) CMTPTypeServiceMethodParamExtnForm( aDataType );
       
    72     CleanupStack::PushL(self);
       
    73     
       
    74     TMTPTypeGuid KUndefinedNamespace(0,0);
       
    75     TUint KPKeyID(0);
       
    76     TUint KParamNum(0);
       
    77     TBuf<1> KName;
       
    78     self->ConstructL( KUndefinedNamespace, KPKeyID, KName, EResserved, KParamNum, CMTPTypeObjectPropDesc::ENone, NULL );
       
    79     return self;
       
    80     }
       
    81 
       
    82    
       
    83 EXPORT_C  CMTPTypeServiceMethodParamExtnForm* CMTPTypeServiceMethodParamExtnForm::NewL( const TUint aDataType, const TMTPTypeGuid  aPKNamespace, const TUint aPKID, const TDesC& aName, const TUint8 aParamType, const TUint8 aParamNum, const TUint8 aFormFlag, const MMTPType* aForm)
       
    84     {
       
    85     CMTPTypeServiceMethodParamExtnForm* self = CMTPTypeServiceMethodParamExtnForm::NewLC( aDataType, aPKNamespace, aPKID, aName, aParamType, aParamNum, aFormFlag, aForm );
       
    86     CleanupStack::Pop(self); 
       
    87     return self;
       
    88     }
       
    89    
       
    90   
       
    91 EXPORT_C  CMTPTypeServiceMethodParamExtnForm* CMTPTypeServiceMethodParamExtnForm::NewLC( const TUint aDataType, const TMTPTypeGuid  aPKNamespace, const TUint aPKID, const TDesC& aName, const TUint8 aParamType, const TUint8 aParamNum, const TUint8 aFormFlag, const MMTPType* aForm)
       
    92     {
       
    93     CMTPTypeServiceMethodParamExtnForm* self = new(ELeave) CMTPTypeServiceMethodParamExtnForm(aDataType);
       
    94     CleanupStack::PushL(self);
       
    95     self->ConstructL( aPKNamespace, aPKID, aName, aParamType, aParamNum, aFormFlag, aForm );
       
    96     return self;
       
    97     }
       
    98 
       
    99 
       
   100 /**
       
   101 Destructor.
       
   102 */
       
   103 EXPORT_C CMTPTypeServiceMethodParamExtnForm::~CMTPTypeServiceMethodParamExtnForm()
       
   104     {
       
   105     iChunkFlat1.Close();
       
   106     delete iChunkName;
       
   107     iChunkFlat2.Close();
       
   108     iChunkForm.Close();
       
   109     }
       
   110 
       
   111 CMTPTypeServiceMethodParamExtnForm::CMTPTypeServiceMethodParamExtnForm(const TUint aDataType) : 
       
   112     CMTPTypeCompoundBase((KJustInTimeConstruction), KNumChunksWithoutForm),
       
   113     iElementInfo(iElementMetaData, ENumElements),
       
   114     iChunkFlat1(KFlat1ChunkSize, *this),
       
   115     iChunkFlat2(KFlat2ChunkSize, *this),
       
   116     iDataType(aDataType),
       
   117     iInitialised(EFalse)
       
   118     {
       
   119 
       
   120     }
       
   121 
       
   122 EXPORT_C TUint CMTPTypeServiceMethodParamExtnForm::Type() const
       
   123     {
       
   124     return EMTPTypeServiceObjPropExtnFormDataset;
       
   125     } 
       
   126 
       
   127 EXPORT_C TInt CMTPTypeServiceMethodParamExtnForm::FirstWriteChunk(TPtr8& aChunk)
       
   128     {
       
   129     /* 
       
   130     Reset the type in preparation for the data stream, by deleting all
       
   131     except the first chunk.
       
   132     */
       
   133     for (TUint i(ChunkCount() - 1); i > EIdFlat1Chunk ; i--)
       
   134       {
       
   135       ChunkRemove(i);
       
   136       }
       
   137       
       
   138     // Setup the write chunk pointer.
       
   139     TInt err(UpdateWriteSequenceErr(CMTPTypeCompoundBase::FirstWriteChunk(aChunk)));
       
   140     switch (err)
       
   141       {
       
   142     case KMTPChunkSequenceCompletion:
       
   143       err = KErrNone;
       
   144       // Don't break, fall through to set the write sequence state.
       
   145       
       
   146     case KErrNone:
       
   147       // Set the write sequence state.
       
   148       iWriteSequenceState = EFlat1Chunk; 
       
   149       
       
   150       /* 
       
   151       Set the write sequence completion state. Initially assume that the 
       
   152       extension form has a FORM field. If no FORM field is subsequently
       
   153       detected in the write data stream then the completion state is 
       
   154       adjusted accordingly.
       
   155       */
       
   156       iWriteSequenceCompletionState = EFormChunk;
       
   157       break;
       
   158       
       
   159     default:
       
   160       break;
       
   161       }
       
   162       
       
   163     return  err;
       
   164     }
       
   165 
       
   166 EXPORT_C TInt CMTPTypeServiceMethodParamExtnForm::NextWriteChunk(TPtr8& aChunk)
       
   167     {
       
   168     TInt err(KMTPChunkSequenceCompletion);
       
   169      
       
   170      if (iWriteSequenceState != EIdle)
       
   171          {
       
   172          err = UpdateWriteSequenceErr(CMTPTypeCompoundBase::NextWriteChunk(aChunk));
       
   173          if ((iWriteSequenceErr == KMTPChunkSequenceCompletion) && (iWriteSequenceState != EIdle))
       
   174              {
       
   175              err = KErrNone;
       
   176              }   
       
   177          }    
       
   178      return err;
       
   179     }
       
   180 
       
   181 EXPORT_C TBool CMTPTypeServiceMethodParamExtnForm::CommitRequired() const
       
   182     {
       
   183     return ETrue;
       
   184     }
       
   185 
       
   186 EXPORT_C MMTPType* CMTPTypeServiceMethodParamExtnForm::CommitChunkL(TPtr8& aChunk)
       
   187     {
       
   188     if (iWriteSequenceErr == KMTPChunkSequenceCompletion)
       
   189         {
       
   190         switch (iWriteSequenceState)
       
   191             {
       
   192         case EFlat1Chunk:     
       
   193             iChunkName = CMTPTypeString::NewL();
       
   194             ChunkAppendL(*iChunkName);
       
   195             break;
       
   196             
       
   197         case ENameChunk:
       
   198             ChunkAppendL(iChunkFlat2);
       
   199             break;
       
   200             
       
   201         case EFlat2Chunk: 
       
   202             {
       
   203             iChunkForm.Close();
       
   204             TUint8 flag(Uint8L(EFormFlag));
       
   205             iChunkForm.SetMeta(flag, iDataType);
       
   206             if (HasFormField(flag))
       
   207                 {
       
   208                 iChunkForm.OpenL(iElementInfo[EForm].iType);
       
   209                 ChunkAppendL(iChunkForm);
       
   210                 SetExpectedChunkCount(KNumChunksWithForm);
       
   211                 }
       
   212             else
       
   213                 {
       
   214                 // Adjust the write sequence completion state.            
       
   215                 iWriteSequenceCompletionState = EFlat2Chunk;
       
   216                 }   
       
   217             }
       
   218             break;
       
   219             
       
   220         case EFormChunk:
       
   221         case EIdle:
       
   222         default:
       
   223             break;
       
   224             }
       
   225         
       
   226     if ( (iWriteSequenceState != EIdle ) && (iWriteSequenceState < iWriteSequenceCompletionState) )
       
   227         {
       
   228         iWriteSequenceState++;
       
   229         }
       
   230     else
       
   231         {
       
   232         iWriteSequenceState = EIdle;
       
   233         }
       
   234     }
       
   235         
       
   236     if (CMTPTypeCompoundBase::CommitRequired())
       
   237         {
       
   238         CMTPTypeCompoundBase::CommitChunkL(aChunk);
       
   239         }
       
   240     return NULL;
       
   241     }
       
   242 
       
   243 TBool CMTPTypeServiceMethodParamExtnForm::HasFormField(TUint8 aFormFlag) const
       
   244     {
       
   245     return ((aFormFlag != CMTPTypeObjectPropDesc::EDateTimeForm) && (aFormFlag != CMTPTypeObjectPropDesc::ENone) && (aFormFlag != CMTPTypeObjectPropDesc::EObjectIDForm) );
       
   246     }
       
   247 
       
   248 TInt CMTPTypeServiceMethodParamExtnForm::UpdateWriteSequenceErr(TInt aErr)
       
   249     {
       
   250     iWriteSequenceErr = aErr;
       
   251     return iWriteSequenceErr;        
       
   252     }
       
   253 
       
   254 TBool CMTPTypeServiceMethodParamExtnForm::ReadableElementL(TInt aElementId) const
       
   255     {
       
   256     __ASSERT_ALWAYS((aElementId < ENumElements), Panic(EMTPTypeBoundsError));
       
   257     
       
   258     TBool ret(ETrue);
       
   259     if (aElementId == EForm)
       
   260         {
       
   261         ret = HasFormField(Uint8L(EFormFlag));
       
   262         }
       
   263     return ret;
       
   264     }
       
   265     
       
   266 TBool CMTPTypeServiceMethodParamExtnForm::WriteableElementL( TInt aElementId ) const
       
   267     {   
       
   268     __ASSERT_ALWAYS((aElementId < ENumElements), Panic(EMTPTypeBoundsError));
       
   269     
       
   270     if (!iInitialised)
       
   271         {
       
   272         return ETrue;    
       
   273         }
       
   274     
       
   275     if (aElementId == EForm)
       
   276         return EFalse;
       
   277     
       
   278     return ETrue;
       
   279     }
       
   280 
       
   281 const CMTPTypeCompoundBase::TElementInfo& CMTPTypeServiceMethodParamExtnForm::ElementInfo(TInt aElementId) const
       
   282     {
       
   283     __ASSERT_ALWAYS((aElementId < ENumElements), Panic(EMTPTypeBoundsError));
       
   284     
       
   285     return iElementInfo[aElementId];  
       
   286     }
       
   287 
       
   288         
       
   289 void CMTPTypeServiceMethodParamExtnForm::ConstructL( const TMTPTypeGuid  aPKNamespace, const TUint aPKID, const TDesC& aName, const TUint8 aParamType, const TUint8 aParamNum, const TUint8 aFormFlag, const MMTPType* aForm )
       
   290     {  
       
   291     for (TUint i(0); (i < ENumElements); i++)
       
   292        {
       
   293        const TElementInfo& element(iElementInfo[i]);
       
   294        if (ChunkCount() <= element.iChunkId)
       
   295            {
       
   296            MMTPType* chunk(NULL);
       
   297            switch (element.iChunkId)
       
   298                {
       
   299            case EIdFlat1Chunk:
       
   300                iChunkFlat1.OpenL();
       
   301                chunk = &iChunkFlat1;
       
   302                break;
       
   303                
       
   304            case EIdNameChunk:
       
   305                iChunkName = CMTPTypeString::NewL();
       
   306                chunk = iChunkName;
       
   307                break;
       
   308                
       
   309            case EIdFlat2Chunk:
       
   310                iChunkFlat2.OpenL();
       
   311                chunk = &iChunkFlat2;
       
   312                break;
       
   313                
       
   314            case EIdFormChunk:
       
   315                iChunkForm.SetMeta(aFormFlag, iDataType);
       
   316                if (HasFormField(aFormFlag))
       
   317                    {
       
   318                    iChunkForm.OpenL(element.iType);
       
   319                    chunk = &iChunkForm;
       
   320                    SetExpectedChunkCount(KNumChunksWithForm);
       
   321                    }
       
   322                break;
       
   323                
       
   324            default:
       
   325                Panic(EMTPTypeBoundsError);
       
   326                break;
       
   327                }
       
   328                    
       
   329            // Some chunks (i.e. FORM) are optional.
       
   330            if (chunk)
       
   331                {
       
   332                ChunkAppendL(*chunk);   
       
   333                }
       
   334            }
       
   335        }
       
   336        
       
   337     // Set the construction values.
       
   338     SetL( EPKeyNamespace, aPKNamespace );
       
   339     SetUint32L( EPKeyID, aPKID );
       
   340     SetStringL( EPropertyName, aName );
       
   341     SetUint8L(EParameterType, aParamType);
       
   342     SetUint8L(EParameterNumber, aParamNum);
       
   343     SetUint8L(EFormFlag, aFormFlag);
       
   344     
       
   345     if (aForm)
       
   346         {
       
   347         if (!HasFormField(aFormFlag))
       
   348             { 
       
   349             User::Leave(KMTPDataTypeInvalid);
       
   350             } 
       
   351         else
       
   352             {
       
   353             SetL(EForm, *aForm); 
       
   354             }
       
   355         }
       
   356     
       
   357     iInitialised = ETrue;
       
   358     }