mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetformatcapabilities.cpp
changeset 0 a2952bb97e68
child 9 bee149131e4b
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mtp/cmtptypeinterdependentpropdesc.h>
       
    19 #include <mtp/cmtptypeobjectpropdesc.h>
       
    20 #include <mtp/mtpprotocolconstants.h>
       
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/cmtptypestring.h>
       
    23 
       
    24 
       
    25 #include "cgetformatcapabilities.h"
       
    26 #include "mmmtpdplogger.h"
       
    27 #include "mmmtpdpconfig.h"
       
    28 #include "tobjectdescription.h"
       
    29 
       
    30 _LIT( KMtpObjDescObjFileName, "[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 7}\\.[[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 2}]?" );
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CGetFormatCapabilities::CGetFormatCapabilities
       
    34 // Standard c++ constructor
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CGetFormatCapabilities::CGetFormatCapabilities( MMTPDataProviderFramework& aFramework,
       
    38         MMTPConnection& aConnection,
       
    39         MMmMtpDpConfig& aDpConfig ) :
       
    40     CRequestProcessor( aFramework, aConnection, 0, NULL ),
       
    41     iDpConfig( aDpConfig )
       
    42     {
       
    43     PRINT( _L( "Operation: CGetFormatCapabilities(0x930A)" ) );
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CGetFormatCapabilities::ConstructL
       
    48 // Second phase constructor
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C void CGetFormatCapabilities::ConstructL()
       
    52     {
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CGetFormatCapabilities::~CGetFormatCapabilities
       
    57 // Second phase constructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 EXPORT_C CGetFormatCapabilities::~CGetFormatCapabilities()
       
    61     {
       
    62     delete iCapabilityList;
       
    63     iCapabilityList = NULL;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CGetFormatCapabilities::CheckRequestL
       
    68 // Ensures the object prop code operation parameter is valid
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C TMTPResponseCode CGetFormatCapabilities::CheckRequestL()
       
    72     {
       
    73     PRINT( _L( "MM MTP => CGetFormatCapabilities::CheckRequestL" ) );
       
    74     TMTPResponseCode response = EMTPRespCodeOK;
       
    75     iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
    76 
       
    77     if ( iFormatCode != KMTPFormatsAll )
       
    78         {
       
    79         response = EMTPRespCodeInvalidObjectFormatCode;
       
    80 
       
    81         const RArray<TUint>* format = iDpConfig.GetSupportedFormat();
       
    82         TInt count = format->Count();
       
    83 
       
    84         for ( TInt i = 0; i < count; i++ )
       
    85             {
       
    86             if ( iFormatCode == (*format)[i] )
       
    87                 {
       
    88                 response = EMTPRespCodeOK;
       
    89                 break;
       
    90                 }
       
    91             }
       
    92         }
       
    93 
       
    94     PRINT1( _L( "MM MTP <= CGetFormatCapabilities::CheckRequestL, response = 0x%X" ), response );
       
    95     return response;
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CGetFormatCapabilities::ServiceL
       
   100 // GetFormatCapabilities request handler
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 EXPORT_C void CGetFormatCapabilities::ServiceL()
       
   104     {
       
   105     PRINT( _L( "MM MTP => CGetFormatCapabilities::ServiceL" ) );
       
   106 
       
   107     delete iCapabilityList;
       
   108     iCapabilityList = NULL;
       
   109 
       
   110     iCapabilityList = CMTPTypeFormatCapabilityList::NewL();
       
   111     iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
   112 
       
   113     if ( KMTPFormatsAll == iFormatCode )
       
   114         {
       
   115         const RArray<TUint>* formatArray = iDpConfig.GetSupportedFormat();
       
   116         TInt count = formatArray->Count();
       
   117         for( TInt i = 0; i < count; i++ )
       
   118             {
       
   119             PRINT( _L( "MM MTP <> CGetFormatCapabilities::ServiceL, KMTPFormatsAll!!!" ) );
       
   120             iFormatCode = ( *formatArray )[i];
       
   121             ServiceInterdepentPropDescL();
       
   122             CMTPTypeFormatCapability* frmCap = CMTPTypeFormatCapability::NewL( iFormatCode, iInterdependentPropDesc );
       
   123             const RArray<TUint>* propertiesArray = iDpConfig.GetSupportedPropertiesL( iFormatCode );
       
   124             TInt num = propertiesArray->Count();
       
   125             for( TInt j = 0;j < num; j++ )
       
   126                 {
       
   127                 CMTPTypeObjectPropDesc* propertyDesc = ServicePropDescL( (*propertiesArray)[j] );
       
   128                 if ( propertyDesc != NULL )
       
   129                     {
       
   130                     frmCap->AppendL( propertyDesc );
       
   131                     }
       
   132                 }//end for j
       
   133             iCapabilityList->AppendL( frmCap );
       
   134             }//end for i
       
   135         }//end if
       
   136     else
       
   137         {
       
   138         ServiceInterdepentPropDescL();
       
   139         PRINT1( _L( "MM MTP <> CGetFormatCapabilities::ServiceL, ONLY one Format!!! formatCode = 0x%X" ), iFormatCode );
       
   140 
       
   141         CMTPTypeFormatCapability* frmCap = CMTPTypeFormatCapability::NewL( iFormatCode, iInterdependentPropDesc );
       
   142         const RArray<TUint>* propertiesArray = iDpConfig.GetSupportedPropertiesL( iFormatCode );
       
   143         TInt num = propertiesArray->Count();
       
   144         for( TInt j = 0;j < num; j++ )
       
   145             {
       
   146             CMTPTypeObjectPropDesc* propertyDesc = ServicePropDescL( ( *propertiesArray )[j] );
       
   147             if ( propertyDesc != NULL )
       
   148                 {
       
   149                 frmCap->AppendL( propertyDesc );
       
   150                 }
       
   151             }//end for j
       
   152         iCapabilityList->AppendL( frmCap );
       
   153         }
       
   154 
       
   155     SendDataL( *iCapabilityList );
       
   156     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServiceL" ) );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CGetFormatCapabilities::ServicePropDescL
       
   161 // Get MTPTypeObjectPropDesc according to property code
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CMTPTypeObjectPropDesc* CGetFormatCapabilities::ServicePropDescL( TUint16 aPropCode )
       
   165     {
       
   166     PRINT1( _L( "MM MTP => CGetFormatCapabilities::ServicePropDescL, aPropCode = 0x%X" ), aPropCode );
       
   167     // implement just like what we did in CGetpropertyDescc::ServiceL
       
   168     CMTPTypeObjectPropDesc* propertyDesc;
       
   169     CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
       
   170 
       
   171     /* Create new PropDesc object to return to device
       
   172      m - signals only limited supported values - hence these requests require the expected form
       
   173      variable to be passed into the NewL contstuctor as well */
       
   174     switch( aPropCode )
       
   175         {
       
   176         case EMTPObjectPropCodeStorageID: // Storage ID
       
   177         case EMTPObjectPropCodeObjectFormat: // Format Code
       
   178         case EMTPObjectPropCodeObjectSize: // Object Size
       
   179         case EMTPObjectPropCodeParentObject: // Parent Object
       
   180         case EMTPObjectPropCodePersistentUniqueObjectIdentifier: // Unique Object Identifier
       
   181         case EMTPObjectPropCodeName: // Name
       
   182         case EMTPObjectPropCodeDateAdded: // Date Added
       
   183             propertyDesc = CMTPTypeObjectPropDesc::NewL( aPropCode );
       
   184             break;
       
   185 
       
   186             // Protection Status (m)
       
   187         case EMTPObjectPropCodeProtectionStatus:
       
   188             propertyDesc = ServiceProtectionStatusL();
       
   189             break;
       
   190 
       
   191             // FileName
       
   192         case EMTPObjectPropCodeObjectFileName:
       
   193             propertyDesc = ServiceFileNameL();
       
   194             break;
       
   195 
       
   196             // Consumable (m)
       
   197         case EMTPObjectPropCodeNonConsumable:
       
   198             propertyDesc = ServiceNonConsumableL();
       
   199             break;
       
   200 
       
   201         case EMTPObjectPropCodeDateModified: // Date Modified
       
   202         case EMTPObjectPropCodeDateCreated: // Date Created
       
   203             propertyInfo.iDataType     = EMTPTypeString;
       
   204             propertyInfo.iFormFlag     = CMTPTypeObjectPropDesc::EDateTimeForm;
       
   205             propertyInfo.iGetSet       = CMTPTypeObjectPropDesc::EReadOnly;
       
   206             propertyDesc = CMTPTypeObjectPropDesc::NewL( aPropCode, propertyInfo, NULL);
       
   207             break;
       
   208 
       
   209         default:
       
   210             propertyDesc = ServiceSpecificPropertyDescL( aPropCode );
       
   211             break;
       
   212         }
       
   213     if ( propertyDesc != NULL )
       
   214         {
       
   215         TUint32 groupCode = GetGroupCode( aPropCode );
       
   216         propertyDesc->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
       
   217         }
       
   218 
       
   219     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServicePropDescL" ) );
       
   220 
       
   221     return propertyDesc;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CGetFormatCapabilities::GetGroupCode
       
   226 // Get MTPTypeObjectPropDesc according to property code
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 TUint32 CGetFormatCapabilities::GetGroupCode( TUint32 aPropCode )
       
   230     {
       
   231     TInt count = sizeof( KPropGroupMapTable );
       
   232     // TODO: if need to refine the search approach to improve performance
       
   233     for( TInt i = 0; i < count; i++ )
       
   234         {
       
   235         if ( aPropCode == KPropGroupMapTable[i].iPropCode )
       
   236             return KPropGroupMapTable[i].iGroupCode;
       
   237         }
       
   238     return EGroupCodeNotDefined;
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CGetFormatCapabilities::ServiceProtectionStatusL
       
   243 // Get MTPTypeObjectPropDesc protection status
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 CMTPTypeObjectPropDesc* CGetFormatCapabilities::ServiceProtectionStatusL()
       
   247     {
       
   248     PRINT( _L( "MM MTP => CGetFormatCapabilities::ServiceProtectionStatusL" ) );
       
   249 
       
   250     CMTPTypeObjectPropDescEnumerationForm* expectedForm =
       
   251         CMTPTypeObjectPropDescEnumerationForm::NewLC( EMTPTypeUINT16 ); // + expectedForm
       
   252 
       
   253     TUint16 values[] =
       
   254         {
       
   255         EMTPProtectionNoProtection,
       
   256         EMTPProtectionReadOnly
       
   257         };
       
   258 
       
   259     TInt numValues = sizeof ( values ) / sizeof ( values[0] ) ;
       
   260     for ( TInt i = 0; i < numValues; i++ )
       
   261         {
       
   262         TMTPTypeUint16 data( values[i] );
       
   263         expectedForm->AppendSupportedValueL( data );
       
   264         }
       
   265 
       
   266     CMTPTypeObjectPropDesc* propertyDesc  = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeProtectionStatus, *expectedForm );
       
   267     CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
       
   268 
       
   269     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServiceProtectionStatusL" ) );
       
   270     return propertyDesc;
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // CGetFormatCapabilities::ServiceFileNameL
       
   275 // Get MTPTypeObjectPropDesc service file name
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 CMTPTypeObjectPropDesc* CGetFormatCapabilities::ServiceFileNameL()
       
   279     {
       
   280     PRINT( _L( "MM MTP => CGetFormatCapabilities::ServiceFileNameL" ) );
       
   281     CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form
       
   282 
       
   283     CMTPTypeObjectPropDesc* ret = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName,
       
   284         CMTPTypeObjectPropDesc::ERegularExpressionForm,
       
   285         form );
       
   286 
       
   287     CleanupStack::PopAndDestroy( form ); // - form
       
   288     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServiceFileNameL" ) );
       
   289     return ret;
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CGetFormatCapabilities::ServiceFileNameL
       
   294 // Get MTPTypeObjectPropDesc service file name
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 CMTPTypeObjectPropDesc* CGetFormatCapabilities::ServiceNonConsumableL()
       
   298     {
       
   299     PRINT( _L( "MM MTP => CGetFormatCapabilities::ServiceNonConsumableL" ) );
       
   300     CMTPTypeObjectPropDescEnumerationForm* expectedForm =
       
   301         CMTPTypeObjectPropDescEnumerationForm::NewLC( EMTPTypeUINT8 ); // + expectedForm
       
   302     TUint8 values[] =
       
   303         {
       
   304         EMTPConsumable,
       
   305         EMTPNonConsumable
       
   306         };
       
   307 
       
   308     TInt numValues = sizeof ( values ) / sizeof ( values[0] );
       
   309     for ( TInt i = 0; i < numValues; i++ )
       
   310         {
       
   311         TMTPTypeUint8 data( values[i] );
       
   312         expectedForm->AppendSupportedValueL( data );
       
   313         }
       
   314 
       
   315     CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
       
   316     propertyInfo.iDataType = EMTPTypeUINT8;
       
   317     propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::EEnumerationForm;
       
   318     propertyInfo.iGetSet = CMTPTypeObjectPropDesc::EReadOnly;
       
   319     CMTPTypeObjectPropDesc* ret = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeNonConsumable,
       
   320         propertyInfo,
       
   321         expectedForm );
       
   322     CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
       
   323 
       
   324     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServiceNonConsumableL" ) );
       
   325     return ret;
       
   326     }
       
   327 
       
   328 // end of file