void CMtfTestActionSmtpGetAttachmentFileFromId::CompareFileL(RFile& aAttachment, const TDesC& aDataFilePath) { RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); RFile dataFile; User::LeaveIfError(dataFile.Open(fs, aDataFilePath, EFileRead|EFileShareReadersOnly)); CleanupClosePushL(fs); TInt fileSize = 0; User::LeaveIfError(dataFile.Size(fileSize)); HBufC8* dataBuffer = HBufC8::NewLC(fileSize); TPtr8 bufferPtr(dataBuffer->Des()); User::LeaveIfError(aAttachment.Size(fileSize)); HBufC8* attachmentData = HBufC8::NewLC(fileSize); TPtr8 attachmentPtr(attachmentData->Des()); TInt compare = attachmentPtr.Compare(bufferPtr); if( compare != 0 ) User::Leave(KErrCorrupt); CleanupStack::PopAndDestroy(4, &fs); // attachmentData, dataBuffer, dataFile, fs }
void CUissSession::TransferDescriptorL( const RMessage2& aMessageFrom, TInt aParameterFrom, const RMessage2& aMessageTo, TInt aParameterTo) { TInt lengthFrom=aMessageFrom.GetDesLengthL(aParameterFrom); // copy data only if there is anything to copy if (lengthFrom) { HBufC8* buffer=HBufC8::NewLC(lengthFrom); TPtr8 bufferPtr(buffer->Des()); aMessageFrom.ReadL(aParameterFrom, bufferPtr); aMessageTo.WriteL(aParameterTo, bufferPtr); CleanupStack::PopAndDestroy(buffer); } }
TBool WidgetUnzipUtilityS60::RunUnzipL() { CZipFileMember* member = iMembers->NextL(); if (member) { CleanupStack::PushL(member); RZipFileMemberReaderStream* stream; User::LeaveIfError(iZipFile->GetInputStreamL(member, stream)); CleanupStack::PushL(stream); HBufC8* buffer = HBufC8::NewLC(member->UncompressedSize()); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize())); TFileName text; text.Copy(*iTempZipPath); text.Append(_L('\\')); text.Append(*member->Name()); HBufC* zipedFileNameAndPath = text.AllocLC(); TInt index = zipedFileNameAndPath->LocateReverse('\\'); if (index >= 0) { TPtrC path = zipedFileNameAndPath->Left(index + 1); iFs.MkDirAll(path); // errors are ok } if (zipedFileNameAndPath->Right(1).Compare(_L('\\')) != 0) { RFile file; CleanupClosePushL(file); file.Replace(iFs,*zipedFileNameAndPath,EFileWrite); User::LeaveIfError(file.Write(*buffer)); CleanupStack::PopAndDestroy(); // file } iUncompressedSize += member->UncompressedSize(); CleanupStack::PopAndDestroy(4); return ETrue; } else { return EFalse; } }
void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions ) { FILE* fp = fopen( filename.c_str() , "rb" ); AutoCloseFile autoClose( fp ); Dali::Integration::Bitmap* bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); Dali::Integration::BitmapPtr bitmapPtr( bitmap ); Dali::ImageAttributes attributes; DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); FILE* writeFp = fopen( targetFilename.c_str(), "wb" ); AutoCloseFile autoCloseWrite( writeFp ); fwrite( bufferPtr, sizeof( Dali::PixelBuffer ), attributes.GetWidth() * attributes.GetHeight(), writeFp ); }
EXPORT_C CMemSpyApiHeap* RMemSpySession::GetHeapL() { CMemSpyApiHeap* aHeap; HBufC8* buffer = HBufC8::NewLC( sizeof(TMemSpyHeapData) ); TPtr8 bufferPtr(buffer->Des()); TIpcArgs args( &bufferPtr ); User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetHeap, args )); TPckgBuf<TMemSpyHeapData> data; data.Copy(bufferPtr.Ptr(), sizeof(TMemSpyHeapData)); aHeap = CMemSpyApiHeap::NewL( data() ); CleanupStack::PopAndDestroy(buffer); return aHeap; }
/** Test MSdpElementBuilder::BuildIntL() */ void CT_DataSdpElementBuilder::DoCmdBuildIntL(MSdpElementBuilder& aElementBuilder, const TDesC& aSection) { iDataWrapper.INFO_PRINTF1(_L("MSdpElementBuilder BuildIntL Call")); TPtrC theString; TPtrC sdpIntBufName; TBool foundParameter=EFalse; if( iDataWrapper.GetStringFromConfig(aSection, KInt(), theString) ) { foundParameter=ETrue; HBufC8* theString8 = HBufC8::NewLC(theString.Length()); theString8->Des().Copy(theString); TPtrC8 stringPtr = theString8->Des(); TRAPD(err, aElementBuilder.BuildIntL(stringPtr)); if(err != KErrNone) { iDataWrapper.ERR_PRINTF2(_L("MSdpElementBuilder BuildIntL failed with error %d"), err); iDataWrapper.SetError(err); } CleanupStack::PopAndDestroy(theString8); } if ( iDataWrapper.GetStringFromConfig(aSection, KSdpIntBufObj(), sdpIntBufName) ) { foundParameter=ETrue; TAny* object=iDataWrapper.GetDataObjectL(sdpIntBufName); TSdpIntBuf<TUint8>* sdpIntBuf = static_cast<TSdpIntBuf<TUint8>*>(object); TSdpIntBuf<TUint8> sdpIntObj = *sdpIntBuf; const TUint8 *tmp=&sdpIntObj[0]; TPtrC8 bufferPtr(tmp, sdpIntObj.Length()); TRAPD(err, aElementBuilder.BuildIntL(bufferPtr)); if ( err!=KErrNone ) { iDataWrapper.ERR_PRINTF2(_L("MSdpElementBuilder BuildIntL failed with error %d"), err); iDataWrapper.SetError(err); } } if (!foundParameter) { iDataWrapper.ERR_PRINTF2(_L("Missing parameter %S"), &KSdpIntBufObj()); iDataWrapper.SetBlockResult(EFail); } }
void CT_DataSdpAttrValueUint::DoCmdNewUintL(const TDesC& aSection) { DestroyData(); TPtrC theString; TPtrC sdpIntBufName; TBool foundParameter=EFalse; if ( GetStringFromConfig(aSection, KInputInt(), theString) ) { foundParameter=ETrue; HBufC8* string8 = HBufC8::NewLC(theString.Length()); string8->Des().Copy(theString); TPtrC8 stringPtr = string8->Des(); TRAPD(err, iAttrValUint = CSdpAttrValueUint::NewUintL(stringPtr)); if ( err!=KErrNone ) { ERR_PRINTF2(_L("CSdpAttrValueUint::NewUintL failed with error %d"), err); SetError(err); } CleanupStack::PopAndDestroy(string8); } if ( GetStringFromConfig(aSection, KSdpIntBufObj(), sdpIntBufName) ) { foundParameter=ETrue; TAny* object=GetDataObjectL(sdpIntBufName); TSdpIntBuf<TUint8>* sdpIntBuf = static_cast<TSdpIntBuf<TUint8>*>(object); TSdpIntBuf<TUint8> sdpIntObj = *sdpIntBuf; const TUint8 *tmp=&sdpIntObj[0]; TPtrC8 bufferPtr(tmp, sdpIntObj.Length()); TRAPD(err, iAttrValUint = CSdpAttrValueUint::NewUintL(bufferPtr)); if ( err!=KErrNone ) { ERR_PRINTF2(_L("CSdpAttrValueInt::NewUintL failed with error %d"), err); SetError(err); } } if (!foundParameter) { ERR_PRINTF2(_L("Missing parameter %S"), &KSdpIntBufObj()); SetBlockResult(EFail); } }
EXPORT_C void RMemSpySession::GetThreadInfoItemsL( RArray<CMemSpyApiThreadInfoItem*> &aInfoItems, TThreadId aId, TMemSpyThreadInfoItemType aType ) { TPckgBuf<TThreadId> id( aId ); TPckgBuf<TMemSpyThreadInfoItemType> type( aType ); TPckgBuf<TInt> count; TInt error = SendReceive( EMemSpyClientServerOpGetThreadInfoItemsCount, TIpcArgs( &id, &type, &count ) ); TInt itemCount = count(); if( error == KErrNone ) { if( itemCount == 0 ) { aInfoItems.Reset(); } else { HBufC8* buffer = HBufC8::NewLC( itemCount * sizeof(TMemSpyThreadInfoItemData) ); TPtr8 bufferPtr(buffer->Des()); TPckgBuf<TInt> requestedCount( itemCount ); TIpcArgs args( &requestedCount, &id, &type, &bufferPtr ); TInt error = SendReceive( EMemSpyClientServerOpGetThreadInfoItems, args ); // TODO check error aInfoItems.Reset(); for(TInt i=0, offset = 0; i < itemCount; i++, offset+=sizeof(TMemSpyThreadInfoItemData)) { TPckgBuf<TMemSpyThreadInfoItemData> data; data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyThreadInfoItemData)); aInfoItems.AppendL(CMemSpyApiThreadInfoItem::NewLC(data())); } CleanupStack::Pop(aInfoItems.Count()); CleanupStack::PopAndDestroy(buffer); } } User::LeaveIfError(error); }
void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions ) { FILE* fp = fopen( image.name.c_str() , "rb" ); AutoCloseFile autoClose( fp ); DALI_TEST_CHECK( fp != NULL ); // Check the header file. unsigned int width(0), height(0); Dali::ImageAttributes attributes; DALI_TEST_CHECK( functions.header( fp, attributes, width, height ) ); DALI_TEST_EQUALS( width, image.reportedWidth, TEST_LOCATION ); DALI_TEST_EQUALS( height, image.reportedHeight, TEST_LOCATION ); // Loading the header moves the pointer within the file so reset to start of file. fseek( fp, 0, 0 ); // Create a bitmap object and store a pointer to that object so it is destroyed at the end. Dali::Integration::Bitmap * bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); Dali::Integration::BitmapPtr bitmapPtr( bitmap ); // Load Bitmap and check its return values. DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); DALI_TEST_EQUALS( image.width, attributes.GetWidth(), TEST_LOCATION ); DALI_TEST_EQUALS( image.height, attributes.GetHeight(), TEST_LOCATION ); // Compare buffer generated with reference buffer. Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); Dali::PixelBuffer* refBufferPtr( image.refBuffer ); for ( unsigned int i = 0; i < image.refBufferSize; ++i, ++bufferPtr, ++refBufferPtr ) { if( *bufferPtr != *refBufferPtr ) { tet_result( TET_FAIL ); tet_printf("%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); break; } } }
// static QString WidgetUnzipUtilityS60::fileContentsL(const QString& aZipFileName, const QString& aFileName, const Qt::CaseSensitivity& cs) { QString zipFileName = QDir::toNativeSeparators(aZipFileName); QString contents; TPtrC16 zName(reinterpret_cast<const TUint16*>(zipFileName.utf16())); RFs iFs; User::LeaveIfError(iFs.Connect()); CZipFile *zipfile = CZipFile::NewL(iFs, zName); CleanupStack::PushL(zipfile); CZipFileMemberIterator *members = zipfile->GetMembersL(); CZipFileMember* member; while ((member = members->NextL()) != 0) { QString filename = QString::fromUtf16(member->Name()->Ptr(), member->Name()->Length()); // If the member is the desired file, extract it if (!filename.compare(aFileName, cs)) { RZipFileMemberReaderStream *stream; zipfile->GetInputStreamL(member, stream); CleanupStack::PushL(stream); HBufC8 *buffer = HBufC8::NewLC(member->UncompressedSize()); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(stream->Read(bufferPtr, member->UncompressedSize())); QByteArray data(reinterpret_cast<const char*>(buffer->Ptr()), buffer->Length()); QString ret(data); CleanupStack::PopAndDestroy(3); // zipfile, stream, buffer return ret; } } CleanupStack::PopAndDestroy(); return contents; }
// Servers EXPORT_C void RMemSpySession::GetServersL(RArray<CMemSpyApiServer*> &aServers) { TPckgBuf<TInt> count; User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetServerCount, TIpcArgs(&count))); TInt requestedCount = count(); HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyServerData)); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetServers, TIpcArgs(&count, &bufferPtr))); aServers.Reset(); TInt receivedCount = Min(count(), requestedCount); for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyServerData)) { TPckgBuf<TMemSpyServerData> data; data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyServerData)); aServers.AppendL(CMemSpyApiServer::NewLC(data())); } CleanupStack::Pop(aServers.Count()); CleanupStack::PopAndDestroy(buffer); }
EXPORT_C void RMemSpySession::GetEComImplementationsL(TUid aInterface, RArray<CMemSpyApiEComImplementation*> &aImplementations) { TPckgBuf<TInt> count; TPckgBuf<TUid> interface(aInterface); User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetEComImplementationCount, TIpcArgs(&count, &interface))); TInt requestedCount = count(); HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyEComImplementationData)); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetEComImplementations, TIpcArgs(&count, &interface, &bufferPtr))); aImplementations.Reset(); TInt receivedCount = Min(count(), requestedCount); for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyEComImplementationData)) { TPckgBuf<TMemSpyEComImplementationData> data; data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyEComImplementationData)); aImplementations.AppendL(CMemSpyApiEComImplementation::NewLC(data())); } CleanupStack::Pop(aImplementations.Count()); CleanupStack::PopAndDestroy(buffer); }
// Threads related methods EXPORT_C void RMemSpySession::GetThreadsL(TProcessId aProcessId, RArray<CMemSpyApiThread*> &aThreads, TSortType aSortType) { TPckgBuf<TInt> count; TPckgBuf<TProcessId> pid(aProcessId); User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetThreadCount, TIpcArgs(&count, &pid))); TInt requestedCount = count(); HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyThreadData)); TPtr8 bufferPtr(buffer->Des()); User::LeaveIfError(SendReceive(EMemSpyClientServerOpGetThreads, TIpcArgs(&count, &bufferPtr, &pid))); aThreads.Reset(); TInt receivedCount = Min(count(), requestedCount); for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyThreadData)) { TPckgBuf<TMemSpyThreadData> data; data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyThreadData)); aThreads.AppendL(CMemSpyApiThread::NewLC(data())); } CleanupStack::Pop(aThreads.Count()); CleanupStack::PopAndDestroy(buffer); }
EXPORT_C void RMemSpySession::GetKernelObjectItemsL( RArray<CMemSpyApiKernelObjectItem*> &aKernelObjectItems, TMemSpyDriverContainerType aForContainer ) { TPckgBuf<TInt> count; TPckgBuf<TMemSpyDriverContainerType> type(aForContainer); User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectItemCount, TIpcArgs(&count, &type) )); TInt requestedCount = count(); HBufC8* buffer = HBufC8::NewLC(requestedCount * sizeof(TMemSpyDriverHandleInfoGeneric)); TPtr8 bufferPtr(buffer->Des()); TIpcArgs args( &count, &type, &bufferPtr ); User::LeaveIfError(SendReceive( EMemSpyClientServerOpGetKernelObjectItems, args )); aKernelObjectItems.Reset(); for(TInt i=0, offset = 0; i<requestedCount; i++, offset+=sizeof(TMemSpyDriverHandleInfoGeneric)) { TPckgBuf<TMemSpyDriverHandleInfoGeneric> data; data.Copy(bufferPtr.Ptr()+offset, sizeof(TMemSpyDriverHandleInfoGeneric)); aKernelObjectItems.AppendL( CMemSpyApiKernelObjectItem::NewLC( data() ) ); } CleanupStack::Pop(aKernelObjectItems.Count()); CleanupStack::PopAndDestroy(buffer); }
// -------------------------------------------------------------------------- // CImageCapture::GetNextFileNameLC // Get the file name // -------------------------------------------------------------------------- HBufC* CImageCapture::GetNextFileNameLC(const TDesC& aName) const { const TInt KNumberLength = 4; // this is to indicate the file numbering, // e.g. 0001, 0002, etc. const TInt KMaxIndex = 10000; const TInt KTimeRecordSize = 512; TPtrC filePathPtr; _LIT(KExtensionpng, ".png"); _LIT(KSlash,"\\"); // Gets the file extension. TPtrC fileExtension; fileExtension.Set(KExtensionpng); filePathPtr.Set(iSettings.iLogPath); TInt result = filePathPtr.LocateReverse('\\'); TPtrC string; if(result!=KErrNotFound) string.Set(filePathPtr.Left(result+1)); TBuf8<KTimeRecordSize> fileName; fileName.Copy(string); if(iXmlFileName.Length()>0) { TInt pos=iXmlFileName.LocateReverse('.'); TPtrC8 ptr; if(pos!=KErrNotFound) { ptr.Set(iXmlFileName.Left(pos)); fileName.Append(ptr); } fileName.Append(KSlash); } fileName.Append(aName); HBufC* newFileName = HBufC::NewLC(fileName.Length()+ KNumberLength + fileExtension.Length() + 1); TPtr newFileNamePtr(newFileName->Des()); newFileNamePtr.Copy(fileName); // Checks whether aNamexxxx.png already exists on the phone or not. // This is to prevent over-riding of any existing images with the same name TBool IsFileExist = ETrue; TInt index = 1; HBufC* buffer = HBufC::NewL(newFileNamePtr.MaxLength()); TPtr bufferPtr(buffer->Des()); while ((index < KMaxIndex) && (IsFileExist)) { bufferPtr.Copy(newFileNamePtr); bufferPtr.AppendNumFixedWidth(index, EDecimal, KNumberLength); bufferPtr.Append(fileExtension); if (BaflUtils::FileExists(CCoeEnv::Static()->FsSession(), *buffer)) { index++; } else { IsFileExist = EFalse; } } delete buffer; // If the index exceeds KMaxIndex, then we don't need to format the file name. if (index >= KMaxIndex) { newFileNamePtr.AppendNum(index); } else { newFileNamePtr.AppendNumFixedWidth(index, EDecimal, KNumberLength); } newFileNamePtr.Append(fileExtension); // If the index greated then KMaxIndex, then rollback to 1 if (index >= KMaxIndex) { index = 1; } return newFileName; }
int rootComputing() { auto listing = OS::getDirListing(options.inputImagePath.c_str()); std::vector<PngImage> images; typedef std::shared_ptr<cl_uint> ImageDataPtr; std::vector<ImageDataPtr> imageData; for (int i=0; i<listing.size() && i<currentSize-1; i++) { std::string filePath = options.inputImagePath + "/" + listing[i]; std::cout << "Opening image file " << filePath.c_str() << std::endl; PngImage image(filePath.c_str()); images.push_back(image); ImageDataPtr dataPtr = image.getData(); imageData.push_back(dataPtr); } std::cout << "Opened " << images.size() << " files" << std::endl; std::vector<MPI::Request> requests; std::cout << "Sendign data to peers\n"; for (int i=1; i<currentSize; i++) { ImageDataPtr dataPtr = imageData[i-1]; Size size; if (i > images.size()) size = { 0, 0 }; else { size.width = images[i-1].getWidth(); size.height = images[i-1].getHeight(); } std::cout << "Sending image size for peer " << i << std::endl; comm.Isend(&size, 2, MPI_INTEGER, i, TAG_IMAGE_SIZE); if(size.width != 0 && size.height != 0) { comm.Isend( (void*) dataPtr.get(), size.width*size.height, MPI_INTEGER, i, TAG_IMAGE_DATA); std::cout << "Sended initial data to peer " << i << std::endl; } } std::cout << "Receiving data from peers\n"; std::vector<ImageDataPtr> buffers; for (int i=1; i<currentSize; i++) { size_t pixCount = images[i-1].getWidth() * images[i-1].getHeight(); ImageDataPtr bufferPtr(new cl_uint[pixCount]); if (pixCount != 0) { MPI::Request r3 = comm.Irecv(bufferPtr.get(), pixCount, MPI_INTEGER, i, TAG_IMAGE_RESULT); requests.push_back(r3); buffers.push_back(bufferPtr); } else break; } for (int i=0; i<requests.size(); i++) { requests[i].Wait(); } std::cout << "All communication operations done" << std::endl; for (int i=0; i<currentSize-1; i++) { //TODO: exit if no tasks for this peer was planed size_t size = images[i].getWidth() * images[i].getHeight(); images[i].setData(buffers[i].get()); std::string name = options.outputImagePath + "/" + std::to_string(i) +".png"; std::cout << "Writing file to " << name << std::endl; images[i].write(name.c_str()); } std::cout << "Done\n"; }