Ejemplo n.º 1
0
void ruby_write_node_bool_to_float(node_t*n, state_t*s)
{
    strf(s, "(");
    write_node(s, n->child[0]);
    strf(s, " ? 1.0 : 0.0");
    strf(s, ")");
}
Ejemplo n.º 2
0
void c_write_node_sqr(node_t*n, state_t*s)
{
    strf(s, "sqr");
    if(n->child[0]->type!=&node_brackets) strf(s, "(");
    write_node(s, n->child[0]);
    if(n->child[0]->type!=&node_brackets) strf(s, ")");
}
Ejemplo n.º 3
0
static void
write_pred(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* pred)
{
	write_node(writer, pred, NULL, NULL, FIELD_PREDICATE, flags);
	write_sep(writer, SEP_P_O);
	copy_node(&writer->context.predicate, pred);
}
Ejemplo n.º 4
0
void FileAllocator::remove_node(FileOffset head_offset, list_node *head,
                                FileOffset node_offset, const list_node *node)
{
    list_node tmp;
    FileOffset tmp_offset;

    if (head->next == node_offset)
    {   // first node; make head skip it
        head->bytes -= node->bytes;
        head->next = node->next;
        if (head->next == 0) // list now empty?
            head->prev = 0;
        else
        {   // correct 'prev' ptr of what's now the first node
            read_node(head->next, &tmp);
            tmp.prev = 0;
            write_node(head->next, &tmp);
        }
        write_node(head_offset, head);
    }
    else
    {   // locate a node that's not the first
        tmp_offset = head->next;
        read_node(tmp_offset, &tmp);
        while (tmp.next != node_offset)
        {
            tmp_offset = tmp.next;
            if (!tmp_offset)
                throw GenericException(__FILE__, __LINE__,
                                       "node not found");
            read_node(tmp_offset, &tmp);
        }
        // tmp/tmp_offset == node before the one to be removed
        tmp.next = node->next;
        write_node(tmp_offset, &tmp);
        if (node->next)
        {   // adjust prev pointer of node->next
            read_node(node->next, &tmp);
            tmp.prev = tmp_offset;
            write_node(node->next, &tmp);
        }
        head->bytes -= node->bytes;
        if (head->prev == node_offset)
            head->prev = node->prev;
        write_node(head_offset, head);
    }
}
Ejemplo n.º 5
0
void ruby_write_node_sub(node_t*n, state_t*s)
{
    int t;
    for(t=0;t<n->num_children;t++) {
        if(t && !node_has_minus_prefix(n->child[t])) strf(s, "-");
        write_node(s, n->child[t]);
    }
}
Ejemplo n.º 6
0
bool FileAllocator::attach(FILE *f, FileOffset reserved_space, bool init)
{
#ifdef DEBUG_FA
    printf("FileAllocator::attach()\n");
#endif
    LOG_ASSERT(f != 0);
    this->f = f;
    this->reserved_space = reserved_space;
    if (fseek(this->f, 0, SEEK_END))
        throw GenericException(__FILE__, __LINE__, "fseek error");
    file_size = ftell(this->f);
    if (file_size < 0)
        throw GenericException(__FILE__, __LINE__, "ftell error");
    // File size should be
    // 0 for new file or at least reserved_space + list headers
    if (file_size == 0)
    {
        if (init == false)
            throw GenericException(__FILE__, __LINE__,
                                   "FileAllocator in read-only mode found empty file");
        // create empty list headers
        memset(&allocated_head, 0, list_node_size);
        memset(&free_head, 0, list_node_size);
        write_node(this->reserved_space, &allocated_head);
        write_node(this->reserved_space+list_node_size, &free_head);
        file_size = ftell(this->f);
        FileOffset expected = reserved_space + 2*list_node_size;
        if (file_size != expected)
             throw GenericException(__FILE__, __LINE__,
                                    "Initialization error: "
                                    "Expected file size %ld, found %ld",
                                    (long) expected, (long) file_size);
        return true; 
    }
    FileOffset expected = this->reserved_space + 2*list_node_size;
    if (file_size < expected)
        throw GenericException(__FILE__, __LINE__,
                               "FileAllocator: Broken file header,"
                               "expected at least %ld bytes",
                               (long) expected);
    // read existing list headers
    read_node(this->reserved_space, &allocated_head);
    read_node(this->reserved_space+list_node_size, &free_head);
    return false; // Didn't initialize the file
}
Ejemplo n.º 7
0
static void
write_nodes(FILE *fp, const NSegment *tree)
{
   if (tree == NULL) return;

   write_node(fp, tree);
   write_nodes(fp, tree->left);
   write_nodes(fp, tree->right);
}
Ejemplo n.º 8
0
void ruby_write_node_block(node_t*n, state_t*s)
{
    int t;
    for(t=0;t<n->num_children;t++) {
        if(t)
            strf(s, "\n");
        write_node(s, n->child[t]);
    }
}
Ejemplo n.º 9
0
static void ruby_write_node_arg_min_or_max(node_t*n, state_t*s, char*min_or_max)
{
    strf(s, "([");
    int t;
    for(t=0;t<n->num_children;t++) {
        if(t) strf(s, ",");
        write_node(s, n->child[t]);
    }
    strf(s, "].each_with_index.map.%s)[1]", min_or_max);
}
Ejemplo n.º 10
0
int ps3_repository_write_highmem_size(unsigned int region_index,
	u64 highmem_size)
{
	return write_node(
		make_first_field("highmem", 0),
		make_field("region", region_index),
		make_field("size", 0),
		0,
		highmem_size, 0);
}
Ejemplo n.º 11
0
bool MemoryDump::draw_tree(Node &node, std::ofstream &ofile, const cmd_opt &opt, std::set<uintptr_t> &declared_nodes, int level)
{
    if (node.visited >= 0 && node.visited <= level) return true;
    if (opt.critical_only && !node.critical) return true;
    if (opt.depth > 0 && level >= opt.depth) return true;
    node.visited = level;

    std::vector<ChildNode*> edges;
    for (auto &&c : node.children) {
        if (c.node->subtree_size >= min_size
            && (!opt.critical_only || c.node->critical)) {
            edges.push_back(&c);
        }
    }
    
    std::sort(edges.begin(), edges.end(),
        [](const ChildNode *a, const ChildNode *b) {
        return a->node->subtree_size > b->node->subtree_size;
    }
    );

    if (opt.max_subnodes > 0 && edges.size() > opt.max_subnodes) { //too many nodes, only write nodes with big sizes;
        edges.resize(opt.max_subnodes);
    }

    bool tail_written = false;
    for (const auto & c : edges) {
        if (!tail_written && declared_nodes.find(node.label) == declared_nodes.end()) {
            write_node(node, ofile, opt);
            declared_nodes.insert(node.label);
            tail_written = true;
        }
        if (declared_nodes.find(c->node->label) == declared_nodes.end()) {
            write_node(*c->node, ofile, opt);
            declared_nodes.insert(c->node->label);
        }
        exporter->write_edge(node, *c->node, ofile, c->edge.str());
        draw_tree(*c->node, ofile, opt, declared_nodes, level + 1);
    }

    return true;
}
Ejemplo n.º 12
0
/*
 *  Tree walking with acending key order
 */
void walk_tree(int fd_in, int fd_out, compact_header_t * tree)
{
    if (tree->left != NULL) {
        walk_tree(fd_in, fd_out, tree->left);
    }
    write_node(fd_in, fd_out, tree, io_buf, IO_BUFFER_SZ);

    if (tree->right != NULL) {
        walk_tree(fd_in, fd_out, tree->right);
    }
    free(tree);
}
Ejemplo n.º 13
0
intset_t*
set_new() 
{
  intset_t *set;
  node_t *min, *max;

  if ((set = (intset_t *) malloc(sizeof (intset_t))) == NULL) 
    {
      perror("malloc");
      EXIT(1);
    }

  node_t** nodes = (node_t**) pgas_app_alloc_rr(2, sizeof(node_t));
  min = nodes[0];
  max = nodes[1];
  write_node(max, VAL_MAX, 0, 0);
  write_node(min, VAL_MIN, OF(max), 0);

  set->head = min;
  return set;
}
Ejemplo n.º 14
0
void c_write_node_arg_min_i(node_t*n, state_t*s)
{
    strf(s, "arg_min_i(%d, ", n->num_children);
    int t;
    for(t=0;t<n->num_children;t++) {
        if(t)
            strf(s, ", ");
        strf(s, "(int)");
        write_node(s, n->child[t]);
    }
    strf(s, ")");
}
Ejemplo n.º 15
0
int ps3_repository_write_highmem_region_count(unsigned int region_count)
{
	int result;
	u64 v1 = (u64)region_count;

	result = write_node(
		make_first_field("highmem", 0),
		make_field("region", 0),
		make_field("count", 0),
		0,
		v1, 0);
	return result;
}
Ejemplo n.º 16
0
/** When this method is called, the writer must handle all nodes contained in the 
	library nodes.
	@return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes ) 
{
	if(mImportStage!=General)
		return true;
		
	Scene *sce = CTX_data_scene(mContext);

	const COLLADAFW::NodePointerArray& nodes = libraryNodes->getNodes();

	for (unsigned int i = 0; i < nodes.getCount(); i++) {
		write_node(nodes[i], NULL, sce, NULL, true);
	}

	return true;
}
Ejemplo n.º 17
0
/*==========================================
 * write_nodes -- Write NODEs to GEDCOM file
 *========================================*/
void
write_nodes (INT levl,       /* level */
             FILE *fp,       /* file */
             XLAT ttm,   /* char map */
             NODE node,      /* root */
             BOOLEAN indent, /* indent? */
             BOOLEAN kids,   /* output kids? */
             BOOLEAN sibs)   /* output sibs? */
{
	if (!node) return;
	write_node(levl, fp, ttm, node, indent);
	if (kids)
		write_nodes(levl+1, fp, ttm, nchild(node), indent, TRUE, TRUE);
	if (sibs)
		write_nodes(levl, fp, ttm, nsibling(node), indent, kids, TRUE);
}
Ejemplo n.º 18
0
static void
dump_nodes (CTaskList  * self,
	    FILE       * file,
	    GtkTreeIter* iter)
{
	GtkTreeIter  iter2;
	gboolean     result;

	for (result = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (self), &iter2, iter, 0);
	     result;
	     result = gtk_tree_model_iter_next (GTK_TREE_MODEL (self), &iter2))
	{
		write_node (GTK_TREE_MODEL (self),
			    &iter2,
			    file);
	}
}
Ejemplo n.º 19
0
void c_write_node_block(node_t*n, state_t*s)
{
    int t;
    if(n->parent) {
        strf(s, "{\n");
        indent(s);
    }
    for(t=0;t<n->num_children;t++) {
        if(t)
            strf(s, "\n");
        write_node(s, n->child[t]);
        strf(s, ";");
    }
    if(n->parent) {
        dedent(s);
        strf(s, "\n}\n");
    }
}
Ejemplo n.º 20
0
static bool
write_list_obj(SerdWriter*        writer,
               SerdStatementFlags flags,
               const SerdNode*    predicate,
               const SerdNode*    object,
               const SerdNode*    datatype,
               const SerdNode*    lang)
{
	if (!strcmp((const char*)object->buf, NS_RDF "nil")) {
		--writer->indent;
		write_sep(writer, SEP_LIST_END);
		return true;
	} else if (!strcmp((const char*)predicate->buf, NS_RDF "first")) {
		write_sep(writer, SEP_LIST_SEP);
		write_node(writer, object, datatype, lang, FIELD_OBJECT, flags);
	}
	return false;
}
Ejemplo n.º 21
0
static int write_nodes(Agraph_t * g, GVJ_t * job, int top, int has_subgs, state_t* sp)
{
    Agnode_t* n;
    int not_first = 0;

    n = agfstnode(g);
    if (!n) {
	if (has_subgs && top) {
	    sp->Level--;
	    gvputs(job, "\n");
	    indent(job, sp->Level);
	    gvputs(job, "]");
	}
	return 0;
    }
    gvputs(job, ",\n");
    if (top) {
	if (!has_subgs) {
            indent(job, sp->Level++);
            gvputs(job, "\"objects\": [\n");
        }
    }
    else {
        indent(job, sp->Level++);
	gvputs(job, "\"nodes\": [\n");
	indent(job, sp->Level);
    }
    for (; n; n = agnxtnode(g, n)) {
	if (IS_CLUSTER(n)) continue;
	if (not_first) 
            if (top)
	        gvputs(job, ",\n");
            else
	        gvputs(job, ",");
	else
	    not_first = 1;
	write_node (n, job, top, sp);
    }
    sp->Level--;
    gvputs(job, "\n");
    indent(job, sp->Level);
    gvputs(job, "]");
    return 1;
}
Ejemplo n.º 22
0
void c_write_node_if(node_t*n, state_t*s)
{
    if(!node_terminates(n) && node_has_consumer_parent(n)) {
        strf(s, "(");
        write_node(s, n->child[0]);
        strf(s, ")?(");
        write_node(s, n->child[1]);
        strf(s, "):(");
        write_node(s, n->child[2]);
        strf(s, ")");
    } else {
        strf(s, "if(");
        write_node(s, n->child[0]);
        strf(s, ")\n");
        indent(s);write_node(s, n->child[1]);
        if(!node_is_missing(n->child[2])) {
            strf(s, ";");dedent(s);
            strf(s, "\nelse\n");
            indent(s);write_node(s, n->child[2]);
        }
        dedent(s);
    }
}
Ejemplo n.º 23
0
void ruby_write_node_if(node_t*n, state_t*s)
{
    if(!node_terminates(n) && node_has_consumer_parent(n)) {
        strf(s, "if ");
        write_node(s, n->child[0]);
        strf(s, " then ");
        indent(s);write_node(s, n->child[1]);dedent(s);
        if(!node_is_missing(n->child[2])) {
            strf(s, " else ");
            indent(s);write_node(s, n->child[2]);dedent(s);
        }
        strf(s, " end");
    } else {
        strf(s, "if ");
        write_node(s, n->child[0]);
        strf(s, " then\n");
        indent(s);write_node(s, n->child[1]);dedent(s);
        if(!node_is_missing(n->child[2])) {
            strf(s, "\nelse\n");
            indent(s);write_node(s, n->child[2]);dedent(s);
        }
        strf(s, "\nend");
    }
}
Ejemplo n.º 24
0
/**
 * ubifs_jrn_write_data - write a data node to the journal.
 * @c: UBIFS file-system description object
 * @inode: inode the data node belongs to
 * @key: node key
 * @buf: buffer to write
 * @len: data length (must not exceed %UBIFS_BLOCK_SIZE)
 *
 * This function writes a data node to the journal. Returns %0 if the data node
 * was successfully written, and a negative error code in case of failure.
 */
int ubifs_jrn_write_data(struct ubifs_info *c, const struct inode *inode,
			 const union ubifs_key *key, const void *buf, int len)
{
	int err, lnum, offs, compr_type, out_len;
	int dlen = UBIFS_DATA_NODE_SZ + UBIFS_BLOCK_SIZE * WORST_COMPR_FACTOR;
	const struct ubifs_inode *ui = ubifs_inode(inode);
	struct ubifs_data_node *data;

	dbg_jrn_key(c, key, "ino %lu, blk %u, len %d, key ",
		    key_ino(c, key), key_block(c, key), len);
	ubifs_assert(len <= UBIFS_BLOCK_SIZE);

	data = kmalloc(dlen, GFP_NOFS);
	if (!data)
		return -ENOMEM;

	data->ch.node_type = UBIFS_DATA_NODE;
	key_write(c, key, &data->key);
	data->size = cpu_to_le32(len);
	zero_data_node_unused(data);

	if (!(ui->flags && UBIFS_COMPR_FL))
		/* Compression is disabled for this inode */
		compr_type = UBIFS_COMPR_NONE;
	else
		compr_type = ui->compr_type;

	out_len = dlen - UBIFS_DATA_NODE_SZ;
	ubifs_compress(buf, len, &data->data, &out_len, &compr_type);
	ubifs_assert(out_len <= UBIFS_BLOCK_SIZE);

	dlen = UBIFS_DATA_NODE_SZ + out_len;
	data->compr_type = cpu_to_le16(compr_type);

	err = make_reservation(c, DATAHD, dlen);
	if (err)
		goto out_free;

	err = write_node(c, DATAHD, data, dlen, &lnum, &offs);
	if (!err)
		ubifs_wbuf_add_ino_nolock(&c->jheads[DATAHD].wbuf,
					  key_ino(c, key));
	release_head(c, DATAHD);
	if (err)
		goto out_ro;

	err = ubifs_tnc_add(c, key, lnum, offs, dlen);
	if (err)
		goto out_ro;

	finish_reservation(c);
	kfree(data);
	return 0;

out_ro:
	ubifs_ro_mode(c, err);
	finish_reservation(c);
out_free:
	kfree(data);
	return err;
}
Ejemplo n.º 25
0
void
mexFunction(int nlhs, mxArray *plhs[],
            int nrhs, const mxArray *prhs[])
{
   FILE *fob;
   mxArray *internal;
   element_t *pe;
   double *pd;
   int compound;
   double uu_to_dbu;

   /* check argument number */
   if (nrhs != 4) {
      mexErrMsgTxt("gds_write_element :  4 input arguments expected.");
   }
   
   /* get file handle argument */
   fob = get_file_ptr((mxArray *)prhs[0]);

   /* get unit conversion factor user units --> database units */
   pd = (double *)mxGetData(prhs[2]);
   uu_to_dbu = pd[0];

   /* decide what to do */
   if ( !get_field_ptr((mxArray *)prhs[1], "internal", &internal) )
      mexErrMsgTxt("gds_write_element :  missing internal data field.");
   pe = (element_t *)mxGetData(internal);

   switch (pe->kind) {
     
      case GDS_BOUNDARY:
	 pd = (double *)mxGetData(prhs[3]); /* compound */
	 compound = (int)pd[0];
	 if ( compound )
	    write_compound_boundary(fob, (mxArray *)prhs[1], uu_to_dbu);
	 else
	    write_boundary(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      case GDS_PATH:
	 pd = (double *)mxGetData(prhs[3]); /* compound */
	 compound = (int)pd[0];
	 if ( compound )
	    write_compound_path(fob, (mxArray *)prhs[1], uu_to_dbu);
	 else
	    write_path(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      case GDS_SREF:
	 pd = (double *)mxGetData(prhs[3]); /* compound */
	 compound = (int)pd[0];
	 if ( compound )
	    write_compound_sref(fob, (mxArray *)prhs[1], uu_to_dbu);
	 else
	    write_sref(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      case GDS_AREF:
	 write_aref(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      case GDS_TEXT:
	 write_text(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      case GDS_NODE:
	 write_node(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      case GDS_BOX:
	 write_box(fob, (mxArray *)prhs[1], uu_to_dbu);
	 break;

      default:
	 mexErrMsgTxt("gds_write_element :  unknown element type.");
   }
}
Ejemplo n.º 26
0
struct stdfss_res *mkdevice(int wpid, struct working_thread *thread, struct stdfss_mkdevice *mkdevice_cmd)
{
	struct stdfss_res *ret = NULL;
	struct smount_info *minf = NULL;
	struct sdevice_info *opening_dinf = NULL;
	char *str = NULL, *strmatched = NULL;
	int parse_ret, dir_exists;
	struct gc_node *dir_base_node = NULL, *device_base_node = NULL;
	unsigned int *block = NULL;
	unsigned int nodeid;
	
	// get device file name from smo
	str = get_string(mkdevice_cmd->path_smo);
	
	ret = check_path(str, thread->command.command);
	if(ret != NULL) return ret;

	char *devstr = get_string(mkdevice_cmd->service_name);

	ret = check_path(devstr, thread->command.command);
	if(ret != NULL)
	{
		free(str);
		return ret;
	}

	// check path is ok
	if(str[len(str)] == '/')
	{
		free(str);
		free(devstr);
		return build_response_msg(thread->command.command, STDFSSERR_INVALID_COMMAND_PARAMS);
	}

	// get mount info
	wait_mutex(&mounted_mutex);
	minf = (struct smount_info *)lpt_getvalue_parcial_matchE(mounted, str, &strmatched);
	leave_mutex(&mounted_mutex);

	if(minf == NULL)
	{
		free(str);
		free(devstr);
		return build_response_msg(mkdevice_cmd->command, STDFSSERR_DEVICE_NOT_MOUNTED);
	}

	// check file does not exist
	parse_ret = parse_directory(TRUE, &dir_base_node, OFS_NODELOCK_EXCLUSIVE | OFS_NODELOCK_BLOCKING, thread->command.command, thread, wpid, minf, str, len(strmatched), NULL, &nodeid, NULL, &dir_exists, &ret);

	if(ret != NULL) free(ret);
	ret = NULL;

	if(parse_ret)
	{
		// file exists
		if(thread->lastdir_parsed_node != NULL)
		{
			nfree(minf->dinf, thread->lastdir_parsed_node);
			thread->lastdir_parsed_node = NULL;
		}
		free(strmatched);
		free(str);
		free(devstr);
		unlock_node(wpid, FALSE, OFS_LOCKSTATUS_OK);
		nfree(minf->dinf, dir_base_node);
		return build_response_msg(thread->command.command, STDFSSERR_FILE_EXISTS);
	}

	if(!dir_exists)
	{
		// worng path
		if(thread->lastdir_parsed_node != NULL)
		{
			nfree(minf->dinf, thread->lastdir_parsed_node);
			thread->lastdir_parsed_node = NULL;
		}
		free(strmatched);
		free(str);
		free(devstr);
		return build_response_msg(thread->command.command, STDFSSERR_FILE_DOESNOTEXIST);
	}

	dir_base_node = nref(minf->dinf, thread->lastdir_parsed_node->nodeid);
	
	free(strmatched);

	// Create device file
	if(!create_file(dir_base_node, str, last_index_of(str, '/') + 1, OFS_DEVICE_FILE, TRUE, minf, wpid, thread->command.command, &nodeid, &device_base_node, OFS_NOFLAGS , &ret))
	{
		nfree(minf->dinf, thread->lastdir_parsed_node);
		nfree(minf->dinf, dir_base_node);
		thread->lastdir_parsed_node = NULL;
		
		free(str);
		free(devstr);
		return ret;
	}
	
	nfree(minf->dinf, thread->lastdir_parsed_node);
	nfree(minf->dinf, dir_base_node);
	thread->lastdir_parsed_node = NULL;
	
	// get a free block 
	block = get_free_blocks(1, TRUE, minf, thread->command.command, wpid, &ret);
	if(ret != NULL)
	{
		free(str);
		free(devstr);
		unlock_node(wpid, FALSE, OFS_LOCKSTATUS_OK);
		nfree(minf->dinf, device_base_node);
		return ret;
	}

	free(str);

	clear_dir_buffer(thread->directory_buffer.buffer);

	// write buffer
	/*
		int LOGIC DEVICE ID: internal ID on the service (4 BYTES)
		int service name size; (4 BYTES)
		char SERVICE NAME[]: name of the device driver (zero terminated devstring) 
	*/
	*((unsigned int *)thread->directory_buffer.buffer) = (unsigned int)mkdevice_cmd->logic_deviceid;
	*((unsigned int *)(thread->directory_buffer.buffer + 4)) = len(devstr);
	mem_copy((unsigned char *)devstr, ((unsigned char *)thread->directory_buffer.buffer + 8), len(devstr) + 1);

	free(devstr);

	write_buffer((char *)thread->directory_buffer.buffer, OFS_DIR_BUFFERSIZE, *block, thread->command.command, wpid, minf, &ret);
	if(ret != NULL)
	{
		free_block(TRUE, TRUE, *block, minf, thread->command.command, wpid, &ret);
		free(block);
		unlock_node(wpid, FALSE, OFS_LOCKSTATUS_OK);
		nfree(minf->dinf, device_base_node);
		return ret;
	}

	// update node
	device_base_node->n.file_size = 8 + len(devstr) + 1;
	device_base_node->n.blocks[0] = *block;

	if(!write_node(device_base_node, minf, wpid, thread->command.command, &ret) || ret != NULL)
	{
		free_block(TRUE, TRUE, *block, minf, thread->command.command, wpid, &ret);
		free(block);
		unlock_node(wpid, FALSE, OFS_LOCKSTATUS_OK);
		nfree(minf->dinf, device_base_node);
		return ret;
	}

	nfree(minf->dinf, device_base_node);

	// unlock device node
	unlock_node(wpid, FALSE, OFS_LOCKSTATUS_OK);	

	return build_response_msg(thread->command.command, STDFSSERR_OK);
}
int main(int argc, char **argv)
{
    // time the program
    struct timeval sysTimeStart, sysTimeEnd;
    gettimeofday(&sysTimeStart, NULL);
    
    mkdir("bplus", 0777);
    
    int i;
    // open file count information
    file_count_t *fc = read_file_count();
    
    // keep track of roots
    bplus_roots_t bpr;
    
    // users
    {
        printf("\n");
        printf("Making user B+ tree with %d users\n", fc->users);
        
        // time this section
        struct timeval startSysTimeSub, endSysTimeSub;
        gettimeofday(&startSysTimeSub, NULL);
        
        // create root
        int_node_t root;
        root.next = -1;
        root.previous = -1;
        root.tableType = TABLE_TYPE_USER;
        root.nodeType = NODE_TYPE_LEAF;
        root.count = 0;
        root.firstFile = -1;
        write_node(0, &root);
        
        int rootFileNum = 0;
        
        for (i = 0; i < fc->users; i++)
        {
            user_t *user = read_user(i);
            rootFileNum = insert_node(rootFileNum, TABLE_TYPE_USER, user->stateId, i);
            free_user(user);
        }
        
        bpr.user = rootFileNum;
        
        // end timing this section
        gettimeofday(&endSysTimeSub, NULL);
        float totalTime = (endSysTimeSub.tv_sec - startSysTimeSub.tv_sec)
        + (endSysTimeSub.tv_usec - startSysTimeSub.tv_usec) / 1000000.0f;
        printf("B+ tree creation time:  %f seconds\n", totalTime);
    }
    
    // cities
    {
        printf("\n");
        printf("Making city B+ tree with %d cities\n", fc->cities);
        
        // time this section
        struct timeval startSysTimeSub, endSysTimeSub;
        gettimeofday(&startSysTimeSub, NULL);
        
        // create root
        int_node_t root;
        root.next = -1;
        root.previous = -1;
        root.tableType = TABLE_TYPE_CITY;
        root.nodeType = NODE_TYPE_LEAF;
        root.count = 0;
        root.firstFile = -1;
        write_node(0, &root);
        
        int rootFileNum = 0;
        
        for (i = 0; i < fc->cities; i++)
        {
            city_t *city = read_city(i);
            rootFileNum = insert_node(rootFileNum, TABLE_TYPE_CITY, city->stateId, i);
            free_city(city);
        }
        
        bpr.city = rootFileNum;
        
        // end timing this section
        gettimeofday(&endSysTimeSub, NULL);
        float totalTime = (endSysTimeSub.tv_sec - startSysTimeSub.tv_sec)
        + (endSysTimeSub.tv_usec - startSysTimeSub.tv_usec) / 1000000.0f;
        printf("B+ tree creation time:  %f seconds\n", totalTime);
    }
    
    //states
    {
        printf("\n");
        printf("Making state B+ tree with %d states\n", fc->states);
        
        // time this section
        struct timeval startSysTimeSub, endSysTimeSub;
        gettimeofday(&startSysTimeSub, NULL);
        
        // create root
        int_node_t root;
        root.next = -1;
        root.previous = -1;
        root.tableType = TABLE_TYPE_STATE;
        root.nodeType = NODE_TYPE_LEAF;
        root.count = 0;
        root.firstFile = -1;
        write_node(0, &root);
        
        int rootFileNum = 0;
        
        for (i = 0; i < fc->states; i++)
        {
            state_t *state = read_state(i);
            rootFileNum = insert_node(rootFileNum, TABLE_TYPE_STATE, (int) hash_state(state), i);
            free_state(state);
        }
        
        bpr.state = rootFileNum;
        
        // end timing this section
        gettimeofday(&endSysTimeSub, NULL);
        float totalTime = (endSysTimeSub.tv_sec - startSysTimeSub.tv_sec)
        + (endSysTimeSub.tv_usec - startSysTimeSub.tv_usec) / 1000000.0f;
        printf("B+ tree creation time:  %f seconds\n", totalTime);
    }
    
    // messages
    {
        printf("\n");
        printf("Making message B+ tree with %d messages\n", fc->messages);
        
        // time this section
        struct timeval startSysTimeSub, endSysTimeSub;
        gettimeofday(&startSysTimeSub, NULL);
        
        // create root
        int_node_t root;
        root.next = -1;
        root.previous = -1;
        root.tableType = TABLE_TYPE_MESSAGE;
        root.nodeType = NODE_TYPE_LEAF;
        root.count = 0;
        root.firstFile = -1;
        write_node(0, &root);
        
        int rootFileNum = 0;
        
        for (i = 0; i < fc->messages; i++)
        {
            message_t *message = read_message(i);
            rootFileNum = insert_node(rootFileNum, TABLE_TYPE_MESSAGE, message->timestampId, i);
            free_message(message);
        }
        
        bpr.message = rootFileNum;
        
        // end timing this section
        gettimeofday(&endSysTimeSub, NULL);
        float totalTime = (endSysTimeSub.tv_sec - startSysTimeSub.tv_sec)
        + (endSysTimeSub.tv_usec - startSysTimeSub.tv_usec) / 1000000.0f;
        printf("B+ tree creation time:  %f seconds\n", totalTime);
    }
    
    // timestamps
    {
        printf("\n");
        printf("Making timestamp B+ tree with %d timestamps\n", fc->timestamps);
        
        // time this section
        struct timeval startSysTimeSub, endSysTimeSub;
        gettimeofday(&startSysTimeSub, NULL);
        
        // create root
        int_node_t root;
        root.next = -1;
        root.previous = -1;
        root.tableType = TABLE_TYPE_TIMESTAMP;
        root.nodeType = NODE_TYPE_LEAF;
        root.count = 0;
        root.firstFile = -1;
        write_node(0, &root);
        
        int rootFileNum = 0;
        
        for (i = 0; i < fc->timestamps; i++)
        {
            timestamp_t *timestamp = read_timestamp(i);
            rootFileNum = insert_node(rootFileNum, TABLE_TYPE_TIMESTAMP, (int) hash_timestamp(timestamp), i);
            free_timestamp(timestamp);
        }
        
        bpr.timestamp = rootFileNum;
        
        // end timing this section
        gettimeofday(&endSysTimeSub, NULL);
        float totalTime = (endSysTimeSub.tv_sec - startSysTimeSub.tv_sec)
        + (endSysTimeSub.tv_usec - startSysTimeSub.tv_usec) / 1000000.0f;
        printf("B+ tree creation time:  %f seconds\n", totalTime);
    }
    
    // datestamps
    {
        printf("\n");
        printf("Making datestamp B+ tree with %d datestamps\n", fc->datestamps);
        
        // time this section
        struct timeval startSysTimeSub, endSysTimeSub;
        gettimeofday(&startSysTimeSub, NULL);
        
        
        // create root
        int_node_t root;
        root.next = -1;
        root.previous = -1;
        root.tableType = TABLE_TYPE_DATESTAMP;
        root.nodeType = NODE_TYPE_LEAF;
        root.count = 0;
        root.firstFile = -1;
        write_node(0, &root);
        
        int rootFileNum = 0;
        
        for (i = 0; i < fc->datestamps; i++)
        {
            datestamp_t *datestamp = read_datestamp(i);
            rootFileNum = insert_node(rootFileNum, TABLE_TYPE_DATESTAMP, (int) hash_datestamp(datestamp), i);
            free_datestamp(datestamp);
        }
        
        bpr.datestamp = rootFileNum;
        
        // end timing this section
        gettimeofday(&endSysTimeSub, NULL);
        float totalTime = (endSysTimeSub.tv_sec - startSysTimeSub.tv_sec)
        + (endSysTimeSub.tv_usec - startSysTimeSub.tv_usec) / 1000000.0f;
        printf("B+ tree creation time:  %f seconds\n", totalTime);
    }
    
    free_file_count(fc);
    
    printf("\n");
    
    print_bplus_roots(&bpr);
    write_bplus_roots(&bpr);
    
    // end timing the program
    gettimeofday(&sysTimeEnd, NULL);
    float totalTime = (sysTimeEnd.tv_sec - sysTimeStart.tv_sec)
    + (sysTimeEnd.tv_usec - sysTimeStart.tv_usec) / 1000000.0f;
    printf("Process time %f seconds\n", totalTime);
    
    return 0;
}
Ejemplo n.º 28
0
std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
{
	Object *ob = NULL;
	bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
	bool read_transform = true;
	std::string id   = node->getOriginalId();
	std::string name = node->getName();

	// if node has child nodes write them
	COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes();

	std::vector<Object *> *objects_done = new std::vector<Object *>();
	std::vector<Object *> *root_objects = new std::vector<Object *>();

	fprintf(stderr,
			"Writing node id='%s', name='%s'\n",
			id.c_str(),
			name.c_str());

	if (is_joint) {
		if (parent_node == NULL) {
			// A Joint on root level is a skeleton without root node.
			// Here we add the armature "on the fly":
			par = bc_add_object(sce, OB_ARMATURE, std::string("Armature").c_str());
			objects_done->push_back(par);
			root_objects->push_back(par);
			object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
			node_map[node->getUniqueId()] = node;
		}
		if (parent_node == NULL || parent_node->getType() != COLLADAFW::Node::JOINT) {
			armature_importer.add_root_joint(node, par);
		}

		if (parent_node == NULL) {
			// for skeletons without root node all has been done above.
			// Skeletons with root node are handled further down.
			goto finally;
		}
	}
	else {
		COLLADAFW::InstanceGeometryPointerArray &geom = node->getInstanceGeometries();
		COLLADAFW::InstanceCameraPointerArray &camera = node->getInstanceCameras();
		COLLADAFW::InstanceLightPointerArray &lamp = node->getInstanceLights();
		COLLADAFW::InstanceControllerPointerArray &controller = node->getInstanceControllers();
		COLLADAFW::InstanceNodePointerArray &inst_node = node->getInstanceNodes();
		size_t geom_done = 0;
		size_t camera_done = 0;
		size_t lamp_done = 0;
		size_t controller_done = 0;
		size_t inst_done = 0;

		// XXX linking object with the first <instance_geometry>, though a node may have more of them...
		// maybe join multiple <instance_...> meshes into 1, and link object with it? not sure...
		// <instance_geometry>
		while (geom_done < geom.getCount()) {
			ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
			                                      material_texture_mapping_map);
			if (ob == NULL) {
				report_unknown_reference(*node, "instance_mesh");
			}
			else {
				objects_done->push_back(ob);
				if (parent_node == NULL) {
					root_objects->push_back(ob);
				}
			}
			++geom_done;
		}
		while (camera_done < camera.getCount()) {
			ob = create_camera_object(camera[camera_done], sce);
			if (ob == NULL) {
				report_unknown_reference(*node, "instance_camera");
			}
			else {
				objects_done->push_back(ob);
				if (parent_node == NULL) {
					root_objects->push_back(ob);
				}
			}
			++camera_done;
		}
		while (lamp_done < lamp.getCount()) {
			ob = create_lamp_object(lamp[lamp_done], sce);
			if (ob == NULL) {
				report_unknown_reference(*node, "instance_lamp");
			}
			else {
				objects_done->push_back(ob);
				if (parent_node == NULL) {
					root_objects->push_back(ob);
				}
			}
			++lamp_done;
		}
		while (controller_done < controller.getCount()) {
			COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry *)controller[controller_done];
			ob = mesh_importer.create_mesh_object(node, geom, true, uid_material_map, material_texture_mapping_map);
			if (ob == NULL) {
				report_unknown_reference(*node, "instance_controller");
			}
			else {
				objects_done->push_back(ob);
				if (parent_node == NULL) {
					root_objects->push_back(ob);
				}
			}
			++controller_done;
		}
		// XXX instance_node is not supported yet
		while (inst_done < inst_node.getCount()) {
			const COLLADAFW::UniqueId& node_id = inst_node[inst_done]->getInstanciatedObjectId();
			if (object_map.find(node_id) == object_map.end()) {
				fprintf(stderr, "Cannot find object for node referenced by <instance_node name=\"%s\">.\n", inst_node[inst_done]->getName().c_str());
				ob = NULL;
			}
			else {
				std::pair<std::multimap<COLLADAFW::UniqueId, Object *>::iterator, std::multimap<COLLADAFW::UniqueId, Object *>::iterator> pair_iter = object_map.equal_range(node_id);
				for (std::multimap<COLLADAFW::UniqueId, Object *>::iterator it2 = pair_iter.first; it2 != pair_iter.second; it2++) {
					Object *source_ob = (Object *)it2->second;
					COLLADAFW::Node *source_node = node_map[node_id];
					ob = create_instance_node(source_ob, source_node, node, sce, is_library_node);
					objects_done->push_back(ob);
					if (parent_node == NULL) {
						root_objects->push_back(ob);
					}
				}
			}
			++inst_done;

			read_transform = false;
		}

		// if node is empty - create empty object
		// XXX empty node may not mean it is empty object, not sure about this
		if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
			//Check if Object is armature, by checking if immediate child is a JOINT node.
			if (is_armature(node)) {
				ob = bc_add_object(sce, OB_ARMATURE, name.c_str());
			}
			else {
				ob = bc_add_object(sce, OB_EMPTY, NULL);
			}
			objects_done->push_back(ob);
			if (parent_node == NULL) {
				root_objects->push_back(ob);
			}
		}
		
		// XXX: if there're multiple instances, only one is stored

		if (!ob) {
			goto finally;
		}

		for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
			ob = *it;
			std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
			BKE_libblock_rename(G.main, &ob->id, (char *)nodename.c_str());
			object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob));
			node_map[node->getUniqueId()] = node;

			if (is_library_node)
				libnode_ob.push_back(ob);
		}


		//create_constraints(et,ob);

	}

	for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
		ob = *it;

		if (read_transform)
			anim_importer.read_node_transform(node, ob);  // overwrites location set earlier

		if (!is_joint) {
			if (par && ob) {
				ob->parent = par;
				ob->partype = PAROBJECT;
				ob->parsubstr[0] = 0;

				//bc_set_parent(ob, par, mContext, false);
			}
		}
	}

	if (objects_done->size() > 0) {
		ob = *objects_done->begin();
	}
	else {
		ob = NULL;
	}

	for (unsigned int i = 0; i < child_nodes.getCount(); i++) {
		std::vector<Object *> *child_objects;
		child_objects = write_node(child_nodes[i], node, sce, ob, is_library_node);
		delete child_objects;
	}


finally:
	delete objects_done;

	return root_objects;
}
Ejemplo n.º 29
0
void DocumentImporter::finish()
{
	if (mImportStage != General)
		return;

	Main *bmain = CTX_data_main(mContext);
	// TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
	Scene *sce = CTX_data_scene(mContext);
	unit_converter.calculate_scale(*sce);

	std::vector<Object *> *objects_to_scale = new std::vector<Object *>();

	/** TODO Break up and put into 2-pass parsing of DAE */
	std::vector<const COLLADAFW::VisualScene *>::iterator it;
	for (it = vscenes.begin(); it != vscenes.end(); it++) {
		PointerRNA sceneptr, unit_settings;
		PropertyRNA *system, *scale;
		
		// for scene unit settings: system, scale_length

		RNA_id_pointer_create(&sce->id, &sceneptr);
		unit_settings = RNA_pointer_get(&sceneptr, "unit_settings");
		system = RNA_struct_find_property(&unit_settings, "system");
		scale = RNA_struct_find_property(&unit_settings, "scale_length");

		if (this->import_settings->import_units) {
			
			switch (unit_converter.isMetricSystem()) {
				case UnitConverter::Metric:
					RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC);
					break;
				case UnitConverter::Imperial:
					RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL);
					break;
				default:
					RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE);
					break;
			}
			float unit_factor = unit_converter.getLinearMeter();
			RNA_property_float_set(&unit_settings, scale, unit_factor);
			fprintf(stdout, "Collada: Adjusting Blender units to Importset units: %f.\n", unit_factor);

		}

		// Write nodes to scene
		const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
		for (unsigned int i = 0; i < roots.getCount(); i++) {
			std::vector<Object *> *objects_done = write_node(roots[i], NULL, sce, NULL, false);
			objects_to_scale->insert(objects_to_scale->end(), objects_done->begin(), objects_done->end());
			delete objects_done;
		}

		// update scene
		DAG_relations_tag_update(bmain);
		WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL);

	}


	mesh_importer.optimize_material_assignements();

	armature_importer.set_tags_map(this->uid_tags_map);
	armature_importer.make_armatures(mContext);
	armature_importer.make_shape_keys();
	DAG_relations_tag_update(bmain);

#if 0
	armature_importer.fix_animation();
#endif

	for (std::vector<const COLLADAFW::VisualScene *>::iterator it = vscenes.begin(); it != vscenes.end(); it++) {
		const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();

		for (unsigned int i = 0; i < roots.getCount(); i++) {
			translate_anim_recursive(roots[i], NULL, NULL);
		}
	}

	if (libnode_ob.size()) {
		Scene *sce = CTX_data_scene(mContext);

		fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size());
		// free all library_nodes
		std::vector<Object *>::iterator it;
		for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) {
			Object *ob = *it;

			Base *base = BKE_scene_base_find(sce, ob);
			if (base) {
				BLI_remlink(&sce->base, base);
				BKE_libblock_free_us(G.main, base->object);
				if (sce->basact == base)
					sce->basact = NULL;
				MEM_freeN(base);
			}
		}
		libnode_ob.clear();

		DAG_relations_tag_update(bmain);
	}
	
	bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units);

	delete objects_to_scale;
}
Ejemplo n.º 30
0
void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
{
	Object *ob = NULL;
	bool is_joint = node->getType() == COLLADAFW::Node::JOINT;

	if (is_joint) {
		if ( par ) {
		Object * empty = par;
		par = add_object(sce, OB_ARMATURE);
		bc_set_parent(par,empty->parent, mContext);
		//remove empty : todo
		object_map[parent_node->getUniqueId()] = par;
		}
		armature_importer.add_joint(node, parent_node == NULL || parent_node->getType() != COLLADAFW::Node::JOINT, par, sce);
	}
	else {
		COLLADAFW::InstanceGeometryPointerArray &geom = node->getInstanceGeometries();
		COLLADAFW::InstanceCameraPointerArray &camera = node->getInstanceCameras();
		COLLADAFW::InstanceLightPointerArray &lamp = node->getInstanceLights();
		COLLADAFW::InstanceControllerPointerArray &controller = node->getInstanceControllers();
		COLLADAFW::InstanceNodePointerArray &inst_node = node->getInstanceNodes();
		size_t geom_done = 0;
		size_t camera_done = 0;
		size_t lamp_done = 0;
		size_t controller_done = 0;
		size_t inst_done = 0;

		// XXX linking object with the first <instance_geometry>, though a node may have more of them...
		// maybe join multiple <instance_...> meshes into 1, and link object with it? not sure...
		// <instance_geometry>
		while (geom_done < geom.getCount()) {
			ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
												  material_texture_mapping_map);
			++geom_done;
		}
		while (camera_done < camera.getCount()) {
			ob = create_camera_object(camera[camera_done], sce);
			++camera_done;
		}
		while (lamp_done < lamp.getCount()) {
			ob = create_lamp_object(lamp[lamp_done], sce);
			++lamp_done;
		}
		while (controller_done < controller.getCount()) {
			COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry*)controller[controller_done];
			ob = mesh_importer.create_mesh_object(node, geom, true, uid_material_map, material_texture_mapping_map);
			++controller_done;
		}
		// XXX instance_node is not supported yet
		while (inst_done < inst_node.getCount()) {
			const COLLADAFW::UniqueId& node_id = inst_node[inst_done]->getInstanciatedObjectId();
			if (object_map.find(node_id) == object_map.end()) {
				fprintf(stderr, "Cannot find node to instanciate.\n");
				ob = NULL;
			}
			else {
				Object *source_ob = object_map[node_id];
				COLLADAFW::Node *source_node = node_map[node_id];

				ob = create_instance_node(source_ob, source_node, node, sce, par, is_library_node);
			}
			++inst_done;
		}
		// if node is empty - create empty object
		// XXX empty node may not mean it is empty object, not sure about this
		if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
			ob = add_object(sce, OB_EMPTY);
		}
		
		// check if object is not NULL
		if (!ob) return;
		
		std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
		rename_id(&ob->id, (char*)nodename.c_str());

		object_map[node->getUniqueId()] = ob;
		node_map[node->getUniqueId()] = node;

		if (is_library_node)
			libnode_ob.push_back(ob);
	}

	anim_importer.read_node_transform(node, ob); // overwrites location set earlier

	if (!is_joint) {
		// if par was given make this object child of the previous 
		if (par && ob)
			bc_set_parent(ob, par, mContext);
	}

	// if node has child nodes write them
	COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes();
	for (unsigned int i = 0; i < child_nodes.getCount(); i++) {	
		write_node(child_nodes[i], node, sce, ob, is_library_node);
	}
}