mtpfws/mtpfw/dataproviders/dputility/src/cmtpsetreferences.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 //
       
    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 "cmtpsetreferences.h"
       
    26 #include "mtpdppanic.h"
       
    27 
       
    28 /**
       
    29 Verification data for the SetReferences request
       
    30 */
       
    31 const TMTPRequestElementInfo KMTPSetReferencesPolicy[] = 
       
    32     {
       
    33         {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, EMTPElementAttrNone, 0, 0, 0}
       
    34     };
       
    35 
       
    36 /**
       
    37 Two-phase construction method
       
    38 @param aPlugin    The data provider plugin
       
    39 @param aFramework    The data provider framework
       
    40 @param aConnection    The connection from which the request comes
       
    41 @return a pointer to the created request processor object
       
    42 */    
       
    43 EXPORT_C MMTPRequestProcessor* CMTPSetReferences::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    44     {
       
    45     CMTPSetReferences* self = new (ELeave) CMTPSetReferences(aFramework, aConnection);
       
    46     return self;
       
    47     }
       
    48 
       
    49 /**
       
    50 Destructor
       
    51 */    
       
    52 EXPORT_C CMTPSetReferences::~CMTPSetReferences()
       
    53     {
       
    54     delete iReferences;
       
    55     }
       
    56 
       
    57 /**
       
    58 Standard c++ constructor
       
    59 */    
       
    60 CMTPSetReferences::CMTPSetReferences(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
    61     CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPSetReferencesPolicy)/sizeof(TMTPRequestElementInfo), KMTPSetReferencesPolicy)
       
    62     {
       
    63     
       
    64     }
       
    65 
       
    66 /**
       
    67 SetReferences request handler
       
    68 start receiving reference data from the initiator
       
    69 */
       
    70 void CMTPSetReferences::ServiceL()
       
    71     {
       
    72     delete iReferences;
       
    73     iReferences = NULL;
       
    74     iReferences = CMTPTypeArray::NewL(EMTPTypeAUINT32);
       
    75     ReceiveDataL(*iReferences);
       
    76     }
       
    77 
       
    78 /**
       
    79 Apply the references to the specified object
       
    80 @return EFalse
       
    81 */    
       
    82 TBool CMTPSetReferences::DoHandleResponsePhaseL()
       
    83     {
       
    84     if(!VerifyReferenceHandlesL())
       
    85         {
       
    86         SendResponseL(EMTPRespCodeInvalidObjectReference);
       
    87         }
       
    88     else
       
    89         {
       
    90         MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr();
       
    91         TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    92         referenceMgr.SetReferencesL(TMTPTypeUint32(objectHandle), *iReferences);
       
    93         SendResponseL(EMTPRespCodeOK);
       
    94         }
       
    95     return EFalse;    
       
    96     }
       
    97 
       
    98 TBool CMTPSetReferences::HasDataphase() const
       
    99     {
       
   100     return ETrue;
       
   101     }
       
   102 
       
   103 /**
       
   104 Verify if the references are valid handles to objects
       
   105 @return ETrue if all the references are good, otherwise, EFalse
       
   106 */    
       
   107 TBool CMTPSetReferences::VerifyReferenceHandlesL() const
       
   108     {
       
   109     __ASSERT_DEBUG(iReferences, User::Invariant());
       
   110     TBool result = ETrue;
       
   111     TInt count = iReferences->NumElements();
       
   112     CMTPObjectMetaData* object(CMTPObjectMetaData::NewLC());
       
   113     MMTPObjectMgr& objectMgr = iFramework.ObjectMgr();
       
   114     for(TInt i = 0; i < count; i++)
       
   115         {
       
   116         TMTPTypeUint32 handle;
       
   117         iReferences->ElementL(i, handle);
       
   118         if(!objectMgr.ObjectL(handle, *object))
       
   119             {
       
   120             result = EFalse;
       
   121             break;
       
   122             }
       
   123         }
       
   124     CleanupStack::PopAndDestroy(object);
       
   125     return result;    
       
   126     }