/* * 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::DoFindChannelL // ---------------------------------------------------------------------------------- void CSensrvTestObserver::DoFindChannelL() { COMPONENT_TRACE( ( _L( "CSensrvTestObserver::DoFindChannelL" ) ) ); CSensrvChannelFinder* channelFinder = CSensrvChannelFinder::NewLC(); TSensrvChannelInfo channelInfo; RSensrvChannelInfoList channelInfoList; CleanupClosePushL( channelInfoList ); TRAPD( err, channelFinder->FindChannelsL( channelInfoList, channelInfo )); if( err ) { COMPONENT_TRACE( ( _L("CSensrvTestCases::FindChannelsL: FindChanels error: %d"), err )); User::Leave( err ); } err = CheckFindResult( channelInfo, channelInfoList ); if( err ) { COMPONENT_TRACE( ( _L("CSensrvTestCases::FindChannelsL: CheckFindResult error: %d"), err )); User::Leave( err ); } CleanupStack::PopAndDestroy( &channelInfoList ); CleanupStack::PopAndDestroy( channelFinder ); }
// ---------------------------------------------------------------------------------- // 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 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); }
// ----------------------------------------------------------------------------- // 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; }
// // ---------------------------------------------------------------------------------- // CEventChannel::RunL() // ---------------------------------------------------------------------------------- // void CEventChannel::RunL() { TBuf<16> location; location.Copy( iChannelInfo.iLocation ); COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() - %S" ), &location ) ); switch( iChannelState ) { case EChannelOpening: { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() - EChannelOpening" ) ) ); TInt err( KErrNone ); if( iStatus.Int() == KErrNone ) { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() iChannelState = EChannelOpen" ) ) ); iChannelState = EChannelOpen; // Find data channel CSensrvChannelFinder* channelFinder = CSensrvChannelFinder::NewLC(); TBufC8<KSensrvLocationLength> location( _L8("First0") ); TBufC8<KSensrvVendorIdLength> vendorId( _L8( "VendorFirst" ) ); TSensrvChannelInfo channelInfo( 0, ESensrvContextTypeNotDefined, ESensrvQuantityNotdefined, 0, location, vendorId, 0, 0 ); RSensrvChannelInfoList channelList(10); TRAP( err, channelFinder->FindChannelsL( channelList, channelInfo ) ); if( !err && channelList.Count() > 0 ) { iChannel = CSensrvChannel::NewL( channelList[ 0 ] ); TRAP( err, iChannel->OpenChannelL() ); } CleanupStack::PopAndDestroy( channelFinder ); channelList.Reset(); } if( err || iStatus.Int() != KErrNone ) { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() iChannelState = EChannelIdle" ) ) ); iChannelState = EChannelIdle; if( !err ) { err = iStatus.Int(); } } iSsyCallback->ChannelOpened( iChannelInfo.iChannelId, err, this, iPropertyProvider ); break; } case EChannelClosing: { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() - EChannelClosing" ) ) ); COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() iChannelState = EChannelIdle" ) ) ); iChannelState = EChannelIdle; if( iChannel ) { iChannel->CloseChannel(); delete iChannel; iChannel = NULL; } iSsyCallback->ChannelClosed( iChannelInfo.iChannelId ); break; } case EChannelOpen: { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() - EChannelOpen" ) ) ); break; } case EChannelListening: { break; } case EChannelStopListening: { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() - EChannelStopListening" ) ) ); COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() iChannelState = EChannelOpen" ) ) ); iChannelState = EChannelOpen; break; } case EChannelBufferFilled: case EChannelForceBufferFilled: { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() - EChannelForceBufferFilled" ) ) ); iSsyCallback->BufferFilled( iChannelInfo.iChannelId, iCounter, iDataBuffer, iMaxDataCount ); iCounter = 0; COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() iChannelState = EChannelListening" ) ) ); iChannelState = EChannelListening; IssueRequest(); break; } default: { COMPONENT_TRACE( ( _L( "EventSsyStub - CEventChannel::RunL() unknown channel state" ) ) ); } } }