Пример #1
0
int CvArrTest::write_default_params( CvFileStorage* fs )
{
    int code = CvTest::write_default_params( fs );
    if( code < 0 )
        return code;

    if( ts->get_testing_mode() == CvTS::CORRECTNESS_CHECK_MODE )
    {
        write_param( fs, "test_case_count", test_case_count );
        write_param( fs, "min_log_array_size", min_log_array_size );
        write_param( fs, "max_log_array_size", max_log_array_size );
    }
    else if( ts->get_testing_mode() == CvTS::TIMING_MODE )
    {
        int i;

        start_write_param( fs ); // make sure we have written the entry header containing the test name
        if( size_list )
        {
            cvStartWriteStruct( fs, "size", CV_NODE_SEQ+CV_NODE_FLOW );
            for( i = 0; size_list[i].width >= 0; i++ )
            {
                cvStartWriteStruct( fs, 0, CV_NODE_SEQ+CV_NODE_FLOW );
                cvWriteInt( fs, 0, size_list[i].width );
                cvWriteInt( fs, 0, size_list[i].height );
                if( whole_size_list &&
                    (whole_size_list[i].width > size_list[i].width ||
                    whole_size_list[i].height > size_list[i].height) )
                {
                    cvWriteInt( fs, 0, whole_size_list[i].width );
                    cvWriteInt( fs, 0, whole_size_list[i].height );
                }
                cvEndWriteStruct( fs );
            }
            cvEndWriteStruct(fs);
        }

        if( depth_list )
        {
            cvStartWriteStruct( fs, "depth", CV_NODE_SEQ+CV_NODE_FLOW );
            for( i = 0; depth_list[i] >= 0; i++ )
                cvWriteString( fs, 0, cvTsGetTypeName(depth_list[i]) );
            cvEndWriteStruct(fs);
        }

        write_int_list( fs, "channels", cn_list, -1, -1 );

        if( optional_mask )
        {
            static const int use_mask[] = { 0, 1 };
            write_int_list( fs, "use_mask", use_mask, 2 );
        }
    }
    return 0;
}
Пример #2
0
int CV_BaseHistTest::write_default_params( CvFileStorage* fs )
{
    CvTest::write_default_params( fs );
    if( ts->get_testing_mode() != CvTS::TIMING_MODE )
    {
        write_param( fs, "test_case_count", test_case_count );
        write_param( fs, "max_log_size", max_log_size );
        write_param( fs, "max_log_array_size", img_max_log_size );
        write_param( fs, "max_dims", max_cdims );
    }
    return 0;
}
static ssize_t dsm_ctrl_write(struct file *file,
				const char __user *buf,
				size_t count,
				loff_t *ppos)
{
	int rc=0;
	static u8 param[DSM_PARAM_SZIE];
	int x;
	mutex_lock(&rx_lock);		
	//pr_info("%s enter. (count:%d)\n", __func__, count);

	rc = copy_from_user(param, buf, count);
	if (rc != 0) {
		//pr_info("copy_from_user failed. (rc=%d)", rc);
		mutex_unlock(&rx_lock);
		return rc;
	}
	//pr_info("----------------------------------------------------\n");
	for(x=0;x<80;x+=4)	{
		//pr_info("[RYAN] dsm_ctrl_write[%d] %d %d %d %d\n", x, param[x], param[x+1], param[x+2], param[x+3]);
	}
	write_param(param);
	mutex_unlock(&rx_lock);

	//pr_info("%s out.(count=%d, rc=%d)\n", __func__, count, rc);
	return rc;
}
Пример #4
0
void Quadrotor::write() {
	int n = (ti_f_ > 0) ? ti_f_ : N_;
	
	brain_->write(n);
	//brain_->pos_->write(ti_f_);
	//brain_->att_->write(ti_f_);
	plant_->write(n);
	telem_->write(n);

	write_param();
}
Пример #5
0
void write_params(list_p p, FILE* f) {
	list_iter_p iter;
	param_p d;
	
	if(p == NULL || f == NULL) return;

	fprintf(f, "%s", BEGIN_TABULAR);
	iter = list_iterator(p);
	for(d = list_next(iter); d != NULL; d = list_next(iter)) {
		write_param(d, f);
	}
	fprintf(f, "%s", END_TABULAR);
}
/*
 * Shared between the interface class declaration and the NS_DECL_IFOO macro
 * provided to aid declaration of implementation classes.  
 * mode...
 *  AS_DECL writes 'NS_IMETHOD foo(string bar, long sil)'
 *  AS_IMPL writes 'NS_IMETHODIMP className::foo(string bar, long sil)'
 *  AS_CALL writes 'foo(bar, sil)'
 */
static gboolean
write_method_signature(IDL_tree method_tree, FILE *outfile, int mode,
                       const char *className)
{
    struct _IDL_OP_DCL *op = &IDL_OP_DCL(method_tree);
    gboolean no_generated_args = TRUE;
    gboolean op_notxpcom =
        (IDL_tree_property_get(op->ident, "notxpcom") != NULL);
    const char *name;
    IDL_tree iter;

    if (mode == AS_DECL) {
        if (op_notxpcom) {
            fputs("NS_IMETHOD_(", outfile);
            if (!write_type(op->op_type_spec, FALSE, outfile))
                return FALSE;
            fputc(')', outfile);
        } else {
            fputs("NS_IMETHOD", outfile);
        }
        fputc(' ', outfile);
    }
    else if (mode == AS_IMPL) {
        if (op_notxpcom) {
            fputs("NS_IMETHODIMP_(", outfile);
            if (!write_type(op->op_type_spec, FALSE, outfile))
                return FALSE;
            fputc(')', outfile);
        } else {
            fputs("NS_IMETHODIMP", outfile);
        }
        fputc(' ', outfile);
    }
    name = IDL_IDENT(op->ident).str;
    if (mode == AS_IMPL) {
        fprintf(outfile, "%s::%c%s(", className, toupper(*name), name + 1);
    } else {
        fprintf(outfile, "%c%s(", toupper(*name), name + 1);
    }
    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
        if (mode == AS_DECL || mode == AS_IMPL) {
            if (!write_param(IDL_LIST(iter).data, outfile))
                return FALSE;
        } else {
            fputs(IDL_IDENT(IDL_PARAM_DCL(IDL_LIST(iter).data)
                            .simple_declarator).str,
                  outfile);
        }
        if ((IDL_LIST(iter).next ||
             (!op_notxpcom && op->op_type_spec) || op->f_varargs))
            fputs(", ", outfile);
        no_generated_args = FALSE;
    }

    /* make IDL return value into trailing out argument */
    if (op->op_type_spec && !op_notxpcom) {
        IDL_tree fake_param = IDL_param_dcl_new(IDL_PARAM_OUT,
                                                op->op_type_spec,
                                                IDL_ident_new("_retval"));
        if (!fake_param)
            return FALSE;
        if (mode == AS_DECL || mode == AS_IMPL) {
            if (!write_param(fake_param, outfile))
                return FALSE;
        } else {
            fputs("_retval", outfile);
        }
        if (op->f_varargs)
            fputs(", ", outfile);
        no_generated_args = FALSE;
    }

    /* varargs go last */
    if (op->f_varargs) {
        if (mode == AS_DECL || mode == AS_IMPL) {
            fputs("nsVarArgs *", outfile);
        }
        fputs("_varargs", outfile);
        no_generated_args = FALSE;
    }

    /*
     * If generated method has no arguments, output 'void' to avoid C legacy
     * behavior of disabling type checking.
     */
    if (no_generated_args && mode == AS_DECL) {
        fputs("void", outfile);
    }

    fputc(')', outfile);

    return TRUE;
}
Пример #7
0
void generate_receiver( FILE *file, struct function *f )
{
	struct param *p;
	struct external *e;

	if( strcmp(f->name->text,pattern_complete(f->options->remote_name->text,f->name->text)) ) {
		fprintf(file,"\t\t/* %s uses the same receiver as %s */\n\n",f->name->text,pattern_complete(f->options->remote_name->text,f->name->text));
		return;
	}

	fprintf(file,"\t\tcase BYPASS_CALL_%s:\n",f->name->text);
	fprintf(file,"\t\t{\n");
	if(!is_void(f->type)) {
		fprintf(file,"\t\t%s result;\n",type_string(f->type));
	}

	/* Declare all the params */

	for( p=f->params; p; p=p->next ) {
		fprintf(file,"\t\t%s %s=0;\n",type_string_noconst(p->type),p->name->text);
	}

	/* Get the params */

	e=f->options->external;
	for( p=f->params; p; p=p->next ) {
		if( p->control->in ) {
			write_param( file, "bypass_packet", "EXTERNAL_IN", p, e );
		}
		if(e) e=e->next;
	}

	/* Allocate space for any out-only parameters */

	for( p=f->params; p; p=p->next ) {
		if( p->control->out && !p->control->in ) {
			write_alloc_param( file, "bypass_response", p );
		}
	}

	fprintf(file,"\t\terrno = 0;\n");

	/* If the function is not supported, send back an error. */
	/* Otherwise, invoke the shadow action */

	if( f->options->not_supported ) {
		fprintf(file,"\t\terrno = EINVAL;\n\n");
        } else {
		if(!is_void(f->type)) {
			fprintf(file,"\t\tresult =");
		} else {
			fprintf(file,"\t\t");
		}
		fprintf(file,"bypass_shadow_action_%s( %s );\n",f->name->text,arg_string(f->params));
	}
	fprintf(file,"\t\tbypass_errno = errno;\n");

	/* Send back errno, then result, then out params */

	fprintf(file,"\t\tTRY(external_errno_map(bypass_response,EXTERNAL_OUT,&bypass_errno));\n");
	if(!is_void(f->type)) {
		fprintf(file,"\t\tTRY(external(bypass_response,EXTERNAL_OUT,&result));\n");
	}

	e=f->options->external;
	for( p=f->params; p; p=p->next ) {
		if( p->control->out ) {
			write_param( file, "bypass_response", "EXTERNAL_OUT", p, e);
		}
		if(e) e=e->next;
	}

	/* All done. */

	fprintf(file,"\t\t}\n");
	fprintf(file,"\t\tbreak;\n\n");
}
Пример #8
0
void generate_sender( FILE *file, struct function *f )
{
	struct param *p;
	char *fail_string;
	struct external *e;

	/* Create an appropriate exception handler */

	if(f->type->stars) {
		fail_string="0";
	} else if(!is_void(f->type)) {
		fail_string="-1";
	} else {
		fail_string="";
	}

	/* Write the function header */

	fprintf(file,"extern \"C\" %s bypass_shadow_%s( %s )\n{\n",type_string(f->type),f->name->text,param_string_noconst(f->params));

	/* Declare private bypass values */

	fprintf(file,"\tstruct packet *bypass_packet=0;\n");
	fprintf(file,"\tint bypass_errno=0;\n");
	fprintf(file,"\tint bypass_number = BYPASS_CALL_%s;\n",f->name->text);

	if(!is_void(f->type)) {
		fprintf(file,"%s result;\n",type_string(f->type));
	}

	write_vararg_decls(file,f->params);

	/* If the connection has not been made, do it now. */
	fprintf(file,"\tif(!bypass_rpc_init()) goto fail;\n");

	/* Start up a new packet */

	fprintf(file,"\tTRY(bypass_packet = packet_create(0));\n");

	/* Send the number of this call */
	
	fprintf(file,"\tTRY(external(bypass_packet,EXTERNAL_OUT,&bypass_number));\n");

	/* Send the params */

	e = f->options->external;
	for( p=f->params; p; p=p->next ) {
		if( p->control->in ) {
			write_param( file, "bypass_packet", "EXTERNAL_OUT", p, e );
		}
		if(e) e=e->next;
	}

	/* Finally, fire off the packet */

	fprintf(file,"\tTRY(packet_put(bypass_rpc_fd_get(),bypass_packet));\n");
	fprintf(file,"\tpacket_delete(bypass_packet);\n");
	fprintf(file,"\tbypass_packet=0;\n\n");

	/* Grab the result packet */

	fprintf(file,"\tTRY(bypass_packet = packet_get(bypass_rpc_fd_get()));\n");

	/* Get errno, then result, then out parameters */

	fprintf(file,"\tTRY(external_errno_map(bypass_packet,EXTERNAL_IN,&bypass_errno));\n");
	if(!is_void(f->type)) {
		fprintf(file,"\t\tTRY(external(bypass_packet,EXTERNAL_IN,&result));\n");
	}

	e = f->options->external;
	for( p=f->params; p; p=p->next ) {
		if( p->control->out ) {
			write_param( file, "bypass_packet", "EXTERNAL_IN", p, e );
		}
		if(e) e=e->next;
	}

	fprintf(file,"\tpacket_delete(bypass_packet);\n");
	fprintf(file,"\terrno = bypass_errno;\n");

	if(!is_void(f->type)) {
		fprintf(file,"\treturn result;\n");
	} else {
		fprintf(file,"\treturn;\n");
	}

	fprintf(file,"\n");

	/* In the event of a network failure, clean up, and close the connection */

	fprintf(file,"\tfail:\n");
	fprintf(file,"\tbypass_errno = errno;\n");
	fprintf(file,"\tif(bypass_packet) packet_delete(bypass_packet);\n");
	fprintf(file,"\tbypass_rpc_close();\n");

	/* If retries are turned on, put a message and sleep */

	fprintf(file,"\tchar message[1024];\n");
	fprintf(file,"\tsprintf(message,\"couldn't execute %%s: %%s\\n\",bypass_call_string(bypass_number),strerror(bypass_errno));\n");
	fprintf(file,"\tif(bypass_failure_passthrough) {\n");
	fprintf(file,"\t\tbypass_debug(message);\n");
	fprintf(file,"\t} else {\n");
	fprintf(file,"\t\tbypass_fatal(message);\n");
	fprintf(file,"\t}\n");
	fprintf(file,"\terrno = bypass_errno;\n");
	fprintf(file,"\treturn %s;\n",fail_string);
	fprintf(file,"}\n\n");
}
Пример #9
0
/**
 * Perform a read, write or just a listing of a parameter
 *
 * \param[in] popt		list,set,get parameter options
 * \param[in] pattern		search filter for the path of the parameter
 * \param[in] value		value to set the parameter if write operation
 * \param[in] mode		what operation to perform with the parameter
 *
 * \retval number of bytes written on success.
 * \retval -errno on error and prints error message.
 */
static int
param_display(struct param_opts *popt, char *pattern, char *value,
	      enum parameter_operation mode)
{
	int dir_count = 0;
	char **dir_cache;
	glob_t paths;
	char *opname = parameter_opname[mode];
	int rc, i;

	rc = cfs_get_param_paths(&paths, "%s", pattern);
	if (rc != 0) {
		rc = -errno;
		if (!popt->po_recursive) {
			fprintf(stderr, "error: %s: param_path '%s': %s\n",
				opname, pattern, strerror(errno));
		}
		return rc;
	}

	dir_cache = calloc(paths.gl_pathc, sizeof(char *));
	if (dir_cache == NULL) {
		rc = -ENOMEM;
		fprintf(stderr,
			"error: %s: allocating '%s' dir_cache[%zd]: %s\n",
			opname, pattern, paths.gl_pathc, strerror(-rc));
		goto out_param;
	}

	for (i = 0; i < paths.gl_pathc; i++) {
		char *param_name = NULL, *tmp;
		char pathname[PATH_MAX];
		struct stat st;
		int rc2;

		if (stat(paths.gl_pathv[i], &st) == -1) {
			fprintf(stderr, "error: %s: stat '%s': %s\n",
				opname, paths.gl_pathv[i], strerror(errno));
			if (rc == 0)
				rc = -errno;
			continue;
		}

		if (popt->po_only_dir && !S_ISDIR(st.st_mode))
			continue;

		param_name = display_name(paths.gl_pathv[i], &st, popt);
		if (param_name == NULL) {
			fprintf(stderr,
				"error: %s: generating name for '%s': %s\n",
				opname, paths.gl_pathv[i], strerror(ENOMEM));
			if (rc == 0)
				rc = -ENOMEM;
			continue;
		}

		/**
		 * For the upstream client the parameter files locations
		 * are split between under both /sys/kernel/debug/lustre
		 * and /sys/fs/lustre. The parameter files containing
		 * small amounts of data, less than a page in size, are
		 * located under /sys/fs/lustre and in the case of large
		 * parameter data files, think stats for example, are
		 * located in the debugfs tree. Since the files are split
		 * across two trees the directories are often duplicated
		 * which means these directories are listed twice which
		 * leads to duplicate output to the user. To avoid scanning
		 * a directory twice we have to cache any directory and
		 * check if a search has been requested twice.
		 */
		if (S_ISDIR(st.st_mode)) {
			int j;

			for (j = 0; j < dir_count; j++) {
				if (!strcmp(dir_cache[j], param_name))
					break;
			}
			if (j != dir_count) {
				free(param_name);
				param_name = NULL;
				continue;
			}
			dir_cache[dir_count++] = strdup(param_name);
		}

		switch (mode) {
		case GET_PARAM:
			/* Read the contents of file to stdout */
			if (S_ISREG(st.st_mode))
				read_param(paths.gl_pathv[i], param_name, popt);
			break;
		case SET_PARAM:
			if (S_ISREG(st.st_mode)) {
				rc2 = write_param(paths.gl_pathv[i],
						  param_name, popt, value);
				if (rc2 < 0 && rc == 0)
					rc = rc2;
			}
			break;
		case LIST_PARAM:
			if (popt->po_show_path)
				printf("%s\n", param_name);
			break;
		}

		/* Only directories are searched recursively if
		 * requested by the user */
		if (!S_ISDIR(st.st_mode) || !popt->po_recursive) {
			free(param_name);
			param_name = NULL;
			continue;
		}

		/* Turn param_name into file path format */
		rc2 = clean_path(popt, param_name);
		if (rc2 < 0) {
			fprintf(stderr, "error: %s: cleaning '%s': %s\n",
				opname, param_name, strerror(-rc2));
			free(param_name);
			param_name = NULL;
			if (rc == 0)
				rc = rc2;
			continue;
		}

		/* Use param_name to grab subdirectory tree from full path */
		tmp = strstr(paths.gl_pathv[i], param_name);

		/* cleanup paramname now that we are done with it */
		free(param_name);
		param_name = NULL;

		/* Shouldn't happen but just in case */
		if (tmp == NULL) {
			if (rc == 0)
				rc = -EINVAL;
			continue;
		}

		rc2 = snprintf(pathname, sizeof(pathname), "%s/*", tmp);
		if (rc2 < 0) {
			/* snprintf() should never an error, and if it does
			 * there isn't much point trying to use fprintf() */
			continue;
		}
		if (rc2 >= sizeof(pathname)) {
			fprintf(stderr, "error: %s: overflow processing '%s'\n",
				opname, pathname);
			if (rc == 0)
				rc = -EINVAL;
			continue;
		}

		rc2 = param_display(popt, pathname, value, mode);
		if (rc2 != 0 && rc2 != -ENOENT) {
			/* errors will be printed by param_display() */
			if (rc == 0)
				rc = rc2;
			continue;
		}
	}

	for (i = 0; i < dir_count; i++)
		free(dir_cache[i]);
	free(dir_cache);
out_param:
	cfs_free_param_data(&paths);
	return rc;
}
Пример #10
0
/*
 * Shared between the interface class declaration and the NS_DECL_IFOO macro
 * provided to aid declaration of implementation classes.  
 * mode...
 */
static gboolean
write_method_signature(IDL_tree method_tree, FILE *outfile, const char *className)
{
    struct _IDL_OP_DCL *op = &IDL_OP_DCL(method_tree);
    gboolean no_generated_args = TRUE;
    gboolean op_notxpcom =
        (IDL_tree_property_get(op->ident, "notxpcom") != NULL);
    const char *name;
    IDL_tree iter;

    if (op_notxpcom && !op->op_type_spec)
        fputs("procedure ", outfile);
    else
        fputs("function ", outfile);

    name = IDL_IDENT(op->ident).str;
    if( is_reserved(name) )
        fputc('_', outfile);
    fprintf(outfile, "%c%s(", toupper(*name), name + 1);

    for (iter = op->parameter_dcls; iter; iter = IDL_LIST(iter).next) {
        if (!write_param(IDL_LIST(iter).data, outfile))
            return FALSE;
        if ((IDL_LIST(iter).next ||
             (!op_notxpcom && op->op_type_spec) || op->f_varargs))
            fputs("; ", outfile);
        no_generated_args = FALSE;
    }

    /* make IDL return value into trailing out argument */
    if (op->op_type_spec && !op_notxpcom) {
        IDL_tree fake_param = IDL_param_dcl_new(IDL_PARAM_OUT,
                                                op->op_type_spec,
                                                IDL_ident_new("_retval"));
        if (!fake_param)
            return FALSE;
        if (!write_param(fake_param, outfile))
            return FALSE;
        if (op->f_varargs)
            fputs("; ", outfile);
        no_generated_args = FALSE;
    }

    /* varargs go last */
    if (op->f_varargs) {
        fputs("_varargs : PVarArgs", outfile);
        no_generated_args = FALSE;
    }

    fputc(')', outfile);

    if (op_notxpcom) {
        if (!interface_write_type(op->op_type_spec, FALSE, FALSE, FALSE, FALSE, NULL, outfile))
            return FALSE;
    } else {
        fputs(": nsresult", outfile);
    }
    fputs("; stdcall", outfile);

    return TRUE;
}