mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetobjectpropdesc.cpp
changeset 25 d881023c13eb
parent 0 a2952bb97e68
child 34 e257e2b6459d
--- a/mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetobjectpropdesc.cpp	Fri Apr 16 15:28:14 2010 +0300
+++ b/mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetobjectpropdesc.cpp	Mon May 03 12:58:40 2010 +0300
@@ -11,22 +11,35 @@
 *
 * Contributors:
 *
-* Description:  Implement operation: GetObjectPropDesc
+* Description: Request processor which handle common property description
 *
 */
 
-
 #include <mtp/cmtptypeobjectpropdesc.h>
-#include <mtp/cmtptypestring.h>
 
 #include "cgetobjectpropdesc.h"
+#include "cdescriptionutility.h"
+#include "mmmtpdpconfig.h"
 #include "tmmmtpdppanic.h"
 #include "mmmtpdplogger.h"
-#include "tobjectdescription.h"
-#include "mmmtpdpconfig.h"
 
-_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}]?" );
-// RegEx is [a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~][a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~ ]{0, 7}\.[[a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~][a-zA-Z!#\$%&'\(\)\-0-9@\^_\`\{\}\~ ]{0, 2}]?
+// -----------------------------------------------------------------------------
+// CGetObjectPropDesc::NewL
+// Constructor
+// -----------------------------------------------------------------------------
+//
+EXPORT_C MMmRequestProcessor* CGetObjectPropDesc::NewL( MMTPDataProviderFramework& aFramework,
+    MMTPConnection& aConnection,
+    MMmMtpDpConfig& aDpConfig )
+    {
+    CGetObjectPropDesc* self = new ( ELeave ) CGetObjectPropDesc( aFramework, aConnection, aDpConfig );
+
+    CleanupStack::PushL(self);
+    self->ConstructL();
+    CleanupStack::Pop(self);
+
+    return self;
+    }
 
 // -----------------------------------------------------------------------------
 // CGetObjectPropDesc::~CGetObjectPropDesc
@@ -35,7 +48,8 @@
 //
 EXPORT_C CGetObjectPropDesc::~CGetObjectPropDesc()
     {
-    delete iObjectProperty;
+    delete iPropertyDesc;
+    iPropertyDesc = NULL;
     }
 
 // -----------------------------------------------------------------------------
@@ -46,21 +60,21 @@
 EXPORT_C CGetObjectPropDesc::CGetObjectPropDesc( MMTPDataProviderFramework& aFramework,
     MMTPConnection& aConnection,
     MMmMtpDpConfig& aDpConfig ) :
-    CRequestProcessor( aFramework, aConnection, 0, NULL ),
-    iObjectProperty( NULL ),
-    iDpConfig( aDpConfig )
+        CRequestProcessor( aFramework, aConnection, 0, NULL ),
+        iDpConfig( aDpConfig ),
+        iPropertyDesc( NULL )
     {
     PRINT( _L( "Operation: GetObjectPropDesc(0x9802)" ) );
     }
 
 // -----------------------------------------------------------------------------
 // CGetObjectPropDesc::ConstructL
-// Second phase constructor
+// The second phase constructor
 // -----------------------------------------------------------------------------
 //
 EXPORT_C void CGetObjectPropDesc::ConstructL()
     {
-
+    // Do nothing
     }
 
 // -----------------------------------------------------------------------------
@@ -72,6 +86,12 @@
     {
     TMTPResponseCode response = CRequestProcessor::CheckRequestL();
 
+    iPropCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
+    iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
+    PRINT2( _L( "MM MTP <> CGetObjectPropDesc::CheckPropCode, propCode = 0x%x, iFormatCode = 0x%x" ),
+        iPropCode,
+        iFormatCode );
+
     if ( response == EMTPRespCodeOK )
         {
         response = CheckFormatL();
@@ -87,203 +107,22 @@
     }
 
 // -----------------------------------------------------------------------------
-// CGetObjectPropDesc::ServiceL
-// GetObjectPropDesc request handler
-// -----------------------------------------------------------------------------
-//
-EXPORT_C void CGetObjectPropDesc::ServiceL()
-    {
-    PRINT( _L( "MM MTP => CGetObjectPropDesc::ServiceL" ) );
-    delete iObjectProperty;
-    iObjectProperty = NULL;
-
-    TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
-    iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
-    PRINT2( _L( "MM MTP <> CGetObjectPropDesc::ServiceL propCode = 0x%x, iFormatCode = 0x%x" ),
-            propCode,
-            iFormatCode );
-
-    CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
-
-    /* Create new PropDesc object to return to device
-     m - signals only limited supported values - hence these requests require the expected form
-     variable to be passed into the NewL contstuctor as well */
-    switch ( propCode )
-        {
-        case EMTPObjectPropCodeStorageID: // Storage ID
-        case EMTPObjectPropCodeObjectFormat: // Format Code
-        case EMTPObjectPropCodeObjectSize: // Object Size
-        case EMTPObjectPropCodeParentObject: // Parent Object
-        case EMTPObjectPropCodePersistentUniqueObjectIdentifier: // Unique Object Identifier
-        case EMTPObjectPropCodeName: // Name
-        case EMTPObjectPropCodeDateAdded: // Date Added
-            iObjectProperty = CMTPTypeObjectPropDesc::NewL( propCode );
-            break;
-
-            // Protection Status (m)
-        case EMTPObjectPropCodeProtectionStatus:
-            ServiceProtectionStatusL();
-            break;
-
-            // FileName
-        case EMTPObjectPropCodeObjectFileName:
-            ServiceFileNameL();
-            break;
-
-            // Consumable (m)
-        case EMTPObjectPropCodeNonConsumable:
-            ServiceNonConsumableL();
-            break;
-
-        case EMTPObjectPropCodeDateModified: // Date Modified
-        case EMTPObjectPropCodeDateCreated: // Date Created
-            propertyInfo.iDataType     = EMTPTypeString;
-            propertyInfo.iFormFlag     = CMTPTypeObjectPropDesc::EDateTimeForm;
-            propertyInfo.iGetSet       = CMTPTypeObjectPropDesc::EReadOnly;
-            iObjectProperty = CMTPTypeObjectPropDesc::NewL( propCode, propertyInfo, NULL);
-            break;
-
-            // Error - Should be caught by CheckRequestL
-        default:
-            ServiceSpecificObjectPropertyL( propCode );
-            break;
-        }
-
-    // Set group code
-    TUint32 groupCode = GetGroupCode( propCode );
-    PRINT1( _L("MM MTP <> CGetObjectPropDesc::ServiceL, groupCode = 0x%x"), groupCode );
-    iObjectProperty->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
-
-    __ASSERT_DEBUG( iObjectProperty, Panic( EMmMTPDpObjectPropertyNull ) );
-
-    SendDataL( *iObjectProperty );
-
-    PRINT( _L( "MM MTP <= CGetObjectPropDesc::ServiceL" ) );
-    }
-
-// -----------------------------------------------------------------------------
-// CGetObjectPropDesc::ServiceProtectionStatusL
-// Create list of possible protection status and create new ObjectPropDesc
-// -----------------------------------------------------------------------------
-//
-void CGetObjectPropDesc::ServiceProtectionStatusL()
-    {
-    CMTPTypeObjectPropDescEnumerationForm* expectedForm =
-        CMTPTypeObjectPropDescEnumerationForm::NewL( EMTPTypeUINT16 );
-    CleanupStack::PushL( expectedForm ); // + expectedForm
-
-    TUint16 values[] =
-        {
-        EMTPProtectionNoProtection,
-        EMTPProtectionReadOnly
-        };
-
-    TInt numValues = sizeof ( values ) / sizeof ( values[0] ) ;
-    for ( TInt i = 0; i < numValues; i++ )
-        {
-        TMTPTypeUint16 data( values[i] );
-        expectedForm->AppendSupportedValueL( data );
-        }
-
-    // Althrough iObjectProperty is released in ServiceL(),
-    // release it here maybe a more safer way :)
-    if ( iObjectProperty != NULL )
-        {
-        delete iObjectProperty;
-        iObjectProperty = NULL;
-        }
-
-    iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeProtectionStatus, *expectedForm );
-    CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
-    }
-
-// -----------------------------------------------------------------------------
-// CGetObjectPropDesc::ServiceFileNameL()
-// Create Regular expression for a file name and create new ObjectPropDesc
-// -----------------------------------------------------------------------------
-//
-void CGetObjectPropDesc::ServiceFileNameL()
-    {
-    CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form
-
-    // Althrough iObjectProperty is released in ServiceL(),
-    // release it here maybe a more safer way
-    if ( iObjectProperty != NULL )
-        {
-        delete iObjectProperty;
-        iObjectProperty = NULL;
-        }
-
-    iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName,
-        CMTPTypeObjectPropDesc::ERegularExpressionForm,
-        form );
-
-    CleanupStack::PopAndDestroy( form ); // - form
-    }
-
-// -----------------------------------------------------------------------------
-// CGetObjectPropDesc::ServiceNonConsumableL
-// Create list of possible nonConsumable values and create new ObjectPropDesc
-// -----------------------------------------------------------------------------
-//
-void CGetObjectPropDesc::ServiceNonConsumableL()
-    {
-    CMTPTypeObjectPropDescEnumerationForm* expectedForm =
-        CMTPTypeObjectPropDescEnumerationForm::NewL( EMTPTypeUINT8 );
-    CleanupStack::PushL( expectedForm ); // + expectedForm
-    TUint8 values[] =
-        {
-        EMTPConsumable,
-        EMTPNonConsumable
-        };
-
-    TInt numValues = sizeof ( values ) / sizeof ( values[0] );
-    for ( TInt i = 0; i < numValues; i++ )
-        {
-        TMTPTypeUint8 data( values[i] );
-        expectedForm->AppendSupportedValueL( data );
-        }
-
-    // Althrough iObjectProperty is released in ServiceL(),
-    // release it here maybe a more safer way :)
-    if ( iObjectProperty != NULL )
-        {
-        delete iObjectProperty;
-        iObjectProperty = NULL;
-        }
-
-    CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
-    propertyInfo.iDataType = EMTPTypeUINT8;
-    propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::EEnumerationForm;
-    propertyInfo.iGetSet = CMTPTypeObjectPropDesc::EReadOnly;
-    iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeNonConsumable,
-        propertyInfo,
-        expectedForm );
-    CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
-    }
-
-// -----------------------------------------------------------------------------
 // CGetObjectPropList::CheckFormatL
-// Ensures the object format operation parameter is valid
+// Ensure the object format operation parameter is valid
 // -----------------------------------------------------------------------------
 //
 TMTPResponseCode CGetObjectPropDesc::CheckFormatL() const
     {
-    TMTPResponseCode response = EMTPRespCodeOK;
-
-    TUint32 formatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
-    PRINT1( _L( "MM MTP <> CGetObjectPropDesc::CheckFormatL formatCode = 0x%x" ), formatCode );
+    TMTPResponseCode response = EMTPRespCodeInvalidObjectFormatCode;
 
-    if( formatCode != 0)
+    if( iFormatCode != KMTPFormatsAll )
         {
-        response = EMTPRespCodeInvalidObjectFormatCode;
-
         const RArray<TUint>* format = iDpConfig.GetSupportedFormat();
         TInt count = format->Count();
 
         for ( TInt i = 0; i < count; i++ )
             {
-            if ( formatCode == (*format)[i] )
+            if ( iFormatCode == (*format)[i] )
                 {
                 response = EMTPRespCodeOK;
                 break;
@@ -296,60 +135,59 @@
 
 // -----------------------------------------------------------------------------
 // CGetObjectPropDesc::CheckPropCodeL
-// Ensures the object prop code operation parameter is valid
+// Ensure the object prop code operation parameter is valid
 // -----------------------------------------------------------------------------
 //
 TMTPResponseCode CGetObjectPropDesc::CheckPropCodeL() const
     {
-    TMTPResponseCode response = EMTPRespCodeOK;
+    TMTPResponseCode response = EMTPRespCodeInvalidObjectPropCode;
 
-    TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
-    PRINT1( _L( "MM MTP <> CGetObjectPropDesc::CheckPropCode, propCode = 0x%x" ), propCode );
-
-    if ( propCode == 0 )
+    if ( iPropCode != KMTPNotSpecified32 && iPropCode != KMTPObjectPropCodeAll )
         {
-        // A propCode of 0 means specification by group (which is not supported)
-        response = EMTPRespCodeSpecificationByGroupUnsupported;
-        }
-    else
-        {
-        TUint32 formatCode  = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
-
-        const RArray<TUint>* properties = NULL;
-        if ( formatCode == KMTPFormatsAll )
-            properties= iDpConfig.GetAllSupportedProperties();
-        else
-            properties = iDpConfig.GetSupportedPropertiesL( formatCode );
+        const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( iFormatCode );
 
         const TInt count = properties->Count();
-        TInt i = 0;
-        for( i = 0; i < count; i++ )
+        for( TInt i = 0; i < count; i++ )
             {
-            if ( (*properties)[i] == propCode )
+            if ( (*properties)[i] == iPropCode )
                 {
+                response = EMTPRespCodeOK;
                 break;
                 }
             }
-
-        if ( i == count )
-            {
-            response = EMTPRespCodeInvalidObjectPropCode;
-            }
         }
 
     return response;
     }
 
-TUint32 CGetObjectPropDesc::GetGroupCode( TUint16 aPropCode )
+// -----------------------------------------------------------------------------
+// CGetObjectPropDesc::ServiceL
+// GetObjectPropDesc request handler
+// -----------------------------------------------------------------------------
+//
+EXPORT_C void CGetObjectPropDesc::ServiceL()
     {
-    TInt count = sizeof( KPropGroupMapTable );
-    // TODO: if need to refine the search approach to improve performance
-    for( TInt i = 0; i < count; i++ )
-        {
-        if ( aPropCode == KPropGroupMapTable[i].iPropCode )
-            return KPropGroupMapTable[i].iGroupCode;
-        }
-    return EGroupCodeNotDefined;
+    PRINT( _L( "MM MTP => CGetObjectPropDesc::ServiceL" ) );
+
+    delete iPropertyDesc;
+    iPropertyDesc = NULL;
+
+    iPropertyDesc = iDpConfig.DescriptionUtility()->NewCommonObjectPropertyL( iPropCode );
+
+    // if iPropertyDesc == NULL, iPropCode is not common property but dp specific one.
+    if( iPropertyDesc == NULL )
+        iPropertyDesc = iDpConfig.DescriptionUtility()->NewSpecificPropDescL( iFormatCode, iPropCode );
+
+    __ASSERT_DEBUG( iPropertyDesc, Panic( EMmMTPDpObjectPropertyNull ) );
+
+    // Set group code
+    TUint32 groupCode = iDpConfig.DescriptionUtility()->GetGroupCode( iPropCode );
+    PRINT1( _L("MM MTP <> CGetObjectPropDesc::ServiceL, groupCode = 0x%x"), groupCode );
+    iPropertyDesc->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
+
+    SendDataL( *iPropertyDesc );
+
+    PRINT( _L( "MM MTP <= CGetObjectPropDesc::ServiceL" ) );
     }
 
 // end of file