예제 #1
0
파일: Sigil.cpp 프로젝트: mdlui/Sigil2
////////////////////////////////////////////////////////////
// event generation loop
////////////////////////////////////////////////////////////
void Sigil::generateEvents()
{
    assert(start_frontend != nullptr);

    assert(parse_backend != nullptr);
    assert(create_backend != nullptr);
    assert(exit_backend != nullptr);

    assert(num_threads > 0);

    /* the event consumers (the backend)
     * are started in the event manager */
    parse_backend();
    mgr = std::make_shared<sgl::EventManager>(num_threads, create_backend);

    start_frontend();
    mgr->finish();

    exit_backend();
}
예제 #2
0
파일: config.c 프로젝트: dajidan/paxosudp
static int 
parse_line(struct evpaxos_config* c, char* line)
{
	int rv;
	char* tok;
	char* sep = " ";
	struct option* opt;
	
	line = strtrim(line);
	tok = strsep(&line, sep);
	
	if (strcasecmp(tok, "a") == 0 || strcasecmp(tok, "acceptor") == 0) {
		if (c->acceptors_count >= MAX_N_OF_PROPOSERS) {
			paxos_log_error("Number of acceptors exceded maximum of: %d\n",
				MAX_N_OF_PROPOSERS);
			return 0;
		}
		struct address* addr = &c->acceptors[c->acceptors_count++];
		return parse_address(line, addr);
	}
	
	if (strcasecmp(tok, "p") == 0 || strcasecmp(tok, "proposer") == 0) {
		if (c->proposers_count >= MAX_N_OF_PROPOSERS) {
			paxos_log_error("Number of proposers exceded maximum of: %d\n",
				MAX_N_OF_PROPOSERS);
			return 0;
		}
		struct address* addr = &c->proposers[c->proposers_count++];
		return parse_address(line, addr);
	}

	if (strcasecmp(tok, "l") == 0 || strcasecmp(tok, "learner") == 0) {
		if (c->learners_count >= MAX_N_OF_PROPOSERS) {
			paxos_log_error("Number of learners exceded maximum of: %d\n",
				MAX_N_OF_PROPOSERS);
			return 0;
		}
		struct address* addr = &c->learners[c->learners_count++];
		return parse_address(line, addr);
	}
	
	if (strcasecmp(tok, "r") == 0 || strcasecmp(tok, "replica") == 0) {
		if (c->proposers_count >= MAX_N_OF_PROPOSERS ||
			c->acceptors_count >= MAX_N_OF_PROPOSERS ) {
				paxos_log_error("Number of replicas exceded maximum of: %d\n",
					MAX_N_OF_PROPOSERS);
				return 0;
		}
		struct address* pro_addr = &c->proposers[c->proposers_count++];
		struct address* acc_addr = &c->acceptors[c->acceptors_count++];
		int rv = parse_address(line, pro_addr);
		address_copy(pro_addr, acc_addr);
		return rv;
	}
	
	line = strtrim(line);
	opt = lookup_option(tok);
	if (opt == NULL)
		return 0;

	switch (opt->type) {
		case option_boolean:
			rv = parse_boolean(line, opt->value);
			if (rv == 0) paxos_log_error("Expected 'yes' or 'no'\n");
			break;
		case option_integer:
			rv = parse_integer(line, opt->value);
			if (rv == 0) paxos_log_error("Expected number\n");
			break;
		case option_string:
			rv = parse_string(line, opt->value);
			if (rv == 0) paxos_log_error("Expected string\n");
			break;
		case option_verbosity:
			rv = parse_verbosity(line, opt->value);
			if (rv == 0) paxos_log_error("Expected quiet, error, info, or debug\n");
			break;
		case option_backend:
			rv = parse_backend(line, opt->value);
			if (rv == 0) paxos_log_error("Expected memory, bdb or lmdb\n");
			break;
		case option_bytes:
			rv = parse_bytes(line, opt->value);
			if (rv == 0) paxos_log_error("Expected number of bytes.\n");
	}
	
	return rv;
}