mtpdataproviders/mtpimagedp/src/cmtpimagedpsetobjectproplist.cpp
changeset 0 d0791faffa3f
child 11 4843bb5893b6
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 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  @file
       
    18  @internalTechnology
       
    19 */
       
    20 
       
    21 #include <mtp/tmtptyperequest.h>
       
    22 #include <mtp/mtpdatatypeconstants.h>
       
    23 #include <mtp/mmtpdataproviderframework.h>
       
    24 #include <mtp/mmtpobjectmgr.h>
       
    25 #include <mtp/cmtpobjectmetadata.h>
       
    26 #include <mtp/cmtptypestring.h>
       
    27 #include <mtp/cmtptypeobjectproplist.h>
       
    28 
       
    29 #include "cmtpimagedpsetobjectproplist.h"
       
    30 #include "cmtpimagedpobjectpropertymgr.h"
       
    31 #include "cmtpimagedp.h"
       
    32 #include "mtpimagedputilits.h"
       
    33 
       
    34 __FLOG_STMT(_LIT8(KComponent,"CMTPImageDpSetObjectPropList");)
       
    35 
       
    36 MMTPRequestProcessor* CMTPImageDpSetObjectPropList::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider)
       
    37     {
       
    38     CMTPImageDpSetObjectPropList* self = new (ELeave) CMTPImageDpSetObjectPropList(aFramework, aConnection,aDataProvider);
       
    39     CleanupStack::PushL(self);
       
    40     self->ConstructL();
       
    41     CleanupStack::Pop(self);
       
    42     return self;
       
    43     }
       
    44     
       
    45 CMTPImageDpSetObjectPropList::~CMTPImageDpSetObjectPropList()
       
    46     {
       
    47     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::~CMTPImageDpSetObjectPropList"));
       
    48     delete iPropertyList;
       
    49     delete iObjectMeta;
       
    50     __FLOG(_L8("<< CMTPImageDpSetObjectPropList::~CMTPImageDpSetObjectPropList"));
       
    51     __FLOG_CLOSE;
       
    52     }
       
    53     
       
    54 CMTPImageDpSetObjectPropList::CMTPImageDpSetObjectPropList(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& aDataProvider) :
       
    55     CMTPRequestProcessor(aFramework, aConnection, 0, NULL),
       
    56     iDataProvider(aDataProvider),
       
    57     iPropertyMgr(aDataProvider.PropertyMgr())		
       
    58     {
       
    59     
       
    60     }
       
    61     
       
    62 void CMTPImageDpSetObjectPropList::ConstructL()
       
    63     {
       
    64     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    65     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::ConstructL"));
       
    66     iPropertyList = CMTPTypeObjectPropList::NewL();
       
    67     iObjectMeta = CMTPObjectMetaData::NewL();
       
    68     __FLOG(_L8("<< CMTPImageDpSetObjectPropList::ConstructL"));
       
    69     }
       
    70 
       
    71 void CMTPImageDpSetObjectPropList::ServiceL()
       
    72     {
       
    73     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::ConstructL"));
       
    74     ReceiveDataL(*iPropertyList);
       
    75     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::ConstructL"));
       
    76     }
       
    77 
       
    78 TBool CMTPImageDpSetObjectPropList::DoHandleResponsePhaseL()
       
    79     {
       
    80     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::DoHandleResponsePhaseL"));
       
    81     MMTPObjectMgr& objects(iFramework.ObjectMgr());
       
    82     TUint32 parameter(0);
       
    83     TMTPResponseCode responseCode(EMTPRespCodeOK);
       
    84     const TUint count(iPropertyList->NumberOfElements());
       
    85     iPropertyList->ResetCursor();
       
    86     __FLOG_VA((_L8("setting %d properties"), count));
       
    87     TUint32 preHandle = KMTPHandleNone;
       
    88     for (TUint i(0); ((i < count) && (responseCode == EMTPRespCodeOK)); i++)
       
    89         {
       
    90         CMTPTypeObjectPropListElement& element=iPropertyList->GetNextElementL(); 
       
    91         TUint32 handle = element.Uint32L(CMTPTypeObjectPropListElement::EObjectHandle);
       
    92         TUint16 propertyCode = element.Uint16L(CMTPTypeObjectPropListElement::EPropertyCode);
       
    93         TUint16 dataType = element.Uint16L(CMTPTypeObjectPropListElement::EDatatype);
       
    94         __FLOG_VA((_L8("set property, propertycode %d, datatype %d, handle %d"), propertyCode, dataType, handle));
       
    95         
       
    96         responseCode = MTPImageDpUtilits::VerifyObjectHandleL(iFramework, handle, *iObjectMeta);
       
    97         if ((EMTPRespCodeOK == responseCode) && (iObjectMeta->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId()))
       
    98             {
       
    99             // Object is owned by the FileDp
       
   100             responseCode = CheckPropCode(propertyCode, dataType);
       
   101             if (responseCode == EMTPRespCodeOK)
       
   102                 {
       
   103                 if(preHandle != handle)
       
   104                     {
       
   105                     iPropertyMgr.SetCurrentObjectL(*iObjectMeta, ETrue);
       
   106                     }
       
   107                 
       
   108                 switch(propertyCode)
       
   109                     {
       
   110                     case EMTPObjectPropCodeObjectFileName:
       
   111                     case EMTPObjectPropCodeName:
       
   112                     case EMTPObjectPropCodeDateModified:
       
   113                         iPropertyMgr.SetPropertyL(TMTPObjectPropertyCode(propertyCode), element.StringL(CMTPTypeObjectPropListElement::EValue));
       
   114                         objects.ModifyObjectL(*iObjectMeta);
       
   115                         break;
       
   116                     case EMTPObjectPropCodeNonConsumable:
       
   117                         iPropertyMgr.SetPropertyL(TMTPObjectPropertyCode(propertyCode), element.Uint8L(CMTPTypeObjectPropListElement::EValue));
       
   118                         objects.ModifyObjectL(*iObjectMeta);
       
   119                         break;                        
       
   120                     default:
       
   121                         responseCode = EMTPRespCodeInvalidObjectPropCode;
       
   122                         break;
       
   123                     }
       
   124                 
       
   125                 }
       
   126             if (responseCode != EMTPRespCodeOK)
       
   127                 {
       
   128                 // Return the index of the failed property in the response.
       
   129                 parameter = i;
       
   130                 }
       
   131             }
       
   132         preHandle = handle;
       
   133         }
       
   134 
       
   135     SendResponseL(responseCode, 1, &parameter);
       
   136     __FLOG(_L8("<< CMTPImageDpSetObjectPropList::DoHandleResponsePhaseL"));
       
   137     return EFalse;
       
   138     }
       
   139 
       
   140 TBool CMTPImageDpSetObjectPropList::HasDataphase() const
       
   141     {
       
   142     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::HasDataphase"));
       
   143     return ETrue;
       
   144     }
       
   145 
       
   146 TMTPResponseCode CMTPImageDpSetObjectPropList::CheckPropCode(TUint16 aPropertyCode, TUint16 aDataType) const
       
   147     {
       
   148     __FLOG(_L8(">> CMTPImageDpSetObjectPropList::CheckPropCode"));
       
   149     TMTPResponseCode responseCode = EMTPRespCodeOK;
       
   150     switch(aPropertyCode)
       
   151         {
       
   152         case EMTPObjectPropCodeStorageID:
       
   153         case EMTPObjectPropCodeObjectFormat:
       
   154         case EMTPObjectPropCodeObjectSize:		
       
   155         case EMTPObjectPropCodeParentObject:
       
   156         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   157         case EMTPObjectPropCodeProtectionStatus:
       
   158         case EMTPObjectPropCodeWidth:
       
   159         case EMTPObjectPropCodeHeight:
       
   160         case EMTPObjectPropCodeImageBitDepth:
       
   161         case EMTPObjectPropCodeRepresentativeSampleFormat:
       
   162         case EMTPObjectPropCodeRepresentativeSampleSize:
       
   163         case EMTPObjectPropCodeRepresentativeSampleHeight:
       
   164         case EMTPObjectPropCodeRepresentativeSampleWidth:
       
   165         case EMTPObjectPropCodeDateCreated:
       
   166             responseCode = 	EMTPRespCodeAccessDenied;
       
   167             break;
       
   168                             
       
   169         case EMTPObjectPropCodeObjectFileName:	
       
   170         case EMTPObjectPropCodeName:
       
   171         case EMTPObjectPropCodeDateModified:
       
   172             if (aDataType != EMTPTypeString)
       
   173                 {
       
   174                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   175                 }
       
   176             break;
       
   177         case EMTPObjectPropCodeNonConsumable:
       
   178             if (aDataType != EMTPTypeUINT8)
       
   179                 {
       
   180                 responseCode = EMTPRespCodeInvalidObjectPropFormat;
       
   181                 }
       
   182             break;            
       
   183         default:
       
   184             responseCode = EMTPRespCodeInvalidObjectPropCode;
       
   185         }
       
   186     __FLOG(_L8("<< CMTPImageDpSetObjectPropList::CheckPropCode"));
       
   187     return responseCode;
       
   188     }
       
   189     
       
   190