Пример #1
0
int main(void)
{
	cfg_opt_t sub_opts[] = {
		CFG_BOOL("bool", cfg_false, CFGF_NONE),
		CFG_STR("string", NULL, CFGF_NONE),
		CFG_INT("int", 0, CFGF_NONE),
		CFG_FLOAT("float", 0.0, CFGF_NONE),
		CFG_END()
	};

	cfg_opt_t opts[] = {
		CFG_BOOL_LIST("bool", cfg_false, CFGF_NONE),
		CFG_STR_LIST("string", NULL, CFGF_NONE),
		CFG_INT_LIST("int", 0, CFGF_NONE),
		CFG_FLOAT_LIST("float", "0.0", CFGF_NONE),
		CFG_SEC("sub", sub_opts,
			CFGF_MULTI | CFGF_TITLE | CFGF_NO_TITLE_DUPES),
		CFG_END()
	};

	char *cmd = NULL;
	const char *reply;
	int res;
	int i;

	cfg = cfg_init(opts, CFGF_NONE);

	for (;;) {
		printf("cli> ");
		fflush(stdout);

		if (cmd)
			free(cmd);
		cmd = input_cmd();
		if (!cmd)
			exit(0);
		res = split_cmd(cmd);
		if (res < 0) {
			printf("Parse error\n");
			continue;
		}
		if (cmdc == 0)
			continue;
		for (i = 0; cmds[i].cmd; ++i) {
			if (strcmp(cmdv[0], cmds[i].cmd))
				continue;
			reply = cmds[i].handler(cmdc, cmdv);
			if (!reply)
				exit(0);
			printf("%s", reply);
			break;
		}
		if (!cmds[i].cmd)
			printf("Unknown command\n");
	}

	cfg_free(cfg);
	return 0;
}
Пример #2
0
cfg_opt_t * get_opt(){
  static cfg_opt_t opts[] = {
                         CFG_STR("user", "root", CFGF_NONE),
                         CFG_STR("password", "", CFGF_NONE),
                         CFG_STR("dbname", "", CFGF_NONE),
                         CFG_STR("ip", "127.0.0.1", CFGF_NONE),
                         CFG_INT("port", 5432, CFGF_NONE),
                         CFG_STR("db_query", "", CFGF_NONE),
                         CFG_INT("svm_type",0, CFGF_NONE),
                         CFG_INT("kernel_type",0,CFGF_NONE),
                         CFG_FLOAT("gamma",0,CFGF_NONE),
                         CFG_FLOAT("C",1,CFGF_NONE),
                         CFG_STR("model_filename", "file.model", CFGF_NONE),
                         CFG_STR("model_list_path","",CFGF_NONE),
                         CFG_STR_LIST("model_list","{}",CFGF_NONE),
                         CFG_STR_LIST("query_list","{}",CFGF_NONE),
                         CFG_STR_LIST("model_label_list","{}",CFGF_NONE),
                         CFG_END()
                        };
      return opts;                  
}
Пример #3
0
/**
 * Parses the config file
 *
 * @return a pointer to the configuration data structure, NULL on failure
 */
static cfg_t * parse_config(void) {
	cfg_t * cfg = NULL;

	cfg_opt_t target_opts[] = {
	                              CFG_STR("comment", 0, CFGF_NONE),
	                              CFG_INT("strip", 0, CFGF_NONE),
	                              CFG_STR("rewrite_prefix", 0, CFGF_NONE),
	                              CFG_FLOAT("prob", 0, CFGF_NONE),
	                              CFG_INT("hash_index", 0, CFGF_NONE),
	                              CFG_STR("rewrite_suffix", 0, CFGF_NONE),
	                              CFG_INT("status", 1, CFGF_NONE),
	                              CFG_INT_LIST("backed_up", NULL, CFGF_NONE),
	                              CFG_INT("backup", -1, CFGF_NONE),
	                              CFG_END()
	                          };

	cfg_opt_t prefix_opts[] = {
	                              CFG_SEC("target", target_opts, CFGF_MULTI | CFGF_TITLE),
	                              CFG_INT("max_targets", -1, CFGF_NONE),
	                              CFG_END()
	                          };

	cfg_opt_t domain_opts[] = {
	                              CFG_SEC("prefix", prefix_opts, CFGF_MULTI | CFGF_TITLE),
	                              CFG_END()
	                          };

	cfg_opt_t opts[] = {
	                       CFG_SEC("domain", domain_opts, CFGF_MULTI | CFGF_TITLE),
	                       CFG_END()
	                   };

	cfg = cfg_init(opts, CFGF_NONE);

	cfg_set_error_function(cfg, conf_error);

	switch (cfg_parse(cfg, config_file)) {
		case CFG_FILE_ERROR: LM_ERR("file not found: %s\n", config_file);
			return NULL;
		case CFG_PARSE_ERROR: LM_ERR("error while parsing %s in line %i, section %s\n",
			                          cfg->filename, cfg->line, cfg->name);
			return NULL;
		case CFG_SUCCESS: break;
	}
	return cfg;
}
Пример #4
0
#include <sys/socket.h>
#include <time.h>

#include "peer.h"

#include <chunk.h>
#include <mon.h>
#include <ul.h>

#define MAX_PACKET_SIZE			2048
#define INITIAL_PKTBUFFER_NUM	10

/** Configuration options for the Source */
cfg_opt_t cfg_source[] = {
	CFG_STR("stream", NULL, CFGF_NONE),
	CFG_FLOAT("chunk_duration", 1.0, CFGF_NONE),
	CFG_END()
};

/** This function gets called periodically and arranges the publishing of a
 * MeasurementRecord with SrcLag = 0.0 
 */
void periodicPublishSrcLag(HANDLE h, void *arg) {
	MeasurementRecord mr;
	memset(&mr, 0, sizeof(mr));
	mr.published_name = "SrcLag";
	mr.value = 0.0;
	mr.originator = mr.targetA = mr.targetB = LocalPeerID;
	mr.channel = channel;
	publishMeasurementRecord(&mr, "SrcLag");
}
Пример #5
0
    CFG_STR("devid_mask", "0", CFGF_NONE),	/* because libconfuse does not support 0xffffffff via */
    CFG_STR("blank_value", "0", CFGF_NONE),	/* the integer option */
    CFG_INT("bytes_per_loc", 0, CFGF_NONE),
    CFG_INT("addr_inc", 0, CFGF_NONE),
    CFG_INT("b_detect", 0, CFGF_NONE),
    CFG_STR("prg_entry_vpp_script", "NO_SCRIPT", CFGF_NONE),
    CFG_INT("ee_bytes_per_word", 0, CFGF_NONE),
    CFG_INT("ee_addr_inc", 0, CFGF_NONE),
    CFG_INT("user_id_hex_bytes", 0, CFGF_NONE),
    CFG_INT("user_id_bytes", 0, CFGF_NONE),
    CFG_INT("prog_mem_hex_bytes", 0, CFGF_NONE),
    CFG_INT("ee_mem_hex_bytes", 0, CFGF_NONE),
    CFG_INT("prg_mem_shift", 0, CFGF_NONE),
    CFG_INT("test_memory_start", 0, CFGF_NONE),
    CFG_INT("test_memory_length", 0, CFGF_NONE),
    CFG_FLOAT("vpp", 0.0, CFGF_NONE)
};

cfg_opt_t device_opts[] = {
    CFG_STR("part_name", "NO_DEV", CFGF_NONE),
    CFG_STR("family", "NO_FAM", CFGF_NONE),
/*	CFG_INT("device_id"                 ,           0, CFGF_NONE), */
    CFG_STR("device_id", "0", CFGF_NONE),
    CFG_INT("program_mem", 0, CFGF_NONE),
    CFG_INT("ee_mem", 0, CFGF_NONE),
    CFG_INT("ee_addr", 0, CFGF_NONE),
    CFG_INT("config_words", 0, CFGF_NONE),
    CFG_INT("config_addr", 0, CFGF_NONE),
    CFG_INT("user_id_words", 0, CFGF_NONE),
    CFG_INT("user_id_addr", 0, CFGF_NONE),
    CFG_INT("bandgap_mask", 0, CFGF_NONE),
Пример #6
0
/*
 * read configuration file
 */
int
read_config(struct program_params *pp)
{
    static cfg_opt_t pv_opts[] = {
        CFG_INT("tier", 0, CFGF_NONE),
        CFG_FLOAT("pinningScore", 0, CFGF_NONE),
        CFG_STR("path", NULL, CFGF_NONE),
        CFG_INT_CB("maxUsedSpace", -1, CFGF_NONE, parse_size_value),
        CFG_END()
    };

    static cfg_opt_t volume_opts[] = {
        CFG_STR("LogicalVolume", NULL, CFGF_NONE),
        CFG_STR("VolumeGroup",   NULL, CFGF_NONE),
        CFG_FLOAT("timeExponent",  1.0/(2<<14), CFGF_NONE),
        CFG_FLOAT("hitScore",      16, CFGF_NONE),
        CFG_FLOAT("readMultiplier", 1, CFGF_NONE),
        CFG_FLOAT("writeMultiplier", 4, CFGF_NONE),
        CFG_INT_CB("pvmoveWait",     5*60, CFGF_NONE, parse_time_value),
        CFG_INT_CB("checkWait",      15*60, CFGF_NONE, parse_time_value),
        CFG_SEC("pv", pv_opts, CFGF_TITLE | CFGF_MULTI),
        CFG_END()
    };

    cfg_opt_t opts[] = {
        CFG_SEC("volume", volume_opts, CFGF_TITLE | CFGF_MULTI),
        CFG_END()
    };

    cfg_t *cfg;

    cfg = cfg_init(opts, CFGF_NONE);
    assert(cfg);

    // add verification functions
    cfg_set_validate_func(cfg, "volume|timeExponent",
        validate_require_positive);
    cfg_set_validate_func(cfg, "volume|hitScore",
        validate_require_positive);
    cfg_set_validate_func(cfg, "volume|readMultiplier",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|writeMultiplier",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|pv|pinningScore",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|pv|tier",
        validate_require_nonnegative);
    cfg_set_validate_func(cfg, "volume|pv|maxUsedSpace",
        validate_require_nonnegative);
    // TODO cfg_set_validate_func(cfg, "volume", validate_pv); // do they belong to volume, is there enough space

    switch(cfg_parse(cfg, pp->conf_file_path)) {
      case CFG_FILE_ERROR:
        fprintf(stderr, "Configuration file \"%s\" could not be read: %s\n",
            pp->conf_file_path, strerror(errno));
        return 1;
      case CFG_SUCCESS:
        break;
      case CFG_PARSE_ERROR:
        fprintf(stderr, "Configuration file errors, aborting\n");
        return 1;
      default:
        fprintf(stderr, "Internal error");
        assert(0);
    }

    pp->cfg = cfg;

    return 0;
}
Пример #7
0
  CFG_STR("bind", NULL, CFGF_NONE ),
  CFG_INT("port", -1, CFGF_NONE ),
  CFG_STR("interface", NULL, CFGF_NONE),
  CFG_SEC("acl", acl_opts, CFGF_NONE),
  CFG_INT("timeout", -1, CFGF_NONE),
  CFG_STR("family", "inet4", CFGF_NONE),
  CFG_BOOL("gzip_output", 0, CFGF_NONE),
  CFG_END()
};

static cfg_opt_t metric_opts[] = {
  CFG_STR("name", NULL, CFGF_NONE ),
#ifdef HAVE_LIBPCRE
  CFG_STR("name_match", NULL, CFGF_NONE ),
#endif
  CFG_FLOAT("value_threshold", -1, CFGF_NONE),
  CFG_STR("title", NULL, CFGF_NONE ),
  CFG_END()
};

static cfg_opt_t collection_group_opts[] = {
  CFG_SEC("metric", metric_opts, CFGF_MULTI),
  CFG_BOOL("collect_once", 0, CFGF_NONE),  
  CFG_INT("collect_every", 60, CFGF_NONE),    
  CFG_INT("time_threshold", 3600, CFGF_NONE),    /* tmax */
  CFG_END()
};

static cfg_opt_t metric_module_param[] = {
  CFG_STR("value", NULL, CFGF_NONE ),
  CFG_END()
Пример #8
0
Файл: conf.c Проект: noushi/bmon
#include <bmon/history.h>
#include <bmon/utils.h>

cfg_t *cfg;

static cfg_opt_t element_opts[] = {
	CFG_STR("description", NULL, CFGF_NONE),
	CFG_BOOL("show", cfg_true, CFGF_NONE),
	CFG_INT("rxmax", 0, CFGF_NONE),
	CFG_INT("txmax", 0, CFGF_NONE),
	CFG_INT("max", 0, CFGF_NONE),
	CFG_END()
};

static cfg_opt_t history_opts[] = {
	CFG_FLOAT("interval", 1.0f, CFGF_NONE),
	CFG_INT("size", 60, CFGF_NONE),
	CFG_STR("type", "64bit", CFGF_NONE),
	CFG_END()
};

static cfg_opt_t attr_opts[] = {
	CFG_STR("description", "", CFGF_NONE),
	CFG_STR("unit", "", CFGF_NONE),
	CFG_STR("type", "counter", CFGF_NONE),
	CFG_BOOL("history", cfg_false, CFGF_NONE),
	CFG_END()
};

static cfg_opt_t variant_opts[] = {
	CFG_FLOAT_LIST("div", "{}", CFGF_NONE),