mtpdataproviders/mtpimagedp/src/cmtpimagedpsetobjectprotection.cpp
changeset 0 d0791faffa3f
child 47 63cf70d3ecd8
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 #include <mtp/cmtptypearray.h>
       
    17 #include <mtp/mmtpdataproviderframework.h>
       
    18 #include <mtp/tmtptyperequest.h>
       
    19 #include <mtp/cmtpobjectmetadata.h>
       
    20 #include <mtp/mmtpreferencemgr.h>
       
    21 #include <mtp/mmtpobjectmgr.h>
       
    22 
       
    23 #include "cmtpimagedpsetobjectreferences.h"
       
    24 #include "mtpimagedputilits.h"
       
    25 #include "cmtpimagedp.h"
       
    26 #include "cmtpimagedpsetobjectprotection.h"
       
    27 
       
    28 __FLOG_STMT(_LIT8(KComponent,"SetObjectProtection");)
       
    29 
       
    30 /**
       
    31 Two-phase construction method
       
    32 @param aPlugin The data provider plugin
       
    33 @param aFramework The data provider framework
       
    34 @param aConnection The connection from which the request comes
       
    35 @return a pointer to the created request processor object
       
    36 */    
       
    37 MMTPRequestProcessor* CMTPImageDpSetObjectProtection::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, CMTPImageDataProvider& /*aDataProvider*/)
       
    38     {
       
    39     CMTPImageDpSetObjectProtection* self = new (ELeave) CMTPImageDpSetObjectProtection(aFramework, aConnection);
       
    40     CleanupStack::PushL(self);
       
    41     self->ConstructL();
       
    42     CleanupStack::Pop(self);
       
    43     return self;
       
    44     }
       
    45 
       
    46 /**
       
    47 Destructor
       
    48 */    
       
    49 CMTPImageDpSetObjectProtection::~CMTPImageDpSetObjectProtection()
       
    50     {
       
    51     __FLOG(_L8(">> CMTPImageDpSetObjectProtection::~CMTPImageDpSetObjectProtection"));
       
    52     delete iObjMeta;
       
    53     __FLOG(_L8("<< CMTPImageDpSetObjectProtection::~CMTPImageDpSetObjectProtection"));
       
    54     
       
    55     __FLOG_CLOSE;
       
    56     }
       
    57 
       
    58 /**
       
    59 Standard c++ constructor
       
    60 */    
       
    61 CMTPImageDpSetObjectProtection::CMTPImageDpSetObjectProtection(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    62     :CMTPRequestProcessor(aFramework, aConnection, 0, NULL), 
       
    63     iRfs(aFramework.Fs())
       
    64     {
       
    65     }
       
    66 
       
    67 /**
       
    68 Second phase constructor
       
    69 */
       
    70 void CMTPImageDpSetObjectProtection::ConstructL()
       
    71     {
       
    72     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
    73     
       
    74     __FLOG(_L8(">> CMTPImageDpSetObjectProtection::ConstructL"));
       
    75     iObjMeta = CMTPObjectMetaData::NewL();
       
    76     __FLOG(_L8("<< CMTPImageDpSetObjectProtection::ConstructL"));
       
    77     
       
    78     }
       
    79 
       
    80 TMTPResponseCode CMTPImageDpSetObjectProtection::CheckRequestL()
       
    81     {
       
    82     __FLOG(_L8(">> CMTPImageDpSetObjectProtection::CheckRequestL"));
       
    83     
       
    84     TUint32 objectHandle = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    85     TUint32 statusValue = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
       
    86    
       
    87     //Check ObjectHanlde
       
    88     TMTPResponseCode responseCode = MTPImageDpUtilits::VerifyObjectHandleL(iFramework, objectHandle, *iObjMeta);
       
    89     
       
    90     if(EMTPRespCodeOK == responseCode)
       
    91         {    
       
    92         //Check parameter value
       
    93         switch(statusValue)
       
    94             {
       
    95             case EMTPProtectionNoProtection:
       
    96             case EMTPProtectionReadOnly:
       
    97                 {
       
    98                 responseCode = EMTPRespCodeOK;
       
    99                 }
       
   100                 break;
       
   101             default:
       
   102                 responseCode = EMTPRespCodeInvalidParameter;
       
   103                 break;     
       
   104             }
       
   105         }
       
   106     __FLOG_VA((_L8("CheckRequestL - Exit with responseCode = 0x%04X"), responseCode));
       
   107     __FLOG(_L8("<< CMTPImageDpSetObjectProtection::CheckRequestL"));
       
   108     
       
   109     return responseCode;
       
   110     }
       
   111 
       
   112 
       
   113 /**
       
   114 Apply the references to the specified object
       
   115 @return EFalse
       
   116 */    
       
   117 TBool CMTPImageDpSetObjectProtection::DoHandleResponsePhaseL()
       
   118     {
       
   119     return EFalse; 
       
   120     }
       
   121 
       
   122 /**
       
   123 GetReferences request handler
       
   124 */    
       
   125 void CMTPImageDpSetObjectProtection::ServiceL()
       
   126     {
       
   127     __FLOG(_L8(">> CMTPImageDpCopyObject::ServiceL"));
       
   128     TUint32 statusValue = Request().Uint32(TMTPTypeRequest::ERequestParameter2);
       
   129     TMTPResponseCode responseCode = EMTPRespCodeOK;
       
   130     TInt ret = KErrNone;
       
   131     
       
   132     switch(statusValue)
       
   133         {
       
   134         case EMTPProtectionNoProtection:
       
   135             {
       
   136             ret = iRfs.SetAtt(iObjMeta->DesC(CMTPObjectMetaData::ESuid),KEntryAttNormal,KEntryAttReadOnly);
       
   137             }
       
   138             break;
       
   139         case EMTPProtectionReadOnly:
       
   140             {
       
   141             ret = iRfs.SetAtt(iObjMeta->DesC(CMTPObjectMetaData::ESuid),KEntryAttReadOnly,KEntryAttNormal);
       
   142             }
       
   143             break;
       
   144         default:
       
   145             responseCode = EMTPRespCodeInvalidParameter;
       
   146             break;
       
   147         }
       
   148     
       
   149     if (ret != KErrNone)
       
   150         {
       
   151         responseCode = EMTPRespCodeAccessDenied;
       
   152         }
       
   153     
       
   154     SendResponseL(responseCode);    
       
   155     __FLOG(_L8("<< CMTPImageDpCopyObject::ServiceL"));
       
   156     }
       
   157