mtpfws/mtpfw/dataproviders/dputility/src/cmtpsvcsetobjectproplist.cpp
changeset 0 d0791faffa3f
child 47 63cf70d3ecd8
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2008-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 // mw/remoteconn/mtpfws/mtpfw/dataproviders/dputility/src/cmtpsetobjectproplist.cpp
       
    15 
       
    16 #include <mtp/cmtpobjectmetadata.h>
       
    17 #include <mtp/cmtptypeobjectproplist.h>
       
    18 #include <mtp/mmtpdataproviderframework.h>
       
    19 #include <mtp/mmtpobjectmgr.h>
       
    20 #include <mtp/mtpdatatypeconstants.h>
       
    21 
       
    22 #include "cmtpsvcsetobjectproplist.h"
       
    23 #include "mmtpservicedataprovider.h"
       
    24 #include "mmtpsvcobjecthandler.h"
       
    25 
       
    26 // Class constants.
       
    27 __FLOG_STMT(_LIT8(KComponent,"SvcSetObjPropList");)
       
    28 
       
    29 EXPORT_C MMTPRequestProcessor* CMTPSvcSetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider)
       
    30 	{
       
    31 	CMTPSvcSetObjectPropList* self = new (ELeave) CMTPSvcSetObjectPropList(aFramework, aConnection, aDataProvider);
       
    32 	CleanupStack::PushL(self);
       
    33 	self->ConstructL();
       
    34 	CleanupStack::Pop(self);
       
    35 	return self;
       
    36 	}
       
    37 
       
    38 EXPORT_C CMTPSvcSetObjectPropList::~CMTPSvcSetObjectPropList()
       
    39 	{
       
    40 	__FLOG(_L8("~CMTPSvcSetObjectPropList - Entry"));
       
    41 	delete iPropertyList;
       
    42 	__FLOG(_L8("~CMTPSvcSetObjectPropList - Exit"));
       
    43 	__FLOG_CLOSE;
       
    44 	}
       
    45 
       
    46 CMTPSvcSetObjectPropList::CMTPSvcSetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, MMTPServiceDataProvider& aDataProvider) :
       
    47 	CMTPRequestProcessor(aFramework, aConnection, 0, NULL),
       
    48 	iDataProvider(aDataProvider)
       
    49 	{
       
    50 	}
       
    51 
       
    52 void CMTPSvcSetObjectPropList::ConstructL()
       
    53 	{
       
    54 	__FLOG_OPEN(KMTPSubsystem, KComponent);
       
    55 	__FLOG(_L8("ConstructL - Entry"));
       
    56 	iPropertyList = CMTPTypeObjectPropList::NewL();
       
    57 	__FLOG(_L8("ConstructL - Exit"));
       
    58 	}
       
    59 
       
    60 void CMTPSvcSetObjectPropList::ServiceL()
       
    61 	{
       
    62 	__FLOG(_L8("ServiceL - Entry"));
       
    63 	ReceiveDataL(*iPropertyList);
       
    64 	__FLOG(_L8("ServiceL - Exit"));
       
    65 	}
       
    66 
       
    67 TBool CMTPSvcSetObjectPropList::DoHandleResponsePhaseL()
       
    68 	{
       
    69 	__FLOG(_L8("DoHandleResponsePhaseL - Entry"));
       
    70 	TUint32 parameter = 0;
       
    71 	TMTPResponseCode responseCode = EMTPRespCodeOK;
       
    72 	
       
    73 	responseCode = SetObjectPropListL(*iPropertyList, parameter);
       
    74 	__FLOG_VA((_L8("SetObjectPropListL - ResponsCode: 0x%x, error index: %u"), responseCode, parameter));
       
    75 	
       
    76 	SendResponseL(responseCode, 1, &parameter);
       
    77 	__FLOG_VA((_L8("DoHandleResponsePhaseL - Exit with responseCode = 0x%04X and failed index: %u"), responseCode, parameter));
       
    78 	return EFalse;
       
    79 	}
       
    80 
       
    81 TMTPResponseCode CMTPSvcSetObjectPropList::SetObjectPropListL(const CMTPTypeObjectPropList& aObjectPropList, TUint32& aParameter)
       
    82 	{
       
    83 	__FLOG(_L8("SetObjectPropListL - Entry"));
       
    84 	TMTPResponseCode responseCode = EMTPRespCodeOK;
       
    85 	const TUint count = aObjectPropList.NumberOfElements();
       
    86 	aObjectPropList.ResetCursor();
       
    87 	CMTPObjectMetaData* objectMetaData  = CMTPObjectMetaData::NewL();
       
    88 	CleanupStack::PushL(objectMetaData);
       
    89 	TUint32 lastHandle = 0;
       
    90 	MMTPSvcObjectHandler* lastHandler = NULL; 
       
    91 	TUint errIndex = 0; // Index number for each segment with the same object handle.
       
    92 	TUint i;
       
    93 	for (i = 0; i < count; i++)
       
    94 		{
       
    95 		CMTPTypeObjectPropListElement& element = aObjectPropList.GetNextElementL();
       
    96 		TUint32 handle = element.Uint32L(CMTPTypeObjectPropListElement::EObjectHandle);	
       
    97 		if (!iFramework.ObjectMgr().ObjectL(handle, *objectMetaData))
       
    98 			{
       
    99 			responseCode = EMTPRespCodeInvalidObjectHandle;
       
   100 			}
       
   101 		else
       
   102 			{
       
   103 			TUint16 formatCode = objectMetaData->Uint(CMTPObjectMetaData::EFormatCode);
       
   104 			const TDesC& suid = objectMetaData->DesC(CMTPObjectMetaData::ESuid);
       
   105 			MMTPSvcObjectHandler* pHandler = iDataProvider.ObjectHandler(formatCode);
       
   106 			if (pHandler)
       
   107 				{
       
   108 				// If the handler is not the last handle, need commit all properties now
       
   109 				if (lastHandle != 0 && lastHandler && lastHandle != handle)
       
   110 					{
       
   111 					TRAPD(err, lastHandler->CommitL());
       
   112 					if (KErrNone != err)
       
   113 						{
       
   114 						lastHandler->RollBack();
       
   115 						responseCode = EMTPRespCodeInvalidObjectHandle;
       
   116 						aParameter = errIndex;
       
   117 						break;
       
   118 						}
       
   119 					// Record the next segment's first index number
       
   120 					errIndex = i;
       
   121 					}
       
   122 				lastHandler = pHandler;
       
   123 				lastHandle = handle;
       
   124 				responseCode = pHandler->SetObjectPropertyL(suid, element, EMTPOpCodeSetObjectPropList);
       
   125 				}
       
   126 			else
       
   127 				{
       
   128 				responseCode = EMTPRespCodeInvalidObjectHandle;
       
   129 				}
       
   130 			}
       
   131 		if (responseCode != EMTPRespCodeOK)
       
   132 			{
       
   133 			aParameter = i;
       
   134 			// All properties prior to the failed property will be updated.
       
   135 			if (i != errIndex && lastHandler)
       
   136 				{
       
   137 				TRAPD(err, lastHandler->CommitL());
       
   138 				if (KErrNone != err)
       
   139 					{
       
   140 					lastHandler->RollBack();
       
   141 					aParameter = errIndex;
       
   142 					}
       
   143 				}
       
   144 			break;
       
   145 			}
       
   146 		}
       
   147 	// Commit all correct properties.
       
   148 	if (responseCode == EMTPRespCodeOK && lastHandler)
       
   149 		{
       
   150 		TRAPD(err, lastHandler->CommitL());
       
   151 		if (KErrNone != err)
       
   152 			{
       
   153 			lastHandler->RollBack();
       
   154 			responseCode = EMTPRespCodeInvalidObjectHandle;
       
   155 			aParameter = errIndex;
       
   156 			}
       
   157 		}
       
   158 	CleanupStack::PopAndDestroy(objectMetaData);
       
   159 	__FLOG_VA((_L8("SetObjectPropListL - Exit with responseCode = 0x%04X"), responseCode));
       
   160 	return responseCode;
       
   161 	}