bool ClassGenerator::initStreams(const QString& baseName, QTextStream& headerStream, QTextStream& sourceStream) { QFile* headerFile = new QFile(baseName + ".h"); QFile* sourceFile = new QFile(baseName + ".cpp"); if (!headerFile->open(IO_WriteOnly) || !sourceFile->open(IO_WriteOnly)) { delete headerFile; delete sourceFile; return false; } headerStream.setDevice(headerFile); sourceStream.setDevice(sourceFile); // create header writeFileHeader(headerStream); openIncludeGuard(baseName, headerStream); // create source writeFileHeader(sourceStream); sourceStream << "// declaration include" << endl; sourceStream << "#include \"" << baseName << ".h\"" << endl; sourceStream << endl; return true; }
/** * Start function */ void IpfixCsExporter::performStart() { writeFileHeader(); addToCurTime(&nextChunkTimeout, maxChunkBufferTime*1000); addToCurTime(&nextFileTimeout, maxFileCreationInterval*1000); registerTimeout(); }
void LodConfigSerializer::exportLodConfig(Ogre::LodConfig& config, Ogre::DataStreamPtr stream, Endian endianMode /*= ENDIAN_NATIVE*/ ) { Ogre::LogManager::getSingleton().logMessage("MeshSerializer writing mesh data to stream " + stream->getName() + "..."); // Decide on endian mode determineEndianness(endianMode); mLodConfig = &config; mStream = stream; if (!stream->isWriteable()) { OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Unable to use stream " + stream->getName() + " for writing", "LodConfigSerializer::export"); } writeFileHeader(); LogManager::getSingleton().logMessage("File header written."); LogManager::getSingleton().logMessage("Writing Lod Config..."); pushInnerChunk(mStream); writeLodConfig(); popInnerChunk(mStream); LogManager::getSingleton().logMessage("LodConfigSerializer export successful."); }
YUV::YUV(char* filename, uint _nRows, uint _nCols, uint _fps, uint _type) : nRows(_nRows), nCols(_nCols), fps(_fps), type(_type) { if (writeFileHeader(filename)) throw new std::runtime_error("Unable to write file header!"); init(); }
void codeGen(TreeNode *syntaxTree, const char *codefile) { writeFileHeader(); writeVarSection(); cGen(syntaxTree); fillCodeSection(); writeTempVarSection(); writeVarRefSection(); fillSection(); writeTempVarRefSection(); fillSection(); updateFileHeader(); }
/*------------------------------------------------------------------------------------------------------------ * ビットマップファイルを書き出す * * path: 書き出すビットマップファイル */ void Bitmap::writeFile(const char *path) const { FILE *ofp = fopen(path, "wb"); if (ofp == 0) { perror("fopen"); fprintf(stderr, "file: %s\n", path); throw MyError("bitmap file open failed", __FUNCTION__); } writeFileHeader(ofp); writeInfoHeader(ofp); writeBitmapData(ofp); fclose(ofp); }
//--------------------------------------------------------------------- void SkeletonSerializer::exportSkeleton(const Skeleton* pSkeleton, DataStreamPtr stream, SkeletonVersion ver, Endian endianMode) { setWorkingVersion(ver); // Decide on endian mode determineEndianness(endianMode); String msg; mStream = stream; if (!stream->isWriteable()) { OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Unable to write to stream " + stream->getName(), "SkeletonSerializer::exportSkeleton"); } writeFileHeader(); // Write main skeleton data LogManager::getSingleton().logMessage("Exporting bones.."); writeSkeleton(pSkeleton, ver); LogManager::getSingleton().logMessage("Bones exported."); // Write all animations unsigned short numAnims = pSkeleton->getNumAnimations(); LogManager::getSingleton().stream() << "Exporting animations, count=" << numAnims; for (unsigned short i = 0; i < numAnims; ++i) { Animation* pAnim = pSkeleton->getAnimation(i); LogManager::getSingleton().stream() << "Exporting animation: " << pAnim->getName(); writeAnimation(pSkeleton, pAnim, ver); LogManager::getSingleton().logMessage("Animation exported."); } // Write links Skeleton::LinkedSkeletonAnimSourceIterator linkIt = pSkeleton->getLinkedSkeletonAnimationSourceIterator(); while(linkIt.hasMoreElements()) { const LinkedSkeletonAnimationSource& link = linkIt.getNext(); writeSkeletonAnimationLink(pSkeleton, link); } }
//--------------------------------------------------------------------- void SkeletonSerializer::exportSkeleton(const Skeleton* pSkeleton, const String& filename, Endian endianMode) { // Decide on endian mode determineEndianness(endianMode); String msg; mpfFile = fopen(filename.c_str(), "wb"); if (!mpfFile) { OGRE_EXCEPT(Exception::ERR_CANNOT_WRITE_TO_FILE, "Unable to open file " + filename + " for writing", "SkeletonSerializer::exportSkeleton"); } writeFileHeader(); // Write main skeleton data LogManager::getSingleton().logMessage("Exporting bones.."); writeSkeleton(pSkeleton); LogManager::getSingleton().logMessage("Bones exported."); // Write all animations unsigned short numAnims = pSkeleton->getNumAnimations(); LogManager::getSingleton().stream() << "Exporting animations, count=" << numAnims; for (unsigned short i = 0; i < numAnims; ++i) { Animation* pAnim = pSkeleton->getAnimation(i); LogManager::getSingleton().stream() << "Exporting animation: " << pAnim->getName(); writeAnimation(pSkeleton, pAnim); LogManager::getSingleton().logMessage("Animation exported."); } // Write links Skeleton::LinkedSkeletonAnimSourceIterator linkIt = pSkeleton->getLinkedSkeletonAnimationSourceIterator(); while(linkIt.hasMoreElements()) { const LinkedSkeletonAnimationSource& link = linkIt.getNext(); writeSkeletonAnimationLink(pSkeleton, link); } fclose(mpfFile); }
void writeImage(char *fileName, IMAGE *image, bool printInfo) { if(printInfo) printf("Writing File...\n"); BMPHeader bmpHeader; FileHeader fileHeader; createDataHeader(image->width, image->height, image->numColors, &bmpHeader); createFileHeader(&bmpHeader,&fileHeader); FILE *fhandle = fopen(fileName,"wb"); writeFileHeader(fhandle, fileHeader, printInfo); writeDataHeader(fhandle, bmpHeader, printInfo); if(image->numColors == 1) writeGreyPalette(fhandle); writeRaster(fhandle, image, printInfo); fclose(fhandle); }
/******************* FUNCTION *********************/ CMRBasicOutputer::CMRBasicOutputer(const std::string & fname,const CMRAbstractSpaceSplitter & splitter) { this->fname = fname; //open result file fp = fopen(fname.c_str(),"w"); //errors if (fp == NULL) { perror(fname.c_str()); abort(); } //write header writeFileHeader(splitter); }
void writeBMP(BMP bmp, FILE* dest) { writeFileHeader(bmp.fileHeader, dest); fwrite(&bmp.size, sizeof(bmp.size), 1, dest); fwrite(&bmp.width, sizeof(bmp.width), 1, dest); fwrite(&bmp.height, sizeof(bmp.height), 1, dest); fwrite(&bmp.planes, sizeof(bmp.planes), 1, dest); fwrite(&bmp.bits, sizeof(bmp.bits), 1, dest); fwrite(&bmp.compression, sizeof(bmp.compression), 1, dest); fwrite(&bmp.imagesize, sizeof(bmp.imagesize), 1, dest); fwrite(&bmp.xresolution, sizeof(bmp.xresolution), 1, dest); fwrite(&bmp.yresolution, sizeof(bmp.yresolution), 1, dest); fwrite(&bmp.ncolours, sizeof(bmp.ncolours), 1, dest); fwrite(&bmp.importantcolours, sizeof(bmp.importantcolours), 1, dest); fwrite(bmp.memory, 1, bmp.imagesize, dest); }
void Foam::overtopping::makeFile() { // Create the overtopping file if not already created if (outputFilePtr_.empty()) { if (debug) { Info<< "Creating output file." << endl; } // File update if (Pstream::master()) { fileName outputDir; word startTimeName = mesh_.time().timeName(mesh_.time().startTime().value()); if (Pstream::parRun()) { // Put in undecomposed case (Note: gives problems for // distributed data running) outputDir = mesh_.time().path()/".."/this->type()/startTimeName; } else { outputDir = mesh_.time().path()/this->type()/startTimeName; } // Create directory if does not exist mkDir(outputDir); // Open new file at start up outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat"))); outputFileForcePtr_.reset ( new OFstream(outputDir/(type() + "_rhoU2A.dat")) ); // Add headers to output data writeFileHeader(); } } }
void BitmapWriter::writeBitmap(Bitmap & bitmap, const char * filePath) { FILE * file = fopen(filePath, "wb"); writeFileHeader(bitmap.fileheader, file); writeInfoHeader(bitmap.infoheader, file); byte zero = 0; for (int i = 0; i < bitmap.height; i++) { for (int j = 0; j < bitmap.width; j++) writePixel(bitmap.get(j, i), file); for (int j = 0; j < bitmap.paddingZeros; j++) fwrite(&zero, sizeof(byte), 1, file); } fclose(file); }
void IpfixCsExporter::onTimeout(void* dataPtr) { timeoutRegistered = false; struct timeval now; gettimeofday(&now, 0); //check if this is one of the desired timeouts if (nextFileTimeout.tv_sec <= now.tv_sec) { //close File, add new one writeChunkList(); writeFileHeader(); addToCurTime(&nextChunkTimeout, maxChunkBufferTime*1000); addToCurTime(&nextFileTimeout, maxFileCreationInterval*1000); } else if (nextChunkTimeout.tv_sec <= now.tv_sec) { writeChunkList(); addToCurTime(&nextChunkTimeout, maxChunkBufferTime*1000); } registerTimeout(); }
status_t TiffWriter::write(Output* out, Endianness end) { status_t ret = OK; EndianOutput endOut(out, end); if (mIfd == NULL) { ALOGE("%s: Tiff header is empty.", __FUNCTION__); return BAD_VALUE; } BAIL_ON_FAIL(writeFileHeader(endOut), ret); uint32_t offset = FILE_HEADER_SIZE; sp<TiffIfd> ifd = mIfd; while(ifd != NULL) { BAIL_ON_FAIL(ifd->writeData(offset, &endOut), ret); offset += ifd->getSize(); ifd = ifd->getNextIfd(); } return ret; }
/* * Prepares an AVFormatContext for output. * Currently, the output format and codecs are hardcoded in this file. */ void Java_com_example_ffmpegtest_recorder_FFmpegWrapper_prepareAVFormatContext(JNIEnv *env, jobject obj, jstring jOutputPath){ init(); // Create AVRational that expects timestamps in microseconds videoSourceTimeBase = av_malloc(sizeof(AVRational)); videoSourceTimeBase->num = 1; videoSourceTimeBase->den = 1000000; audioSourceTimeBase = av_malloc(sizeof(AVRational)); audioSourceTimeBase->num = 1; audioSourceTimeBase->den = 1000000; AVFormatContext *inputFormatContext; outputPath = (*env)->GetStringUTFChars(env, jOutputPath, NULL); outputFormatContext = avFormatContextForOutputPath(outputPath, outputFormatName); LOGI("post avFormatContextForOutputPath"); // For copying AVFormatContext from sample file: /* inputFormatContext = avFormatContextForInputPath(sampleFilePath, outputFormatName); LOGI("post avFormatContextForInputPath"); copyAVFormatContext(&outputFormatContext, &inputFormatContext); LOGI("post copyAVFormatContext"); */ // For manually crafting AVFormatContext addVideoStream(outputFormatContext); addAudioStream(outputFormatContext); av_opt_set_int(outputFormatContext->priv_data, "hls_time", hlsSegmentDurationSec, 0); int result = openFileForWriting(outputFormatContext, outputPath); if(result < 0){ LOGE("openFileForWriting error: %d", result); } writeFileHeader(outputFormatContext); }
void Foam::functionObjectFile::createFiles() { if (Pstream::master()) { const word startTimeName = obr_.time().timeName(obr_.time().startTime().value()); label i = 0; forAllConstIter(wordHashSet, names_, iter) { if (!filePtrs_.set(i)) { fileName outputDir(baseFileDir()/prefix_/startTimeName); mkDir(outputDir); word fName(iter.key()); // check if file already exists IFstream is(outputDir/(fName + ".dat")); if (is.good()) { fName = fName + "_" + obr_.time().timeName(); } filePtrs_.set(i, new OFstream(outputDir/(fName + ".dat"))); initStream(filePtrs_[i]); writeFileHeader(i); i++; } } } }
int main (int argc, char **argv) { // Variables for recording the time. time_t rawtime; struct tm * timeinfo; // Variables for describing the scan. float startvalue,endvalue,stepsize; // Variables for storing text char fileName[BUFSIZE],comments[BUFSIZE]; // A file used to indicate that we are collecting data. char dataCollectionFileName[] = "/home/pi/.takingData"; // Used to store error codes int err; FILE *dataCollectionFlagFile, *fp; /* Check to make sure that the proper arguments were supplied. */ if (argc==5) { startvalue=atof(argv[1]); endvalue=atof(argv[2]); stepsize=atof(argv[3]); strcpy(comments,argv[4]); } else { printf("Usage:\n"); printf("$ sudo ./RbAbsorbScan <begin> <end> <step> <comments>\n"); printf(" (0.0 - 117.5) \n"); return 0; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("Unable to open file: %s\n",dataCollectionFileName); exit(1); } initializeBoard(); initializeUSB1208(); if (endvalue>117.5) endvalue=117.5; if (startvalue>117.5) endvalue=117.5; if (startvalue<0) startvalue=0; if (endvalue<0) endvalue=0; if (startvalue>endvalue) { printf("error: startvalue > endvalue.\nYeah, i could just swap them in code.. or you could just enter them in correctly. :-)\n"); return 1; } // Get file name. use format "RbAbs"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); if (stat(fileName, &st) == -1){ // Create the directory for the Day's data mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/RbAbs%F_%H%M%S.dat",timeinfo); printf("\n%s\n",fileName); writeFileHeader(fileName, comments); fp=fopen(fileName,"a"); if (!fp) { printf("unable to open file: %s\n",fileName); exit(1); } err=setMirror(0); if(err>0) printf("Error Occured While setting Flip Mirror: %d\n",err); collectAndRecordData(fileName, startvalue, endvalue, stepsize); setVortexPiezo(45.0); // Return Piezo to 45.0 V closeUSB1208(); graphData(fileName); fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }
/* Applies a threshold filter to a BMP file and writes the result to another. Takes care of opening and closing the output file. */ int applyThreshold(FILE* inFile, struct bmpFileHeader* fileHead, struct bmpInfoHeader* infoHead, char* outFileName, float threshold) { // check that threshold value is in range if (threshold < 0.0 || threshold > 1.0) { fprintf(stderr, "Threshold value not in range.\n"); return EXIT_FAILURE; } // open file for writing FILE *outFile = fopen(outFileName, "w+"); // check that file opened okay if (outFile == NULL) { fprintf(stderr, "Unable to open file: %s for writing.\n", outFileName); return EXIT_FAILURE; } // write the headers to the output file, checking for errors if (writeFileHeader(fileHead, outFile) != 0) { fprintf(stderr, "Unable to write file header.\n"); return EXIT_FAILURE; } if (writeInfoHeader(infoHead, outFile) != 0) { fprintf(stderr, "Unable to write info header.\n"); return EXIT_FAILURE; } // calculate amount of padding added to width int padding = (4 - (infoHead->width*3 % 4)) % 4; // to store pixel being worked on struct pixel* curPixel = NULL; // run through pixels, modifying and saving them to out file for (int i = 0; i < infoHead->height; i++) { for (int j = 0; j < infoHead->width; j++) { // get a pixel curPixel = getPixel(inFile); // make sure we actually got a pixel if (curPixel == NULL) { fprintf(stderr, "Unable to get pixel.\n"); return EXIT_FAILURE; } double maxPixelValue = pow(2, infoHead->colourDepth/3) - 1; // calculate individual intensity values for each colour double redIntensity = (curPixel->red)/maxPixelValue; double greenIntensity = (curPixel->green)/maxPixelValue; double blueIntensity = (curPixel->blue)/maxPixelValue; // determine if pixel above thresh, make it black/white accordingly if ((redIntensity + greenIntensity + blueIntensity)/3.0 > threshold) { const uint32_t white = 0xFFFFFF; // write pixel, checking for error if (fwrite(&white, 3, 1, outFile) != 1) { fprintf(stderr, "Unable to write white pixel to file.\n"); return EXIT_FAILURE; } } else { const uint32_t black = 0x000000; // write pixel, checking for error if(fwrite(&black, 3, 1, outFile) != 1) { fprintf(stderr, "Unable to write black pixel to file.\n"); return EXIT_FAILURE; } } } // move in-file on by padding amount fseek(inFile, padding, SEEK_CUR); // add padding to out-file for (int k = 0; k < padding; k++) { fputc(0x00, outFile); } } // free memory allocated to pixel storage free(curPixel); // close the output file, checking for error if (fclose(outFile) != 0) { fprintf(stderr, "Unable to close output file: %s.\n", outFileName); return EXIT_FAILURE; } // if program gets to here, everything is okay return EXIT_SUCCESS; }
int cropImage(FILE* inFile, struct bmpFileHeader* fileHead, struct bmpInfoHeader* infoHead, char* outFileName, int cropWidth, int cropHeight, int cropStart[]) { // check that cropping parameters make sense if (((cropWidth + cropStart[0]) > infoHead->width) || ((cropHeight + cropStart[1]) > infoHead->height)) { fprintf(stderr, "Cropping parameters incorrect.\n"); return EXIT_FAILURE; } // open file for writing FILE *outFile = fopen(outFileName, "w+"); // check that file opened okay if (outFile == NULL) { fprintf(stderr, "Unable to open file: %s for writing.\n", outFileName); return EXIT_FAILURE; } // store old width/height for use in loop LONG oldWidth = infoHead->width; LONG oldHeight = infoHead->height; // calculate padding used in old image int oldPadding = (4 - (oldWidth*sizeof(struct pixel) % 4)) % 4; // calculate padding to be used in new image int newPadding = (4 - (cropWidth*sizeof(struct pixel) % 4)) % 4; // new image size infoHead->imageSize = (cropWidth*sizeof(struct pixel) + newPadding)*cropHeight; // file size fileHead->fileSize = sizeof(struct bmpFileHeader) + sizeof(struct bmpInfoHeader) + infoHead->imageSize; // new dimensions infoHead->width = cropWidth; infoHead->height = cropHeight; // write the headers to the output file, checking for errors if (writeFileHeader(fileHead, outFile) != 0) { fprintf(stderr, "Unable to write file header.\n"); return EXIT_FAILURE; } if (writeInfoHeader(infoHead, outFile) != 0) { fprintf(stderr, "Unable to write info header.\n"); return EXIT_FAILURE; } // to store pixel being worked on struct pixel* curPixel = NULL; // run through old pixels, discarding those which are to be cropped // and writing the rest to file for (int i = 0; i < oldHeight; i++) { // only run through line if we're out of region to be cropped if (!(i < (oldHeight - cropStart[1] - cropHeight) || i > (oldHeight - cropStart[1]))) { for (int j = 0; j < oldWidth; j++) { // only write to file if not in cropped region if (!(j < cropStart[0] || j > cropStart[0] + cropWidth)) { // read in the current pixel curPixel = getPixel(inFile); // make sure read worked if (curPixel == NULL) { fprintf(stderr, "Unable to read pixel.\n"); return EXIT_FAILURE; } // write current pixel, checking for error if (writePixel(curPixel, outFile) != EXIT_SUCCESS) { fprintf(stderr, "Unable to write pixel.\n"); return EXIT_FAILURE; } } else { // move old file on by a pixel fseek(inFile, sizeof(struct pixel), SEEK_CUR); } } } else { // move old file on by width + padding fseek(inFile, oldWidth*sizeof(struct pixel) + oldPadding, SEEK_CUR); } // move old file on by padding fseek(inFile, oldPadding, SEEK_CUR); // add padding to new file for (int k = 0; k < newPadding; k++) { fputc(0x00, outFile); } } // free memory allocated to current pixel storage free(curPixel); // close the output file, checking for error if (fclose(outFile) != 0) { fprintf(stderr, "Unable to close output file: %s.\n", outFileName); return EXIT_FAILURE; } // if program gets to here, everything is okay return EXIT_SUCCESS; }
/** * adds information to cs-record structure and pushing into chained list */ void IpfixCsExporter::onDataRecord(IpfixDataRecord* record) { if ((record->templateInfo->setId != TemplateInfo::NetflowTemplate) && (record->templateInfo->setId != TemplateInfo::IpfixTemplate) && (record->templateInfo->setId != TemplateInfo::IpfixDataTemplate)) { record->removeReference(); return; } //create a new Ipfix_basic_flow and fill it with data Ipfix_basic_flow* csRecord = new Ipfix_basic_flow(); TemplateInfo::FieldInfo* fi; csRecord->record_length = htons(sizeof(Ipfix_basic_flow)-2); /* total length of this record in bytes minus this element*/ csRecord->src_export_mode = CS_E_PLAIN; csRecord->dst_export_mode = CS_E_PLAIN; csRecord->ipversion = 4; /* expected 4 (for now) */ int idx; idx = record->templateInfo->getFieldIndex(IPFIX_TYPEID_sourceIPv4Address, 0); if (idx >= 0) { fi = &record->templateInfo->fieldInfo[idx]; csRecord->source_ipv4_address = *(uint32_t*)(record->data + fi->offset); // set export mode if anonymisationType IE is directly after this field if (idx<record->templateInfo->fieldCount-1) { fi = &record->templateInfo->fieldInfo[idx+1]; if (fi->type==InformationElement::IeInfo(IPFIX_ETYPEID_anonymisationType, IPFIX_PEN_vermont) && *(uint8_t*)(record->data + fi->offset)==1) { csRecord->src_export_mode = exportMode; } } } else { msg(MSG_DEBUG, "failed to determine source ip for record, assuming 0.0.0.0"); csRecord->source_ipv4_address = 0; } idx = record->templateInfo->getFieldIndex(IPFIX_TYPEID_destinationIPv4Address, 0); if (idx >= 0) { fi = &record->templateInfo->fieldInfo[idx]; csRecord->destination_ipv4_address = *(uint32_t*)(record->data + fi->offset); // set export mode if anonymisationType IE is directly after this field if (idx<record->templateInfo->fieldCount-1) { fi = &record->templateInfo->fieldInfo[idx+1]; if (fi->type==InformationElement::IeInfo(IPFIX_ETYPEID_anonymisationType, IPFIX_PEN_vermont) && *(uint8_t*)(record->data + fi->offset)==1) { csRecord->dst_export_mode = exportMode; } } } else { msg(MSG_DEBUG, "failed to determine destination ip for record, assuming 0.0.0.0"); csRecord->destination_ipv4_address = 0; } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_protocolIdentifier, 0); if (fi != 0) { csRecord->protocol_identifier = *(uint8_t*)(record->data + fi->offset); } else { msg(MSG_DEBUG, "failed to determine protocol for record, using 0"); csRecord->protocol_identifier = 0; } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_sourceTransportPort, 0); if (fi != 0) { csRecord->source_transport_port = *(uint16_t*)(record->data + fi->offset);/* encode udp/tcp ports here */ } else { msg(MSG_DEBUG, "failed to determine source port for record, assuming 0"); csRecord->source_transport_port = 0; } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_destinationTransportPort, 0); if (fi != 0) { csRecord->destination_transport_port = *(uint16_t*)(record->data + fi->offset);/* encode udp/tcp ports here */ } else { msg(MSG_DEBUG, "failed to determine destination port for record, assuming 0"); csRecord->destination_transport_port = 0; } // IPFIX_TYPEID_icmpTypeCodeIPv4 (ICMP type * 256) + ICMP code (network-byte order!) fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_icmpTypeCodeIPv4, 0); if (fi != 0) { csRecord->icmp_type_ipv4 = *(uint8_t*)(record->data + fi->offset); csRecord->icmp_code_ipv4 = *(uint8_t*)(record->data + fi->offset + 1); } else { csRecord->icmp_type_ipv4 = 0; csRecord->icmp_code_ipv4 = 0; } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_tcpControlBits, 0); if (fi != 0) { csRecord->tcp_control_bits = *(uint8_t*)(record->data + fi->offset); } uint64_t timestart = retrieveTime(record, IPFIX_TYPEID_flowStartNanoseconds, IPFIX_TYPEID_flowStartMilliseconds, IPFIX_TYPEID_flowStartSeconds, 0); uint64_t revtimestart = retrieveTime(record, IPFIX_TYPEID_flowStartNanoseconds, IPFIX_TYPEID_flowStartMilliseconds, IPFIX_TYPEID_flowStartSeconds, IPFIX_PEN_reverse); if (revtimestart>0 && revtimestart<timestart) csRecord->flow_start_milliseconds = htonll(revtimestart); else csRecord->flow_start_milliseconds = htonll(timestart); uint64_t timeend = retrieveTime(record, IPFIX_TYPEID_flowEndNanoseconds, IPFIX_TYPEID_flowEndMilliseconds, IPFIX_TYPEID_flowEndSeconds, 0); uint64_t revtimeend = retrieveTime(record, IPFIX_TYPEID_flowEndNanoseconds, IPFIX_TYPEID_flowEndMilliseconds, IPFIX_TYPEID_flowEndSeconds, IPFIX_PEN_reverse); if (revtimeend>0 && revtimeend>timeend) csRecord->flow_end_milliseconds = htonll(revtimeend); else csRecord->flow_end_milliseconds = htonll(timeend); fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_octetDeltaCount, 0); if (fi != 0) { csRecord->octet_total_count = *(uint64_t*)(record->data + fi->offset); } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_packetDeltaCount, 0); if (fi != 0) { csRecord->packet_total_count = *(uint64_t*)(record->data + fi->offset); } csRecord->biflow_direction = 0; fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_octetDeltaCount, IPFIX_PEN_reverse); if (fi != 0) { csRecord->rev_octet_total_count = *(uint64_t*)(record->data + fi->offset); } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_packetDeltaCount, IPFIX_PEN_reverse); if (fi != 0) { csRecord->rev_packet_total_count = *(uint64_t*)(record->data + fi->offset); } fi = record->templateInfo->getFieldInfo(IPFIX_TYPEID_tcpControlBits, IPFIX_PEN_reverse); if (fi != 0) { csRecord->rev_tcp_control_bits = *(uint8_t*)(record->data + fi->offset); } //add data to linked list chunkList.push_back(csRecord); chunkListSize++; //check if maxChunkBufferRecords is reached if(chunkListSize == maxChunkBufferRecords) writeChunkList(); //check if maxFileSize is reached currentFileSize += sizeof(Ipfix_basic_flow); if(currentFileSize > maxFileSize*1024){ //close File, add new one writeChunkList(); writeFileHeader(); } record->removeReference(); }
status_t TiffWriter::write(Output* out, StripSource** sources, size_t sourcesCount, Endianness end) { status_t ret = OK; EndianOutput endOut(out, end); if (mIfd == NULL) { ALOGE("%s: Tiff header is empty.", __FUNCTION__); return BAD_VALUE; } uint32_t totalSize = getTotalSize(); KeyedVector<uint32_t, uint32_t> offsetVector; for (size_t i = 0; i < mNamedIfds.size(); ++i) { if (mNamedIfds[i]->uninitializedOffsets()) { uint32_t stripSize = mNamedIfds[i]->getStripSize(); if (mNamedIfds[i]->setStripOffset(totalSize) != OK) { ALOGE("%s: Could not set strip offsets.", __FUNCTION__); return BAD_VALUE; } totalSize += stripSize; WORD_ALIGN(totalSize); offsetVector.add(mNamedIfds.keyAt(i), totalSize); } } size_t offVecSize = offsetVector.size(); if (offVecSize != sourcesCount) { ALOGE("%s: Mismatch between number of IFDs with uninitialized strips (%zu) and" " sources (%zu).", __FUNCTION__, offVecSize, sourcesCount); return BAD_VALUE; } BAIL_ON_FAIL(writeFileHeader(endOut), ret); uint32_t offset = FILE_HEADER_SIZE; sp<TiffIfd> ifd = mIfd; while(ifd != NULL) { BAIL_ON_FAIL(ifd->writeData(offset, &endOut), ret); offset += ifd->getSize(); ifd = ifd->getNextIfd(); } if (LOG_NDEBUG == 0) { log(); } for (size_t i = 0; i < offVecSize; ++i) { uint32_t ifdKey = offsetVector.keyAt(i); uint32_t sizeToWrite = mNamedIfds[ifdKey]->getStripSize(); bool found = false; for (size_t j = 0; j < sourcesCount; ++j) { if (sources[j]->getIfd() == ifdKey) { if ((ret = sources[i]->writeToStream(endOut, sizeToWrite)) != OK) { ALOGE("%s: Could not write to stream, received %d.", __FUNCTION__, ret); return ret; } ZERO_TILL_WORD(&endOut, sizeToWrite, ret); found = true; break; } } if (!found) { ALOGE("%s: No stream for byte strips for IFD %u", __FUNCTION__, ifdKey); return BAD_VALUE; } assert(offsetVector[i] == endOut.getCurrentOffset()); } return ret; }