mtpfws/mtpfw/dataproviders/devdp/src/cmtpgetdeviceinfo.cpp
changeset 0 d0791faffa3f
child 3 8b094906a049
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 /**
       
    17  @file
       
    18  @internalComponent
       
    19 */
       
    20 #include <f32file.h> 
       
    21 #include <mtp/cmtpdataproviderplugin.h>
       
    22 #include <mtp/cmtptypearray.h>
       
    23 #include <mtp/cmtptypestring.h>
       
    24 #include <mtp/mtpdataproviderapitypes.h>
       
    25 #include <mtp/tmtptyperequest.h>
       
    26 
       
    27 #include "cmtpdataprovider.h"
       
    28 #include "cmtpdataprovidercontroller.h"
       
    29 #include "cmtpdevicedatastore.h"
       
    30 #include "cmtpgetdeviceinfo.h"
       
    31 #include "cmtptypedeviceinfo.h"
       
    32 #include "rmtpframework.h"
       
    33 #include "mtpdevdppanic.h"
       
    34 #include "mtpdevicedpconst.h"
       
    35 #include "rmtpdevicedpsingletons.h"
       
    36 #include "cmtpdevicedpconfigmgr.h"
       
    37 #include "cmtpservicemgr.h"
       
    38 
       
    39 // Class constants.
       
    40 __FLOG_STMT(_LIT8(KComponent,"GetDeviceInfo");)
       
    41 
       
    42 /**
       
    43 This identifies, in hundredths, the PTP version this device can support
       
    44 */
       
    45 static const TUint16 KMTPStandardVersion = 100;
       
    46 
       
    47 /**
       
    48 This identifies the PTP vendor-extension version that are in use by this device
       
    49 */
       
    50 static const TUint32 KMTPVendorExtensionId = 0x00000006;
       
    51 
       
    52 /**
       
    53 This identifies, in hundredths, the version of the MTP standard that this device supports
       
    54 */
       
    55 static const TUint16 KMTPVersion = 100;    // Currently 100
       
    56 
       
    57 static const TInt KMTPArrayGranularity = 15;
       
    58 
       
    59 /**
       
    60 Two-phase construction method
       
    61 @param aPlugin    The data provider plugin
       
    62 @param aFramework    The data provider framework
       
    63 @param aConnection    The connection from which the request comes
       
    64 @return a pointer to the created request processor object
       
    65 */    
       
    66 MMTPRequestProcessor* CMTPGetDeviceInfo::NewL(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection)
       
    67     {
       
    68     CMTPGetDeviceInfo* self = new (ELeave) CMTPGetDeviceInfo(aFramework, aConnection);
       
    69     CleanupStack::PushL(self);
       
    70     self->ConstructL();
       
    71     CleanupStack::Pop(self);
       
    72     return self;
       
    73     }
       
    74 
       
    75 /**
       
    76 Destructor.
       
    77 */    
       
    78 CMTPGetDeviceInfo::~CMTPGetDeviceInfo()
       
    79     {    
       
    80     __FLOG(_L8("~CMTPGetDeviceInfo - Entry"));
       
    81     delete iDeviceInfo;
       
    82     iDpSingletons.Close();
       
    83     iSingletons.Close();
       
    84     __FLOG(_L8("~CMTPGetDeviceInfo - Exit"));
       
    85     __FLOG_CLOSE;
       
    86     }
       
    87 
       
    88 /**
       
    89 Constructor.
       
    90 */    
       
    91 CMTPGetDeviceInfo::CMTPGetDeviceInfo(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) :
       
    92     CMTPRequestProcessor(aFramework, aConnection, 0, NULL)
       
    93     {
       
    94     
       
    95     }
       
    96     
       
    97 /**
       
    98 GetDeviceInfo request handler. Build and send device info data set.
       
    99 */    
       
   100 void CMTPGetDeviceInfo::ServiceL()
       
   101     {
       
   102     __FLOG(_L8("ServiceL - Entry"));
       
   103     BuildDeviceInfoL();
       
   104     SendDataL(*iDeviceInfo);
       
   105     __FLOG(_L8("ServiceL - Exit"));
       
   106     }
       
   107 
       
   108 /**
       
   109 Second-phase constructor.
       
   110 */        
       
   111 void CMTPGetDeviceInfo::ConstructL()
       
   112     {
       
   113     __FLOG_OPEN(KMTPSubsystem, KComponent);
       
   114     __FLOG(_L8("ConstructL - Entry")); 
       
   115     iSingletons.OpenL();
       
   116     iDpSingletons.OpenL(iFramework);
       
   117     iDeviceInfo = CMTPTypeDeviceInfo::NewL();
       
   118     __FLOG(_L8("ConstructL - Exit")); 
       
   119     }
       
   120 
       
   121 /**
       
   122 Populates device info data set
       
   123 */
       
   124 void CMTPGetDeviceInfo::BuildDeviceInfoL()
       
   125     {
       
   126     __FLOG(_L8("BuildDeviceInfoL - Entry")); 
       
   127     CMTPDeviceDataStore& device(iDpSingletons.DeviceDataStore());
       
   128     iDeviceInfo->SetUint16L(CMTPTypeDeviceInfo::EStandardVersion, KMTPStandardVersion);
       
   129     iDeviceInfo->SetUint32L(CMTPTypeDeviceInfo::EMTPVendorExtensionID, KMTPVendorExtensionId);
       
   130     iDeviceInfo->SetUint16L(CMTPTypeDeviceInfo::EMTPVersion, KMTPVersion);
       
   131     iDeviceInfo->SetStringL(CMTPTypeDeviceInfo::EMTPExtensions, iDpSingletons.DeviceDataStore().MTPExtensions());    
       
   132     iDeviceInfo->SetUint16L(CMTPTypeDeviceInfo::EFunctionalMode, EMTPFunctionalModeStandard);    
       
   133     iDeviceInfo->SetStringL(CMTPTypeDeviceInfo::EManufacturer, device.Manufacturer());
       
   134     iDeviceInfo->SetStringL(CMTPTypeDeviceInfo::EModel, device.Model());
       
   135     iDeviceInfo->SetStringL(CMTPTypeDeviceInfo::EDeviceVersion, device.DeviceVersion());
       
   136     iDeviceInfo->SetStringL(CMTPTypeDeviceInfo::ESerialNumber, device.SerialNumber());
       
   137     
       
   138     CMTPDataProviderController& dps(iSingletons.DpController());
       
   139     SetSupportedOperationsL(dps);
       
   140     SetSupportedEventsL(dps);
       
   141     SetSupportedDevicePropertiesL();
       
   142     SetSupportedCaptureFormatsL(dps);
       
   143     SetSupportedPlaybackFormatsL(dps);
       
   144     
       
   145     __FLOG(_L8("BuildDeviceInfoL - Exit")); 
       
   146     }
       
   147 
       
   148 /**
       
   149 Populates the supported operations field in the device info data set
       
   150 It enumerates the installed data provider plugins and retrieves the supported operations
       
   151 @param aDpController    A reference to the data provider controller
       
   152 */    
       
   153 void CMTPGetDeviceInfo::SetSupportedOperationsL(CMTPDataProviderController& aDpController)
       
   154     {
       
   155     __FLOG(_L8("SetSupportedOperationsL - Entry")); 
       
   156     
       
   157     TInt count = aDpController.Count();    
       
   158     RArray<TUint> supportedOperations(KMTPArrayGranularity);
       
   159     CleanupClosePushL(supportedOperations);
       
   160     const TInt32 KMTPImplementationUidDeviceDp(0x102827AF);
       
   161     const TInt32 KMTPImplementationUidFileDp(0x102827B0);
       
   162     const TInt32 KMTPImplementationUidProxyDp(0x102827B1);
       
   163     const TInt32 KMTPFrameworkDpCount(3);
       
   164     TBool bOnlyInternalDpLoad = count > KMTPFrameworkDpCount ? EFalse : ETrue;
       
   165     while(count--)
       
   166         {
       
   167         TInt32 uid = aDpController.DataProviderByIndexL(count).ImplementationUid().iUid;
       
   168         // The filter is added for licencee's request which will filtrate the symbian's internal
       
   169         // dp's supported enhance mode operations to make licencee's dp work.
       
   170         // Every new internal dp need add it's implementation id here to filtrate and increase
       
   171         // the KMTPFrameworkDpCount number.
       
   172         if ((uid == KMTPImplementationUidDeviceDp ||
       
   173             uid == KMTPImplementationUidFileDp ||
       
   174             uid == KMTPImplementationUidProxyDp) && !bOnlyInternalDpLoad)
       
   175             {
       
   176             AddToArrayWithFilterL(supportedOperations, aDpController.DataProviderByIndexL(count).SupportedCodes(EOperations));
       
   177             }
       
   178         else
       
   179             {
       
   180             AddToArrayL(supportedOperations, aDpController.DataProviderByIndexL(count).SupportedCodes(EOperations));
       
   181             }
       
   182         }
       
   183 
       
   184     CMTPTypeArray* mtpOperationsArray = CMTPTypeArray::NewL(EMTPTypeAUINT16, supportedOperations);
       
   185     CleanupStack::PopAndDestroy(&supportedOperations);
       
   186     CleanupStack::PushL(mtpOperationsArray); //unnecessary if Set operation below does not leave,         
       
   187     iDeviceInfo->SetL(CMTPTypeDeviceInfo::EOperationsSupported, *mtpOperationsArray);
       
   188     CleanupStack::PopAndDestroy(mtpOperationsArray);  
       
   189     __FLOG(_L8("SetSupportedOperationsL - Exit"));      
       
   190     }
       
   191 
       
   192 /**
       
   193 Populates the supported events field in the device info data set
       
   194 It enumerates the installed data provider plugins and retrieves the supported events
       
   195 @param aDpController    A reference to the data provider controller
       
   196 */    
       
   197 void CMTPGetDeviceInfo::SetSupportedEventsL(CMTPDataProviderController& aDpController)
       
   198     {
       
   199     __FLOG(_L8("SetSupportedEventsL - Entry"));
       
   200     TInt count = aDpController.Count();    
       
   201     RArray<TUint> supportedEvents(KMTPArrayGranularity);
       
   202     CleanupClosePushL(supportedEvents);
       
   203     while(count--)
       
   204         {
       
   205         AddToArrayL(supportedEvents, aDpController.DataProviderByIndexL(count).SupportedCodes(EEvents));
       
   206         }
       
   207     
       
   208     CMTPTypeArray* mtpEventArray = CMTPTypeArray::NewL(EMTPTypeAUINT16, supportedEvents);
       
   209     CleanupStack::PopAndDestroy(&supportedEvents);
       
   210     CleanupStack::PushL(mtpEventArray); //unnecessary if Set operation below does not leave,         
       
   211     iDeviceInfo->SetL(CMTPTypeDeviceInfo::EEventsSupported, *mtpEventArray);
       
   212     CleanupStack::PopAndDestroy(mtpEventArray);  
       
   213     __FLOG(_L8("SetSupportedEventsL - Exit"));  
       
   214     }
       
   215 
       
   216 /**
       
   217 Populates the supported device properties field in the device info data set
       
   218 */       
       
   219 void CMTPGetDeviceInfo::SetSupportedDevicePropertiesL()
       
   220 	{ 
       
   221 	__FLOG(_L8("SetSupportedDevicePropertiesL - Entry"));  
       
   222 	iDeviceInfo->SetL(CMTPTypeDeviceInfo::EDevicePropertiesSupported, 
       
   223 	iDpSingletons.DeviceDataStore().GetSupportedDeviceProperties());
       
   224 	__FLOG(_L8("SetSupportedDevicePropertiesL - Exit"));  
       
   225 	}
       
   226 
       
   227 /**
       
   228 Populates the supported capture formats field in the device info data set
       
   229 It enumerates the installed data provider plugins and retrieves the supported capture formats
       
   230 @param aDpController    A reference to the data provider controller
       
   231 */    
       
   232 void CMTPGetDeviceInfo::SetSupportedCaptureFormatsL(CMTPDataProviderController& aDpController)
       
   233     {
       
   234     __FLOG(_L8("SetSupportedCaptureFormatsL - Entry"));
       
   235     TInt count = aDpController.Count();    
       
   236     RArray<TUint> supportedCaptureFormats(KMTPArrayGranularity);
       
   237     CleanupClosePushL(supportedCaptureFormats);
       
   238 //get the formt supported information from the devdp rss file
       
   239   //and store it into the CArrayFix by passing the reference of the array.
       
   240   RArray<TUint> orderedFormats(KMTPArrayGranularity);
       
   241   CleanupClosePushL(orderedFormats);
       
   242   //get the count form the formt supported struct.
       
   243   TRAPD(errorCode,iDpSingletons.ConfigMgr().GetRssConfigInfoArrayL(orderedFormats, EDevDpFormats));
       
   244   if(KErrNone != errorCode)
       
   245 	  {
       
   246 	  __FLOG(_L8("There is an issue in reading format info from rss file "));
       
   247 	  }
       
   248 	
       
   249     while(count--)
       
   250         {
       
   251         AddToArrayL(supportedCaptureFormats, aDpController.DataProviderByIndexL(count).SupportedCodes(EObjectCaptureFormats));
       
   252         }
       
   253 	TInt insertIndex = 0;
       
   254 	//Remove the existing formats from the supportedPlaybackFormats and insert the 
       
   255 	//elements from orderedFormats at the begining.	
       
   256 	for(TInt orderedElements = 0; orderedElements <orderedFormats.Count(); orderedElements++ )
       
   257 		{
       
   258 	TInt index = supportedCaptureFormats.Find(orderedFormats[orderedElements]);	  
       
   259 	if(KErrNotFound != index)
       
   260 		{
       
   261 		supportedCaptureFormats.Remove(index);
       
   262 		//insert at insertindex position to make sure that value inserted at begening.
       
   263 		supportedCaptureFormats.Insert(orderedFormats[orderedElements], insertIndex);
       
   264 		insertIndex++;
       
   265 		}//else nothing 	  	
       
   266 		}
       
   267 	
       
   268 	//The formats which are defined in Device Service Extension should not be reported by GetDeviceInfo
       
   269 	RemoveServiceFormat(supportedCaptureFormats);
       
   270 	
       
   271 #ifdef _DEBUG
       
   272 	for(TInt i =0 ; i < supportedCaptureFormats.Count(); i++)
       
   273 	{
       
   274 	__FLOG_VA((_L8("Playback formats = %d"), supportedCaptureFormats[i]));
       
   275 	}
       
   276 #endif 
       
   277 	//before deleting make sure all the elements are added to supportedPlaybackFormats
       
   278 	CleanupStack::PopAndDestroy(&orderedFormats);
       
   279 
       
   280     CMTPTypeArray* mtpCaptureFormatArray = CMTPTypeArray::NewL(EMTPTypeAUINT16, supportedCaptureFormats);
       
   281     CleanupStack::PopAndDestroy(&supportedCaptureFormats);
       
   282     CleanupStack::PushL(mtpCaptureFormatArray); //unnecessary if Set operation below does not leave,         
       
   283     iDeviceInfo->SetL(CMTPTypeDeviceInfo::ECaptureFormats, *mtpCaptureFormatArray);
       
   284     CleanupStack::PopAndDestroy(mtpCaptureFormatArray); 
       
   285     __FLOG(_L8("SetSupportedCaptureFormatsL - Exit"));   
       
   286     }
       
   287 
       
   288 /**
       
   289 Populates the supported playback formats field in the device info data set
       
   290 It enumerates the installed data provider plugins and retrieves the supported playback formats
       
   291 @param aDpController    A reference to the data provider controller
       
   292 */    
       
   293 void CMTPGetDeviceInfo::SetSupportedPlaybackFormatsL(CMTPDataProviderController& aDpController)
       
   294     {
       
   295     __FLOG(_L8("SetSupportedPlaybackFormatsL - Entry"));
       
   296     TInt count = aDpController.Count();    
       
   297     RArray<TUint> supportedPlaybackFormats(KMTPArrayGranularity);	
       
   298     CleanupClosePushL(supportedPlaybackFormats);
       
   299 	
       
   300     //get the formt supported information from the devdp rss file
       
   301     //and store it into the CArrayFix by passing the reference of the array.
       
   302     RArray<TUint> orderedFormats(KMTPArrayGranularity);
       
   303     CleanupClosePushL(orderedFormats);
       
   304     //get the count form the formt supported struct.
       
   305     TRAPD(errorCode,iDpSingletons.ConfigMgr().GetRssConfigInfoArrayL(orderedFormats, EDevDpFormats));
       
   306 	if(KErrNone != errorCode)
       
   307 		{
       
   308 		__FLOG(_L8("There is an issue in reading format info from rss file "));
       
   309 		}
       
   310 
       
   311     while(count--)
       
   312         {
       
   313         AddToArrayL(supportedPlaybackFormats, aDpController.DataProviderByIndexL(count).SupportedCodes(EObjectPlaybackFormats));       
       
   314         }
       
   315 
       
   316 	TInt insertIndex = 0;
       
   317 	//Remove the existing formats from the supportedPlaybackFormats and insert the 
       
   318 	//elements from orderedFormats at the begining.	
       
   319  	for(TInt orderedElements = 0; orderedElements <orderedFormats.Count(); orderedElements++ )
       
   320  		{
       
   321 		TInt index = supportedPlaybackFormats.Find(orderedFormats[orderedElements]);	  
       
   322 		if(KErrNotFound != index)
       
   323 			{
       
   324 			supportedPlaybackFormats.Remove(index);
       
   325 			//insert at insertindex position to make sure that value inserted at begening.
       
   326 			supportedPlaybackFormats.Insert(orderedFormats[orderedElements], insertIndex);
       
   327 			insertIndex++;
       
   328 			}//else nothing 	  	
       
   329  		}
       
   330  	
       
   331  	//The formats which are defined in Device Service Extension should not be reported by GetDeviceInfo
       
   332  	RemoveServiceFormat(supportedPlaybackFormats);
       
   333  	
       
   334 #ifdef _DEBUG
       
   335 	for(TInt i =0 ; i < supportedPlaybackFormats.Count(); i++)
       
   336 	{
       
   337 	__FLOG_VA((_L8("Playback formats = %d"), supportedPlaybackFormats[i]));
       
   338 	}
       
   339 #endif 
       
   340     //before deleting make sure all the elements are added to supportedPlaybackFormats
       
   341     CleanupStack::PopAndDestroy(&orderedFormats);
       
   342 	
       
   343     CMTPTypeArray* mtpPlaybackFormatArray = CMTPTypeArray::NewL(EMTPTypeAUINT16, supportedPlaybackFormats);    
       
   344     CleanupStack::PopAndDestroy(&supportedPlaybackFormats);
       
   345     CleanupStack::PushL(mtpPlaybackFormatArray); //unnecessary if Set operation below does not leave,         
       
   346     iDeviceInfo->SetL(CMTPTypeDeviceInfo::EPlaybackFormats, *mtpPlaybackFormatArray);
       
   347     CleanupStack::PopAndDestroy(mtpPlaybackFormatArray);  
       
   348     __FLOG(_L8("SetSupportedPlaybackFormatsL - Exit"));  
       
   349     }
       
   350 
       
   351 /**
       
   352 Add elements from source array to the destination array without duplication
       
   353 @param aDestArray    The destination array
       
   354 @param aSrcArray    The source array
       
   355 */
       
   356 void CMTPGetDeviceInfo::AddToArrayL(RArray<TUint>& aDestArray, const RArray<TUint>& aSrcArray) const
       
   357     {
       
   358     TInt count(aSrcArray.Count());
       
   359     for (TInt i(0); (i < count); i++)
       
   360         {
       
   361         TInt err(aDestArray.InsertInOrder(aSrcArray[i]));
       
   362         if ((err != KErrNone) && (err != KErrAlreadyExists))
       
   363             {
       
   364             User::Leave(err);
       
   365             }
       
   366         }
       
   367     }
       
   368 
       
   369 /**
       
   370 Add elements from source array to the destination array without duplication
       
   371 User filter to help licensee's data provider's supported operation.
       
   372 @param aDestArray    The destination array
       
   373 @param aSrcArray    The source array
       
   374 */
       
   375 void CMTPGetDeviceInfo::AddToArrayWithFilterL(RArray<TUint>& aDestArray, const RArray<TUint>& aSrcArray) const
       
   376     {
       
   377     TInt count(aSrcArray.Count());
       
   378     for (TInt i(0); (i < count); i++)
       
   379         {
       
   380         // Apply filter
       
   381         if(aSrcArray[i] == EMTPOpCodeGetObjectPropList ||
       
   382            aSrcArray[i] == EMTPOpCodeSetObjectPropList||
       
   383            aSrcArray[i] == EMTPOpCodeSendObjectPropList ||
       
   384 			aSrcArray[i] == EMTPOpCodeGetFormatCapabilities )
       
   385             {
       
   386             __FLOG_VA((_L8("Filter ignored operation: %d"), aSrcArray[i]));
       
   387             continue;
       
   388             }
       
   389 
       
   390         TInt err(aDestArray.InsertInOrder(aSrcArray[i]));
       
   391         if ((err != KErrNone) && (err != KErrAlreadyExists))
       
   392             {
       
   393             User::Leave(err);
       
   394             }
       
   395         }
       
   396     }
       
   397 
       
   398 
       
   399 void CMTPGetDeviceInfo::RemoveServiceFormat(RArray<TUint>& aSupportedCaptureFormats)
       
   400 	{
       
   401 	__FLOG(_L8("RemovetServiceFormat - Entry"));
       
   402 	
       
   403 	TInt count = aSupportedCaptureFormats.Count();
       
   404 	count--;
       
   405 	while(count>=0)
       
   406 		{
       
   407         if(iSingletons.ServiceMgr().IsServiceFormatCode( aSupportedCaptureFormats[count] ))
       
   408             aSupportedCaptureFormats.Remove(count);
       
   409         count--;
       
   410 		}
       
   411 	__FLOG(_L8("RemovetServiceFormat - Exit")); 
       
   412 	}