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