mtpfws/mtpfw/dataproviders/dputility/src/cmtpsvcdeleteobject.cpp
changeset 47 63cf70d3ecd8
parent 0 d0791faffa3f
equal deleted inserted replaced
44:a5deb6b96675 47:63cf70d3ecd8
    19 
    19 
    20 #include "cmtpsvcdeleteobject.h"
    20 #include "cmtpsvcdeleteobject.h"
    21 #include "mtpdpconst.h"
    21 #include "mtpdpconst.h"
    22 #include "mmtpservicedataprovider.h"
    22 #include "mmtpservicedataprovider.h"
    23 #include "mmtpsvcobjecthandler.h"
    23 #include "mmtpsvcobjecthandler.h"
       
    24 #include "OstTraceDefinitions.h"
       
    25 #ifdef OST_TRACE_COMPILER_IN_USE
       
    26 #include "cmtpsvcdeleteobjectTraces.h"
       
    27 #endif
       
    28 
    24 
    29 
    25 // Class constants.
    30 // Class constants.
    26 __FLOG_STMT(_LIT8(KComponent,"SvcDeleteObject");)
       
    27 
    31 
    28 EXPORT_C MMTPRequestProcessor* CMTPSvcDeleteObject::NewL(MMTPDataProviderFramework& aFramework, 
    32 EXPORT_C MMTPRequestProcessor* CMTPSvcDeleteObject::NewL(MMTPDataProviderFramework& aFramework, 
    29 												MMTPConnection& aConnection, 
    33 												MMTPConnection& aConnection, 
    30 												MMTPServiceDataProvider& aDataProvider)
    34 												MMTPServiceDataProvider& aDataProvider)
    31 	{
    35 	{
    33 	return self;
    37 	return self;
    34 	}
    38 	}
    35 
    39 
    36 EXPORT_C CMTPSvcDeleteObject::~CMTPSvcDeleteObject()
    40 EXPORT_C CMTPSvcDeleteObject::~CMTPSvcDeleteObject()
    37 	{
    41 	{
    38 	__FLOG(_L8("~CMTPSvcDeleteObject - Entry"));
    42 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_CMTPSVCDELETEOBJECT_DES_ENTRY );
    39 	iObjectHandles.Close();
    43 	iObjectHandles.Close();
    40 	delete iReceivedObjectMetaData;
    44 	delete iReceivedObjectMetaData;
    41 	__FLOG(_L8("~CMTPSvcDeleteObject - Exit"));
    45 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_CMTPSVCDELETEOBJECT_DES_EXIT );
    42 	__FLOG_CLOSE;
       
    43 	}
    46 	}
    44 
    47 
    45 CMTPSvcDeleteObject::CMTPSvcDeleteObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider) :
    48 CMTPSvcDeleteObject::CMTPSvcDeleteObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider) :
    46 	CMTPRequestProcessor(aFramework, aConnection, 0, NULL), iDataProvider(aDataProvider), iDeleteError(KErrNone)
    49 	CMTPRequestProcessor(aFramework, aConnection, 0, NULL), iDataProvider(aDataProvider), iDeleteError(KErrNone)
    47 	{
    50 	{
    48 	__FLOG_OPEN(KMTPSubsystem, KComponent);
    51 	OstTrace0( TRACE_NORMAL, CMTPSVCDELETEOBJECT_CMTPSVCDELETEOBJECT, "CMTPSvcDeleteObject - Constructed" );
    49 	__FLOG(_L8("CMTPSvcDeleteObject - Constructed"));
       
    50 	}
    52 	}
    51 
    53 
    52 /**
    54 /**
    53 DeleteObject request handler
    55 DeleteObject request handler
    54 */
    56 */
    55 void CMTPSvcDeleteObject::LoadAllObjHandlesL(TUint32 aParentHandle)
    57 void CMTPSvcDeleteObject::LoadAllObjHandlesL(TUint32 aParentHandle)
    56 	{
    58 	{
    57 	__FLOG(_L8("LoadAllObjHandlesL - Entry"));
    59 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_LOADALLOBJHANDLESL_ENTRY );
    58 	const TUint32 KFormatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
    60 	const TUint32 KFormatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
    59 	RMTPObjectMgrQueryContext context;
    61 	RMTPObjectMgrQueryContext context;
    60 	CleanupClosePushL(context);
    62 	CleanupClosePushL(context);
    61 
    63 
    62 	do
    64 	do
    65 		TMTPObjectMgrQueryParams  params(storageId, KFormatCode, aParentHandle);
    67 		TMTPObjectMgrQueryParams  params(storageId, KFormatCode, aParentHandle);
    66 		iFramework.ObjectMgr().GetObjectHandlesL(params, context, iObjectHandles);
    68 		iFramework.ObjectMgr().GetObjectHandlesL(params, context, iObjectHandles);
    67 		}
    69 		}
    68 	while (!context.QueryComplete());
    70 	while (!context.QueryComplete());
    69 	CleanupStack::PopAndDestroy(&context);
    71 	CleanupStack::PopAndDestroy(&context);
    70 	__FLOG(_L8("LoadAllObjHandlesL - Exit"));
    72 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_LOADALLOBJHANDLESL_EXIT );
    71 	}
    73 	}
    72 
    74 
    73 void CMTPSvcDeleteObject::ServiceL()
    75 void CMTPSvcDeleteObject::ServiceL()
    74 	{
    76 	{
    75 	__FLOG(_L8("ServiceL - Entry"));
    77 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_SERVICEL_ENTRY );
    76 	if (iFormatCode == EMTPFormatCodeAssociation)
    78 	if (iFormatCode == EMTPFormatCodeAssociation)
    77 		{
    79 		{
    78 		// Framework may send deleteobject for a directory, allow framework do this.
    80 		// Framework may send deleteobject for a directory, allow framework do this.
    79 		SendResponseL(EMTPRespCodeOK);
    81 		SendResponseL(EMTPRespCodeOK);
       
    82 		OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_SERVICEL_EXIT );
    80 		return;
    83 		return;
    81 		}
    84 		}
    82 	
    85 	
    83 	const TUint32 KHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
    86 	const TUint32 KHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
    84 	
    87 	
    93 		{
    96 		{
    94 		TMTPResponseCode responseCode = iObjectHandler->DeleteObjectL(*iReceivedObjectMetaData);
    97 		TMTPResponseCode responseCode = iObjectHandler->DeleteObjectL(*iReceivedObjectMetaData);
    95 		// Remove from framework.
    98 		// Remove from framework.
    96 		iFramework.ObjectMgr().RemoveObjectL(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid));
    99 		iFramework.ObjectMgr().RemoveObjectL(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid));
    97 		SendResponseL(responseCode);
   100 		SendResponseL(responseCode);
    98 		__FLOG_VA((_L8("Delete single object exit with response code = 0x%04X"), responseCode));
   101 		OstTrace1( TRACE_NORMAL, CMTPSVCDELETEOBJECT_SERVICEL, 
    99 		}
   102 		        "Delete single object exit with response code = 0x%04X", responseCode );
   100 	__FLOG(_L8("ServiceL - Exit"));
   103 		}
       
   104 	OstTraceFunctionExit0( DUP1_CMTPSVCDELETEOBJECT_SERVICEL_EXIT );
   101 	}
   105 	}
   102 
   106 
   103 void CMTPSvcDeleteObject::RunL()
   107 void CMTPSvcDeleteObject::RunL()
   104 	{
   108 	{
   105 	__FLOG(_L8("RunL - Entry"));
   109 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_RUNL_ENTRY );
   106 	__FLOG_VA((_L8("the number of objects to be deleted is %d, iDeleteIndex is %d"), iObjectHandles.Count(), iDeleteIndex));
   110 	OstTraceExt2( TRACE_NORMAL, CMTPSVCDELETEOBJECT_RUNL, 
       
   111 	        "the number of objects to be deleted is %d, iDeleteIndex is %d", iObjectHandles.Count(), iDeleteIndex );
   107 
   112 
   108 	if (iStatus != KErrNone)
   113 	if (iStatus != KErrNone)
   109 		{
   114 		{
   110 		iDeleteError = iStatus.Int();
   115 		iDeleteError = iStatus.Int();
   111 		}
   116 		}
   126 			iSuccessDeletion = ETrue;
   131 			iSuccessDeletion = ETrue;
   127 			}
   132 			}
   128 		else
   133 		else
   129 			{
   134 			{
   130 			++errCount;
   135 			++errCount;
   131 			__FLOG_VA((_L8("Delete object failed, SUID:%S"), &(iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid))));
   136 			OstTraceExt1( TRACE_NORMAL, DUP1_CMTPSVCDELETEOBJECT_RUNL, 
       
   137 			        "Delete object failed, SUID:%S", iReceivedObjectMetaData->DesC(CMTPObjectMetaData::ESuid));
   132 			}
   138 			}
   133 		}
   139 		}
   134 
   140 
   135 	// Remove object from framework
   141 	// Remove object from framework
   136 	iFramework.ObjectMgr().RemoveObjectsL(*objectDeleted);
   142 	iFramework.ObjectMgr().RemoveObjectsL(*objectDeleted);
   143 	else 
   149 	else 
   144 		{
   150 		{
   145 		TInt err = (errCount > 0) ? KErrGeneral : KErrNone;
   151 		TInt err = (errCount > 0) ? KErrGeneral : KErrNone;
   146 		CompleteSelf(err);
   152 		CompleteSelf(err);
   147 		}
   153 		}
   148 	__FLOG(_L8("RunL - Exit")); 
   154 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_RUNL_EXIT );
   149 	}
   155 	}
   150 
   156 
   151 /**
   157 /**
   152 Handle an error in the delete loop by storing the error code and continuing deleting.
   158 Handle an error in the delete loop by storing the error code and continuing deleting.
   153 */
   159 */
   154 TInt CMTPSvcDeleteObject::RunError(TInt aError)
   160 TInt CMTPSvcDeleteObject::RunError(TInt aError)
   155 	{
   161 	{
   156 	__FLOG(_L8("RunError - Entry")); 
   162 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_RUNERROR_ENTRY );
   157 	CompleteSelf(aError);
   163 	CompleteSelf(aError);
   158 	__FLOG(_L8("RunError - Exit"));
   164 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_RUNERROR_EXIT );
   159 	return KErrNone;
   165 	return KErrNone;
   160 	}
   166 	}
   161 
   167 
   162 /**
   168 /**
   163 Complete myself
   169 Complete myself
   164 */
   170 */
   165 void CMTPSvcDeleteObject::CompleteSelf(TInt aError)
   171 void CMTPSvcDeleteObject::CompleteSelf(TInt aError)
   166 	{
   172 	{
   167 	__FLOG(_L8("CompleteSelf - Entry"));
   173 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_COMPLETESELF_ENTRY );
   168 	SetActive();
   174 	SetActive();
   169 	TRequestStatus* status = &iStatus;
   175 	TRequestStatus* status = &iStatus;
   170 	*status = KRequestPending;
   176 	*status = KRequestPending;
   171 	User::RequestComplete(status, aError);
   177 	User::RequestComplete(status, aError);
   172 	__FLOG(_L8("CompleteSelf - Exit"));
   178 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_COMPLETESELF_EXIT );
   173 	}
   179 	}
   174 
   180 
   175 TMTPResponseCode CMTPSvcDeleteObject::CheckRequestL()
   181 TMTPResponseCode CMTPSvcDeleteObject::CheckRequestL()
   176 	{
   182 	{
   177 	__FLOG(_L8("CheckRequestL - Entry"));
   183 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_CHECKREQUESTL_ENTRY );
   178 	TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL();
   184 	TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL();
   179 	if (EMTPRespCodeOK == responseCode)
   185 	if (EMTPRespCodeOK == responseCode)
   180 		{
   186 		{
   181 		TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   187 		TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
   182 		iReceivedObjectMetaData = CMTPObjectMetaData::NewL();
   188 		iReceivedObjectMetaData = CMTPObjectMetaData::NewL();
   190 				{
   196 				{
   191 				iFormatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode);
   197 				iFormatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode);
   192 				if (iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EDataProviderId) != iFramework.DataProviderId() && (iFormatCode != EMTPFormatCodeAssociation))
   198 				if (iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EDataProviderId) != iFramework.DataProviderId() && (iFormatCode != EMTPFormatCodeAssociation))
   193 					{
   199 					{
   194 					responseCode = EMTPRespCodeInvalidObjectHandle;
   200 					responseCode = EMTPRespCodeInvalidObjectHandle;
   195 					__FLOG(_L8("DataProviderId dismatch"));
   201 					OstTrace0( TRACE_WARNING, DUP1_CMTPSVCDELETEOBJECT_CHECKREQUESTL, "DataProviderId dismatch" );
   196 					}
   202 					}
   197 				else
   203 				else
   198 					{
   204 					{
   199 					responseCode = CheckFmtAndSetHandler(iFormatCode);
   205 					responseCode = CheckFmtAndSetHandler(iFormatCode);
   200 					}
   206 					}
   214 				responseCode = CheckFmtAndSetHandler(iFormatCode);
   220 				responseCode = CheckFmtAndSetHandler(iFormatCode);
   215 				}
   221 				}
   216 			}
   222 			}
   217 		}
   223 		}
   218 
   224 
   219 	__FLOG_VA((_L8("CheckRequestL Exit with response code = 0x%04X"), responseCode));
   225 	OstTrace1( TRACE_NORMAL, CMTPSVCDELETEOBJECT_CHECKREQUESTL, "Exit with response code = 0x%04X", responseCode );
       
   226 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_CHECKREQUESTL_EXIT );
   220 	return responseCode;
   227 	return responseCode;
   221 	}
   228 	}
   222 
   229 
   223 void CMTPSvcDeleteObject::ProcessFinalPhaseL()
   230 void CMTPSvcDeleteObject::ProcessFinalPhaseL()
   224 	{
   231 	{
   225 	__FLOG(_L8("ProcessFinalPhaseL - Entry"));
   232 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_PROCESSFINALPHASEL_ENTRY );
   226 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   233 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   227 	if (iDeleteError != KErrNone)
   234 	if (iDeleteError != KErrNone)
   228 		{
   235 		{
   229 		if (iSuccessDeletion)
   236 		if (iSuccessDeletion)
   230 			{
   237 			{
   234 			{
   241 			{
   235 			responseCode = EMTPRespCodeStoreReadOnly;
   242 			responseCode = EMTPRespCodeStoreReadOnly;
   236 			}
   243 			}
   237 		}
   244 		}
   238 	SendResponseL(responseCode);
   245 	SendResponseL(responseCode);
   239 	__FLOG_VA((_L8("ProcessFinalPhaseL - Exit with response code = 0x%04X"), responseCode));
   246 	OstTrace1( TRACE_NORMAL, CMTPSVCDELETEOBJECT_PROCESSFINALPHASEL, "Exit with response code = 0x%04X", responseCode );
       
   247 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_PROCESSFINALPHASEL_EXIT );
   240 	}
   248 	}
   241 
   249 
   242 TMTPResponseCode CMTPSvcDeleteObject::CheckFmtAndSetHandler(TUint32 aFormatCode)
   250 TMTPResponseCode CMTPSvcDeleteObject::CheckFmtAndSetHandler(TUint32 aFormatCode)
   243 	{
   251 	{
   244 	__FLOG(_L8("CheckFmtAndSetHandler - Entry")); 
   252 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_CHECKFMTANDSETHANDLER_ENTRY );
   245 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   253 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   246 	iObjectHandler = iDataProvider.ObjectHandler(aFormatCode);
   254 	iObjectHandler = iDataProvider.ObjectHandler(aFormatCode);
   247 	if (!iObjectHandler)
   255 	if (!iObjectHandler)
   248 		{
   256 		{
   249 		responseCode = EMTPRespCodeInvalidObjectFormatCode;
   257 		responseCode = EMTPRespCodeInvalidObjectFormatCode;
   250 		}
   258 		}
   251 	__FLOG(_L8("CheckFmtAndSetHandler - Exit"));
   259 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_CHECKFMTANDSETHANDLER_EXIT );
   252 	return responseCode;
   260 	return responseCode;
   253 	}
   261 	}
   254 
   262 
   255 TMTPResponseCode CMTPSvcDeleteObject::DeleteObjectL(const CMTPObjectMetaData& aObjectMetaData)
   263 TMTPResponseCode CMTPSvcDeleteObject::DeleteObjectL(const CMTPObjectMetaData& aObjectMetaData)
   256 	{
   264 	{
   257 	__FLOG(_L8("DeleteObjectL - Entry"));
   265 	OstTraceFunctionEntry0( CMTPSVCDELETEOBJECT_DELETEOBJECTL_ENTRY );
   258 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   266 	TMTPResponseCode responseCode = EMTPRespCodeOK;
   259 	TUint16 formatCode = aObjectMetaData.Uint(CMTPObjectMetaData::EFormatCode);
   267 	TUint16 formatCode = aObjectMetaData.Uint(CMTPObjectMetaData::EFormatCode);
   260 	responseCode = CheckFmtAndSetHandler(formatCode);
   268 	responseCode = CheckFmtAndSetHandler(formatCode);
   261 	if (EMTPRespCodeOK == responseCode)
   269 	if (EMTPRespCodeOK == responseCode)
   262 		{
   270 		{
   263 		responseCode = iObjectHandler->DeleteObjectL(aObjectMetaData);
   271 		responseCode = iObjectHandler->DeleteObjectL(aObjectMetaData);
   264 		}
   272 		}
   265 	__FLOG(_L8("DeleteObjectL - Exit"));
   273 	OstTraceFunctionExit0( CMTPSVCDELETEOBJECT_DELETEOBJECTL_EXIT );
   266 	return responseCode;
   274 	return responseCode;
   267 	}
   275 	}