Exemplo n.º 1
0
	peer_request file_storage::map_file(int file_index, size_type file_offset
		, int size) const
	{
		TORRENT_ASSERT(file_index < num_files());
		TORRENT_ASSERT(file_index >= 0);

		peer_request ret;
		if (file_index < 0 || file_index >= num_files())
		{
			ret.piece = m_num_pieces;
			ret.start = 0;
			ret.length = 0;
			return ret;
		}

		size_type offset = file_offset + this->file_offset(file_index);

		if (offset >= total_size())
		{
			ret.piece = m_num_pieces;
			ret.start = 0;
			ret.length = 0;
		}
		else
		{
			ret.piece = int(offset / piece_length());
			ret.start = int(offset % piece_length());
			ret.length = size;
			if (offset + size > total_size())
				ret.length = total_size() - offset;
		}
		return ret;
	}
Exemplo n.º 2
0
   size_type total_size_with_header() const
   {
      return get_rounded_size
               ( size_type(sizeof(Header))
			   , size_type(::boost::alignment_of<block_header<size_type> >::value))
           + total_size();
   }
Exemplo n.º 3
0
static char		*parse_prompt_tokens(t_list *tokens)
{
	size_t		size;
	char		*str;
	size_t		i;
	size_t		len;
	t_token		*token;

	size = total_size(tokens);
	str = (char *)malloc(sizeof(char) * (size + 1));
	i = 0;
	while (tokens)
	{
		token = get_token(&tokens);
		len = ft_strlen(token->lexeme);
		if (token->type == CHARS)
			ft_strncpy(str + i, token->lexeme, len);
		else
		{
			add_color(token, str + i, len);
			i += COLOR_STR_SIZE;
		}
		i += len;
		tokens = tokens->next;
	}
	str[i] = '\0';
	return (str);
}
Exemplo n.º 4
0
void
persistent_write (url dir, string key, string val,
                  url file, unsigned int code)
{
  string v= local_prefix (dir) * key;
  if (is_directory (file)) {
    persistent_update_key (dir, key, file, code);
    persistent_write (dir, key, val,
                      persistent_file [v], persistent_hash [v]);
  }
  else {
    hashmap<string,string> map ("");
    if (is_regular (file))
      map= persistent_read_map (file);
    map (key)= val;
    if (code == 0 || (N (map) <= MAX_INNER && total_size (map) <= MAX_SIZE))
      persistent_write_map (file, map);
    else {
      remove (file);
      mkdir (file);
      iterator<string> it= iterate (map);
      while (it->busy ()) {
        string skey= it->next ();
        string sval= map [skey];
        string sv  = local_prefix (dir) * skey;
        unsigned int scode= persistent_hash [sv];
        persistent_write (dir, skey, sval, file, scode);
      }
    }
  }
}
Exemplo n.º 5
0
 inline float const* fend(array const& a) {
     if(a.dtype() != dtype_t::float_) {
         throw std::runtime_error(
           "fend is called but dtype is not float");
     }
     return fbegin(a) + total_size(a);
 }
Exemplo n.º 6
0
 std::size_t total_size_with_header() const
 {
    return get_rounded_size
             (  sizeof(Header)
             ,  detail::alignment_of<block_header>::value)
         + total_size();
 }
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
	TDB_DATA key;
	TDB_CONTEXT *tdb;

	if (argc != 2)
		barf("Usage: xs_tdb_dump <tdbfile>");

	tdb = tdb_open(talloc_strdup(NULL, argv[1]), 0, 0, O_RDONLY, 0);
	if (!tdb)
		barf_perror("Could not open %s", argv[1]);

	key = tdb_firstkey(tdb);
	while (key.dptr) {
		TDB_DATA data;
		struct record_hdr *hdr;

		data = tdb_fetch(tdb, key);
		hdr = (void *)data.dptr;
		if (data.dsize < sizeof(*hdr))
			fprintf(stderr, "%.*s: BAD truncated\n",
				(int)key.dsize, key.dptr);
		else if (data.dsize != total_size(hdr))
			fprintf(stderr, "%.*s: BAD length %i for %i/%i/%i (%i)\n",
				(int)key.dsize, key.dptr, (int)data.dsize,
				hdr->num_perms, hdr->datalen,
				hdr->childlen, total_size(hdr));
		else {
			unsigned int i;
			char *p;

			printf("%.*s: ", (int)key.dsize, key.dptr);
			for (i = 0; i < hdr->num_perms; i++)
				printf("%s%c%i",
				       i == 0 ? "" : ",",
				       perm_to_char(hdr->perms[i].perms),
				       hdr->perms[i].id);
			p = (void *)&hdr->perms[hdr->num_perms];
			printf(" %.*s\n", hdr->datalen, p);
			p += hdr->datalen;
			for (i = 0; i < hdr->childlen; i += strlen(p+i)+1)
				printf("\t-> %s\n", p+i);
		}
		key = tdb_nextkey(tdb, key);
	}
	return 0;
}
Exemplo n.º 8
0
STATIC int
complete_pars(negotiation_state_t *state, pdu_t *pdu)
{
	int len;
	uint8_t *bp;
#ifdef ISCSI_TEST_MODE
	test_pars_t *tp = pdu->connection->test_pars;
	neg_desc_t *nd = NULL;
#endif

	len = total_size(state->pars, state->num_pars);

#ifdef ISCSI_TEST_MODE
	if (tp != NULL) {
		while ((nd = TAILQ_FIRST(&pdu->connection->test_pars->negs)) != NULL &&
			   nd->entry.state < state->auth_state) {
			TAILQ_REMOVE(&tp->negs, nd, link);
			free(nd, M_TEMP);
		}
		if (nd != NULL && nd->entry.state == state->auth_state) {
			if (nd->entry.flags & ISCSITEST_NEGOPT_REPLACE)
				len = 0;
			len += nd->entry.size;
		} else
			nd = NULL;
	}
#endif

	DEB(10, ("complete_pars: n=%d, len=%d\n", state->num_pars, len));

	if ((bp = malloc(len, M_TEMP, M_WAITOK)) == NULL) {
		DEBOUT(("*** Out of memory in complete_pars\n"));
		return ISCSI_STATUS_NO_RESOURCES;
	}
	pdu->temp_data = bp;

#ifdef ISCSI_TEST_MODE
	if (nd == NULL || !(nd->entry.flags & ISCSITEST_NEGOPT_REPLACE))
		if ((bp = put_par_block(pdu->temp_data, len,
				state->pars, state->num_pars)) == NULL) {
			DEBOUT(("Bad parameter in complete_pars\n"));
			return ISCSI_STATUS_PARAMETER_INVALID;
		}
	if (nd != NULL) {
		memcpy(bp, nd->entry.value, nd->entry.size);
		TAILQ_REMOVE(&tp->negs, nd, link);
		free(nd, M_TEMP);
	}
#else
	if (put_par_block(pdu->temp_data, len, state->pars,
			state->num_pars) == 0) {
		DEBOUT(("Bad parameter in complete_pars\n"));
		return ISCSI_STATUS_PARAMETER_INVALID;
	}
#endif

	pdu->temp_data_len = len;
	return 0;
}
Exemplo n.º 9
0
/* -------------------------------------------------------------------- */
rc_t temp_registry_merge( temp_registry * self,
                          KDirectory * dir,
                          const char * output_filename,
                          size_t buf_size,
                          bool show_progress,
                          bool force,
                          compress_t compress )
{
    rc_t rc = 0;
    if ( self == NULL )
        rc = RC( rcVDB, rcNoTarg, rcConstructing, rcSelf, rcNull );
    else if ( output_filename == NULL )
        rc = RC( rcVDB, rcNoTarg, rcConstructing, rcParam, rcNull );
    else
    {
        struct bg_progress * progress = NULL;
        
        if ( show_progress )
        {
            rc = KOutMsg( "concat :" );
            if ( rc == 0 )
            {
                uint64_t total = total_size( dir, &self -> lists );
                rc = bg_progress_make( &progress, total, 0, 0 ); /* progress_thread.c */
            }
        }
        
        if ( rc == 0 )
        {
            uint32_t first;
            uint32_t count = count_valid_entries( &self -> lists, &first ); /* above */
            if ( count == 1 )
            {
                /* we have only ONE set of files... */
                VNamelist * l = VectorGet ( &self -> lists, first );
                VNamelistReorder ( l, false );
                rc = execute_concat( dir,
                    output_filename,
                    l,
                    buf_size,
                    progress,
                    force,
                    compress ); /* concatenator.c */
            }
            else if ( count > 1 )
            {
                /* we have MULTIPLE sets of files... */
                cmn_merge cmn = { dir, output_filename, buf_size, progress, force, compress };
                on_merge_ctx omc = { &cmn, 0 };
                VectorInit( &omc . threads, 0, count );
                VectorForEach ( &self -> lists, false, on_merge, &omc );
                join_and_release_threads( &omc . threads ); /* helper.c */
            }
            
            bg_progress_release( progress ); /* progress_thread.c ( ignores NULL )*/
        }
    }
    return rc;
}
/* Sets geometry to given size. */
void SquareItemWithSidePaneLayout::setGeometry(const QRect& rect) {
	/*
	 * We check if the item is set and
	 * if size is the same previously received.
	 * If either is false nothing is done.
	 */
	if(
		!this->hasBothItems() ||
		areRectsEqual(*this->lastReceivedRect, rect))
	{
		return;
	}
	/* Replace the last received rectangle. */
	setLastReceivedRect(rect);

	// calculate proper size
	const int sidepane_width = dynamic_cast<SidePane *>(sidepane_item->widget())->desiredWidth();
	//const int total_width = rect.width() - sidepane_width;
	
	// calculate all the sizes
	int height;
	QPoint pos;

	float aspect_ratio=1.5;

	if(rect.height()*aspect_ratio < rect.width() - sidepane_width)
	{
		height = rect.height() - this->margin();
		pos.setX(rect.width()/2 - (height*aspect_ratio + sidepane_width)/2);
	}
	else
	{
		height = (rect.width() - sidepane_width - this->margin())/aspect_ratio;
		pos.setY(rect.height()/2 - height/2);
	}
	QSize glwidget_size(height*aspect_ratio, height);
	QSize sidepane_size(sidepane_width, height);
	QSize total_size(height + sidepane_width, height);

	// calculate positions
	QPoint glwidget_pos(pos);
	QPoint sidepane_pos(pos + QPoint(height*aspect_ratio, 0));
	QPoint total_pos(glwidget_pos);

	// backup
	QRect* oldRect = this->_geometry;
	delete oldRect;

	// set geometries
	this->glwidget_item->setGeometry(QRect(glwidget_pos, glwidget_size));
	this->sidepane_item->setGeometry(QRect(sidepane_pos, sidepane_size));
	this->_geometry = new QRect(total_pos, total_size);
	QLayout::setGeometry(*this->_geometry);
}
Exemplo n.º 11
0
	int file_storage::piece_size(int index) const
	{
		TORRENT_ASSERT(index >= 0 && index < num_pieces());
		if (index == num_pieces()-1)
		{
			size_type size_except_last = num_pieces() - 1;
			size_except_last *= size_type(piece_length());
			size_type size = total_size() - size_except_last;
			TORRENT_ASSERT(size > 0);
			TORRENT_ASSERT(size <= piece_length());
			return int(size);
		}
		else
			return piece_length();
	}
void Data_analysis_gui::save_as_image( const QString& filename, 
                                       const QString& format,
                                       bool show_stats, bool show_grid ) {
  // get a file name and the name of the filter to use to save the image.
  // 3 filters are available: PNG, BMP, and Postscript. Postscript is not
  // available on Windows (Qt limitation).


  // Create a blank image of the correct dimensions
  int extra_width = 15;
  int min_height = 0;
  if( show_stats ) {
    extra_width = 200;
    min_height = 250;
  }
  QSize total_size( plot_->size().width() + extra_width, 
                    std::max( min_height, plot_->size().height()+10 ) );
  QPixmap pix( total_size );
  pix.fill();
  QPainter painter( &pix );
  

  // draw the content of the plot

  QwtPlotPrintFilter filter;
  if( show_grid )
    filter.setOptions( QwtPlotPrintFilter::PrintTitle | QwtPlotPrintFilter::PrintGrid );
  else
    filter.setOptions( QwtPlotPrintFilter::PrintTitle );

  QRect rect = plot_->rect();
  rect.setY( rect.y() + 10 );
  plot_->print( &painter, rect, filter );


  // Add the summary statistics to the image if requested

  if( show_stats ) {
    QFont font = plot_->axisFont( QwtPlot::xBottom );
    painter.setFont( font );
    int text_y_start = std::max( 40, total_size.height()/2 - 100 );
    painter.translate( plot_->size().width()+15 , text_y_start );
    paint_stats( painter );
  }


  // Finally, save the pixmap in the required format

  if( format == "Postscript" || format == "PS" ) {
    /*
#if defined(WIN32) || defined(_WIN32)
    if (show_stats)
		build_stats();
    SimplePs ps(filename,plot_, _stats,show_stats);
	if (!ps.isopen()){
		QMessageBox::warning(this,"Unable to save file",
		"Failed to save ps file",QMessageBox::Ok,
		Qt::NoButton);
		return;
	}
	savePostScript(ps);

#else
    */
    QPrinter printer;
    
    printer.setOutputFormat(QPrinter::PostScriptFormat);
    printer.setOutputFileName( filename );
    printer.setPageSize( QPrinter::A6 );
    printer.setFullPage( true );
    printer.setOrientation( QPrinter::Landscape );
    plot_->print(printer, filter);

    QPainter P(&printer);
    //P.begin(&printer);
    //paint_stats(P);
    P.drawPixmap(QPoint(0,0),pix);

    //#endif
  }
  else {
    QByteArray tmp = format.toLatin1();
    pix.save( filename, tmp.constData() );
  }

}
Exemplo n.º 13
0
static void
calculate_tiles(struct fd_batch *batch)
{
	struct fd_context *ctx = batch->ctx;
	struct fd_gmem_stateobj *gmem = &ctx->gmem;
	struct pipe_scissor_state *scissor = &batch->max_scissor;
	struct pipe_framebuffer_state *pfb = &batch->framebuffer;
	const uint32_t gmem_alignw = ctx->screen->gmem_alignw;
	const uint32_t gmem_alignh = ctx->screen->gmem_alignh;
	const uint32_t gmem_size = ctx->screen->gmemsize_bytes;
	uint32_t minx, miny, width, height;
	uint32_t nbins_x = 1, nbins_y = 1;
	uint32_t bin_w, bin_h;
	uint32_t max_width = bin_width(ctx->screen);
	uint8_t cbuf_cpp[MAX_RENDER_TARGETS] = {0}, zsbuf_cpp[2] = {0};
	uint32_t i, j, t, xoff, yoff;
	uint32_t tpp_x, tpp_y;
	bool has_zs = !!(batch->resolve & (FD_BUFFER_DEPTH | FD_BUFFER_STENCIL));
	int tile_n[ARRAY_SIZE(ctx->pipe)];

	if (has_zs) {
		struct fd_resource *rsc = fd_resource(pfb->zsbuf->texture);
		zsbuf_cpp[0] = rsc->cpp;
		if (rsc->stencil)
			zsbuf_cpp[1] = rsc->stencil->cpp;
	}
	for (i = 0; i < pfb->nr_cbufs; i++) {
		if (pfb->cbufs[i])
			cbuf_cpp[i] = util_format_get_blocksize(pfb->cbufs[i]->format);
		else
			cbuf_cpp[i] = 4;
	}

	if (!memcmp(gmem->zsbuf_cpp, zsbuf_cpp, sizeof(zsbuf_cpp)) &&
		!memcmp(gmem->cbuf_cpp, cbuf_cpp, sizeof(cbuf_cpp)) &&
		!memcmp(&gmem->scissor, scissor, sizeof(gmem->scissor))) {
		/* everything is up-to-date */
		return;
	}

	if (fd_mesa_debug & FD_DBG_NOSCIS) {
		minx = 0;
		miny = 0;
		width = pfb->width;
		height = pfb->height;
	} else {
		/* round down to multiple of alignment: */
		minx = scissor->minx & ~(gmem_alignw - 1);
		miny = scissor->miny & ~(gmem_alignh - 1);
		width = scissor->maxx - minx;
		height = scissor->maxy - miny;
	}

	bin_w = align(width, gmem_alignw);
	bin_h = align(height, gmem_alignh);

	/* first, find a bin width that satisfies the maximum width
	 * restrictions:
	 */
	while (bin_w > max_width) {
		nbins_x++;
		bin_w = align(width / nbins_x, gmem_alignw);
	}

	if (fd_mesa_debug & FD_DBG_MSGS) {
		debug_printf("binning input: cbuf cpp:");
		for (i = 0; i < pfb->nr_cbufs; i++)
			debug_printf(" %d", cbuf_cpp[i]);
		debug_printf(", zsbuf cpp: %d; %dx%d\n",
				zsbuf_cpp[0], width, height);
	}

	/* then find a bin width/height that satisfies the memory
	 * constraints:
	 */
	while (total_size(cbuf_cpp, zsbuf_cpp, bin_w, bin_h, gmem) > gmem_size) {
		if (bin_w > bin_h) {
			nbins_x++;
			bin_w = align(width / nbins_x, gmem_alignw);
		} else {
			nbins_y++;
			bin_h = align(height / nbins_y, gmem_alignh);
		}
	}

	DBG("using %d bins of size %dx%d", nbins_x*nbins_y, bin_w, bin_h);

	gmem->scissor = *scissor;
	memcpy(gmem->cbuf_cpp, cbuf_cpp, sizeof(cbuf_cpp));
	memcpy(gmem->zsbuf_cpp, zsbuf_cpp, sizeof(zsbuf_cpp));
	gmem->bin_h = bin_h;
	gmem->bin_w = bin_w;
	gmem->nbins_x = nbins_x;
	gmem->nbins_y = nbins_y;
	gmem->minx = minx;
	gmem->miny = miny;
	gmem->width = width;
	gmem->height = height;

	/*
	 * Assign tiles and pipes:
	 *
	 * At some point it might be worth playing with different
	 * strategies and seeing if that makes much impact on
	 * performance.
	 */

#define div_round_up(v, a)  (((v) + (a) - 1) / (a))
	/* figure out number of tiles per pipe: */
	tpp_x = tpp_y = 1;
	while (div_round_up(nbins_y, tpp_y) > 8)
		tpp_y += 2;
	while ((div_round_up(nbins_y, tpp_y) *
			div_round_up(nbins_x, tpp_x)) > 8)
		tpp_x += 1;

	/* configure pipes: */
	xoff = yoff = 0;
	for (i = 0; i < ARRAY_SIZE(ctx->pipe); i++) {
		struct fd_vsc_pipe *pipe = &ctx->pipe[i];

		if (xoff >= nbins_x) {
			xoff = 0;
			yoff += tpp_y;
		}

		if (yoff >= nbins_y) {
			break;
		}

		pipe->x = xoff;
		pipe->y = yoff;
		pipe->w = MIN2(tpp_x, nbins_x - xoff);
		pipe->h = MIN2(tpp_y, nbins_y - yoff);

		xoff += tpp_x;
	}

	for (; i < ARRAY_SIZE(ctx->pipe); i++) {
		struct fd_vsc_pipe *pipe = &ctx->pipe[i];
		pipe->x = pipe->y = pipe->w = pipe->h = 0;
	}

#if 0 /* debug */
	printf("%dx%d ... tpp=%dx%d\n", nbins_x, nbins_y, tpp_x, tpp_y);
	for (i = 0; i < 8; i++) {
		struct fd_vsc_pipe *pipe = &ctx->pipe[i];
		printf("pipe[%d]: %ux%u @ %u,%u\n", i,
				pipe->w, pipe->h, pipe->x, pipe->y);
	}
#endif

	/* configure tiles: */
	t = 0;
	yoff = miny;
	memset(tile_n, 0, sizeof(tile_n));
	for (i = 0; i < nbins_y; i++) {
		uint32_t bw, bh;

		xoff = minx;

		/* clip bin height: */
		bh = MIN2(bin_h, miny + height - yoff);

		for (j = 0; j < nbins_x; j++) {
			struct fd_tile *tile = &ctx->tile[t];
			uint32_t p;

			assert(t < ARRAY_SIZE(ctx->tile));

			/* pipe number: */
			p = ((i / tpp_y) * div_round_up(nbins_x, tpp_x)) + (j / tpp_x);

			/* clip bin width: */
			bw = MIN2(bin_w, minx + width - xoff);

			tile->n = tile_n[p]++;
			tile->p = p;
			tile->bin_w = bw;
			tile->bin_h = bh;
			tile->xoff = xoff;
			tile->yoff = yoff;

			t++;

			xoff += bw;
		}

		yoff += bh;
	}

#if 0 /* debug */
	t = 0;
	for (i = 0; i < nbins_y; i++) {
		for (j = 0; j < nbins_x; j++) {
			struct fd_tile *tile = &ctx->tile[t++];
			printf("|p:%u n:%u|", tile->p, tile->n);
		}
		printf("\n");
	}
#endif
}
Exemplo n.º 14
0
void message::seal(bool fillCrc, bool is_placeholder /*= false*/)
{
    dassert  (!is_read(), "seal can only be applied to write mode messages");
    if (is_placeholder)
    {
        std::string dummy;
        dummy.resize(_msg_header.serialized_size(), '\0');
        _writer->write((const char*)&dummy[0], _msg_header.serialized_size());
    }
    else
    {
        header().body_length = total_size() - message_header::serialized_size();

        if (fillCrc)
        {
            // compute data crc if necessary
            if (header().body_crc32 == 0)
            {
                std::vector<blob> buffers;
                _writer->get_buffers(buffers);

                buffers[0] = buffers[0].range(message_header::serialized_size());

                uint32_t crc32 = 0;
                uint32_t len = 0;
                for (auto it = buffers.begin(); it != buffers.end(); it++)
                {
                    uint32_t lcrc = crc32::compute(it->data(), it->length(), crc32);

                    /*uintxx_t uInitialCrcAB,
                    uintxx_t uInitialCrcA,
                    uintxx_t uFinalCrcA,
                    uint64_t uSizeA,
                    uintxx_t uInitialCrcB,
                    uintxx_t uFinalCrcB,
                    uint64_t uSizeB*/
                    crc32 = crc32::concatenate(
                        0, 
                        0, crc32, len, 
                        crc32, lcrc, it->length()
                        );

                    len += it->length();
                }

                dassert  (len == (uint32_t)header().body_length, "data length is wrong");
                header().body_crc32 = crc32;
            }

            blob bb = _writer->get_first_buffer();
            dassert  (bb.length() >= _msg_header.serialized_size(), "the reserved blob size for message must be greater than the header size to ensure header is contiguous");
            header().hdr_crc32 = 0;
            binary_writer writer(bb);
            _msg_header.marshall(writer);

            header().hdr_crc32 = crc32::compute(bb.data(), message_header::serialized_size(), 0);
            *(uint32_t*)bb.data() = header().hdr_crc32;
        }

        // crc is not enabled
        else
        {
            blob bb = _writer->get_first_buffer();
            dassert  (bb.length() >= _msg_header.serialized_size(), "the reserved blob size for message must be greater than the header size to ensure header is contiguous");
            binary_writer writer(bb);
            _msg_header.marshall(writer);
        }
    }
}
Exemplo n.º 15
0
 // Returns true when the packet is fully captured.
 bool is_complete() const { return captured_size() == total_size(); }