Exemplo n.º 1
0
bool MtpDevice::sendObject(MtpObjectInfo* info, int srcFD) {
    Mutex::Autolock autoLock(mMutex);

    int remaining = info->mCompressedSize;
    mRequest.reset();
    mRequest.setParameter(1, info->mHandle);
    if (sendRequest(MTP_OPERATION_SEND_OBJECT)) {
        // send data header
        writeDataHeader(MTP_OPERATION_SEND_OBJECT, remaining);

        char buffer[65536];
        while (remaining > 0) {
            int count = read(srcFD, buffer, sizeof(buffer));
            if (count > 0) {
                int written = mData.write(mRequestOut, buffer, count);
                // FIXME check error
                remaining -= count;
            } else {
                break;
            }
        }
    }
    MtpResponseCode ret = readResponse();
    return (remaining == 0 && ret == MTP_RESPONSE_OK);
}
Exemplo n.º 2
0
/*!  
 *  Writes collection file for parallel output. 
 *  Is called by rank 0 in VTK::Write()
 */
void VTKRectilinearGrid::writeCollection( ){

    std::fstream str ;

    FileHandler     fhp, fho ;

    fhp = fh ;
    fho = fh ;

    fhp.setParallel(false) ;
    fhp.setAppendix("pvtr") ;

    fho.setDirectory(".") ;

    str.open( fhp.getPath( ), std::ios::out ) ;

    //Writing XML header
    str << "<?xml version=\"1.0\"?>" << std::endl;

    //Writing Piece Information
    str << "<VTKFile type=\"PRectilinearGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << std::endl;
    str << "  <PRectilinearGrid WholeExtent= \"" 
        << global_index[0][0] << " " << global_index[0][1]<< " "
        << global_index[1][0] << " " << global_index[1][1]<< " "
        << global_index[2][0] << " " << global_index[2][1]<< " "
        << "GhostLevel=\"0\">" << std::endl;



    //Header for Data
    writeDataHeader( str, true );

    //Wring Geometry Information
    str << "      <PCoordinates>" << std::endl;
    writePDataArray( str, *geometry[0] ) ;
    writePDataArray( str, *geometry[1] ) ;
    writePDataArray( str, *geometry[2] ) ;
    str << "      </PCoordinates>" << std::endl;


    for( int i=0; i<nr_procs; i++){
        fho.setBlock(i) ;
        extension3D_t &index = proc_index[i] ;

        str << "    <Piece Extent= \" " 
            << index[0][0] << " " << index[0][1] << " "
            << index[1][0] << " " << index[1][1] << " "
            << index[2][0] << " " << index[2][1] << " "
            << "\" Source= \"" << fho.getPath() << "\"/>" << std::endl;
    };

    str << "  </PRectilinearGrid>"  << std::endl;
    str << "</VTKFile>" << std::endl;

    str.close() ;


    return ;
};
void writeTrace(const char* traceFileName)
{
    FILE *fp = fopen(traceFileName, "w");
    if (fp == NULL) {
        perror(traceFileName);
        exit(1);
    }
    writeKeys(fp);
    writeDataHeader(fp);
    writeDataRecords(fp);
    fclose(fp);
}
Exemplo n.º 4
0
/*!  
 *  Writes entire VTR but the data.
 */
void VTKRectilinearGrid::writeMetaData( ){

    std::fstream str;

    str.open( fh.getPath( ), std::ios::out ) ;

    //Writing XML header
    str << "<?xml version=\"1.0\"?>" << std::endl;

    //Writing Piece Information
    str << "<VTKFile type=\"RectilinearGrid\" version=\"0.1\" byte_order=\"LittleEndian\"  header_type=\"" << HeaderType << "\">" << std::endl; 
    str << "  <RectilinearGrid WholeExtent= \"" 
        << global_index[0][0] << " " << global_index[0][1]<< " "
        << global_index[1][0] << " " << global_index[1][1]<< " "
        << global_index[2][0] << " " << global_index[2][1]<< " "
        << "\" >" << std::endl;

    str << "    <Piece Extent= \" " 
        << local_index[0][0] << " " << local_index[0][1]<< " "
        << local_index[1][0] << " " << local_index[1][1]<< " "
        << local_index[2][0] << " " << local_index[2][1]<< " "
        << "\" >" << std::endl;



    //Header for Data
    writeDataHeader( str, false ) ;

    //Wring Geometry Information   
    str << "       <Coordinates>" << std::endl;
    writeDataArray( str, *geometry[0] ) ;
    writeDataArray( str, *geometry[1] ) ;
    writeDataArray( str, *geometry[2] ) ;
    str << "       </Coordinates>" << std::endl;

    //Closing Piece
    str << "    </Piece>" << std::endl;
    str << "  </RectilinearGrid>" << std::endl;

    //Write Appended Section
    str << "  <AppendedData encoding=\"raw\">" << std::endl;
    str << "_" ;
    str << std::endl ;

    //Closing XML
    str << "</VTKFile>" << std::endl;

    str.close() ;

    return ;
};
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
/*!  
 *  Writes collection file for parallel output. 
 *  Is called by rank 0 in VTK::Write()
 */
void VTKUnstructuredGrid::writeCollection( ){

  std::fstream str ;

  FileHandler     fhp, fho ;

  fhp = fh ;
  fho = fh ;

  fhp.setParallel(false) ;
  fhp.setAppendix("pvtu") ;

  fho.setDirectory(".") ;

  str.open( fhp.getName( ), std::ios::out ) ;

  //Writing XML header
  str << "<?xml version=\"1.0\"?>" << std::endl;

  //Writing Piece Information
  str << "<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << std::endl;
  str << "  <PUnstructuredGrid GhostLevel=\"0\">"  << std::endl;;

  //Header for Data
  writeDataHeader( str, true );

  //Wring Geometry Information
  str << "      <PPoints>" << std::endl;
  writePDataArray( str, geometry[0] ) ;
  str << std::endl ;
  str << "      </PPoints>" << std::endl;


  for( int i=0; i<nr_procs; i++){
    fho.setBlock(i) ;
    str << "    <Piece  Source=\"" << fho.getName() <<  "\"/>" << std::endl;
  };

  str << "  </PUnstructuredGrid>"  << std::endl;
  str << "</VTKFile>" << std::endl;

  str.close() ;


  return ;
};
Exemplo n.º 7
0
/*!  
 *  Writes entire VTU but the data.
 */
void VTKUnstructuredGrid::writeMetaData( ){

    std::fstream str ;
    std::string line ; 
    
    str.open( fh.getName( ), std::ios::out ) ;
    
    //Writing XML header
    str << "<?xml version=\"1.0\"?>" << std::endl;
    
    //Writing Piece Information
    str << "<VTKFile type=\"UnstructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"" << HeaderType << "\">" << std::endl;
    str << "  <UnstructuredGrid>"  << std::endl;;
    str << "    <Piece  NumberOfPoints=\"" << nr_points << "\" NumberOfCells=\"" << nr_cells << "\">" << std::endl;
    
    //Header for Data
    writeDataHeader( str, false );
    
    //Wring Geometry Information
    str << "      <Points>" << std::endl ;;
    writeDataArray( str, geometry[0] ) ;
    str << "      </Points>" << std::endl;
    
    str << "      <Cells>" << std::endl ;;
    writeDataArray( str, geometry[1] ) ;
    writeDataArray( str, geometry[2] ) ;
    writeDataArray( str, geometry[3] ) ;
    str << "      </Cells>" << std::endl;
    
    //Closing Piece
    str << "    </Piece>" << std::endl;
    str << "  </UnstructuredGrid>"  << std::endl;
    
    //Appended Section
    
    str << "  <AppendedData encoding=\"raw\">" << std::endl;
    str << "_" ;
    str << std::endl ;
    str << "</VTKFile>" << std::endl;
    
    str.close() ;
    
    return ;
};