mmappcomponents/mmmtpdataprovider/mmmtpdprequestprocessor/src/cgetobjectpropdesc.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:  Implement operation: GetObjectPropDesc
    14 * Description: Request processor which handle common property description
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
       
    19 #include <mtp/cmtptypeobjectpropdesc.h>
    18 #include <mtp/cmtptypeobjectpropdesc.h>
    20 #include <mtp/cmtptypestring.h>
       
    21 
    19 
    22 #include "cgetobjectpropdesc.h"
    20 #include "cgetobjectpropdesc.h"
       
    21 #include "cdescriptionutility.h"
       
    22 #include "mmmtpdpconfig.h"
    23 #include "tmmmtpdppanic.h"
    23 #include "tmmmtpdppanic.h"
    24 #include "mmmtpdplogger.h"
    24 #include "mmmtpdplogger.h"
    25 #include "tobjectdescription.h"
       
    26 #include "mmmtpdpconfig.h"
       
    27 
    25 
    28 _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 // -----------------------------------------------------------------------------
    29 // 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}]?
    27 // CGetObjectPropDesc::NewL
       
    28 // Constructor
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C MMmRequestProcessor* CGetObjectPropDesc::NewL( MMTPDataProviderFramework& aFramework,
       
    32     MMTPConnection& aConnection,
       
    33     MMmMtpDpConfig& aDpConfig )
       
    34     {
       
    35     CGetObjectPropDesc* self = new ( ELeave ) CGetObjectPropDesc( aFramework, aConnection, aDpConfig );
       
    36 
       
    37     CleanupStack::PushL(self);
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop(self);
       
    40 
       
    41     return self;
       
    42     }
    30 
    43 
    31 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    32 // CGetObjectPropDesc::~CGetObjectPropDesc
    45 // CGetObjectPropDesc::~CGetObjectPropDesc
    33 // Destructor
    46 // Destructor
    34 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    35 //
    48 //
    36 EXPORT_C CGetObjectPropDesc::~CGetObjectPropDesc()
    49 EXPORT_C CGetObjectPropDesc::~CGetObjectPropDesc()
    37     {
    50     {
    38     delete iObjectProperty;
    51     delete iPropertyDesc;
       
    52     iPropertyDesc = NULL;
    39     }
    53     }
    40 
    54 
    41 // -----------------------------------------------------------------------------
    55 // -----------------------------------------------------------------------------
    42 // CGetObjectPropDesc::CGetObjectPropDesc
    56 // CGetObjectPropDesc::CGetObjectPropDesc
    43 // Standard c++ constructor
    57 // Standard c++ constructor
    44 // -----------------------------------------------------------------------------
    58 // -----------------------------------------------------------------------------
    45 //
    59 //
    46 EXPORT_C CGetObjectPropDesc::CGetObjectPropDesc( MMTPDataProviderFramework& aFramework,
    60 EXPORT_C CGetObjectPropDesc::CGetObjectPropDesc( MMTPDataProviderFramework& aFramework,
    47     MMTPConnection& aConnection,
    61     MMTPConnection& aConnection,
    48     MMmMtpDpConfig& aDpConfig ) :
    62     MMmMtpDpConfig& aDpConfig ) :
    49     CRequestProcessor( aFramework, aConnection, 0, NULL ),
    63         CRequestProcessor( aFramework, aConnection, 0, NULL ),
    50     iObjectProperty( NULL ),
    64         iDpConfig( aDpConfig ),
    51     iDpConfig( aDpConfig )
    65         iPropertyDesc( NULL )
    52     {
    66     {
    53     PRINT( _L( "Operation: GetObjectPropDesc(0x9802)" ) );
    67     PRINT( _L( "Operation: GetObjectPropDesc(0x9802)" ) );
    54     }
    68     }
    55 
    69 
    56 // -----------------------------------------------------------------------------
    70 // -----------------------------------------------------------------------------
    57 // CGetObjectPropDesc::ConstructL
    71 // CGetObjectPropDesc::ConstructL
    58 // Second phase constructor
    72 // The second phase constructor
    59 // -----------------------------------------------------------------------------
    73 // -----------------------------------------------------------------------------
    60 //
    74 //
    61 EXPORT_C void CGetObjectPropDesc::ConstructL()
    75 EXPORT_C void CGetObjectPropDesc::ConstructL()
    62     {
    76     {
    63 
    77     // Do nothing
    64     }
    78     }
    65 
    79 
    66 // -----------------------------------------------------------------------------
    80 // -----------------------------------------------------------------------------
    67 // CGetObjectPropList::CheckRequestL
    81 // CGetObjectPropList::CheckRequestL
    68 // Verify the reqeust and returns it
    82 // Verify the reqeust and returns it
    69 // -----------------------------------------------------------------------------
    83 // -----------------------------------------------------------------------------
    70 //
    84 //
    71 EXPORT_C TMTPResponseCode CGetObjectPropDesc::CheckRequestL()
    85 EXPORT_C TMTPResponseCode CGetObjectPropDesc::CheckRequestL()
    72     {
    86     {
    73     TMTPResponseCode response = CRequestProcessor::CheckRequestL();
    87     TMTPResponseCode response = CRequestProcessor::CheckRequestL();
       
    88 
       
    89     iPropCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
    90     iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
       
    91     PRINT2( _L( "MM MTP <> CGetObjectPropDesc::CheckPropCode, propCode = 0x%x, iFormatCode = 0x%x" ),
       
    92         iPropCode,
       
    93         iFormatCode );
    74 
    94 
    75     if ( response == EMTPRespCodeOK )
    95     if ( response == EMTPRespCodeOK )
    76         {
    96         {
    77         response = CheckFormatL();
    97         response = CheckFormatL();
    78         }
    98         }
    85     PRINT1( _L("MM MTP <= CGetObjectPropDesc::CheckRequestL response = 0x%x"), response );
   105     PRINT1( _L("MM MTP <= CGetObjectPropDesc::CheckRequestL response = 0x%x"), response );
    86     return response;
   106     return response;
    87     }
   107     }
    88 
   108 
    89 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
    90 // CGetObjectPropDesc::ServiceL
       
    91 // GetObjectPropDesc request handler
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 EXPORT_C void CGetObjectPropDesc::ServiceL()
       
    95     {
       
    96     PRINT( _L( "MM MTP => CGetObjectPropDesc::ServiceL" ) );
       
    97     delete iObjectProperty;
       
    98     iObjectProperty = NULL;
       
    99 
       
   100     TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
       
   101     iFormatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
       
   102     PRINT2( _L( "MM MTP <> CGetObjectPropDesc::ServiceL propCode = 0x%x, iFormatCode = 0x%x" ),
       
   103             propCode,
       
   104             iFormatCode );
       
   105 
       
   106     CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
       
   107 
       
   108     /* Create new PropDesc object to return to device
       
   109      m - signals only limited supported values - hence these requests require the expected form
       
   110      variable to be passed into the NewL contstuctor as well */
       
   111     switch ( propCode )
       
   112         {
       
   113         case EMTPObjectPropCodeStorageID: // Storage ID
       
   114         case EMTPObjectPropCodeObjectFormat: // Format Code
       
   115         case EMTPObjectPropCodeObjectSize: // Object Size
       
   116         case EMTPObjectPropCodeParentObject: // Parent Object
       
   117         case EMTPObjectPropCodePersistentUniqueObjectIdentifier: // Unique Object Identifier
       
   118         case EMTPObjectPropCodeName: // Name
       
   119         case EMTPObjectPropCodeDateAdded: // Date Added
       
   120             iObjectProperty = CMTPTypeObjectPropDesc::NewL( propCode );
       
   121             break;
       
   122 
       
   123             // Protection Status (m)
       
   124         case EMTPObjectPropCodeProtectionStatus:
       
   125             ServiceProtectionStatusL();
       
   126             break;
       
   127 
       
   128             // FileName
       
   129         case EMTPObjectPropCodeObjectFileName:
       
   130             ServiceFileNameL();
       
   131             break;
       
   132 
       
   133             // Consumable (m)
       
   134         case EMTPObjectPropCodeNonConsumable:
       
   135             ServiceNonConsumableL();
       
   136             break;
       
   137 
       
   138         case EMTPObjectPropCodeDateModified: // Date Modified
       
   139         case EMTPObjectPropCodeDateCreated: // Date Created
       
   140             propertyInfo.iDataType     = EMTPTypeString;
       
   141             propertyInfo.iFormFlag     = CMTPTypeObjectPropDesc::EDateTimeForm;
       
   142             propertyInfo.iGetSet       = CMTPTypeObjectPropDesc::EReadOnly;
       
   143             iObjectProperty = CMTPTypeObjectPropDesc::NewL( propCode, propertyInfo, NULL);
       
   144             break;
       
   145 
       
   146             // Error - Should be caught by CheckRequestL
       
   147         default:
       
   148             ServiceSpecificObjectPropertyL( propCode );
       
   149             break;
       
   150         }
       
   151 
       
   152     // Set group code
       
   153     TUint32 groupCode = GetGroupCode( propCode );
       
   154     PRINT1( _L("MM MTP <> CGetObjectPropDesc::ServiceL, groupCode = 0x%x"), groupCode );
       
   155     iObjectProperty->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
       
   156 
       
   157     __ASSERT_DEBUG( iObjectProperty, Panic( EMmMTPDpObjectPropertyNull ) );
       
   158 
       
   159     SendDataL( *iObjectProperty );
       
   160 
       
   161     PRINT( _L( "MM MTP <= CGetObjectPropDesc::ServiceL" ) );
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CGetObjectPropDesc::ServiceProtectionStatusL
       
   166 // Create list of possible protection status and create new ObjectPropDesc
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void CGetObjectPropDesc::ServiceProtectionStatusL()
       
   170     {
       
   171     CMTPTypeObjectPropDescEnumerationForm* expectedForm =
       
   172         CMTPTypeObjectPropDescEnumerationForm::NewL( EMTPTypeUINT16 );
       
   173     CleanupStack::PushL( expectedForm ); // + expectedForm
       
   174 
       
   175     TUint16 values[] =
       
   176         {
       
   177         EMTPProtectionNoProtection,
       
   178         EMTPProtectionReadOnly
       
   179         };
       
   180 
       
   181     TInt numValues = sizeof ( values ) / sizeof ( values[0] ) ;
       
   182     for ( TInt i = 0; i < numValues; i++ )
       
   183         {
       
   184         TMTPTypeUint16 data( values[i] );
       
   185         expectedForm->AppendSupportedValueL( data );
       
   186         }
       
   187 
       
   188     // Althrough iObjectProperty is released in ServiceL(),
       
   189     // release it here maybe a more safer way :)
       
   190     if ( iObjectProperty != NULL )
       
   191         {
       
   192         delete iObjectProperty;
       
   193         iObjectProperty = NULL;
       
   194         }
       
   195 
       
   196     iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeProtectionStatus, *expectedForm );
       
   197     CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CGetObjectPropDesc::ServiceFileNameL()
       
   202 // Create Regular expression for a file name and create new ObjectPropDesc
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CGetObjectPropDesc::ServiceFileNameL()
       
   206     {
       
   207     CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form
       
   208 
       
   209     // Althrough iObjectProperty is released in ServiceL(),
       
   210     // release it here maybe a more safer way
       
   211     if ( iObjectProperty != NULL )
       
   212         {
       
   213         delete iObjectProperty;
       
   214         iObjectProperty = NULL;
       
   215         }
       
   216 
       
   217     iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName,
       
   218         CMTPTypeObjectPropDesc::ERegularExpressionForm,
       
   219         form );
       
   220 
       
   221     CleanupStack::PopAndDestroy( form ); // - form
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CGetObjectPropDesc::ServiceNonConsumableL
       
   226 // Create list of possible nonConsumable values and create new ObjectPropDesc
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void CGetObjectPropDesc::ServiceNonConsumableL()
       
   230     {
       
   231     CMTPTypeObjectPropDescEnumerationForm* expectedForm =
       
   232         CMTPTypeObjectPropDescEnumerationForm::NewL( EMTPTypeUINT8 );
       
   233     CleanupStack::PushL( expectedForm ); // + expectedForm
       
   234     TUint8 values[] =
       
   235         {
       
   236         EMTPConsumable,
       
   237         EMTPNonConsumable
       
   238         };
       
   239 
       
   240     TInt numValues = sizeof ( values ) / sizeof ( values[0] );
       
   241     for ( TInt i = 0; i < numValues; i++ )
       
   242         {
       
   243         TMTPTypeUint8 data( values[i] );
       
   244         expectedForm->AppendSupportedValueL( data );
       
   245         }
       
   246 
       
   247     // Althrough iObjectProperty is released in ServiceL(),
       
   248     // release it here maybe a more safer way :)
       
   249     if ( iObjectProperty != NULL )
       
   250         {
       
   251         delete iObjectProperty;
       
   252         iObjectProperty = NULL;
       
   253         }
       
   254 
       
   255     CMTPTypeObjectPropDesc::TPropertyInfo propertyInfo;
       
   256     propertyInfo.iDataType = EMTPTypeUINT8;
       
   257     propertyInfo.iFormFlag = CMTPTypeObjectPropDesc::EEnumerationForm;
       
   258     propertyInfo.iGetSet = CMTPTypeObjectPropDesc::EReadOnly;
       
   259     iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeNonConsumable,
       
   260         propertyInfo,
       
   261         expectedForm );
       
   262     CleanupStack::PopAndDestroy( expectedForm ); // - expectedForm
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CGetObjectPropList::CheckFormatL
   110 // CGetObjectPropList::CheckFormatL
   267 // Ensures the object format operation parameter is valid
   111 // Ensure the object format operation parameter is valid
   268 // -----------------------------------------------------------------------------
   112 // -----------------------------------------------------------------------------
   269 //
   113 //
   270 TMTPResponseCode CGetObjectPropDesc::CheckFormatL() const
   114 TMTPResponseCode CGetObjectPropDesc::CheckFormatL() const
   271     {
   115     {
   272     TMTPResponseCode response = EMTPRespCodeOK;
   116     TMTPResponseCode response = EMTPRespCodeInvalidObjectFormatCode;
   273 
   117 
   274     TUint32 formatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
   118     if( iFormatCode != KMTPFormatsAll )
   275     PRINT1( _L( "MM MTP <> CGetObjectPropDesc::CheckFormatL formatCode = 0x%x" ), formatCode );
       
   276 
       
   277     if( formatCode != 0)
       
   278         {
   119         {
   279         response = EMTPRespCodeInvalidObjectFormatCode;
       
   280 
       
   281         const RArray<TUint>* format = iDpConfig.GetSupportedFormat();
   120         const RArray<TUint>* format = iDpConfig.GetSupportedFormat();
   282         TInt count = format->Count();
   121         TInt count = format->Count();
   283 
   122 
   284         for ( TInt i = 0; i < count; i++ )
   123         for ( TInt i = 0; i < count; i++ )
   285             {
   124             {
   286             if ( formatCode == (*format)[i] )
   125             if ( iFormatCode == (*format)[i] )
   287                 {
   126                 {
   288                 response = EMTPRespCodeOK;
   127                 response = EMTPRespCodeOK;
   289                 break;
   128                 break;
   290                 }
   129                 }
   291             }
   130             }
   294     return response;
   133     return response;
   295     }
   134     }
   296 
   135 
   297 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   298 // CGetObjectPropDesc::CheckPropCodeL
   137 // CGetObjectPropDesc::CheckPropCodeL
   299 // Ensures the object prop code operation parameter is valid
   138 // Ensure the object prop code operation parameter is valid
   300 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   301 //
   140 //
   302 TMTPResponseCode CGetObjectPropDesc::CheckPropCodeL() const
   141 TMTPResponseCode CGetObjectPropDesc::CheckPropCodeL() const
   303     {
   142     {
   304     TMTPResponseCode response = EMTPRespCodeOK;
   143     TMTPResponseCode response = EMTPRespCodeInvalidObjectPropCode;
   305 
   144 
   306     TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter1 );
   145     if ( iPropCode != KMTPNotSpecified32 && iPropCode != KMTPObjectPropCodeAll )
   307     PRINT1( _L( "MM MTP <> CGetObjectPropDesc::CheckPropCode, propCode = 0x%x" ), propCode );
       
   308 
       
   309     if ( propCode == 0 )
       
   310         {
   146         {
   311         // A propCode of 0 means specification by group (which is not supported)
   147         const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( iFormatCode );
   312         response = EMTPRespCodeSpecificationByGroupUnsupported;
       
   313         }
       
   314     else
       
   315         {
       
   316         TUint32 formatCode  = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
       
   317 
       
   318         const RArray<TUint>* properties = NULL;
       
   319         if ( formatCode == KMTPFormatsAll )
       
   320             properties= iDpConfig.GetAllSupportedProperties();
       
   321         else
       
   322             properties = iDpConfig.GetSupportedPropertiesL( formatCode );
       
   323 
   148 
   324         const TInt count = properties->Count();
   149         const TInt count = properties->Count();
   325         TInt i = 0;
   150         for( TInt i = 0; i < count; i++ )
   326         for( i = 0; i < count; i++ )
       
   327             {
   151             {
   328             if ( (*properties)[i] == propCode )
   152             if ( (*properties)[i] == iPropCode )
   329                 {
   153                 {
       
   154                 response = EMTPRespCodeOK;
   330                 break;
   155                 break;
   331                 }
   156                 }
   332             }
       
   333 
       
   334         if ( i == count )
       
   335             {
       
   336             response = EMTPRespCodeInvalidObjectPropCode;
       
   337             }
   157             }
   338         }
   158         }
   339 
   159 
   340     return response;
   160     return response;
   341     }
   161     }
   342 
   162 
   343 TUint32 CGetObjectPropDesc::GetGroupCode( TUint16 aPropCode )
   163 // -----------------------------------------------------------------------------
       
   164 // CGetObjectPropDesc::ServiceL
       
   165 // GetObjectPropDesc request handler
       
   166 // -----------------------------------------------------------------------------
       
   167 //
       
   168 EXPORT_C void CGetObjectPropDesc::ServiceL()
   344     {
   169     {
   345     TInt count = sizeof( KPropGroupMapTable );
   170     PRINT( _L( "MM MTP => CGetObjectPropDesc::ServiceL" ) );
   346     // TODO: if need to refine the search approach to improve performance
   171 
   347     for( TInt i = 0; i < count; i++ )
   172     delete iPropertyDesc;
   348         {
   173     iPropertyDesc = NULL;
   349         if ( aPropCode == KPropGroupMapTable[i].iPropCode )
   174 
   350             return KPropGroupMapTable[i].iGroupCode;
   175     iPropertyDesc = iDpConfig.DescriptionUtility()->NewCommonObjectPropertyL( iPropCode );
   351         }
   176 
   352     return EGroupCodeNotDefined;
   177     // if iPropertyDesc == NULL, iPropCode is not common property but dp specific one.
       
   178     if( iPropertyDesc == NULL )
       
   179         iPropertyDesc = iDpConfig.DescriptionUtility()->NewSpecificPropDescL( iFormatCode, iPropCode );
       
   180 
       
   181     __ASSERT_DEBUG( iPropertyDesc, Panic( EMmMTPDpObjectPropertyNull ) );
       
   182 
       
   183     // Set group code
       
   184     TUint32 groupCode = iDpConfig.DescriptionUtility()->GetGroupCode( iPropCode );
       
   185     PRINT1( _L("MM MTP <> CGetObjectPropDesc::ServiceL, groupCode = 0x%x"), groupCode );
       
   186     iPropertyDesc->SetUint32L( CMTPTypeObjectPropDesc::EGroupCode, groupCode );
       
   187 
       
   188     SendDataL( *iPropertyDesc );
       
   189 
       
   190     PRINT( _L( "MM MTP <= CGetObjectPropDesc::ServiceL" ) );
   353     }
   191     }
   354 
   192 
   355 // end of file
   193 // end of file