mtpfws/mtpfw/dataproviders/dputility/src/cmtpsvcsetreferences.cpp
changeset 0 d0791faffa3f
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 // mw/remoteconn/mtpfws/mtpfw/dataproviders/dputility/src/cmtpsvcsetreferences.cpp
       
    15 
       
    16 
       
    17 #include <mtp/cmtpobjectmetadata.h>
       
    18 #include <mtp/cmtptypearray.h>
       
    19 #include <mtp/tmtptyperequest.h>
       
    20 #include <mtp/mmtpdataproviderframework.h>
       
    21 #include <mtp/mmtpobjectmgr.h>
       
    22 #include <mtp/mmtpreferencemgr.h>
       
    23 #include <mtp/mtpdatatypeconstants.h>
       
    24 
       
    25 #include "cmtpsvcsetreferences.h"
       
    26 #include "mmtpservicedataprovider.h"
       
    27 #include "mmtpsvcobjecthandler.h"
       
    28 
       
    29 __FLOG_STMT(_LIT8(KComponent,"SvcSetRef");)
       
    30 
       
    31 EXPORT_C MMTPRequestProcessor* CMTPSvcSetReferences::NewL(MMTPDataProviderFramework& aFramework, 
       
    32 												MMTPConnection& aConnection, 
       
    33 												MMTPServiceDataProvider& aDataProvider)
       
    34 	{
       
    35 	CMTPSvcSetReferences* self = new (ELeave) CMTPSvcSetReferences(aFramework, aConnection, aDataProvider);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 EXPORT_C CMTPSvcSetReferences::~CMTPSvcSetReferences()
       
    40 	{
       
    41 	__FLOG(_L8("~CMTPSvcGetReferences - Entry"));
       
    42 	delete iReferences;
       
    43 	delete iReceivedObjectMetaData;
       
    44 	__FLOG(_L8("~CMTPSvcGetReferences - Exit"));
       
    45 	__FLOG_CLOSE; 
       
    46 	}
       
    47 
       
    48 /**
       
    49 Standard c++ constructor
       
    50 */    
       
    51 CMTPSvcSetReferences::CMTPSvcSetReferences(MMTPDataProviderFramework& aFramework, 
       
    52 										MMTPConnection& aConnection, 
       
    53 										MMTPServiceDataProvider& aDataProvider) :
       
    54 	CMTPRequestProcessor(aFramework, aConnection, 0, NULL), 
       
    55 	iDataProvider(aDataProvider)
       
    56 	{
       
    57 	__FLOG_OPEN(KMTPSubsystem, KComponent);
       
    58 	__FLOG(_L8("Constructed"));
       
    59 	}
       
    60 
       
    61 /**
       
    62 SetReferences request handler
       
    63 start receiving reference data from the initiator
       
    64 */
       
    65 void CMTPSvcSetReferences::ServiceL()
       
    66 	{
       
    67 	__FLOG(_L8("ServiceL - Entry"));
       
    68 	delete iReferences;
       
    69 	iReferences = NULL;
       
    70 	iReferences = CMTPTypeArray::NewL(EMTPTypeAUINT32);
       
    71 	ReceiveDataL(*iReferences);
       
    72 	__FLOG(_L8("ServiceL - Exit"));
       
    73 	}
       
    74 
       
    75 TBool CMTPSvcSetReferences::DoHandleResponsePhaseL()
       
    76 	{
       
    77 	__FLOG(_L8("DoHandleResponsePhaseL - Entry"));
       
    78 	if(!VerifyReferenceHandlesL())
       
    79 		{
       
    80 		SendResponseL(EMTPRespCodeInvalidObjectReference);
       
    81 		}
       
    82 	else
       
    83 		{
       
    84 		TUint16 formatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode);
       
    85 		TMTPResponseCode responseCode = EMTPRespCodeOK;
       
    86 		responseCode = (iDataProvider.ObjectHandler(formatCode))->SetObjectReferenceL(*iReceivedObjectMetaData, *iReferences);
       
    87 		SendResponseL(responseCode);
       
    88 		}
       
    89 	__FLOG(_L8("DoHandleResponsePhaseL - Exit"));
       
    90 	return EFalse;
       
    91 	}
       
    92 
       
    93 TBool CMTPSvcSetReferences::HasDataphase() const
       
    94 	{
       
    95 	return ETrue;
       
    96 	}
       
    97 
       
    98 TBool CMTPSvcSetReferences::VerifyReferenceHandlesL() const
       
    99 	{
       
   100 	__FLOG(_L8("VerifyReferenceHandlesL - Entry"));
       
   101 	__ASSERT_DEBUG(iReferences, User::Invariant());
       
   102 	TBool result = ETrue;
       
   103 	TInt count = iReferences->NumElements();
       
   104 	CMTPObjectMetaData* object = CMTPObjectMetaData::NewLC();
       
   105 	MMTPObjectMgr& objectMgr = iFramework.ObjectMgr();
       
   106 	for(TInt i = 0; i < count; i++)
       
   107 		{
       
   108 		TMTPTypeUint32 handle;
       
   109 		iReferences->ElementL(i, handle);
       
   110 		if(!objectMgr.ObjectL(handle, *object))
       
   111 			{
       
   112 			result = EFalse;
       
   113 			break;
       
   114 			}
       
   115 		}
       
   116 	CleanupStack::PopAndDestroy(object);
       
   117 	__FLOG(_L8("VerifyReferenceHandlesL - Exit"));
       
   118 	return result;
       
   119 	}
       
   120 
       
   121 TMTPResponseCode CMTPSvcSetReferences::CheckRequestL()
       
   122 	{
       
   123 	__FLOG(_L8("CheckRequestL - Entry"));
       
   124 
       
   125 	TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL();
       
   126 	if (EMTPRespCodeOK == responseCode)
       
   127 		{
       
   128 		TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
   129 		iReceivedObjectMetaData = CMTPObjectMetaData::NewL();
       
   130 		// Check object handle
       
   131 		MMTPObjectMgr& objMgr(iFramework.ObjectMgr());
       
   132 		// Check whether object handle is valid
       
   133 		if (objMgr.ObjectL(objectHandle, *iReceivedObjectMetaData))
       
   134 			{
       
   135 			// Check whether the owner of this object is correct data provider
       
   136 			if (iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EDataProviderId) != iFramework.DataProviderId())
       
   137 				{
       
   138 				responseCode = EMTPRespCodeInvalidObjectHandle;
       
   139 				__FLOG(_L8("CheckRequestL - DataProviderId dismatch"));
       
   140 				}
       
   141 			else
       
   142 				{
       
   143 				// Check format code
       
   144 				TUint16 formatCode = iReceivedObjectMetaData->Uint(CMTPObjectMetaData::EFormatCode);
       
   145 				if (!iDataProvider.ObjectHandler(formatCode))
       
   146 					{
       
   147 					responseCode = EMTPRespCodeInvalidObjectHandle;
       
   148 					}
       
   149 				}
       
   150 			}
       
   151 		else
       
   152 			{
       
   153 			responseCode = EMTPRespCodeInvalidObjectHandle;
       
   154 			}
       
   155 		}
       
   156 	__FLOG_VA((_L8("CheckRequestL - Exit with code: 0x%04X"), responseCode));
       
   157 	return responseCode;
       
   158 	}