mtpdataproviders/mtppictbridgedp/src/cmtppictbridgedpgetobjectproplist.cpp
changeset 0 d0791faffa3f
child 11 4843bb5893b6
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 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 #include <mtp/cmtptypestring.h>
       
    18 #include <mtp/mmtpobjectmgr.h>
       
    19 #include <mtp/cmtptypeobjectproplist.h>
       
    20 #include <mtp/cmtptypearray.h>
       
    21 #include <mtp/mmtpdataproviderframework.h>
       
    22 #include <mtp/cmtpobjectmetadata.h>
       
    23 #include "cmtppictbridgedpgetobjectproplist.h"
       
    24 #include "mtppictbridgedppanic.h"
       
    25 #include "mtppictbridgedpconst.h"
       
    26 #include "cptpserver.h"
       
    27 
       
    28 /**
       
    29 Two-phase construction method
       
    30 @param aFramework   The data provider framework
       
    31 @param aConnection  The connection object
       
    32 @param aDataProvider  The pictbridge Dp
       
    33 */
       
    34 MMTPRequestProcessor* CMTPPictBridgeDpGetObjectPropList::NewL(
       
    35     MMTPDataProviderFramework& aFramework,
       
    36     MMTPConnection& aConnection,
       
    37     CMTPPictBridgeDataProvider& aDataProvider )
       
    38     {  
       
    39     CMTPPictBridgeDpGetObjectPropList* self = new (ELeave) CMTPPictBridgeDpGetObjectPropList(aFramework, aConnection, aDataProvider);
       
    40     CleanupStack::PushL( self );
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop( self );
       
    43     return self;
       
    44     }
       
    45 
       
    46 /**
       
    47 Destructor
       
    48 */
       
    49 CMTPPictBridgeDpGetObjectPropList::~CMTPPictBridgeDpGetObjectPropList()
       
    50     {
       
    51     __FLOG(_L8("+~CMTPPictBridgeDpGetObjectPropList()"));
       
    52     
       
    53     delete iHandles;
       
    54     delete iPropertyList;
       
    55     iDpSingletons.Close();
       
    56     delete iObjMeta;
       
    57     
       
    58     __FLOG(_L8("-~CMTPPictBridgeDpGetObjectPropList()"));
       
    59     __FLOG_CLOSE;
       
    60     }
       
    61 
       
    62 /**
       
    63 Standard c++ constructor
       
    64 */  
       
    65 CMTPPictBridgeDpGetObjectPropList::CMTPPictBridgeDpGetObjectPropList(
       
    66     MMTPDataProviderFramework& aFramework,
       
    67     MMTPConnection& aConnection,
       
    68     CMTPPictBridgeDataProvider& aDataProvider ) :
       
    69     CMTPRequestProcessor(aFramework, aConnection, 0, NULL ),
       
    70     iPictBridgeDP(aDataProvider)
       
    71     {
       
    72     }
       
    73 
       
    74 /**
       
    75 ConstructL
       
    76 */      
       
    77 void CMTPPictBridgeDpGetObjectPropList::ConstructL()
       
    78     {
       
    79     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    80     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::ConstructL()"));
       
    81     
       
    82 	iDpSingletons.OpenL(iFramework);
       
    83     iPropertyList = CMTPTypeObjectPropList::NewL();
       
    84 	iObjMeta = CMTPObjectMetaData::NewL();
       
    85 	
       
    86 	__FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::ConstructL()"));
       
    87     }
       
    88 
       
    89 /**
       
    90 ServiceL
       
    91 */  
       
    92 void CMTPPictBridgeDpGetObjectPropList::ServiceL()
       
    93     {
       
    94     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::ServiceL()"));
       
    95     
       
    96     GetObjectHandlesL();
       
    97     TInt numObjects(iHandles->NumElements());
       
    98     TUint32 propCode( Request().Uint32( TMTPTypeRequest::ERequestParameter3 ));
       
    99     // get group code
       
   100 	TUint32 groupCode(Request().Uint32(TMTPTypeRequest::ERequestParameter4));
       
   101 	TBool isDiscoveryFile( EFalse );
       
   102 	
       
   103     for ( TInt i(0); i < numObjects; i++ )
       
   104         {
       
   105         TUint32 handle( iHandles->ElementUint(i) );
       
   106         iFramework.ObjectMgr().ObjectL(handle, *iObjMeta);
       
   107         TFileName file(iObjMeta->DesC(CMTPObjectMetaData::ESuid));
       
   108         TInt ret = iFramework.Fs().Entry(iObjMeta->DesC(CMTPObjectMetaData::ESuid), iFileEntry);
       
   109         if (( ret != KErrNone )&& ( handle == iPictBridgeDP.PtpServer()->DeviceDiscoveryHandle() ))
       
   110             {
       
   111             isDiscoveryFile = ETrue;
       
   112             }
       
   113         else
       
   114             {
       
   115             User::Leave( ret );
       
   116             }
       
   117         
       
   118         if ( KMaxTUint == propCode )
       
   119             {
       
   120             ServiceAllPropertiesL( handle, isDiscoveryFile );
       
   121             }
       
   122         else if ( 0 == propCode )
       
   123             {
       
   124             ServiceGroupPropertiesL( handle, groupCode, isDiscoveryFile );
       
   125             }
       
   126         else 
       
   127             {
       
   128             ServiceOneObjectPropertyL( handle, propCode, isDiscoveryFile );
       
   129             } 
       
   130         isDiscoveryFile = EFalse;
       
   131         }
       
   132     SendDataL( *iPropertyList );
       
   133     
       
   134     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::ServiceL()"));
       
   135     }
       
   136 
       
   137 /**
       
   138 CheckRequestL
       
   139 */
       
   140 TMTPResponseCode CMTPPictBridgeDpGetObjectPropList::CheckRequestL()
       
   141     {
       
   142     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::CheckRequestL()"));
       
   143     
       
   144     TMTPResponseCode result = CMTPRequestProcessor::CheckRequestL();
       
   145 
       
   146     if ( result == EMTPRespCodeOK )
       
   147         {
       
   148         result = CheckPropCode();
       
   149         }
       
   150     if ( result == EMTPRespCodeOK )
       
   151         {
       
   152         result = CheckDepth();
       
   153         }
       
   154     
       
   155     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::CheckRequestL()"));
       
   156     return result;
       
   157     }
       
   158 
       
   159 /**
       
   160 CheckPropCode
       
   161 */
       
   162 TMTPResponseCode CMTPPictBridgeDpGetObjectPropList::CheckPropCode() const
       
   163     {
       
   164     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::CheckPropCode()"));
       
   165     
       
   166     TMTPResponseCode response = EMTPRespCodeOK;
       
   167     TUint32 formatCode = Request().Uint32( TMTPTypeRequest::ERequestParameter2 );
       
   168     TUint32 propCode = Request().Uint32( TMTPTypeRequest::ERequestParameter3 );
       
   169 
       
   170     if(( propCode != KMaxTUint ) && ( propCode != 0 ))
       
   171         {
       
   172          const TInt count = sizeof(KMTPPictBridgeDpSupportedProperties) / sizeof(KMTPPictBridgeDpSupportedProperties[0]);
       
   173          TInt i(0);
       
   174          for( i = 0; i < count; i++ )
       
   175            {
       
   176            if( KMTPPictBridgeDpSupportedProperties[i] == propCode )
       
   177              {
       
   178              break;
       
   179              }
       
   180            }
       
   181          if( i == count )
       
   182            {
       
   183            response = EMTPRespCodeInvalidObjectPropCode;
       
   184            }
       
   185         }
       
   186     
       
   187     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::CheckPropCode()"));
       
   188     return response;
       
   189     }
       
   190 
       
   191 /**
       
   192 CheckDepth
       
   193 */
       
   194 TMTPResponseCode CMTPPictBridgeDpGetObjectPropList::CheckDepth() const
       
   195     {
       
   196     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::CheckDepth()"));
       
   197     TMTPResponseCode response = EMTPRespCodeSpecificationByDepthUnsupported;
       
   198 
       
   199     // We either support no depth at all, or 1 depth or (0xFFFFFFFF) with objecthandle as 0x00000000
       
   200     TUint32 handle( Request().Uint32(TMTPTypeRequest::ERequestParameter1 ));
       
   201     TUint32 depth( Request().Uint32(TMTPTypeRequest::ERequestParameter5 ));
       
   202 
       
   203     if ((0 == depth ) || ( 1 == depth ) ||
       
   204             ( KMaxTUint == depth && KMTPHandleNone == handle )) 
       
   205         {
       
   206         response = EMTPRespCodeOK;
       
   207         }
       
   208     
       
   209     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::CheckDepth()"));
       
   210     return response; 
       
   211     }
       
   212 
       
   213 /**
       
   214 GetObjectHandlesL
       
   215 */
       
   216 void CMTPPictBridgeDpGetObjectPropList::GetObjectHandlesL()
       
   217     {
       
   218     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::GetObjectHandlesL()"));
       
   219     
       
   220     TUint32 handle(Request().Uint32(TMTPTypeRequest::ERequestParameter1));
       
   221     TUint32 formatCode(Request().Uint32(TMTPTypeRequest::ERequestParameter2));
       
   222     TUint32 depth(Request().Uint32(TMTPTypeRequest::ERequestParameter5));
       
   223 
       
   224     delete iHandles;
       
   225     iHandles = NULL;
       
   226 
       
   227     if (KMTPHandleAll == handle)
       
   228         {
       
   229         GetObjectHandlesL(KMTPStorageAll, formatCode, KMTPHandleNone);
       
   230         }
       
   231     else if (KMTPHandleNone == handle)
       
   232         {
       
   233         GetRootObjectHandlesL(formatCode, depth);
       
   234         }
       
   235     else 
       
   236         {
       
   237         iHandles = CMTPTypeArray::NewL(EMTPTypeAUINT32);
       
   238         iHandles->AppendUintL(handle);
       
   239         }
       
   240     
       
   241     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::GetObjectHandlesL()"));
       
   242     }
       
   243 
       
   244 /**
       
   245 GetObjectHandlesL
       
   246 */
       
   247 void CMTPPictBridgeDpGetObjectPropList::GetObjectHandlesL( TUint32 aStorageId, TUint32 aFormatCode, TUint32 aParentHandle )
       
   248     {
       
   249     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::GetObjectHandlesL()"));
       
   250     
       
   251     RMTPObjectMgrQueryContext   context;
       
   252     RArray<TUint>               handles;
       
   253     TMTPObjectMgrQueryParams    params( aStorageId, aFormatCode, aParentHandle );
       
   254     CleanupClosePushL( context );
       
   255     CleanupClosePushL( handles );
       
   256 
       
   257     delete iHandles;
       
   258     iHandles = CMTPTypeArray::NewL( EMTPTypeAUINT32 );
       
   259 
       
   260     do
       
   261         {
       
   262         iFramework.ObjectMgr().GetObjectHandlesL( params, context, handles );
       
   263         iHandles->AppendL( handles );
       
   264         }
       
   265     while( !context.QueryComplete() );
       
   266 
       
   267     CleanupStack::PopAndDestroy( &handles );
       
   268     CleanupStack::PopAndDestroy( &context );
       
   269     
       
   270     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::GetObjectHandlesL()"));
       
   271     }
       
   272 
       
   273 /**
       
   274 GetRootObjectHandlesL
       
   275 */
       
   276 void CMTPPictBridgeDpGetObjectPropList::GetRootObjectHandlesL( TUint32 aFormatCode, TUint32 aDepth )
       
   277     {
       
   278     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::GetRootObjectHandlesL()"));
       
   279     
       
   280     if ( KMaxTUint == aDepth )
       
   281         {
       
   282         GetObjectHandlesL( KMTPStorageAll, aFormatCode, KMTPHandleNone );
       
   283         }
       
   284     else if ( 0 == aDepth )
       
   285         {
       
   286         delete iHandles;
       
   287         iHandles = CMTPTypeArray::NewL( EMTPTypeAUINT32 );    //empty array
       
   288         }
       
   289     else
       
   290         {
       
   291         GetObjectHandlesL( KMTPStorageAll, aFormatCode, KMTPHandleNoParent );
       
   292         }
       
   293     
       
   294     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::GetRootObjectHandlesL()"));
       
   295     }
       
   296 
       
   297 /**
       
   298 ServiceAllPropertiesL
       
   299 */
       
   300 void CMTPPictBridgeDpGetObjectPropList::ServiceAllPropertiesL( TUint32 aHandle, TBool aDiscoveryFile )
       
   301     {
       
   302     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::ServiceAllPropertiesL()"));
       
   303     
       
   304     if ( iFramework.ObjectMgr().ObjectOwnerId( aHandle ) == iFramework.DataProviderId() )
       
   305         {
       
   306         for ( TUint i(0); i < (sizeof(KMTPPictBridgeDpSupportedProperties) / sizeof(KMTPPictBridgeDpSupportedProperties[0])); i++ )
       
   307             {
       
   308             ServiceOneObjectPropertyL( aHandle, KMTPPictBridgeDpSupportedProperties[i], aDiscoveryFile );
       
   309             }
       
   310         }
       
   311     
       
   312     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::ServiceAllPropertiesL()"));
       
   313     }
       
   314 
       
   315 /**
       
   316 ServiceGroupPropertiesL
       
   317 */
       
   318 void CMTPPictBridgeDpGetObjectPropList::ServiceGroupPropertiesL(TUint32 aHandle,TUint16 aGroupCode, TBool aDiscoveryFile )
       
   319 	{
       
   320 	__FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::ServiceGroupPropertiesL()"));
       
   321 	TBool supportGroupCode = ( aGroupCode >0 )&&( aGroupCode < KMTPDpPropertyGroupNumber+1 );
       
   322 	if ( supportGroupCode && ( iFramework.ObjectMgr().ObjectOwnerId(aHandle) == iFramework.DataProviderId() ))
       
   323         {
       
   324         for (TUint propCodeIndex(0); propCodeIndex < KMTPDpPropertyNumber; propCodeIndex++)
       
   325             {
       
   326             TUint16 propCode = KMTPDpPropertyGroups[aGroupCode][propCodeIndex];  
       
   327             if(propCode != 0)
       
   328             	{
       
   329             	ServiceOneObjectPropertyL(aHandle, propCode, aDiscoveryFile );
       
   330             	}
       
   331             }
       
   332         }
       
   333 	
       
   334 	__FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::ServiceGroupPropertiesL()"));
       
   335 	}
       
   336 
       
   337 /**
       
   338 ServiceOneObjectPropertyL
       
   339 */
       
   340 void CMTPPictBridgeDpGetObjectPropList::ServiceOneObjectPropertyL( TUint32 aHandle, TUint32 aPropCode, TBool aDiscoveryFile )
       
   341     {
       
   342     __FLOG(_L8("+CMTPPictBridgeDpGetObjectPropList::ServiceOneObjectPropertyL()"));
       
   343     
       
   344     if ( iFramework.ObjectMgr().ObjectOwnerId( aHandle ) == iFramework.DataProviderId() )
       
   345         {
       
   346         switch(aPropCode)
       
   347             {
       
   348         case EMTPObjectPropCodeNonConsumable:
       
   349             {
       
   350             
       
   351             TUint8 value = iObjMeta->Uint(CMTPObjectMetaData::ENonConsumable);
       
   352             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   353             propElem.SetUint8L(CMTPTypeObjectPropListElement::EValue, value);
       
   354             iPropertyList->CommitPropElemL(propElem);
       
   355             }        
       
   356             break;
       
   357             
       
   358         case EMTPObjectPropCodeObjectFormat:
       
   359         	{
       
   360             TUint16 value = iObjMeta->Uint(CMTPObjectMetaData::EFormatCode);
       
   361             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   362             propElem.SetUint16L(CMTPTypeObjectPropListElement::EValue, value);
       
   363             iPropertyList->CommitPropElemL(propElem);
       
   364         	}
       
   365         	break;
       
   366             case EMTPObjectPropCodeProtectionStatus:
       
   367             {
       
   368             TUint16 value( 1 );
       
   369             if( !aDiscoveryFile ) 
       
   370                 {
       
   371                 value = iFileEntry.IsReadOnly();
       
   372                 }
       
   373             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   374             propElem.SetUint16L(CMTPTypeObjectPropListElement::EValue, value);
       
   375             iPropertyList->CommitPropElemL(propElem);
       
   376             }
       
   377             break;
       
   378             case EMTPObjectPropCodeStorageID:
       
   379         	{
       
   380             TUint32 value = iObjMeta->Uint(CMTPObjectMetaData::EStorageId);
       
   381             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   382             propElem.SetUint32L(CMTPTypeObjectPropListElement::EValue, value);
       
   383             iPropertyList->CommitPropElemL(propElem);
       
   384         	}
       
   385         	break;
       
   386             case EMTPObjectPropCodeParentObject:
       
   387             {
       
   388             TUint32 value = iObjMeta->Uint(CMTPObjectMetaData::EParentHandle);
       
   389             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   390             propElem.SetUint32L(CMTPTypeObjectPropListElement::EValue, value);
       
   391             iPropertyList->CommitPropElemL(propElem);
       
   392             }
       
   393             break;
       
   394             case EMTPObjectPropCodeObjectSize:
       
   395             {
       
   396             TUint64 value( 0 );
       
   397             if( !aDiscoveryFile ) 
       
   398                 {
       
   399                 value = iFileEntry.FileSize();
       
   400                 }
       
   401             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   402             propElem.SetUint64L(CMTPTypeObjectPropListElement::EValue, value);
       
   403             iPropertyList->CommitPropElemL(propElem);
       
   404             }
       
   405             break;
       
   406             case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   407             {
       
   408             TMTPTypeUint128 value = iFramework.ObjectMgr().PuidL(aHandle);
       
   409             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   410             propElem.SetUint128L(CMTPTypeObjectPropListElement::EValue, value.UpperValue(), value.LowerValue());
       
   411             iPropertyList->CommitPropElemL(propElem); 
       
   412             }        
       
   413             break;
       
   414             case EMTPObjectPropCodeDateModified:
       
   415         	{
       
   416             TBuf<64> dateString;
       
   417             if ( !aDiscoveryFile )
       
   418                 {
       
   419                 iDpSingletons.MTPUtility().TTime2MTPTimeStr(iFileEntry.iModified, dateString);
       
   420                 }
       
   421             else{
       
   422                 TTime modifiedTime( 0 );
       
   423                 modifiedTime.HomeTime();
       
   424                 iDpSingletons.MTPUtility().TTime2MTPTimeStr( modifiedTime, dateString );
       
   425                 }
       
   426                     	
       
   427             CMTPTypeString* value = CMTPTypeString::NewLC(dateString);
       
   428             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   429             propElem.SetStringL(CMTPTypeObjectPropListElement::EValue, value->StringChars());
       
   430             iPropertyList->CommitPropElemL(propElem);
       
   431             CleanupStack::PopAndDestroy(value);
       
   432         	}
       
   433         	break;
       
   434             case EMTPObjectPropCodeObjectFileName:
       
   435         	{
       
   436         	CMTPTypeString* value( NULL );
       
   437         	if ( !aDiscoveryFile )
       
   438         	    {
       
   439         	    value = CMTPTypeString::NewLC(iFileEntry.iName);
       
   440         	    }
       
   441         	else
       
   442         	    {
       
   443         	    TParse parse;
       
   444         	    parse.Set( iObjMeta->DesC(CMTPObjectMetaData::ESuid), NULL, NULL );
       
   445         	    value = CMTPTypeString::NewLC( parse.NameAndExt() );
       
   446         	    }
       
   447             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   448             propElem.SetStringL(CMTPTypeObjectPropListElement::EValue, value->StringChars());
       
   449             iPropertyList->CommitPropElemL(propElem);
       
   450             CleanupStack::PopAndDestroy(value);
       
   451         	}
       
   452         	break;
       
   453             case EMTPObjectPropCodeName:
       
   454             {
       
   455             CMTPTypeString* value = CMTPTypeString::NewLC(iObjMeta->DesC(CMTPObjectMetaData::EName));
       
   456             CMTPTypeObjectPropListElement& propElem = iPropertyList->ReservePropElemL(aHandle, aPropCode);
       
   457             propElem.SetStringL(CMTPTypeObjectPropListElement::EValue, value->StringChars());
       
   458             iPropertyList->CommitPropElemL(propElem);
       
   459             CleanupStack::PopAndDestroy(value);
       
   460             }
       
   461             break;
       
   462             default:
       
   463                 {
       
   464                 Panic( EMTPPictBridgeDpUnsupportedProperty );
       
   465                 }
       
   466                 break;
       
   467             }
       
   468         }
       
   469     __FLOG(_L8("-CMTPPictBridgeDpGetObjectPropList::ServiceOneObjectPropertyL()"));
       
   470     }
       
   471