examples/SFExamples/RecipeEx/src/DeviceCapabilitiesScan.cpp

00001 // Symbian Foundation Example Code
00002 // 
00003 // This software is in the public domain. No copyright is claimed, and you 
00004 // may use it for any purpose without license from the Symbian Foundation.
00005 // No warranty for any purpose is expressed or implied by the authors or
00006 // the Symbian Foundation. 
00007 
00008 
00009 #include <VersionInfo.h> 
00010 #include <F32File.h> 
00011 #include <W32std.h>
00012 #include <HAL.h>
00013 #include <aknutils.h>
00014 
00016 #include <ecom/ecom.h>
00017 #include <mmf/common/mmfcontrollerpluginresolver.h>
00018 
00020 #include <sensrvchannelfinder.h>
00021 #include <sensrvchannel.h>
00022 #include <sensrvmagnetometersensor.h>
00023 #include <sensrvgeneralproperties.h>
00024 #include <sensrvmagnetometersensor.h>
00025 #include <sensrvaccelerometersensor.h>
00026 #include <sensrvmagneticnorthsensor.h>
00027 #include <sensrvproximitysensor.h>
00028 #include <sensrvilluminationsensor.h>
00029 #include <sensrvorientationsensor.h>
00030 #include <sensrvdatalistener.h> 
00031 #include <sensrvtappingsensor.h> 
00032 #include <sensrvtypes.h> 
00033 #include <PtiEngine.h>
00034 #include <ptilanguage.h>
00035 
00036 
00038 #include "DeviceCapabilitiesScan.h"
00039 #include "LogContainer.h"
00040 
00041 // Constants
00042 
00044 #define KMmfUidPluginInterfaceCodec                             0x101F4AA6
00045 //#define KMmfUidPluginInterfaceFormatEncode            0x101F53BF
00046 //#define KMmfUidPluginInterfaceFormatDecode            0x101F53BE
00047 //#define KMmfUidPluginInterfaceDataSource              0x101F53AF
00048 //#define KMmfUidPluginInterfaceDataSink                        0x101F53B0
00049 //#define KMmfUidPluginInterfaceController              0x101F4F47
00050 //#define KMmfUidPluginInterfaceHwDevice                        0x101F4AA8
00051 //#define KUidDevVideoDecoderHwDeviceDefine     0x101fb4be
00052 //#define KUidDevVideoPostProcessorHwDeviceDefine 0x101fb4bf
00053 //#define KUidDevVideoEncoderHwDeviceDefine     0x101fb4c0
00054 //#define KUidDevVideoPreProcessorHwDeviceDefine  0x101fb4c1
00055 
00056 static TInt interfaceUids[]=
00057         {
00058         KMmfUidPluginInterfaceCodec//,
00059         //KMmfUidPluginInterfaceFormatEncode,
00060         //KMmfUidPluginInterfaceFormatDecode,
00061         //KMmfUidPluginInterfaceDataSource,
00062         //KMmfUidPluginInterfaceDataSink,
00063         //KMmfUidPluginInterfaceController,
00064         //KMmfUidPluginInterfaceHwDevice,
00065         //KUidDevVideoDecoderHwDeviceDefine,
00066         //KUidDevVideoPostProcessorHwDeviceDefine,
00067         //KUidDevVideoEncoderHwDeviceDefine,
00068         //KUidDevVideoPreProcessorHwDeviceDefine
00069         };
00070 
00072 _LIT(KFailure, "Failed to retrieve capabilities with error code %d");
00073 
00075 _LIT(KDisplayMode0, "ENone");
00076 _LIT(KDisplayMode1, "EGray2");
00077 _LIT(KDisplayMode2, "EGray4");
00078 _LIT(KDisplayMode3, "EGray16");
00079 _LIT(KDisplayMode4, "EGray256");
00080 _LIT(KDisplayMode5, "EColor16");
00081 _LIT(KDisplayMode6, "EColor256");
00082 _LIT(KDisplayMode7, "EColor64K");
00083 _LIT(KDisplayMode8, "EColor16M");
00084 _LIT(KDisplayMode9, "ERgb");
00085 _LIT(KDisplayMode10, "EColor4K");
00086 _LIT(KDisplayMode11, "EColor16MU");
00087 _LIT(KDisplayMode12, "EColor16MA");
00088 _LIT(KDisplayMode13, "EColor16MAP");
00089 _LIT(KDisplayMode14, "EColorLast");
00090 
00092 _LIT(KOrientation0, "EGraphicsOrientationNormal");
00093 _LIT(KOrientation1, "EGraphicsOrientationRotated90");
00094 _LIT(KOrientation2, "EGraphicsOrientationRotated180");
00095 _LIT(KOrientation3, "EGraphicsOrientationRotated270");
00096 
00098 _LIT(KTxtChannelDoubleTapping, "DoubleTapping");        
00099 _LIT(KTxtChannelTapping, "Tapping");    
00100 _LIT(KTxtChannelOrientation, "Orientation");    
00101 _LIT(KTxtChannelRotation, "Rotation");
00102 _LIT(KTxtChannelProximity, "Proximity");
00103 _LIT(KTxtChannelMagnetometer, "Magnetometer");  
00104 _LIT(KTxtChannelMagneticNorth, "Magnetic North");       
00105 _LIT(KTxtChannelAmbientLight, "Ambient Light");
00106 _LIT(KTxtChannelAccelerometer, "Accelerometer");
00107 _LIT(KTxtChannelUnknown, "Unknown");
00108 
00109 
00113 CDeviceCapabilitiesScan::CDeviceCapabilitiesScan(CLogContainer* aLogView) :
00114         CActive(EPriorityStandard), 
00115         iLogView(aLogView)
00116         {
00117         }
00118 
00122 CDeviceCapabilitiesScan* CDeviceCapabilitiesScan::NewLC(CLogContainer* aLogView)
00123         {
00124         CDeviceCapabilitiesScan* self = new (ELeave) CDeviceCapabilitiesScan(aLogView);
00125         CleanupStack::PushL(self);
00126         self->ConstructL();
00127         return self;
00128         }
00129 
00133 CDeviceCapabilitiesScan* CDeviceCapabilitiesScan::NewL(CLogContainer* aLogView)
00134         {
00135         CDeviceCapabilitiesScan* self = CDeviceCapabilitiesScan::NewLC(aLogView);
00136         CleanupStack::Pop(self); 
00137         return self;
00138         }
00139 
00141 void CDeviceCapabilitiesScan::ConstructL()
00142         {
00143         CActiveScheduler::Add(this); // Add to scheduler
00144         }
00145 
00147 CDeviceCapabilitiesScan::~CDeviceCapabilitiesScan()
00148         {
00149         Cancel(); // Cancel any request, if outstanding
00150         // Delete instance variables if any
00151         }
00152 
00154 void CDeviceCapabilitiesScan::DoCancel()
00155         {
00156         }
00157 
00159 void CDeviceCapabilitiesScan::Start()
00160         {
00161         Cancel(); // Cancel any request, just to be sure
00162                 
00163         // Begin in the uninitialized state then complete the active object.
00164         // We can then move to the next state within the RunL.
00165         iState = EUninitialized;
00166         SelfComplete(KErrNone);
00167         }
00168 
00170 void CDeviceCapabilitiesScan::RunL()
00171         {
00172         if (iStatus.Int()!=KErrNone)
00173                 {
00174                 TBuf<50> errBuf;
00175                 errBuf.Format(KFailure, iStatus.Int());
00176                 if (iLogView)
00177                         {
00178                         iLogView->LogEntryL(errBuf);
00179                         iState = EError;
00180                         return;
00181                         }
00182                 }
00183         
00184         switch (iState)
00185                 {
00186                 case EUninitialized:
00187                         {
00188                         // First we will discover platform version information.
00189                         TRAPD(err, DiscoverPlatformVersionTextL());
00190                         SelfComplete(err);
00191                         break;
00192                         }
00193                 case EDiscoveringPlatformVersion:
00194                         {
00195                         // Get screen data
00196                         TRAPD(err, DiscoverDisplayScreensInfoL());
00197                         SelfComplete(err);
00198                         break;
00199                         }
00200                 case EDiscoveringDisplayScreenInfo:
00201                         {
00202                         // Get Touch support
00203                         TRAPD(ret, DiscoverAvailableInputModesL());
00204                         SelfComplete(ret);
00205                         break;
00206                         }
00207                 case EDiscoveringInputCapabilities:     
00208                         {
00209                         // Discover multimedia plugin support
00210                         TRAPD(err, DiscoverMultimediaPluginSupportL());
00211                         SelfComplete(err);
00212                         break;
00213                         }       
00214                 case EDiscoveringMultimediaEcomPlugins:
00215                         {
00216                         // Discover available sensors
00217                         TRAPD(err, DiscoverAvailableSensorsL());
00218                         SelfComplete(err);
00219                         break;
00220                         }       
00221                 default:
00222                         break;
00223                 }
00224         
00225         }
00226 
00227 TInt CDeviceCapabilitiesScan::RunError(TInt /*aError*/)
00228         {
00229         return KErrNone;
00230         }
00231 
00233 void CDeviceCapabilitiesScan::SelfComplete(TInt aErr)
00234         {
00235         iStatus = KRequestPending;
00236         SetActive();
00237         TRequestStatus* pStatus = &iStatus;
00238         User::RequestComplete(pStatus,aErr);
00239         }
00240 
00241 
00242 /*
00243  * Discover and log the platform version information string
00244  */
00245 void CDeviceCapabilitiesScan::DiscoverPlatformVersionTextL()
00246         {
00247         _LIT(KTxtPlatformVersionTitle, "Identifying Platform");
00248         _LIT(KTxtPlatformVersion, "Platform Version: %d.%d");
00249         _LIT(KTxtPlatformVersionUnavailable, "Platform Version: Unavailable");
00250         
00251         iState = EDiscoveringPlatformVersion;
00252         iLogView->LogSectionTitleL(KTxtPlatformVersionTitle);
00253         
00254         RFs fs;
00255         User::LeaveIfError(fs.Connect());
00256         CleanupClosePushL(fs);
00257         
00258         VersionInfo::TPlatformVersion platformVersion;
00259         TInt ret = VersionInfo::GetVersion(platformVersion, fs);
00260         
00261         CleanupStack::PopAndDestroy(&fs);
00262         
00263         if (ret == KErrNone)
00264                 {
00265                 iLogView->LogEntryL(KTxtPlatformVersion, platformVersion.iMajorVersion, platformVersion.iMinorVersion);
00266                 }
00267         else
00268                 {
00269                 iLogView->LogEntryL(KTxtPlatformVersionUnavailable);
00270                 }
00271         
00272         }
00273 
00274 void CDeviceCapabilitiesScan::FormatScreenInfoByModeL(CWsScreenDevice& aScreenDevice, TInt aScreenMode)
00275         {
00276         _LIT(KTxtDisplayScreensStep3, "Screen mode: %d");
00277         _LIT(KTxtDisplayScreensStep4, "Width: %d pixels, %d twips");    
00278         _LIT(KTxtDisplayScreensStep5, "Height: %d pixels, %d twips");
00279         _LIT(KTxtDisplayScreensStep6, "Orientation: %S");       
00280         
00281         // Discover screen orientation, height and width in pixels and twips, for this screen mode
00282         TPixelsTwipsAndRotation result;
00283         aScreenDevice.GetScreenModeSizeAndRotation(aScreenMode, result);
00284 
00285         // Log mode.
00286         iLogView->LogEntryL(KTxtDisplayScreensStep3, aScreenMode);
00287         
00288         // Log width and height
00289         iLogView->LogEntryL(KTxtDisplayScreensStep4, result.iPixelSize.iWidth, result.iTwipsSize.iWidth);
00290         iLogView->LogEntryL(KTxtDisplayScreensStep5, result.iPixelSize.iHeight, result.iTwipsSize.iHeight);     
00291         
00292         // Log orientation
00293         iLogView->LogEntryL(KTxtDisplayScreensStep6, &(Orientation(result.iRotation))); 
00294         }
00295 
00296 void CDeviceCapabilitiesScan::DiscoverDisplayScreensInfoL()
00297         {
00298         _LIT(KTxtDisplayScreensTitle, "Screen information");
00299         _LIT(KTxtDisplayScreensStep1, "Number of screens: %d");
00300         _LIT(KTxtDisplayScreensStep2, "Screen: %d, Display mode: %S");
00301         
00302         iState = EDiscoveringDisplayScreenInfo;
00303         iLogView->LogSectionTitleL(KTxtDisplayScreensTitle);
00304 
00305         RWsSession wsSession;
00306         User::LeaveIfError(wsSession.Connect());
00307         CleanupClosePushL(wsSession);
00308         
00309         TInt numScreens=0;      
00310         User::LeaveIfError(  HAL::Get( HAL::EDisplayNumberOfScreens, numScreens ) ) ; 
00311         
00312         // Log the number of screens
00313         iLogView->LogEntryL(KTxtDisplayScreensStep1, numScreens);
00314 
00315         for (TInt i=0; i<numScreens; i++)
00316                 {
00317                 CWsScreenDevice* screenDevice = new (ELeave) CWsScreenDevice(wsSession);
00318                 CleanupStack::PushL(screenDevice);
00319                 User::LeaveIfError(screenDevice->Construct(i));
00320                 
00321                 // Log the screen number and display mode
00322                 iLogView->LogEntryL(KTxtDisplayScreensStep2, i, &(DisplayMode(screenDevice->DisplayMode())));
00323 
00324                 for (TInt j=0; j<screenDevice->NumScreenModes(); j++)
00325                         {
00326                         FormatScreenInfoByModeL(*screenDevice, j);                      
00327                         }
00328                 
00329                 CleanupStack::PopAndDestroy(screenDevice);
00330                 screenDevice = NULL;
00331                 }
00332 
00333         CleanupStack::PopAndDestroy(&wsSession);
00334         }
00335 
00337 const TDesC& CDeviceCapabilitiesScan::DisplayMode(TDisplayMode aMode)
00338         {
00339         switch (aMode)
00340                 {
00342                 case ENone:
00343                         {
00344                         return KDisplayMode0;
00345                         }
00347                 case EGray2:
00348                         {
00349                         return KDisplayMode1;
00350                         }
00352                 case EGray4:
00353                         {
00354                         return KDisplayMode2;
00355                         }
00357                 case EGray16:
00358                         {
00359                         return KDisplayMode3;
00360                         }
00362                 case EGray256:
00363                         {
00364                         return KDisplayMode4;
00365                         }
00367                 case EColor16:
00368                         {
00369                         return KDisplayMode5;
00370                         }
00372                 case EColor256:
00373                         {
00374                         return KDisplayMode6;
00375                         }
00377                 case EColor64K:
00378                         {
00379                         return KDisplayMode7;
00380                         }
00382                 case EColor16M:
00383                         {
00384                         return KDisplayMode8;
00385                         }
00387                 case ERgb:
00388                         {
00389                         return KDisplayMode9;
00390                         }
00392                 case EColor4K:
00393                         {
00394                         return KDisplayMode10;
00395                         }
00397                 case EColor16MU:
00398                         {
00399                         return KDisplayMode11;
00400                         }
00402                 case EColor16MA:
00403                         {
00404                         return KDisplayMode12;
00405                         }
00407                 case EColor16MAP:
00408                         {
00409                         return KDisplayMode13;
00410                         }
00411                 //Place holder for additional modes
00412                 case EColorLast:                
00413                         {
00414                         return KDisplayMode14;
00415                         }
00416                 default:
00417                         return KNullDesC;
00418                 }
00419         }
00420         
00422 const TDesC& CDeviceCapabilitiesScan::Orientation(CFbsBitGc::TGraphicsOrientation aOrientation)
00423         {
00424         switch (aOrientation)
00425                 {
00427                 case CFbsBitGc::EGraphicsOrientationNormal:
00428                         {
00429                         return KOrientation0;                   
00430                         }                       
00432                 case CFbsBitGc::EGraphicsOrientationRotated90:
00433                         {
00434                         return KOrientation1;                   
00435                         }                       
00437                 case CFbsBitGc::EGraphicsOrientationRotated180:
00438                         {
00439                         return KOrientation2;                   
00440                         }                       
00442                 case CFbsBitGc::EGraphicsOrientationRotated270:
00443                         {
00444                         return KOrientation3;                   
00445                         }                       
00446                 default:
00447                         return KNullDesC;
00448                 }               
00449         }
00450 
00451 /* Check if touch or pen support is provided */
00452 void CDeviceCapabilitiesScan::CheckForTouchSupportL()
00453         {
00454         _LIT(KTxtTouchSupported, "\nTouch supported\n");
00455         _LIT(KTxtTouchNotSupported, "\nTouch not supported\n");
00456         
00457         if (AknLayoutUtils::PenEnabled())
00458                 {
00459                 iLogView->LogEntryL(KTxtTouchSupported);
00460                 }
00461         else
00462                 {
00463                 iLogView->LogEntryL(KTxtTouchNotSupported);
00464                 }
00465         }
00466 
00467 /* Discover available input modes */
00468 void CDeviceCapabilitiesScan::DiscoverAvailableInputModesL()
00469         {
00470         _LIT(KTxtInputCapabilities, "Input Capabilities");
00471         
00472         iLogView->LogSectionTitleL(KTxtInputCapabilities);
00473         iState = EDiscoveringInputCapabilities; 
00474         
00475         // Display available modes for a particular language 
00476         EnumerateAvailableInputModesL();
00477         
00478         // Check for touch support
00479         CheckForTouchSupportL();
00480         }
00481 
00482 /* Enumerate available input modes */
00483 void CDeviceCapabilitiesScan::EnumerateAvailableInputModesL()
00484         {
00485         _LIT(KInputMode, "Input mode %d");
00488         CPtiEngine* ptiEngine = CPtiEngine::NewL();
00489         CleanupStack::PushL(ptiEngine);
00490         
00491         CPtiCoreLanguage* currentLanguage = static_cast<CPtiCoreLanguage*>(ptiEngine->GetLanguage(User::Language()));
00492         if (currentLanguage)
00493                 {
00494                 RArray<TInt> modes;
00495                 CleanupClosePushL(modes);
00496                 currentLanguage->GetAvailableInputModesL(modes);
00497                 
00498                 for (TInt count=0; count < modes.Count(); count++)
00499                         {
00500                         iLogView->LogEntryL(KInputMode, modes[count]);                  
00501                         }
00502 
00503                 CleanupStack::PopAndDestroy(&modes);
00504                 }
00505 
00506         CleanupStack::PopAndDestroy(ptiEngine); 
00507         }
00508 
00509 /* Discover and log multimedia plugin support */        
00510 void CDeviceCapabilitiesScan::DiscoverMultimediaPluginSupportL()
00511         {
00512         _LIT(KTxtMultimediaTitle, "\nMultimedia support\n");
00513         _LIT(KTxtMultimediaInterfaceUid, "interface uid: 0x%08x");
00514         _LIT(KTxtMultimediaFailure, "Failed to list implementations: err %d");
00515         _LIT(KTxtMultimediaPluginDetails, "ECOM plugin: 0x%08x %S;");
00516         
00517         iState = EDiscoveringMultimediaEcomPlugins;
00518         iLogView->LogSectionTitleL(KTxtMultimediaTitle);
00519         
00520         RImplInfoPtrArray impls;
00521         CleanupResetAndDestroyPushL(impls);
00522 
00523         for(TInt ui=0;ui!=sizeof(interfaceUids)/sizeof(interfaceUids[0]);++ui)
00524                 {
00525                 iLogView->LogEntryL(KTxtMultimediaInterfaceUid,interfaceUids[ui]);
00526                 
00527                 impls.ResetAndDestroy();
00528                 TRAPD(leaveCode,REComSession::ListImplementationsL(TUid::Uid(interfaceUids[ui]),impls));
00529                 if(leaveCode!=KErrNone)
00530                         {
00531                         iLogView->LogEntryL(KTxtMultimediaFailure, leaveCode);
00532                         }
00533                 else for(TInt i=0,count=impls.Count();i!=count;++i)
00534                         {
00535                         CImplementationInformation* info = impls[i];
00536                         iLogView->LogEntryL(KTxtMultimediaPluginDetails, info->ImplementationUid().iUid,&info->DisplayName());
00542                         }
00543                 }
00544         CleanupStack::PopAndDestroy(&impls);    
00545         }
00546 
00548 void CDeviceCapabilitiesScan::DiscoverAvailableSensorsL()
00549         {
00550         _LIT(KTxtSensorTitle, "Sensor information");
00551         _LIT(KTxtChannelCount, "Channel count: %d");
00552         _LIT(KTxtChannelsAvailable, "Available channels");      
00553         
00554         iState = EDiscoveringAvailableSensors;
00555         iLogView->LogSectionTitleL(KTxtSensorTitle);
00556         
00557         CSensrvChannelFinder* SensrvChannelFinder = CSensrvChannelFinder::NewLC(); 
00558         RSensrvChannelInfoList ChannelInfoList;
00559         CleanupClosePushL( ChannelInfoList );
00560                         
00561         TSensrvChannelInfo mySearchConditions; // none, so matches all.
00562         SensrvChannelFinder->FindChannelsL(ChannelInfoList,mySearchConditions);
00563 
00564         iLogView->LogEntryL(KTxtChannelCount, ChannelInfoList.Count());
00565         iLogView->LogEntryL(KTxtChannelsAvailable);
00566 
00567         for (TInt i = 0; i < ChannelInfoList.Count() ; i++)
00568                 {
00569                 TSensrvChannelInfo channelInfo = ChannelInfoList[i];
00570                 switch (channelInfo.iChannelType)
00571                         {
00572                         /* Note that the S60 5th SDK v1.0 declares the double-tapping
00573                         * channel id but doesn't define the associated class for data.
00574                         */
00575                         case KSensrvChannelTypeIdAccelerometerDoubleTappingData:
00576                                 {
00577                                 iLogView->LogEntryL(KTxtChannelDoubleTapping);
00578                                 break;  
00579                                 }
00580                         /* Note that the S60 5th SDK v1.0 declares the class for tapping
00581                         * data but doesn't declare the associated channel id, so we resort
00582                         * to using the data type id here (it's fortunately the same).
00583                         */
00584                         case TSensrvTappingData::KDataTypeId:
00585                                 {
00586                                 iLogView->LogEntryL(KTxtChannelTapping);
00587                                 break;  
00588                                 }
00589                         case KSensrvChannelTypeIdProximityMonitor:
00590                                 {
00591                                 iLogView->LogEntryL(KTxtChannelProximity);
00592                                 break;  
00593                                 }
00594                         case KSensrvChannelTypeIdOrientationData:
00595                                 {
00596                                 iLogView->LogEntryL(KTxtChannelOrientation);
00597                                 break;  
00598                                 }
00599                         case KSensrvChannelTypeIdRotationData:
00600                                 {
00601                                 iLogView->LogEntryL(KTxtChannelRotation);
00602                                 break;  
00603                                 }
00604                         case KSensrvChannelTypeIdMagnetometerXYZAxisData:
00605                                 {
00606                                 iLogView->LogEntryL(KTxtChannelMagnetometer);
00607                                 break;  
00608                                 }
00609                         case KSensrvChannelTypeIdMagneticNorthData:
00610                                 {
00611                                 iLogView->LogEntryL(KTxtChannelMagneticNorth);
00612                                 break;  
00613                                 }
00614                         case KSensrvChannelTypeIdAmbientLightData:
00615                                 {
00616                                 iLogView->LogEntryL(KTxtChannelAmbientLight);
00617                                 break;  
00618                                 }
00619                         case KSensrvChannelTypeIdAccelerometerXYZAxisData:              
00620                                 {
00621                                 iLogView->LogEntryL(KTxtChannelAccelerometer);
00622                                 break;  
00623                                 }
00624                         default:
00625                                 {
00626                                 iLogView->LogEntryL(KTxtChannelUnknown);
00627                                 break;  
00628                                 }
00629                         }
00630                 }
00631                 
00632         CleanupStack::PopAndDestroy( 2, SensrvChannelFinder ); // ChannelnfoList and SensrvChannelFinder
00633         }
00634 
00635 // End of file
00636 

Generated by  doxygen 1.6.2