mtpfws/mtpfw/dataproviders/dputility/src/cmtpgetobjectpropvalue.cpp
changeset 0 d0791faffa3f
child 2 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 <f32file.h>
       
    17 #include <mtp/tmtptyperequest.h>
       
    18 #include <mtp/tmtptypeuint8.h>
       
    19 #include <mtp/tmtptypeuint32.h>
       
    20 #include <mtp/tmtptypeuint64.h>
       
    21 #include <mtp/tmtptypeuint128.h>
       
    22 #include <mtp/cmtptypestring.h>
       
    23 #include <mtp/mmtpdataproviderframework.h>
       
    24 #include <mtp/mtpprotocolconstants.h>
       
    25 #include <mtp/mmtpobjectmgr.h>
       
    26 
       
    27 #include "cmtpgetobjectpropvalue.h"
       
    28 #include "mtpdpconst.h"
       
    29 #include "mtpdppanic.h"
       
    30 
       
    31 
       
    32 /**
       
    33 Verification data for the GetObjectPropValue request
       
    34 */
       
    35 const TMTPRequestElementInfo KMTPGetObjectPropValuePolicy[] = 
       
    36     {
       
    37     	{TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, EMTPElementAttrNone, 0, 0, 0},   	
       
    38      };
       
    39 
       
    40 /**
       
    41 Two-phase construction method
       
    42 @param aPlugin	The data provider plugin
       
    43 @param aFramework	The data provider framework
       
    44 @param aConnection	The connection from which the request comes
       
    45 @return a pointer to the created request processor object
       
    46 */ 
       
    47 EXPORT_C MMTPRequestProcessor* CMTPGetObjectPropValue::NewL(
       
    48 											MMTPDataProviderFramework& aFramework,
       
    49 											MMTPConnection& aConnection)
       
    50 	{
       
    51 	CMTPGetObjectPropValue* self = new (ELeave) CMTPGetObjectPropValue(aFramework, aConnection);
       
    52 	CleanupStack::PushL(self);
       
    53 	self->ConstructL();
       
    54 	CleanupStack::Pop(self);
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 /**
       
    59 Destructor
       
    60 */		
       
    61 EXPORT_C CMTPGetObjectPropValue::~CMTPGetObjectPropValue()
       
    62 	{
       
    63 	delete iMTPTypeString;	
       
    64 	delete iObjMeta;
       
    65 	}
       
    66 
       
    67 /**
       
    68 Standard c++ constructor
       
    69 */		
       
    70 CMTPGetObjectPropValue::CMTPGetObjectPropValue(
       
    71 									MMTPDataProviderFramework& aFramework,
       
    72 									MMTPConnection& aConnection)
       
    73 	:CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPGetObjectPropValuePolicy)/sizeof(TMTPRequestElementInfo), KMTPGetObjectPropValuePolicy),
       
    74 	iRfs(aFramework.Fs())
       
    75 	{
       
    76 	}
       
    77 
       
    78 /**
       
    79 Verify request
       
    80 */
       
    81 TMTPResponseCode CMTPGetObjectPropValue::CheckRequestL()
       
    82 	{
       
    83 	TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL();
       
    84 	TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
       
    85 	
       
    86 	if(responseCode == EMTPRespCodeOK)
       
    87 		{
       
    88 		if(propCode != EMTPObjectPropCodeAssociationType && propCode != EMTPObjectPropCodeAssociationDesc)
       
    89 			{
       
    90 			const TInt count = sizeof(KMTPDpSupportedProperties) / sizeof(TUint16);
       
    91 			TInt i = 0;
       
    92 			for(i = 0; i < count; i++)
       
    93 				{
       
    94 				if(KMTPDpSupportedProperties[i] == propCode)
       
    95 					{
       
    96 					break;
       
    97 					}
       
    98 				}
       
    99 			if(i == count)
       
   100 				{
       
   101 				responseCode = EMTPRespCodeInvalidObjectPropCode;
       
   102 				}		
       
   103 			}
       
   104 		else
       
   105 			{
       
   106 			TUint32 handle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
   107 			CMTPObjectMetaData* meta = iRequestChecker->GetObjectInfo(handle);
       
   108 			__ASSERT_DEBUG(meta, Panic(EMTPDpObjectNull));
       
   109 			
       
   110 			TUint16 format = meta->Uint(CMTPObjectMetaData::EFormatCode);
       
   111 			if(format != EMTPFormatCodeAssociation)
       
   112 				responseCode = EMTPRespCodeInvalidObjectPropCode;
       
   113 			}
       
   114 		}
       
   115 	return responseCode;	
       
   116 	}
       
   117 	
       
   118 /**
       
   119 GetObjectPropValue request handler
       
   120 */		
       
   121 void CMTPGetObjectPropValue::ServiceL()
       
   122 	{
       
   123 	__ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull));
       
   124 	
       
   125 	TUint32 handle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
   126 	iFramework.ObjectMgr().ObjectL(TMTPTypeUint32(handle), *iObjMeta);
       
   127 	User::LeaveIfError(iRfs.Entry(iObjMeta->DesC(CMTPObjectMetaData::ESuid), iFileEntry));
       
   128 	
       
   129 	TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
       
   130 	switch(propCode)
       
   131 		{
       
   132 		case EMTPObjectPropCodeStorageID:
       
   133 			ServiceStorageIdL();
       
   134 			break;
       
   135 		case EMTPObjectPropCodeObjectFormat:
       
   136 			ServiceObjectFormatL();
       
   137 			break;
       
   138 		case EMTPObjectPropCodeProtectionStatus:
       
   139 			ServiceProtectionStatusL();
       
   140 			break;
       
   141 		case EMTPObjectPropCodeObjectSize:
       
   142 			ServiceObjectSizeL();
       
   143 			break;
       
   144 		case EMTPObjectPropCodeAssociationType:						
       
   145 			ServiceObjectAssociationTypeL();
       
   146 			break;
       
   147 		case EMTPObjectPropCodeAssociationDesc:
       
   148 			ServiceObjectAssociationDescL();
       
   149 			break;
       
   150 		case EMTPObjectPropCodeObjectFileName:
       
   151 			ServiceFileNameL();
       
   152 			break;
       
   153 		case EMTPObjectPropCodeDateModified:
       
   154 			ServiceDateModifiedL();
       
   155 			break;
       
   156 		case EMTPObjectPropCodeParentObject:
       
   157 			ServiceParentObjectL();
       
   158 			break;
       
   159 		case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   160 			ServicePuidL();
       
   161 			break;
       
   162 		case EMTPObjectPropCodeName:
       
   163 			ServiceNameL();
       
   164 			break;
       
   165 		case EMTPObjectPropCodeNonConsumable:
       
   166 			ServiceNonConsumableL();
       
   167 			break;
       
   168 		default:
       
   169 			Panic(EMTPDpUnsupportedProperty);
       
   170 		}	
       
   171 	}
       
   172 
       
   173 /**
       
   174 Second-phase construction
       
   175 */					
       
   176 void CMTPGetObjectPropValue::ConstructL()
       
   177 	{
       
   178 	iObjMeta	= CMTPObjectMetaData::NewL();
       
   179 	iMTPTypeString = CMTPTypeString::NewL();
       
   180 	}		
       
   181 
       
   182 void CMTPGetObjectPropValue::ServiceStorageIdL()
       
   183 	{
       
   184 	iMTPTypeUint32.Set(iObjMeta->Uint(CMTPObjectMetaData::EStorageId));	
       
   185 	SendDataL(iMTPTypeUint32);
       
   186 	}
       
   187 	
       
   188 void CMTPGetObjectPropValue::ServiceObjectFormatL()
       
   189 	{
       
   190 	iMTPTypeUint16.Set(iObjMeta->Uint(CMTPObjectMetaData::EFormatCode));
       
   191 	
       
   192 	SendDataL(iMTPTypeUint16);	
       
   193 	}
       
   194 	
       
   195 void CMTPGetObjectPropValue::ServiceProtectionStatusL()
       
   196 	{
       
   197 	iMTPTypeUint16.Set(iFileEntry.IsReadOnly());
       
   198 
       
   199 	SendDataL(iMTPTypeUint16);	
       
   200 	}
       
   201 	
       
   202 void CMTPGetObjectPropValue::ServiceObjectSizeL()
       
   203 	{
       
   204 	iMTPTypeUint64.Set(iFileEntry.iSize);
       
   205 
       
   206 	SendDataL(iMTPTypeUint64);
       
   207 	}
       
   208 	
       
   209 void CMTPGetObjectPropValue::ServiceObjectAssociationTypeL()	
       
   210 	{
       
   211 	iMTPTypeUint16.Set(iObjMeta->Uint(CMTPObjectMetaData::EFormatSubCode));
       
   212 
       
   213 	SendDataL(iMTPTypeUint16);
       
   214 	}
       
   215 
       
   216 void CMTPGetObjectPropValue::ServiceObjectAssociationDescL()	
       
   217 	{
       
   218 	iMTPTypeUint64.Set(0x00000000);
       
   219 	SendDataL(iMTPTypeUint64);
       
   220 	}	
       
   221 	
       
   222 void CMTPGetObjectPropValue::ServiceFileNameL()
       
   223 	{
       
   224 	iMTPTypeString->SetL(iFileEntry.iName);
       
   225 	SendDataL(*iMTPTypeString);
       
   226 	}
       
   227 	
       
   228 void CMTPGetObjectPropValue::ServiceDateModifiedL()
       
   229 	{
       
   230 	_LIT(KMTPDateStringFormat,"%F%Y%M%DT%H%T%S");	
       
   231 	TBuf<64> dateString;	
       
   232 	iFileEntry.iModified.FormatL(dateString,KMTPDateStringFormat);
       
   233 	iMTPTypeString->SetL(dateString);
       
   234 	SendDataL(*iMTPTypeString);
       
   235 	}
       
   236 	
       
   237 void CMTPGetObjectPropValue::ServiceParentObjectL()
       
   238 	{
       
   239     TUint32 parentHandle = iObjMeta->Uint(CMTPObjectMetaData::EParentHandle);
       
   240     if (parentHandle == KMTPHandleNoParent)
       
   241         {
       
   242         parentHandle = 0;
       
   243         }
       
   244     iMTPTypeUint32.Set(parentHandle);
       
   245 
       
   246     SendDataL(iMTPTypeUint32);
       
   247 	}
       
   248 	
       
   249 void CMTPGetObjectPropValue::ServicePuidL()
       
   250 	{
       
   251 	iMTPTypeUint128 = iFramework.ObjectMgr().PuidL((TUint32)iObjMeta->Uint(CMTPObjectMetaData::EHandle));
       
   252 	SendDataL(iMTPTypeUint128);
       
   253 	}
       
   254 	
       
   255 void CMTPGetObjectPropValue::ServiceNameL()
       
   256 	{
       
   257 	iMTPTypeString->SetL(iObjMeta->DesC(CMTPObjectMetaData::EName));
       
   258 	SendDataL(*iMTPTypeString);
       
   259 	}
       
   260 	
       
   261 void CMTPGetObjectPropValue::ServiceNonConsumableL()
       
   262 	{
       
   263 	iMTPTypeUint8.Set((iObjMeta->Uint(CMTPObjectMetaData::ENonConsumable)));
       
   264 	SendDataL(iMTPTypeUint8);
       
   265 	}
       
   266 
       
   267 
       
   268 
       
   269 	
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 
       
   280 
       
   281 
       
   282 
       
   283 
       
   284 
       
   285 
       
   286 	
       
   287 
       
   288 	
       
   289 
       
   290 
       
   291    	
       
   292 
       
   293 	
       
   294 
       
   295 
       
   296 
       
   297 
       
   298 
       
   299