mtpdataproviders/mtpimagedp/src/mtpimagedpgetformatcapabilities.cpp
changeset 0 d0791faffa3f
child 2 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/cmtptypeinterdependentpropdesc.h>
       
    22 #include <mtp/cmtptypeobjectpropdesc.h>
       
    23 #include <mtp/mtpprotocolconstants.h>
       
    24 #include <mtp/mmtpdataproviderframework.h>
       
    25 #include <mtp/cmtptypestring.h>
       
    26 
       
    27 #include "cmtpimagedpgetformatcapabilities.h"
       
    28 #include "cmtpimagedp.h"
       
    29 
       
    30 __FLOG_STMT(_LIT8(KComponent,"ImageDpGetFormatCapabilities");)
       
    31 MMTPRequestProcessor* CMTPImageDpGetFormatCapabilities::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection,CMTPImageDataProvider& /*aDataProvider*/)
       
    32     {
       
    33     CMTPImageDpGetFormatCapabilities* self = new (ELeave) CMTPImageDpGetFormatCapabilities(aFramework, aConnection);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL();
       
    36     CleanupStack::Pop(self);
       
    37     return self;
       
    38     }
       
    39     
       
    40 CMTPImageDpGetFormatCapabilities::~CMTPImageDpGetFormatCapabilities()
       
    41     {
       
    42     __FLOG(_L8(">> ~CMTPPictureDpGetObject"));
       
    43     delete iCapabilityList;
       
    44     __FLOG(_L8("<< ~CMTPPictureDpGetObject"));
       
    45     __FLOG_CLOSE;
       
    46     }
       
    47 
       
    48 void CMTPImageDpGetFormatCapabilities::ServiceL()
       
    49     {
       
    50     __FLOG(_L8(">> CMTPPictureDpGetFormatCapabilities::ServiceL"));
       
    51     delete iCapabilityList;
       
    52     iCapabilityList = NULL;
       
    53     iCapabilityList = CMTPTypeFormatCapabilityList::NewL();
       
    54     BuildFormatExifJpegL();
       
    55     SendDataL(*iCapabilityList); 
       
    56     __FLOG(_L8("<< CMTPPictureDpGetFormatCapabilities::ServiceL"));   
       
    57     }
       
    58     
       
    59 void CMTPImageDpGetFormatCapabilities::BuildFormatExifJpegL()
       
    60     {
       
    61     __FLOG(_L8(">> CMTPPictureDpGetFormatCapabilities::BuildFormatExifJpegL"));
       
    62     CMTPTypeInterdependentPropDesc*  interDesc = CMTPTypeInterdependentPropDesc::NewLC();
       
    63     CMTPTypeFormatCapability* frmCap = CMTPTypeFormatCapability::NewLC( EMTPFormatCodeEXIFJPEG ,interDesc );
       
    64     
       
    65     //EMTPObjectPropCodeStorageID
       
    66     CMTPTypeObjectPropDesc* desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeStorageID);
       
    67     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeStorageID)); 
       
    68     frmCap->AppendL(desc);
       
    69     CleanupStack::Pop(1, desc);
       
    70     
       
    71     //EMTPObjectPropCodeObjectFormat
       
    72     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeObjectFormat);
       
    73     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeObjectFormat));
       
    74     frmCap->AppendL(desc);
       
    75     CleanupStack::Pop(1, desc);
       
    76     
       
    77     //EMTPObjectPropCodeProtectionStatus
       
    78     frmCap->AppendL( ServiceProtectionStatusL() );
       
    79     
       
    80     //EMTPObjectPropCodeObjectSize
       
    81     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeObjectSize);
       
    82     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeObjectSize));
       
    83     frmCap->AppendL(desc);
       
    84     CleanupStack::Pop(1, desc);
       
    85     
       
    86     //EMTPObjectPropCodeObjectFileName
       
    87     _LIT(KMtpObjDescObjFileName, "[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 7}\\.[[a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~][a-zA-Z!#\\$%&'\\(\\)\\-0-9@\\^_\\`\\{\\}\\~ ]{0, 2}]?");
       
    88     CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName );
       
    89     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeObjectFileName, CMTPTypeObjectPropDesc::ERegularExpressionForm, form);
       
    90     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeObjectFileName));
       
    91     frmCap->AppendL(desc);
       
    92     CleanupStack::Pop(1, desc); 
       
    93     CleanupStack::PopAndDestroy(form ); 
       
    94     
       
    95     //EMTPObjectPropCodeDateModified
       
    96     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeDateModified);
       
    97     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeDateModified));
       
    98     frmCap->AppendL(desc);
       
    99     CleanupStack::Pop(1, desc);
       
   100     
       
   101     //EMTPObjectPropCodeParentObject
       
   102     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeParentObject);
       
   103     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeParentObject));
       
   104     frmCap->AppendL(desc);
       
   105     CleanupStack::Pop(1, desc);
       
   106     
       
   107     //EMTPObjectPropCodePersistentUniqueObjectIdentifier
       
   108     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodePersistentUniqueObjectIdentifier);
       
   109     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodePersistentUniqueObjectIdentifier));
       
   110     frmCap->AppendL(desc);
       
   111     CleanupStack::Pop(1, desc);
       
   112 
       
   113     //EMTPObjectPropCodeName
       
   114     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeName);
       
   115     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeName));
       
   116     frmCap->AppendL(desc);
       
   117     CleanupStack::Pop(1, desc);
       
   118     
       
   119     //EMTPObjectPropCodeNonConsumable
       
   120     frmCap->AppendL(ServiceNonConsumableL() );
       
   121     
       
   122     
       
   123     
       
   124     CMTPTypeObjectPropDesc::TPropertyInfo info;
       
   125     info.iDataType     = EMTPTypeString;
       
   126     info.iFormFlag     = CMTPTypeObjectPropDesc::EDateTimeForm;
       
   127     info.iGetSet       = CMTPTypeObjectPropDesc::EReadOnly;
       
   128     //EMTPObjectPropCodeDateCreated
       
   129     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeDateCreated, info, NULL);
       
   130     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeDateCreated));
       
   131     frmCap->AppendL(desc);
       
   132     CleanupStack::Pop(1, desc);
       
   133     
       
   134     info.iDataType     = EMTPTypeUINT32;
       
   135     info.iFormFlag     = CMTPTypeObjectPropDesc::ERangeForm;
       
   136     
       
   137     CMTPTypeObjectPropDescRangeForm* expectedForm = CMTPTypeObjectPropDescRangeForm::NewLC(EMTPTypeUINT32);
       
   138     expectedForm->SetUint32L(CMTPTypeObjectPropDescRangeForm::EMinimumValue, 0x00000001);
       
   139     expectedForm->SetUint32L(CMTPTypeObjectPropDescRangeForm::EMaximumValue, 0x20000000);
       
   140     expectedForm->SetUint32L(CMTPTypeObjectPropDescRangeForm::EStepSize, 0x00000001);
       
   141     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeWidth, info, expectedForm);
       
   142     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeWidth));
       
   143     frmCap->AppendL(desc);
       
   144     CleanupStack::Pop(1, desc);
       
   145     
       
   146     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeHeight, info, expectedForm);
       
   147     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeHeight));
       
   148     frmCap->AppendL(desc);
       
   149     CleanupStack::Pop(1, desc);
       
   150     
       
   151     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeImageBitDepth, info, expectedForm);
       
   152     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeImageBitDepth));
       
   153     frmCap->AppendL(desc);
       
   154     CleanupStack::Pop(1, desc);
       
   155     
       
   156     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeRepresentativeSampleSize, info, expectedForm);
       
   157     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeRepresentativeSampleSize));
       
   158     frmCap->AppendL(desc);
       
   159     CleanupStack::Pop(1, desc);
       
   160     
       
   161     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeRepresentativeSampleHeight, info, expectedForm);
       
   162     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeRepresentativeSampleHeight));
       
   163     frmCap->AppendL(desc);
       
   164     CleanupStack::Pop(1, desc);
       
   165     
       
   166     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeRepresentativeSampleWidth, info, expectedForm);
       
   167     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeRepresentativeSampleWidth));
       
   168     frmCap->AppendL(desc);
       
   169     CleanupStack::Pop(1, desc);
       
   170     CleanupStack::PopAndDestroy(expectedForm);
       
   171     
       
   172     info.iDataType = EMTPTypeUINT16;
       
   173     info.iFormFlag = CMTPTypeObjectPropDesc::EEnumerationForm;
       
   174     CMTPTypeObjectPropDescEnumerationForm* expectedEnumForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT16);
       
   175     CleanupStack::PushL(expectedEnumForm);
       
   176     TUint16 values[] = {EMTPFormatCodeEXIFJPEG};
       
   177     TUint   numValues((sizeof(values) / sizeof(values[0])));
       
   178     for (TUint i = 0; i < numValues; i++)
       
   179         {
       
   180         TMTPTypeUint16 data(values[i]);
       
   181         expectedEnumForm->AppendSupportedValueL(data);
       
   182         }
       
   183     desc = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeRepresentativeSampleFormat, info, expectedEnumForm);
       
   184     desc->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeRepresentativeSampleFormat));
       
   185     frmCap->AppendL(desc);
       
   186     CleanupStack::Pop(1, desc);
       
   187     CleanupStack::PopAndDestroy(expectedEnumForm);
       
   188     
       
   189     iCapabilityList->AppendL(frmCap);
       
   190     CleanupStack::Pop(frmCap);
       
   191     CleanupStack::Pop(interDesc);
       
   192     __FLOG(_L8("<< CMTPPictureDpGetFormatCapabilities::BuildFormatExifJpegL"));
       
   193     }
       
   194 
       
   195 
       
   196 CMTPTypeObjectPropDesc* CMTPImageDpGetFormatCapabilities::ServiceProtectionStatusL()
       
   197     {
       
   198     __FLOG(_L8(">> CMTPPictureDpGetFormatCapabilities::ServiceProtectionStatusL"));
       
   199     CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT16);
       
   200     CleanupStack::PushL(expectedForm);
       
   201     //Currently, we only support EMTPProtectionNoProtection and EMTPProtectionReadOnly
       
   202 //  TUint16 values[] = {EMTPProtectionNoProtection, EMTPProtectionReadOnly, EMTPProtectionReadOnlyData, EMTPProtectionNonTransferable};
       
   203     TUint16 values[] = {EMTPProtectionNoProtection, EMTPProtectionReadOnly};
       
   204     TUint   numValues((sizeof(values) / sizeof(values[0])));
       
   205     for (TUint i = 0; i < numValues; i++)
       
   206         {
       
   207         TMTPTypeUint16 data(values[i]);
       
   208         expectedForm->AppendSupportedValueL(data);
       
   209         }
       
   210     CMTPTypeObjectPropDesc* ret = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeProtectionStatus, *expectedForm);
       
   211     ret->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeProtectionStatus));
       
   212     CleanupStack::Pop(1, ret);
       
   213     CleanupStack::PopAndDestroy(expectedForm);
       
   214     __FLOG(_L8("<< CMTPPictureDpGetFormatCapabilities::ServiceProtectionStatusL"));
       
   215     return ret;
       
   216    
       
   217     }
       
   218 
       
   219 CMTPTypeObjectPropDesc* CMTPImageDpGetFormatCapabilities::ServiceNonConsumableL()
       
   220     {
       
   221     __FLOG(_L8(">> CMTPPictureDpGetFormatCapabilities::ServiceNonConsumableL"));
       
   222     CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT8);
       
   223     CleanupStack::PushL(expectedForm);
       
   224     TUint8 values[] = {0,1};
       
   225     TUint   numValues((sizeof(values) / sizeof(values[0])));
       
   226     for (TUint i = 0; i < numValues; i++)
       
   227         {
       
   228         TMTPTypeUint8 data(values[i]);
       
   229         expectedForm->AppendSupportedValueL(data);
       
   230         }   
       
   231     CMTPTypeObjectPropDesc* ret = CMTPTypeObjectPropDesc::NewLC(EMTPObjectPropCodeNonConsumable, *expectedForm);
       
   232     ret->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode, GetPropertyGroupNumber(EMTPObjectPropCodeNonConsumable));
       
   233     CleanupStack::Pop(1, ret);
       
   234     CleanupStack::PopAndDestroy(expectedForm);
       
   235     __FLOG(_L8("<< CMTPPictureDpGetFormatCapabilities::ServiceNonConsumableL"));
       
   236     return ret;
       
   237     }
       
   238 
       
   239 
       
   240 TMTPResponseCode CMTPImageDpGetFormatCapabilities::CheckRequestL()
       
   241     {
       
   242     __FLOG(_L8(">> CMTPPictureDpGetFormatCapabilities::CheckRequestL"));
       
   243     iFormatCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
   244     if((iFormatCode != EMTPFormatCodeEXIFJPEG) && (iFormatCode != KMTPFormatsAll))
       
   245         {
       
   246         return EMTPRespCodeInvalidObjectFormatCode;
       
   247         }
       
   248     __FLOG(_L8("<< CMTPPictureDpGetFormatCapabilities::CheckRequestL"));   
       
   249     return EMTPRespCodeOK; 
       
   250     }
       
   251     
       
   252 
       
   253 CMTPImageDpGetFormatCapabilities::CMTPImageDpGetFormatCapabilities(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
   254     CMTPRequestProcessor(aFramework, aConnection, 0, NULL)
       
   255     {
       
   256     }
       
   257     
       
   258 void CMTPImageDpGetFormatCapabilities::ConstructL()
       
   259     {
       
   260     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   261     __FLOG(_L8(">> CMTPPictureDpGetFormatCapabilities::ConstructL"));
       
   262     __FLOG(_L8("<< CMTPPictureDpGetFormatCapabilities::ConstructL"));
       
   263     }
       
   264 
       
   265 TUint16 CMTPImageDpGetFormatCapabilities::GetPropertyGroupNumber(const TUint16 aPropCode) const
       
   266     {
       
   267     for( TInt propCodeIndex = 0 ; propCodeIndex < KMTPImageDpGroupOneSize ; propCodeIndex++)
       
   268         {
       
   269             if(KMTPImageDpGroupOneProperties[propCodeIndex] == aPropCode)
       
   270                 {
       
   271                 return KMTPImageDpPropertyGroupOneNumber;
       
   272                 }
       
   273         }
       
   274     
       
   275     // if not foud, the group number should be 0.
       
   276     return 0;
       
   277     }
       
   278    
       
   279 
       
   280