mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetformatcapabilities.cpp
changeset 25 d881023c13eb
parent 0 a2952bb97e68
child 34 e257e2b6459d
equal deleted inserted replaced
21:a05c44bc3c61 25:d881023c13eb
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <mtp/cmtptypeinterdependentpropdesc.h>
    18 #include <mtp/cmtptypeinterdependentpropdesc.h>
    19 #include <mtp/cmtptypeobjectpropdesc.h>
    19 #include <mtp/cmtptypeobjectpropdesc.h>
    20 #include <mtp/mtpprotocolconstants.h>
       
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/cmtptypestring.h>
       
    23 
       
    24 
    20 
    25 #include "cgetformatcapabilities.h"
    21 #include "cgetformatcapabilities.h"
       
    22 #include "cdescriptionutility.h"
       
    23 #include "mmmtpdpconfig.h"
    26 #include "mmmtpdplogger.h"
    24 #include "mmmtpdplogger.h"
    27 #include "mmmtpdpconfig.h"
       
    28 #include "tobjectdescription.h"
       
    29 
    25 
    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}]?" );
    26 // -----------------------------------------------------------------------------
       
    27 // CGetFormatCapabilities::NewL
       
    28 // Constructor
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C MMmRequestProcessor* CGetFormatCapabilities::NewL( MMTPDataProviderFramework& aFramework,
       
    32     MMTPConnection& aConnection,
       
    33     MMmMtpDpConfig& aDpConfig )
       
    34     {
       
    35     CGetFormatCapabilities* self = new ( ELeave ) CGetFormatCapabilities( aFramework, aConnection, aDpConfig );
       
    36 
       
    37     CleanupStack::PushL(self);
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop(self);
       
    40 
       
    41     return self;
       
    42     }
    31 
    43 
    32 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    33 // CGetFormatCapabilities::CGetFormatCapabilities
    45 // CGetFormatCapabilities::CGetFormatCapabilities
    34 // Standard c++ constructor
    46 // Standard c++ constructor
    35 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    36 //
    48 //
    37 EXPORT_C CGetFormatCapabilities::CGetFormatCapabilities( MMTPDataProviderFramework& aFramework,
    49 EXPORT_C CGetFormatCapabilities::CGetFormatCapabilities( MMTPDataProviderFramework& aFramework,
    38         MMTPConnection& aConnection,
    50     MMTPConnection& aConnection,
    39         MMmMtpDpConfig& aDpConfig ) :
    51     MMmMtpDpConfig& aDpConfig ) :
    40     CRequestProcessor( aFramework, aConnection, 0, NULL ),
    52         CRequestProcessor( aFramework, aConnection, 0, NULL ),
    41     iDpConfig( aDpConfig )
    53         iDpConfig( aDpConfig )
    42     {
    54     {
    43     PRINT( _L( "Operation: CGetFormatCapabilities(0x930A)" ) );
    55     PRINT( _L( "Operation: CGetFormatCapabilities(0x930A)" ) );
    44     }
    56     }
    45 
    57 
    46 // -----------------------------------------------------------------------------
    58 // -----------------------------------------------------------------------------
    47 // CGetFormatCapabilities::ConstructL
    59 // CGetFormatCapabilities::ConstructL
    48 // Second phase constructor
    60 // The second phase constructor
    49 // -----------------------------------------------------------------------------
    61 // -----------------------------------------------------------------------------
    50 //
    62 //
    51 EXPORT_C void CGetFormatCapabilities::ConstructL()
    63 EXPORT_C void CGetFormatCapabilities::ConstructL()
    52     {
    64     {
       
    65     // Do nothing
    53     }
    66     }
    54 
    67 
    55 // -----------------------------------------------------------------------------
    68 // -----------------------------------------------------------------------------
    56 // CGetFormatCapabilities::~CGetFormatCapabilities
    69 // CGetFormatCapabilities::~CGetFormatCapabilities
    57 // Second phase constructor
    70 // Destructor
    58 // -----------------------------------------------------------------------------
    71 // -----------------------------------------------------------------------------
    59 //
    72 //
    60 EXPORT_C CGetFormatCapabilities::~CGetFormatCapabilities()
    73 EXPORT_C CGetFormatCapabilities::~CGetFormatCapabilities()
    61     {
    74     {
    62     delete iCapabilityList;
    75     delete iCapabilityList;
    89                 break;
   102                 break;
    90                 }
   103                 }
    91             }
   104             }
    92         }
   105         }
    93 
   106 
    94     PRINT1( _L( "MM MTP <= CGetFormatCapabilities::CheckRequestL, response = 0x%X" ), response );
   107     PRINT1( _L( "MM MTP <= CGetFormatCapabilities::CheckRequestL, response = 0x%x" ), response );
    95     return response;
   108     return response;
    96     }
   109     }
    97 
   110 
    98 // -----------------------------------------------------------------------------
   111 // -----------------------------------------------------------------------------
    99 // CGetFormatCapabilities::ServiceL
   112 // CGetFormatCapabilities::ServiceL
   106 
   119 
   107     delete iCapabilityList;
   120     delete iCapabilityList;
   108     iCapabilityList = NULL;
   121     iCapabilityList = NULL;
   109 
   122 
   110     iCapabilityList = CMTPTypeFormatCapabilityList::NewL();
   123     iCapabilityList = CMTPTypeFormatCapabilityList::NewL();
   111     iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
   112 
   124 
   113     if ( KMTPFormatsAll == iFormatCode )
   125     if ( KMTPFormatsAll == iFormatCode )
   114         {
   126         {
   115         const RArray<TUint>* formatArray = iDpConfig.GetSupportedFormat();
   127         const RArray<TUint>* formatArray = iDpConfig.GetSupportedFormat();
   116         TInt count = formatArray->Count();
   128         TInt count = formatArray->Count();
   117         for( TInt i = 0; i < count; i++ )
   129         for( TInt i = 0; i < count; i++ )
   118             {
   130             {
   119             PRINT( _L( "MM MTP <> CGetFormatCapabilities::ServiceL, KMTPFormatsAll!!!" ) );
   131             PRINT( _L( "MM MTP <> CGetFormatCapabilities::ServiceL, KMTPFormatsAll!!!" ) );
       
   132 
   120             iFormatCode = ( *formatArray )[i];
   133             iFormatCode = ( *formatArray )[i];
   121             ServiceInterdepentPropDescL();
   134             ServiceOneFormatCapabilitiesL( iFormatCode );
   122             CMTPTypeFormatCapability* frmCap = CMTPTypeFormatCapability::NewL( iFormatCode, iInterdependentPropDesc );
   135             }
   123             const RArray<TUint>* propertiesArray = iDpConfig.GetSupportedPropertiesL( iFormatCode );
   136         }
   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     else
   137         {
   138         ServiceOneFormatCapabilitiesL( iFormatCode );
   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 
   139 
   155     SendDataL( *iCapabilityList );
   140     SendDataL( *iCapabilityList );
   156     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServiceL" ) );
   141     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServiceL" ) );
       
   142     }
       
   143 
       
   144 void CGetFormatCapabilities::ServiceOneFormatCapabilitiesL( TUint aFormatCode )
       
   145     {
       
   146     CMTPTypeInterdependentPropDesc* interdependentPropDesc = iDpConfig.DescriptionUtility()->NewInterdepentPropDescL( iDpConfig, aFormatCode );
       
   147     CMTPTypeFormatCapability* frmCap = CMTPTypeFormatCapability::NewL( aFormatCode, interdependentPropDesc );
       
   148 
       
   149     const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( aFormatCode );
       
   150     TInt num = properties->Count();
       
   151     for ( TInt i = 0; i < num; i++ )
       
   152         {
       
   153         CMTPTypeObjectPropDesc* propertyDesc = ServiceOnePropDescL( ( *properties )[i] );
       
   154         if ( propertyDesc != NULL )
       
   155             {
       
   156             frmCap->AppendL( propertyDesc );
       
   157             }
       
   158         }
       
   159     iCapabilityList->AppendL( frmCap );
   157     }
   160     }
   158 
   161 
   159 // -----------------------------------------------------------------------------
   162 // -----------------------------------------------------------------------------
   160 // CGetFormatCapabilities::ServicePropDescL
   163 // CGetFormatCapabilities::ServicePropDescL
   161 // Get MTPTypeObjectPropDesc according to property code
   164 // Get MTPTypeObjectPropDesc according to property code
   162 // -----------------------------------------------------------------------------
   165 // -----------------------------------------------------------------------------
   163 //
   166 //
   164 CMTPTypeObjectPropDesc* CGetFormatCapabilities::ServicePropDescL( TUint16 aPropCode )
   167 CMTPTypeObjectPropDesc* CGetFormatCapabilities::ServiceOnePropDescL( TUint16 aPropCode )
   165     {
   168     {
   166     PRINT1( _L( "MM MTP => CGetFormatCapabilities::ServicePropDescL, aPropCode = 0x%X" ), aPropCode );
   169     PRINT1( _L( "MM MTP => CGetFormatCapabilities::ServicePropDescL, aPropCode = 0x%x" ), aPropCode );
       
   170 
   167     // implement just like what we did in CGetpropertyDescc::ServiceL
   171     // implement just like what we did in CGetpropertyDescc::ServiceL
   168     CMTPTypeObjectPropDesc* propertyDesc;
   172     CMTPTypeObjectPropDesc* propertyDesc =
   169     CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
   173         iDpConfig.DescriptionUtility()->NewCommonObjectPropertyL( aPropCode );
   170 
   174 
   171     /* Create new PropDesc object to return to device
   175     if ( propertyDesc == NULL )
   172      m - signals only limited supported values - hence these requests require the expected form
   176         propertyDesc = iDpConfig.DescriptionUtility()->NewSpecificPropDescL( iFormatCode, aPropCode );
   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 
   177 
   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 )
   178     if ( propertyDesc != NULL )
   214         {
   179         {
   215         TUint32 groupCode = GetGroupCode( aPropCode );
   180         TUint32 groupCode = iDpConfig.DescriptionUtility()->GetGroupCode( aPropCode );
   216         propertyDesc->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
   181         propertyDesc->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
   217         }
   182         }
   218 
   183 
   219     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServicePropDescL" ) );
   184     PRINT( _L( "MM MTP <= CGetFormatCapabilities::ServicePropDescL" ) );
   220 
   185 
   221     return propertyDesc;
   186     return propertyDesc;
   222     }
   187     }
   223 
   188 
   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
   189 // end of file