mtpdataproviders/mtppictbridgedp/src/cmtppictbridgedpgetobjectpropdesc.cpp
changeset 0 d0791faffa3f
child 2 4843bb5893b6
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 #include <f32file.h>
       
    17 #include <mtp/tmtptyperequest.h>
       
    18 #include <mtp/mmtpdataproviderframework.h>
       
    19 #include <mtp/mtpprotocolconstants.h>
       
    20 #include <mtp/mmtpobjectmgr.h>
       
    21 #include <mtp/cmtptypeobjectpropdesc.h>
       
    22 
       
    23 #include <mtp/cmtptypestring.h>
       
    24 #include "cmtppictbridgedpgetobjectpropdesc.h"
       
    25 #include "mtppictbridgedpconst.h"
       
    26 #include "mtppictbridgedppanic.h"
       
    27 
       
    28  
       
    29 _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}]?");
       
    30 
       
    31 /**
       
    32 Two-phase construction method
       
    33 @param aPlugin  The data provider plugin
       
    34 @param aFramework   The data provider framework
       
    35 @param aConnection  The connection from which the request comes
       
    36 @param aDataProvider  The pictBridge dataprovider
       
    37 @return a pointer to the created request processor object
       
    38 */ 
       
    39 MMTPRequestProcessor* CMTPPictBridgeGetObjectPropDesc::NewL(
       
    40     MMTPDataProviderFramework& aFramework, 
       
    41     MMTPConnection& aConnection,
       
    42     CMTPPictBridgeDataProvider& aDataProvider )
       
    43     {
       
    44     CMTPPictBridgeGetObjectPropDesc* self = new (ELeave) CMTPPictBridgeGetObjectPropDesc(aFramework, aConnection, aDataProvider);
       
    45     CleanupStack::PushL(self);
       
    46     self->ConstructL();
       
    47     CleanupStack::Pop(self);
       
    48     return self;
       
    49     }
       
    50 
       
    51 /**
       
    52 Destructor
       
    53 */      
       
    54 CMTPPictBridgeGetObjectPropDesc::~CMTPPictBridgeGetObjectPropDesc()
       
    55     {   
       
    56     delete iObjectProperty;
       
    57     }
       
    58 
       
    59 /**
       
    60 Standard c++ constructor
       
    61 */  
       
    62 CMTPPictBridgeGetObjectPropDesc::CMTPPictBridgeGetObjectPropDesc(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection, CMTPPictBridgeDataProvider& aDataProvider)
       
    63     :CMTPRequestProcessor(aFramework, aConnection, 0, NULL), iPictBridgeDP(aDataProvider)
       
    64     {
       
    65     }
       
    66     
       
    67 /**
       
    68 GetObjectPropDesc request handler
       
    69 */  
       
    70 void CMTPPictBridgeGetObjectPropDesc::ServiceL()
       
    71     {
       
    72     delete iObjectProperty;
       
    73     iObjectProperty = NULL; 
       
    74     
       
    75     TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter1);
       
    76     switch(propCode)
       
    77         {
       
    78         case EMTPObjectPropCodeStorageID:
       
    79             ServiceStorageIdL();
       
    80             break;
       
    81         case EMTPObjectPropCodeObjectFormat:
       
    82             ServiceObjectFormatL();
       
    83             break;
       
    84         case EMTPObjectPropCodeProtectionStatus:
       
    85             ServiceProtectionStatusL();
       
    86             break;
       
    87         case EMTPObjectPropCodeObjectSize:
       
    88             ServiceObjectSizeL();
       
    89             break;
       
    90         case EMTPObjectPropCodeObjectFileName:
       
    91             ServiceFileNameL();
       
    92             break;
       
    93         case EMTPObjectPropCodeDateModified:
       
    94             ServiceDateModifiedL();
       
    95             break;
       
    96         case EMTPObjectPropCodeParentObject:
       
    97             ServiceParentObjectL();
       
    98             break;
       
    99         case EMTPObjectPropCodePersistentUniqueObjectIdentifier:
       
   100             ServicePuidL();
       
   101             break;
       
   102         case EMTPObjectPropCodeName:
       
   103             ServiceNameL();
       
   104             break;
       
   105         case EMTPObjectPropCodeNonConsumable:
       
   106             ServiceNonConsumableL();
       
   107             break;
       
   108         default:
       
   109             Panic(EMTPPictBridgeDpUnsupportedProperty);
       
   110         }
       
   111     __ASSERT_DEBUG(iObjectProperty, Panic(EMTPPictBridgeDpObjectPropertyNull));
       
   112     iObjectProperty->SetUint32L(CMTPTypeObjectPropDesc::EGroupCode,GetPropertyGroupNumber(propCode));
       
   113     SendDataL(*iObjectProperty);    
       
   114     }
       
   115 
       
   116 
       
   117 /**
       
   118 Second-phase construction
       
   119 */          
       
   120 void CMTPPictBridgeGetObjectPropDesc::ConstructL()
       
   121     {
       
   122     }
       
   123         
       
   124 
       
   125 void CMTPPictBridgeGetObjectPropDesc::ServiceStorageIdL()
       
   126     {
       
   127     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeStorageID);    
       
   128     }
       
   129     
       
   130 void CMTPPictBridgeGetObjectPropDesc::ServiceObjectFormatL()
       
   131     {   
       
   132     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeObjectFormat); 
       
   133     }
       
   134     
       
   135 void CMTPPictBridgeGetObjectPropDesc::ServiceProtectionStatusL()
       
   136     {
       
   137     CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT16);
       
   138     CleanupStack::PushL(expectedForm);
       
   139     //Currently, we only support EMTPProtectionNoProtection and EMTPProtectionReadOnly
       
   140     TUint16 values[] = {EMTPProtectionNoProtection, EMTPProtectionReadOnly};
       
   141     TUint   numValues((sizeof(values) / sizeof(values[0])));
       
   142     for (TUint i = 0; i < numValues; i++)
       
   143         {
       
   144         TMTPTypeUint16 data(values[i]);
       
   145         expectedForm->AppendSupportedValueL(data);
       
   146         }  
       
   147     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeProtectionStatus, *expectedForm);          
       
   148     CleanupStack::PopAndDestroy(expectedForm);
       
   149     }
       
   150     
       
   151 void CMTPPictBridgeGetObjectPropDesc::ServiceObjectSizeL()
       
   152     {
       
   153     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeObjectSize);   
       
   154     }
       
   155     
       
   156     
       
   157 void CMTPPictBridgeGetObjectPropDesc::ServiceFileNameL()
       
   158     {
       
   159         CMTPTypeString* form = CMTPTypeString::NewLC( KMtpObjDescObjFileName ); // + form
       
   160         // Althrough iObjectProperty is released in ServiceL(),
       
   161         // release it here maybe a more safer way 
       
   162         if ( iObjectProperty != NULL )
       
   163         {
       
   164         delete iObjectProperty;
       
   165         iObjectProperty = NULL;
       
   166         }
       
   167 
       
   168         iObjectProperty = CMTPTypeObjectPropDesc::NewL( EMTPObjectPropCodeObjectFileName,
       
   169             CMTPTypeObjectPropDesc::ERegularExpressionForm,
       
   170             form );
       
   171 
       
   172         CleanupStack::PopAndDestroy( form ); // - form
       
   173     }
       
   174     
       
   175 void CMTPPictBridgeGetObjectPropDesc::ServiceDateModifiedL()
       
   176     {
       
   177     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeDateModified);
       
   178     }
       
   179     
       
   180 void CMTPPictBridgeGetObjectPropDesc::ServiceParentObjectL()
       
   181     {
       
   182     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeParentObject);
       
   183     }
       
   184     
       
   185 void CMTPPictBridgeGetObjectPropDesc::ServicePuidL()
       
   186     {
       
   187     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodePersistentUniqueObjectIdentifier);
       
   188     }
       
   189     
       
   190 void CMTPPictBridgeGetObjectPropDesc::ServiceNameL()
       
   191     {
       
   192     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeName); 
       
   193     }
       
   194     
       
   195 void CMTPPictBridgeGetObjectPropDesc::ServiceNonConsumableL()
       
   196     {
       
   197     CMTPTypeObjectPropDescEnumerationForm* expectedForm = CMTPTypeObjectPropDescEnumerationForm::NewL(EMTPTypeUINT8);
       
   198     CleanupStack::PushL(expectedForm);
       
   199     TUint8 values[] = {0,1};
       
   200     TUint   numValues((sizeof(values) / sizeof(values[0])));
       
   201     for (TUint i = 0; i < numValues; i++)
       
   202         {
       
   203         TMTPTypeUint8 data(values[i]);
       
   204         expectedForm->AppendSupportedValueL(data);
       
   205         }   
       
   206     iObjectProperty = CMTPTypeObjectPropDesc::NewL(EMTPObjectPropCodeNonConsumable, *expectedForm);     
       
   207     CleanupStack::PopAndDestroy(expectedForm);
       
   208     }
       
   209 
       
   210 
       
   211     
       
   212 TUint16  CMTPPictBridgeGetObjectPropDesc::GetPropertyGroupNumber(const TUint16 aPropCode) const
       
   213     {
       
   214     // begin from group 1, since group 0 is not used
       
   215     for(int group = 1; group <= KMTPDpPropertyGroupNumber; group++)
       
   216         {
       
   217         for( int propCodeIndex = 0 ; propCodeIndex < KMTPDpPropertyNumber ; propCodeIndex++)
       
   218             {
       
   219                 if(KMTPDpPropertyGroups[group][propCodeIndex] == aPropCode)
       
   220                     {
       
   221                     return group;
       
   222                     }
       
   223             }
       
   224         }
       
   225     
       
   226     // if not foud, the group number should be 0.
       
   227     return 0;
       
   228     }
       
   229