LOCAL_C void TestReadFromStreamL() { test.Next (_L ("@SYMTestCaseID:SYSLIB-EUSERHL-UT-4010")); test.Next(_L("Test creating LString from a stream")); RFs fs; fs.Connect() OR_LEAVE; LSTRING outString = _TS("This is a test string written to a stream"); //Create a buffer to contain the stream CBufFlat* buf = CBufFlat::NewL(outString.MaxLength()); //Create a write stream RBufWriteStream outStream; outStream.Open(*buf); //write some data to the stream outStream << outString; outStream.CommitL(); //Open a readstream RBufReadStream inStream; inStream.Open(*buf); //Create an LString from the stream LSTRING inString; inString.CreateL(inStream,outString.Length()); test(inString == outString); delete buf; }
/*! * The leaving function that queries the SQL database * * \a aSqlQuery An SQL query * \return the list of matched contact ids */ QList<QContactLocalId> CntSymbianSrvConnection::searchContactIdsL(const TDesC& aSqlQuery, QueryType aQueryType) { readContactsToBufferL(aSqlQuery, aQueryType); RBufReadStream readStream; QList<QContactLocalId> list; TInt item; readStream.Open(*m_buffer); while ((item = readStream.ReadInt32L()) != 0) { list << item; } return list; }
/*! * The leaving function that queries the SQL database * * \a aSqlQuery An SQL query * \return the list of matched contact ids */ QList<QContact> CntSymbianSrvConnection::searchContactNamesL(const TDesC& aSqlQuery) { readContactsToBufferL(aSqlQuery, CntSymbianSrvConnection::CntSearchResultList); RBufReadStream readStream; QList<QContact> contacts; TInt id; TBuf<256> firstName; TBuf<256> lastName; TBuf<256> company; readStream.Open(*m_buffer); while ((id = readStream.ReadInt32L()) != 0) { readStream >> firstName; readStream >> lastName; readStream >> company; QContact contact, tempContact; QContactName name; name.setFirstName(QString::fromUtf16(firstName.Ptr(), firstName.Length())); name.setLastName(QString::fromUtf16(lastName.Ptr(), lastName.Length())); tempContact.saveDetail(&name); QContactOrganization organization; organization.setName(QString::fromUtf16(company.Ptr(), company.Length())); tempContact.saveDetail(&organization); QContactManager::Error error(QContactManager::NoError); QString label = m_manager->synthesizedDisplayLabel(tempContact, &error); if (error != QContactManager::NoError) { continue; } tempContact.clearDetails(); m_manager->setContactDisplayLabel(&contact, label); QContactId contactId; contactId.setLocalId(id); contactId.setManagerUri(m_manager->managerUri()); contact.setId(contactId); contacts << contact; } return contacts; }
/*! * The leaving function that queries the SQL database * * \a aSqlQuery An SQL query * \return the list of matched contact ids and phonenumber values */ QList<QPair<QContactLocalId, QString> > CntSymbianSrvConnection::searchPhoneNumbersL(const TDesC& aSqlQuery, QueryType aQueryType) { readContactsToBufferL(aSqlQuery, aQueryType); RBufReadStream readStream; QList<QPair<QContactLocalId, QString> > list; TInt item; TBuf<256> extraValue; readStream.Open(*m_buffer); while ((item = readStream.ReadInt32L()) != 0) { readStream >> extraValue; QContactLocalId id = item; list.append(qMakePair(id,QString::fromUtf16(extraValue.Ptr(), extraValue.Length()))); } return list; }
// --------------------------------------------------------- // CLbsLocInfoConversionHandler::GetWlanInfoArrayL // (other items were commented in a header). // --------------------------------------------------------- // void CLbsLocInfoConversionHandler::GetWlanInfoArrayL( RBufReadStream& readStream, CLbsLocationInfo& aDesLocationInfo ) { // Read the count of converted info. TInt convertedInfoCount = readStream.ReadInt8L(); for( TInt i=0;i<convertedInfoCount;i++ ) { CLbsWlanInfo* wlanInfo = CLbsWlanInfo::NewL(); CleanupStack::PushL( wlanInfo ); wlanInfo->InternaliseL( readStream ); aDesLocationInfo.AddAreaInfoL( wlanInfo ); CleanupStack::Pop( wlanInfo ); } }
void CCntItemMsgHandler::FindAsyncTextDefInitL(const RMessage2& aMessage) { /* Initialisation for asynchronous find using CContactTextDef and array of "find words" constructed on the client-side and required on the server-side for matching. **/ CheckForManagerL(); // CContactTextDef can be NULL in which case the client will have // passed an empty descriptor. CContactTextDef* textDef = NULL; // Assuming that a KNullDesC parameter results in max length of 0. if(aMessage.GetDesLengthL(1) > 0) { // Use packager to unpack CContactTextDef. iPackager.SetBufferFromMessageL(aMessage,1); textDef = iPackager.UnpackCntTextDefLC(); CleanupStack::Pop(textDef); } // Unpack the CDesCArray manually as the packager does not package // both. CBufFlat* bufFlat = CBufFlat::NewL(1 << 8); CleanupStack::PushL(bufFlat); bufFlat->ExpandL(0,aMessage.GetDesLengthL(0)); TPtr8 ptr8(bufFlat->Ptr(0)); aMessage.ReadL(0,ptr8); RBufReadStream readStream; readStream.Open(*bufFlat); TInt count = readStream.ReadInt32L(); CDesCArray* unpacked = new (ELeave) CDesCArrayFlat(8); CleanupStack::PushL(unpacked); for(TInt i=0;i<count;++i) { TBuf<256> buf; TInt length = readStream.ReadInt32L(); readStream.ReadL(buf,length); unpacked->AppendL(buf); } readStream.Close(); // Persistence Layer does the actual initialisation and also takes // ownership of textDef. MLplCollection& collection = iManager->GetPersistenceLayer().FactoryL().GetCollectorL(); collection.FindAsyncTextDefInitL(*unpacked,textDef); CleanupStack::PopAndDestroy(unpacked); CleanupStack::PopAndDestroy(bufFlat); aMessage.Complete(KErrNone); }
void CASYStubCmdHandlerBase::ProcessObjectL( const TProcessCmdId aCommand, const TASYCmdParams& aCmdParams ) { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL() - CAccPolObjectBase" ) ) ); RBufReadStream rStrm; TUint32 name; aCmdParams().iNameRecord.GetName( name ); if( name == KAccAudioStreamsFormat ) { switch( aCommand ) { case ECmdGetObjectValue: { CAccPolAudioStreamFormatCon* container1 = CAccPolAudioStreamFormatCon::NewLC(); CAccPolAudioStreamFormatCon* container2 = CAccPolAudioStreamFormatCon::NewLC(); RProperty prop; CBufFlat* buf = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( buf ); buf->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); TPtr8 ptr( buf->Ptr( 0 ) ); TInt retval = prop.Get( KTFAccessoryTestProperty, KTFAccessoryObjectMethod, ptr ); ( void )rStrm.Open( *buf ); rStrm.PushL(); container1->InternalizeL( rStrm ); rStrm.Close(); rStrm.Pop(); for( TInt i = 0; i < container1->Count(); i++ ) { container2->AddL( *container1->AtL( i ) ); } ProcessResponseL( *container2 ); CleanupStack::PopAndDestroy( buf ); CleanupStack::PopAndDestroy( container2 ); CleanupStack::PopAndDestroy( container1 ); } break; case ECmdSetObjectValue: { CAccPolAudioStreamFormatCon* container1 = CAccPolAudioStreamFormatCon::NewLC(); CAccPolAudioStreamFormatCon* container2 = CAccPolAudioStreamFormatCon::NewLC(); RProperty prop; CBufFlat* buf = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( buf ); buf->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); TPtr8 ptr( buf->Ptr( 0 ) ); TInt retval = prop.Get( KTFAccessoryTestProperty, KTFAccessoryObjectMethod, ptr ); ( void )rStrm.Open( *buf ); rStrm.PushL(); container1->InternalizeL( rStrm ); rStrm.Close(); rStrm.Pop(); // Read objects from proxy ObjectConDataFromProxyL( *container2 ); //externalize container to bufFromServer CBufFlat* bufFromServer = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( bufFromServer ); bufFromServer->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); RBufWriteStream wStrm; ( void )wStrm.Open( *bufFromServer ); wStrm.PushL(); container2->ExternalizeL( wStrm ); wStrm.CommitL(); wStrm.Close(); wStrm.Pop(); TPtr8 ptrbufFromServer( bufFromServer->Ptr( 0 ) ); //bufFromServer content must equal to buf content TInt err = ( 0 == memcompare( reinterpret_cast<TUint8*> ( &ptrbufFromServer ), sizeof( bufFromServer ), reinterpret_cast<TUint8*> ( &ptr ), sizeof( bufFromServer ) ) ) ? KErrNone : KErrGeneral; ProcessResponseL( *container2, err ); // same container which was received from server CleanupStack::PopAndDestroy( bufFromServer ); CleanupStack::PopAndDestroy( buf ); CleanupStack::PopAndDestroy( container2 ); CleanupStack::PopAndDestroy( container1 ); } break; default: { COMPONENT_TRACE( ( _L( "BTASYStub - CBTBTASYStubCmdHandlerBase::ProcessCommandL() - CAccPolObjectBase - ERROR: unhandled command" ) ) ); TRACE_ASSERT_ALWAYS; User::Panic( _L("ASY Stub"), KErrGeneral ); } break; } } else if( name == KAccAudioUnits ) { CAccPolAudioTopologyObjectCon* container1 = CAccPolAudioTopologyObjectCon::NewLC(); CAccPolAudioTopologyObjectCon* container2 = CAccPolAudioTopologyObjectCon::NewLC(); RProperty prop; CBufFlat* buf = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( buf ); buf->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); TPtr8 ptr( buf->Ptr( 0 ) ); TInt retval = prop.Get( KTFAccessoryTestProperty, KTFAccessoryObjectMethod, ptr ); ( void )rStrm.Open( *buf ); rStrm.PushL(); container1->InternalizeL( rStrm ); rStrm.Close(); rStrm.Pop(); for( TInt i = 0; i < container1->Count(); i++ ) { container2->AddL( *container1->AtL( i ) ); } ProcessResponseL( *container2 ); CleanupStack::PopAndDestroy( buf ); CleanupStack::PopAndDestroy( container2 ); CleanupStack::PopAndDestroy( container1 ); } else if( name == KAccAudioControl ) { if( aCommand == ECmdSetObjectValue ) { CAccPolAudioTopologyObjectCon* container1 = CAccPolAudioTopologyObjectCon::NewLC(); // Get object from proxy ObjectConDataFromProxyL( *container1 ); for( TInt i = 0; i < container1->Count(); i++ ) { if( container1->AtL( i )->ObjectType() == EAccPolAudioVolumeControlObject ) { CAccPolVolumeControl* mVolume = ( CAccPolVolumeControl* )container1->AtL( i ); if( mVolume->UnitId() == 2 && mVolume->Channel() == KAccRightFrontChannel ) { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - right channel volume level=%f" ), mVolume->VolumeDb() ) ); COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - right channel volume min level=%f" ), mVolume->MinVolumeDb() ) ); COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - right channel volume max level=%f" ), mVolume->MaxVolumeDb() ) ); COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - right channel volume res level=%f" ), mVolume->VolumeResDb() ) ); } if( mVolume->UnitId() == 2 && mVolume->Channel() == KAccLeftFrontChannel ) { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - left channel volume level=%f" ), mVolume->VolumeDb() ) ); COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - left channel volume min level=%f" ), mVolume->MinVolumeDb() ) ); COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - left channel volume max level=%f" ), mVolume->MaxVolumeDb() ) ); COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - SET - left channel volume res level=%f" ), mVolume->VolumeResDb() ) ); } } else { CAccPolMuteControl* mMute = ( CAccPolMuteControl* )container1->AtL( i ); if( mMute->Channel() == KAccMasterChannel ) { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - KAccSetAudioControl - mute=%d" ), mMute->Mute() ) ); } } } ProcessResponseL( *container1 ); CleanupStack::PopAndDestroy( container1 ); } else if( aCommand == ECmdGetObjectValue ) { CAccPolAudioTopologyObjectCon* container1 = CAccPolAudioTopologyObjectCon::NewLC(); CAccPolAudioTopologyObjectCon* container2 = CAccPolAudioTopologyObjectCon::NewLC(); RProperty prop; CBufFlat* buf = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( buf ); buf->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); TPtr8 ptr( buf->Ptr( 0 ) ); TInt retval = prop.Get( KTFAccessoryTestProperty, KTFAccessoryObjectMethod, ptr ); ( void )rStrm.Open( *buf ); rStrm.PushL(); container2->InternalizeL( rStrm ); rStrm.Close(); rStrm.Pop(); // Read object --> after that assign new value ObjectConDataFromProxyL( *container1 ); if( container1->AtL( 0 )->ObjectType() == EAccPolAudioVolumeControlObject ) { CAccPolVolumeControl* rightVolume = ( CAccPolVolumeControl* )container2->AtL( 0 ); CAccPolVolumeControl* leftVolume = ( CAccPolVolumeControl* )container2->AtL( 1 ); if( reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 0 ) )->Channel() == KAccRightFrontChannel ) { reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 0 ) )->SetVolumeDb( rightVolume->VolumeDb() ); reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 0 ) )->SetMinVolumeDb( rightVolume->MinVolumeDb() ); reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 0 ) )->SetMaxVolumeDb( rightVolume->MaxVolumeDb() ); reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 0 ) )->SetVolumeResDb( rightVolume->VolumeResDb() ); } if( reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 1 ) )->Channel() == KAccLeftFrontChannel ) { reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 1 ) )->SetVolumeDb( rightVolume->VolumeDb() ); reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 1 ) )->SetMinVolumeDb( rightVolume->MinVolumeDb() ); reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 1 ) )->SetMaxVolumeDb( rightVolume->MaxVolumeDb() ); reinterpret_cast<CAccPolVolumeControl*> ( container1->AtL( 1 ) )->SetVolumeResDb( rightVolume->VolumeResDb() ); } } else { CAccPolMuteControl* psMute = ( CAccPolMuteControl* )container2->AtL( 0 ); if( reinterpret_cast<CAccPolMuteControl*> ( container1->AtL( 0 ) )->Channel() == KAccMasterChannel ) { reinterpret_cast<CAccPolMuteControl*> ( container1->AtL( 0 ) )->SetMute( psMute->Mute() ); } } ProcessResponseL( *container1 ); CleanupStack::PopAndDestroy( buf ); CleanupStack::PopAndDestroy( container2 ); CleanupStack::PopAndDestroy( container1 ); } else { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - No control object to found!" ) ) ); } } else if( name == KAccVideoHdmiAttributes ) { switch( aCommand ) { case ECmdGetObjectValue: { // Create buffer CBufFlat* buf = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( buf ); buf->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); // Read container from P&S TPtr8 bufPtr( buf->Ptr( 0 ) ); TInt err = RProperty::Get( KTFAccessoryTestProperty, KTFAccessoryObjectMethod, bufPtr ); if( err == KErrNone ) { // Stream HDMI container from data read from P&S CAccPolHdmiObjectCon* con = CAccPolHdmiObjectCon::NewLC(); RBufReadStream readStream( *buf ); readStream.PushL(); con->InternalizeL( readStream ); // Change all aatributes in speaker allocation to false RAccPolHdmiSpeakerAllocationArray array; CleanupClosePushL( array ); con->GetHdmiSpeakerAllocationObjectsL( array ); if( array.Count() ) { CAccPolHdmiSpeakerAllocation* speakerAllocation = array[0]; CAccPolHdmiSpeakerAllocation::THdmiSpeakerAllocation bits = CAccPolHdmiSpeakerAllocation::EHdmiSpeakerUnknown; speakerAllocation->SetSpeakerAllocation( bits ); } CleanupStack::PopAndDestroy( &array ); // Process response ProcessResponseL( *con, err ); // Cleanup CleanupStack::PopAndDestroy( &readStream ); CleanupStack::PopAndDestroy( con ); } // Cleanup CleanupStack::PopAndDestroy( buf ); break; } case ECmdSetObjectValue: default: { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - Nothing to do!" ) ) ); break; } } } else if( name == KAccVideoFormat ) { switch( aCommand ) { case ECmdGetObjectValue: { // Create buffer CBufFlat* buf = CBufFlat::NewL( KAccSrvObjectBaseStreamBufGranularity ); CleanupStack::PushL( buf ); buf->ResizeL( KAccSrvObjectBaseStreamBufMaxSize ); // Read container from P&S TPtr8 bufPtr( buf->Ptr( 0 ) ); TInt err = RProperty::Get( KTFAccessoryTestProperty, KTFAccessoryObjectMethod, bufPtr ); if( err == KErrNone ) { // Stream HDMI object container format from data read from P&S CAccPolHdmiObjectCon* con = CAccPolHdmiObjectCon::NewLC(); RBufReadStream readStream( *buf ); readStream.PushL(); con->InternalizeL( readStream ); CleanupStack::PopAndDestroy( &readStream ); // Set video format to interlaced mode RAccPolHdmiVideoFormatArray array; CleanupClosePushL( array ); con->GetHdmiVideoFormatObjectsL( array ); if( array.Count() ) { CAccPolHdmiVideoFormat* videoFormat = array[0]; videoFormat->SetInterlaced( ETrue ); } CleanupStack::PopAndDestroy( &array ); // Process response ProcessResponseL( *con, err ); // Cleanup CleanupStack::PopAndDestroy( con ); } // Cleanup CleanupStack::PopAndDestroy( buf ); break; } case ECmdSetObjectValue: default: { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - Nothing to do!" ) ) ); break; } } } else { COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - Nothing to do!" ) ) ); } /*CleanupStack::PopAndDestroy( buf ); CleanupStack::PopAndDestroy( container ); CleanupStack::PopAndDestroy( aObject ); */ COMPONENT_TRACE( ( _L( "ASYStub - CASYStubCmdHandlerBase::ProcessCommandL - return void - CAccPolObjectBase" ) ) ); }