mtpfws/mtpfw/dataproviders/devdp/src/cmtpgetstorageids.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 #include <mtp/cmtptypearray.h>
       
    17 #include <mtp/mmtpdataproviderframework.h>
       
    18 #include <mtp/mtpdatatypeconstants.h>
       
    19 #include <mtp/mmtpobjectmgr.h>
       
    20 #include <mtp/tmtptyperequest.h>
       
    21 #include <mtp/mtpdataproviderapitypes.h>
       
    22 
       
    23 #include "cmtpgetstorageids.h"
       
    24 #include "cmtpstoragemgr.h"
       
    25 #include "mtpdevdppanic.h"
       
    26 #include "mtpdevicedpconst.h"
       
    27 #include "cmtpdataprovidercontroller.h"
       
    28 #include "cmtpdataprovider.h"
       
    29 
       
    30 /**
       
    31 GetStorageIds request processor factory method.
       
    32 @param aPlugin The data provider plugin.
       
    33 @param aFramework The data provider framework
       
    34 @param aConnection The connection on which the request is being processed.
       
    35 @return A pointer to an GetStorageIds request processor. Ownership IS 
       
    36 transfered.
       
    37 @leave One of the system wide error codes, if a processing failure occurs.
       
    38 */
       
    39 MMTPRequestProcessor* CMTPGetStorageIds::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    40     {    
       
    41     CMTPGetStorageIds* self = new (ELeave) CMTPGetStorageIds(aFramework, aConnection);
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop(self);
       
    45     return self;
       
    46     }
       
    47 
       
    48 /**
       
    49 Destructor.
       
    50 */    
       
    51 CMTPGetStorageIds::~CMTPGetStorageIds()
       
    52     {    
       
    53     delete iStorageIds;
       
    54     iFrameworkSingletons.Close();
       
    55     }
       
    56 
       
    57 /**
       
    58 Constructor.
       
    59 */    
       
    60 CMTPGetStorageIds::CMTPGetStorageIds(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
    61     CMTPRequestProcessor(aFramework, aConnection, 0, NULL)
       
    62     {
       
    63     
       
    64     }
       
    65        
       
    66 void CMTPGetStorageIds::ServiceL()
       
    67     {
       
    68     BuildStorageIdsL();
       
    69     SendDataL(*iStorageIds);    
       
    70     }
       
    71 
       
    72 /**
       
    73 Second-phase constructor.
       
    74 */        
       
    75 void CMTPGetStorageIds::ConstructL()
       
    76     {
       
    77     iFrameworkSingletons.OpenL();
       
    78     }
       
    79 
       
    80 /**
       
    81 Constructs an MTP StorageID array dataset.
       
    82 @leave One of the system wide error codes, if a processing failure occurs.
       
    83 */
       
    84 void CMTPGetStorageIds::BuildStorageIdsL()
       
    85     {
       
    86     // Retrieve the available logical StorageIDs
       
    87     RPointerArray<const CMTPStorageMetaData> storages;
       
    88     CleanupClosePushL(storages);
       
    89     iFrameworkSingletons.StorageMgr().GetLogicalStoragesL(TMTPStorageMgrQueryParams(), storages);
       
    90     
       
    91     // Construct the dataset.
       
    92     iStorageIds = CMTPTypeArray::NewL(EMTPTypeAUINT32);
       
    93     RArray<TUint> storageIds;
       
    94     CleanupClosePushL(storageIds);
       
    95     const TUint KCount(storages.Count());
       
    96     TUint dpid = 0;
       
    97     for (TUint i(0); (i < KCount); i++)
       
    98         {
       
    99         dpid = iFrameworkSingletons.StorageMgr().LogicalStorageOwner( storages[i]->Uint(CMTPStorageMetaData::EStorageId) );
       
   100         // The storage ID of service data providers will not be reported in GetStorageIDs operation.
       
   101         if( iFrameworkSingletons.DpController().DataProviderL(dpid).SupportedCodes( EServiceIDs ).Count() != 0 )
       
   102         	{
       
   103 			continue;
       
   104 			}
       
   105            
       
   106         TUint storageId = storages[i]->Uint(CMTPStorageMetaData::EStorageId);
       
   107         if(EDriveE == iFrameworkSingletons.StorageMgr().DriveNumber(storageId))
       
   108         	{
       
   109         	storageIds.InsertL(storageId, 0);
       
   110         	}
       
   111         else
       
   112         	{
       
   113         	storageIds.AppendL(storageId);
       
   114         	}
       
   115         }
       
   116     iStorageIds->AppendL(storageIds);
       
   117     CleanupStack::PopAndDestroy(2, &storages);
       
   118     }
       
   119