// ---------------------------------------------------------------------------------- // CSSYControlOrientation::CreateAndRegisterChannelsL() // ---------------------------------------------------------------------------------- // void CSSYControlOrientation::CreateAndRegisterChannelsL( const TSSsyChannelInfo* aChannelConfigurations, const TUint aNumberofConfigurations ) { SSY_TRACE_IN(); ASSERT_ALWAYS_SSY( aChannelConfigurations ); ASSERT_ALWAYS_SSY( aNumberofConfigurations ); RSensrvChannelInfoList channelInfoList; for ( TInt index = 0; index < aNumberofConfigurations; index++ ) { CSSYChannel* channel( NULL ); TSensrvChannelInfo channelInfo ( aChannelConfigurations[index].iChannelId, aChannelConfigurations[index].iContextType, aChannelConfigurations[index].iQuantity, aChannelConfigurations[index].iChannelType, aChannelConfigurations[index].iLocation, aChannelConfigurations[index].iVendorId, aChannelConfigurations[index].iDataItemSize, aChannelConfigurations[index].iDataTypeId ); switch ( channelInfo.iChannelType ) { case KSensrvChannelTypeIdOrientationData: // Intentional flowthrough case KSensrvChannelTypeIdRotationData: channel = CSSYChannel::NewL( iSensorProperties, iCallback, channelInfo ); break; default: ASSERT_ALWAYS_SSY( 0 ); break; } if ( channel ) { User::LeaveIfError(iChannelArray.Append( channel )); User::LeaveIfError(channelInfoList.Append( channelInfo)); } } // Register channels to the client SSY_TRACE_TRAP( err, iCallback->RegisterChannelsL( channelInfoList ) ); // Update ChannelId for ( TInt i = 0; i < iChannelArray.Count(); i++ ) { (*iChannelArray[i]).SetChannelId( channelInfoList[i].iChannelId ); } channelInfoList.Reset(); channelInfoList.Close(); SSY_TRACE_OUT(); }
/* * FindSensorL is used to find if a specific sensor is available on the * device, if FindSensorL leaves then the sensor is not supported */ void CSensorBackendSym::FindSensorL() { // This method scans the device for the availability // of specified sensor using Sensor APIs CSensrvChannelFinder* finder = CSensrvChannelFinder::NewLC(); RSensrvChannelInfoList channelList; TSensrvChannelInfo channelInfo; channelInfo.iChannelType = iBackendData.iSensorType; // Retrieve the list of channels available finder->FindChannelsL( channelList, channelInfo ); CleanupStack::PopAndDestroy(finder); // Iterate the channel list and look for required sensor for (TInt i = 0; i<channelList.Count(); i++) { // Iterate the available channels if (channelList[i].iChannelType == iBackendData.iSensorType) { // Required sensor found iBackendData.iChannelInfo = channelList[i]; channelList.Close(); return; } } // Required sensor not found, leave with error channelList.Close(); iBackendData.iSensorAvailable = EFalse; User::Leave(KErrNotFound); }
void HbSensorListener::startSensorChannel() { #ifdef Q_OS_SYMBIAN CSensrvChannelFinder *sensrvChannelFinder = CSensrvChannelFinder::NewLC(); RSensrvChannelInfoList channelInfoList; CleanupClosePushL(channelInfoList); TSensrvChannelInfo mySearchConditions; //Search only Orientation events. mySearchConditions.iChannelType = KSensrvChannelTypeIdOrientationData; TRAPD(err, sensrvChannelFinder->FindChannelsL(channelInfoList, mySearchConditions)); if (!err) { if (channelInfoList.Count()) { TRAP(err, mSensrvChannel = CSensrvChannel::NewL(channelInfoList[0])); if (!err) { TRAP(err, mSensrvChannel->OpenChannelL()); if (!err) { TRAP_IGNORE(mSensrvChannel->StartDataListeningL(this, 1, 1, 0)); } else { qWarning("HbSensorListener::startSensorChannel fails, error code = %d", err); } } } channelInfoList.Close(); CleanupStack::Pop(&channelInfoList); CleanupStack::PopAndDestroy(sensrvChannelFinder); } else { qWarning("HbSensorListener::startSensorChannel fails, error code = %d", err); } #endif }
// ---------------------------------------------------------------------------------- // CSensrvTestObserver::DoOpenChannel // ---------------------------------------------------------------------------------- void CSensrvTestObserver::DoOpenChannelL( TInt aExpectedResult ) { COMPONENT_TRACE( ( _L( "CSensrvTestObserver::DoOpenChannelL()" ) ) ); TInt lastOpenedChannel( 0 ); TInt channelIndex( 0 ); TSensrvChannelInfo channelInfo; RSensrvChannelInfoList channelInfoList; CleanupClosePushL( channelInfoList ); CSensrvChannelFinder* channelFinder; channelFinder = CSensrvChannelFinder::NewLC(); RProperty::Get( KPSUidSensrvTest, KSensrvLatestOpenedChannel, lastOpenedChannel ); channelFinder->FindChannelsL( channelInfoList, channelInfo ); for( TInt i=0 ; i<channelInfoList.Count() ; i++ ) { if( channelInfoList[i].iChannelId == lastOpenedChannel ) { channelIndex = 1; } } iSensorChannel = CSensrvChannel::NewL( channelInfoList[ channelIndex ] ); TBuf<16> location; location.Copy( iSensorChannel->GetChannelInfo().iLocation ); COMPONENT_TRACE( ( _L( "CSensrvTestObserver::DoOpenChannelL - Channel %S"), &location )); TRAPD( err, iSensorChannel->OpenChannelL() ); if( err != aExpectedResult ) { User::Leave( err ); } CleanupStack::PopAndDestroy( channelFinder ); CleanupStack::PopAndDestroy( &channelInfoList ); // <--- results in Close() being called on "channelInfoList". }
void XQSensorPrivate::FindChannelL(TSensrvChannelTypeId aType, TSensrvChannelInfo& aChannelInfo) { if (!iSensrvChannelFinder) { iSensrvChannelFinder = CSensrvChannelFinder::NewL(); } RSensrvChannelInfoList sensrvChannelInfoList; CleanupClosePushL(sensrvChannelInfoList); TSensrvChannelInfo sensrvChannelInfo; sensrvChannelInfo.iChannelType = aType; iSensrvChannelFinder->FindChannelsL(sensrvChannelInfoList, sensrvChannelInfo); if(sensrvChannelInfoList.Count() == 0) { User::Leave(KErrNotFound); } aChannelInfo = sensrvChannelInfoList[0]; CleanupStack::PopAndDestroy(&sensrvChannelInfoList); }
void CSensorListener::ConstructL(TUint32 aSensorType) { CSensrvChannelFinder* sensrvChannelFinder = CSensrvChannelFinder::NewLC(); RSensrvChannelInfoList channelInfoList; CleanupClosePushL(channelInfoList); TSensrvChannelInfo mySearchConditions; mySearchConditions.iChannelType = aSensorType; sensrvChannelFinder->FindChannelsL(channelInfoList,mySearchConditions); if (channelInfoList.Count()) { iSensrvChannel = CSensrvChannel::NewL(channelInfoList[0]); } channelInfoList.Close(); CleanupStack::Pop( &channelInfoList ); CleanupStack::PopAndDestroy( sensrvChannelFinder ); }
void CMagnetometer::ConstructL() { CSensrvChannelFinder* sensorChannelFinder = CSensrvChannelFinder::NewLC(); RSensrvChannelInfoList channelInfoList; CleanupClosePushL(channelInfoList); TSensrvChannelInfo mySearchConditions; mySearchConditions.iChannelType = KSensrvChannelTypeIdMagnetometerXYZAxisData; sensorChannelFinder->FindChannelsL(channelInfoList, mySearchConditions); TSensrvChannelInfo channelInfo; if (channelInfoList.Count() > 0) channelInfo = channelInfoList[0]; else User::Leave(KErrNotFound); CleanupStack::PopAndDestroy(&channelInfoList); CleanupStack::PopAndDestroy(sensorChannelFinder); iSensorChannel = CSensrvChannel::NewL(channelInfo); iSensorChannel->OpenChannelL(); // Get current calibration value TSensrvProperty property; iSensorChannel->GetPropertyL(KSensrvPropCalibrationLevel, KSensrvItemIndexNone, property); TInt calibration = 0; property.GetValue(calibration); iCalibration = calibration == 0? ENone : calibration == 1? ELow : calibration == 2? EModerate : calibration == 3? EHigh : ENone; iSensorChannel->SetPropertyListenerL(this); }
// ----------------------------------------------------------------------------- // CSensrvTest::FindChannels // // ----------------------------------------------------------------------------- // TInt CSensrvTest::FindChannels( RSensrvChannelInfoList& aChannelInfoList, TSensrvChannelInfo& aSearchConditions ) { RDebug::Print( _L("CSensrvTest::FindChanels: Find channels...") ); if( !iChannelFinder ) { // Create channel finder RDebug::Print( _L("CSensrvTest::FindChanels: Create iChannelFinder") ); iChannelFinder = CSensrvSensorChannelFinder::NewL(); } TRAPD( err, iChannelFinder->FindChannelsL( aChannelInfoList, aSearchConditions ) ); if( err ) { RDebug::Print( _L("CSensrvTest::FindChanels: Leave: %d"), err ); return err; } RDebug::Print( _L("CSensrvTest::FindChanels: Channel count: %d"), aChannelInfoList.Count() ); return KErrNone; }
// ----------------------------------------------------------------------------- // CSensrvTestCases::CheckFindResult // // ----------------------------------------------------------------------------- // TInt CSensrvTestObserver::CheckFindResult( TSensrvChannelInfo& aSearchConditions, RSensrvChannelInfoList aChannelInfoList ) { COMPONENT_TRACE( _L("CSensrvTestObserver::CheckFindResult") ); COMPONENT_TRACE( ( _L("### conditions: ChannelId=%d, ContextType=%d, Quantity=%d, ChannelType=%d, Location=%S, VendorId=%S, DataItemSize=%d"), aSearchConditions.iChannelId, aSearchConditions.iContextType, aSearchConditions.iQuantity, aSearchConditions.iChannelType, &aSearchConditions.iLocation, &aSearchConditions.iVendorId, aSearchConditions.iDataItemSize )); // Find all channels TBufC8<1> nullBuf( KNullDesC8 ); TSensrvChannelInfo channelInfo( 0, ESensrvContextTypeNotDefined, ESensrvQuantityNotdefined, 0, nullBuf, nullBuf, 0, 0 ); RSensrvChannelInfoList allChannelList(10); CleanupClosePushL( allChannelList ); CSensrvChannelFinder* channelFinder = CSensrvChannelFinder::NewLC(); TRAPD( err, channelFinder->FindChannelsL( allChannelList, channelInfo )); if( err ) { COMPONENT_TRACE( ( _L("CSensrvTestCases::CheckFindResult: Find all channels Leave: %d"), err )); return err; } // RSensrvChannelInfoList acceptedChannels(10); for( TInt i = 0; i < allChannelList.Count(); i++ ) { if( allChannelList[i].IsMatch( aSearchConditions ) ) { acceptedChannels.Append( allChannelList[i] ); } } if( acceptedChannels.Count() != aChannelInfoList.Count() ) { // Test fails. COMPONENT_TRACE( ( _L("CSensrvTestCases::CheckFindResult: Test fails") )); COMPONENT_TRACE( ( _L(" required count %d"), acceptedChannels.Count() )); COMPONENT_TRACE( ( _L(" found channels count %d"), aChannelInfoList.Count() )); return KErrGeneral; } TBool testFail( EFalse ); // Check all channels infos for( TInt i = 0; i < aChannelInfoList.Count(); i++ ) { COMPONENT_TRACE( ( _L(" ###channel info [%d]:"), i )); COMPONENT_TRACE( ( _L(" ### ChannelId=%d, ContextType=%d, Quantity=%d, ChannelType=%d, Location=%S, VendorId=%S, DataItemSize=%d"), aChannelInfoList[i].iChannelId, aChannelInfoList[i].iContextType, aChannelInfoList[i].iQuantity, aChannelInfoList[i].iChannelType, &aChannelInfoList[i].iLocation, &aChannelInfoList[i].iVendorId, aChannelInfoList[i].iDataItemSize )); TBool found( EFalse ); for( TInt x = 0; x < acceptedChannels.Count(); x++ ) { if( acceptedChannels[x].iChannelId == aChannelInfoList[i].iChannelId ) { found = ETrue; break; } } if( found ) { COMPONENT_TRACE( _L(" -OK-") ); } else { COMPONENT_TRACE( _L(" -FAIL-") ); testFail = ETrue; } } CleanupStack::PopAndDestroy( channelFinder ); CleanupStack::PopAndDestroy( &allChannelList ); if( testFail ) { return KErrGeneral; } return KErrNone; }