Exemplo n.º 1
0
int fetch_isp_tbl(struct isp_init_config *isp_ini_cfg, char* tbl_patch)
{
	int len, ret = 0;
	char isp_gamma_tbl_path[128] = "\0",isp_hdr_tbl_path[128] = "\0",isp_lsc_tbl_path[128] = "\0";
	char *buf;
	strcpy(isp_gamma_tbl_path, tbl_patch);
	strcpy(isp_hdr_tbl_path, tbl_patch);
	strcpy(isp_lsc_tbl_path, tbl_patch);

	strcat(isp_gamma_tbl_path, "gamma_tbl.bin");
	strcat(isp_hdr_tbl_path, "hdr_tbl.bin");
	strcat(isp_lsc_tbl_path, "lsc_tbl.bin");

	printk("isp_tbl_path = %s\n",isp_gamma_tbl_path);
	buf = (char*)kzalloc(SIZE_OF_LSC_TBL,GFP_KERNEL);

	/* fetch gamma_tbl table! */

	len = cfg_read_file(isp_gamma_tbl_path,buf,SIZE_OF_GAMMA_TBL);
	if(len < 0)
	{
		vfe_warn("read gamma_tbl from gamma_tbl.bin failed!\n");
		ret =  -1;
	}
	else
	{
		memcpy(isp_ini_cfg->isp_tunning_settings.gamma_tbl, buf, len);
	}

	/* fetch lsc table! */
	len = cfg_read_file(isp_lsc_tbl_path,buf,SIZE_OF_LSC_TBL);
	if(len < 0)
	{
		vfe_warn("read lsc_tbl from lsc_tbl.bin failed!\n");
		ret =  -1;
	}
	else
	{
		memcpy(isp_ini_cfg->isp_tunning_settings.lsc_tbl, buf, len);
	}
	/* fetch hdr_tbl table!*/
	len = cfg_read_file(isp_hdr_tbl_path,buf,SIZE_OF_HDR_TBL);
	if(len < 0)
	{
		vfe_warn("read hdr_tbl from hdr_tbl.bin failed!\n");
		ret =  -1;
	}
	else
	{
		memcpy(isp_ini_cfg->isp_tunning_settings.hdr_tbl, buf, len);
	}

	if(buf)
	{
		kfree(buf);
	}
	return ret;
}
Exemplo n.º 2
0
/*
 * name:    cfg_read_ini
 * func:    API: read from file, parse mainkey and sunkey value,save to cfg_setction
 * input��  char *file_path
 * output�� struct cfg_section **cfg_section
 * return�� error number
 */
int cfg_read_ini(char *file_path, struct cfg_section **cfg_section)
{
//  struct file* fp;
  unsigned int i;
  struct cfg_section *cfg_sct = *(cfg_section);
//  loff_t pos = 0;
//  mm_segment_t old_fs;
	char *buf;
	int buf_len, ret = 0;
	
	buf = (char*)kzalloc(INI_MAX_CHAR_NUM,GFP_KERNEL);

#if 0	
	/* file operation */
  fp = filp_open(file_path,O_RDONLY,0);
	
  if(IS_ERR(fp)) {
    vfe_err("open cfg file failed!\n");
    return -EFAULT;
  }
  
	old_fs = get_fs();
	set_fs(KERNEL_DS);
	buf_len = vfs_read(fp, buf, INI_MAX_CHAR_NUM, &pos);
	buf[buf_len] = '\0';
	set_fs(old_fs);
	
	if(fp)
    filp_close(fp,NULL);
#else
	buf_len = cfg_read_file(file_path, buf, INI_MAX_CHAR_NUM);
	if(buf_len < 0) {
	  ret = -1;
	  goto rd_ini_end;
	}
	buf[buf_len] = '\0';
#endif	
	//printk("cfg len = %d\n",buf_len);
	
	/* parse file */
	
  cfg_sct->mainkey_cnt = cfg_get_sections(buf, cfg_sct->mainkey_name);

//  cfg_sct->mainkey_cnt = 4;
//  strcpy(cfg_sct->mainkey_name[0],"isp_func"/*"isp_func"*/);   
//  strcpy(cfg_sct->mainkey_name[1],"isp_tbl"/*"isp_tbl"*/);   
//  strcpy(cfg_sct->mainkey_name[2],"isp_para"/*"isp_para"*/);   
//  strcpy(cfg_sct->mainkey_name[3],"sensor_func"/*"sensor_func"*/);   
	
	for(i = 0; i < cfg_sct->mainkey_cnt; i++)
	{
      cfg_sct->mainkey[i]->subkey_cnt = cfg_get_all_keys_value(buf,cfg_sct->mainkey[i]);
	}

rd_ini_end:		
  if(buf)
    kfree(buf);

  return ret;
}
Exemplo n.º 3
0
Config cfg_new_from_file(const char* filename) {
    Config cfg = cfg_new();
    if(cfg_read_file(cfg, filename) != CFG_OKAY) {
        cfg_destroy(cfg);
        cfg = NULL;
    }
    return cfg;
}
Exemplo n.º 4
0
int
fsd_conf_init(const char *filepath, fsd_conf_t **cfgp)
{
	int err, debug, base, port;
	unsigned int cnt;
	cfg_t *mcfg = NULL;
	fs_log_t *log = NULL;
	char value[CFG_VALUE_LEN_MAX], host[128], path[256], logfile[256];
	uint64_t salt;
	
	err = fs_log_init(NULL, &log);
	
	if (err == ERR_OK && (err = cfg_init(&mcfg)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Cannot initialize 'cfg'");
	
	if (err == ERR_OK && (err = cfg_read_file(mcfg, filepath)) != ERR_OK) {
		if (filepath != NULL)
			fs_error(log, "[ CONFIG ] Cannot load config file '%s'", filepath);
	}
	
	if (err == ERR_OK && (*cfgp = malloc(sizeof(fsd_conf_t))) == NULL)
		err = ERR_MEMORY;
	
	/* Checking for debug variable */
	if (err == ERR_OK && (err = cfg_get(mcfg, "debug", (char *)&value)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Cannot find 'debug' variable in config file");
	
	if (err == ERR_OK && (err = str2int(value, &debug)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Invalid Type of 'debug' = '%s'. Cardinal is required", value);
	
	if (err == ERR_OK)
		(*cfgp)->debug = debug;
	
	/* Checking for port variable */
	if (err == ERR_OK && (err = cfg_get(mcfg, "port", (char *)&value)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Cannot find 'port' variable in config file");

	if (err == ERR_OK && (err = str2int(value, &port)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Invalid Type of 'port' = '%s'. Cardinal is required", value);
	
	if (err == ERR_OK && (port < 2 || port > (1 << 16))) {
		fs_error(log, "[ CONFIG ] variable 'port' = %d is out of range <1, %d>", port, (1 << 16));
		err = ERR_CONFIG;
	}
	
	if (err == ERR_OK)
		(*cfgp)->port = (uint16_t)port;
	
	/* Checking for host variable */
	if (err == ERR_OK && (err = cfg_get(mcfg, "host", (char *)&host)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Cannot find 'host' variable in config file");
	
	if (err == ERR_OK)
		strncpy((*cfgp)->host, host, strlen(host) + 1);
	
	/* Checking for path variable */
	if (err == ERR_OK && (err = cfg_get(mcfg, "path", (char *)&path)) != ERR_OK)
		fs_error(log, "[ CONFIG ] Cannot find 'path' variable in config file");
	
	if (err == ERR_OK && !fs_dir_exist(path)) {
		fs_error(log, "[ CONFIG ] 'path' = '%s' not exist or no permission", path);
		err = ERR_FILESYSTEM;
	}
	
	if (err == ERR_OK)
		strncpy((*cfgp)->path, path, strlen(path) + 1);
	
	/* Checking for logfile variable */
	if (err == ERR_OK && cfg_get(mcfg, "logfile", (char *)&logfile) == ERR_OK) {
		strncpy((char *)&(*cfgp)->logfile, logfile, strlen(logfile) + 1);
		(*cfgp)->logfile[strlen(logfile)] = '\0';
	} else if (err == ERR_OK) {
		(*cfgp)->logfile[0] = '\0';
	}
	
	/* Checking for salt variable */
	if (err == ERR_OK && cfg_get(mcfg, "salt", (char *)&value) == ERR_OK) {
		if (err == ERR_OK && (err = str2uint64_t(value, &salt)) != ERR_OK)
			fs_error(log, "[ CONFIG ] Invalid Type of 'salt' = '%s'. Long cardinal is required", value);
		else
			(*cfgp)->salt = salt;
	} else 
		(*cfgp)->salt = FS_DEFAULT_SALT;
		
	/* Checking for base variable */
	if (err == ERR_OK && cfg_get(mcfg, "base", (char *)&value) == ERR_OK) {
		if (err == ERR_OK && (err = str2int(value, &base)) != ERR_OK)
			fs_error(log, "[ CONFIG ] Invalid Type of 'base' = '%s'. Cardinal is required", value);
		else {
			if (err == ERR_OK && (base < 2 || base > 62)) {
				fs_error(log, "[ CONFIG ] variable 'base' = %d is out of range <2, 62>", base);
				err = ERR_CONFIG;
			} else 
				(*cfgp)->base = (uint8_t)base;
		}			
	} else
		(*cfgp)->base = FS_DEFAULT_BASE;
	
	/* Checking form allowed_ips variable*/
	cnt = 0;
	if (err == ERR_OK && cfg_get(mcfg, "allowed_ips", (char *)&value) == ERR_OK) {
		if (str_split(value, ",", &cnt, &((*cfgp)->allowed_ips)) == ERR_OK) {
			for (unsigned int j = 0; j < cnt; j++) {
				str_strip((*cfgp)->allowed_ips[j], " \n\t", (char *)&value);
				strncpy((*cfgp)->allowed_ips[j], value, strlen(value));
				(*cfgp)->allowed_ips[j][strlen(value)] = '\0';
			}
		}
	}
	
	if (err == ERR_OK)
		(*cfgp)->allowed_ips_cnt = cnt;
	
	cfg_fini(mcfg);
	fs_log_fini(log);
	
	return (err);
}
Exemplo n.º 5
0
int main(int argc, char* argv[]) {
    int nprocs, myid, root;
    int Ncells, Nmodes;
    Cell* cells;

    Config cfg = cfg_new();

    /* Initialize MPI */
    MPI_Init(&argc, &argv);
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Comm_size(comm, &nprocs);
    MPI_Comm_rank(comm, &myid);
    root = nprocs - 1;

    /* Parse command line switches */
    int opt;
    const char* optstring = "hc:";
    while((opt = getopt(argc, argv, optstring)) != -1) {
        switch(opt) {
        case 'h':
            print_usage(stdout, argv[0]);
            return 0;
        case 'c':
            cfg_read_file(cfg, optarg);
            break;
        default:
            print_usage(stderr, argv[0]);
            MPI_Abort(comm, 1);
        }
    }

    /* Parse additional command line options */
    for(int i = optind; i < argc; i++)
        cfg_read_line(cfg, argv[i]);

    /* Debugging... */
    if(myid == root) {
        printf("# Config options\n");
        cfg_write(cfg, stdout);
    }

    if(myid == 0) {
        printf("Testing malloc...\n");
        char* test = (char*) malloc(72000*sizeof(char));
        if(test == NULL) {
            fprintf(stderr, "Could not allocate a measly 72000 bytes!\n");
            perror("system error:");
        }
        free(test);
    }

    /* Make sure all the necessary options are provided */
    if(!cfg_has_keys(cfg, "cellfile,specfile", ",")) {
        print_usage(stderr, argv[0]);
        MPI_Abort(comm, 1);
    }
    const char* cellfile = cfg_get(cfg, "cellfile");
    const char* specfile = cfg_get(cfg, "specfile");

    /* Read cells from file */
    if(myid == 0) printf("Reading cells from '%s' ...\n", cellfile);
    cells = ReadCells(comm, cellfile, Ncells);
    if(cells == NULL) {
        if(myid == 0) fprintf(stderr, "Failed to read cells.\n");
        if(myid == 0) perror("system error");
        MPI_Abort(comm, 1);
    }
    else {
        if(myid == 0) printf("Read %d cells.\n", Ncells);
        if(myid == 0) printf("  cells[0] = { %d, %d, %g, %g, %g, %g, %g, %g, %g, %g }\n", cells[0].a, cells[0].G, cells[0].rmin, cells[0].rmax, cells[0].mumin, cells[0].mumax, cells[0].phimin, cells[0].phimax, cells[0].Veff, cells[0].Nbar);
    }

    /* Read KL mode coefficients */
    Matrix B;   // cell -> KL mode projection matrix
    Matrix C;   // full covariance matrix in KL basis (diagonal)
    if(myid == 0) printf("Reading KL spectrum from '%s' ...\n", specfile);
    if(ReadSpectrum(comm, specfile, Nmodes, Ncells, B, C) != 0) {
        if(myid == 0) fprintf(stderr, "Failed to read spectrum.\n");
        if(myid == 0) perror("system error");
        MPI_Abort(comm, 1);
    }
    else {
        if(myid == 0) printf("Read spectrum: Nmodes = %d, Ncells = %d\n", Nmodes, Ncells);
    }

    /* Clean up nicely */
    free(cells);
    MPI_Finalize();

    return 0;
}