示例#1
0
cfw_client_t * system_setup(T_QUEUE *q, handle_msg_cb_t cb, void *cb_data)
{
	cfw_client_t * client;

	/* Initialize OS abstraction */
	os_init();

	/* Setup BSP and get main queue */
	*q = bsp_setup();

	/* start Quark watchdog */
	wdt_start(WDT_MAX_TIMEOUT_MS);

	/* Component framework and services setup */
	client = cfw_app_setup(*q, cb, cb_data);
	pr_info(LOG_MODULE_MAIN, "cfw init done");

	/* Cproxy is another (deprecated) way to communicate with the component
	 * framework, used by some test commands and some services. Initialize
	 * it here. */
	cproxy_init(*q);

	/* Initialize ARC shared structure and start it. */
	shared_data->ports = port_get_port_table();
	shared_data->services = services;
	shared_data->service_mgr_port_id = cfw_get_service_mgr_port_id();
	start_arc(0);

	return client;
}
示例#2
0
void tapioca_start(int recovery) {
	int rv;
	rv = sm_init(lp_config, base);
	assert(rv >= 0);
	rv = cproxy_init(paxos_config, base);
	assert(rv >= 0);
	if (recovery)
		sm_recovery();
	event_base_dispatch(base);
}
示例#3
0
void tapioca_start_and_join(void) {
	int rv;
	struct peer* p;
	rv = sm_init(lp_config, base);
	assert(rv >= 0);
	rv = cproxy_init(paxos_config, base);
	assert(rv >= 0);
	cproxy_submit_join(NodeType, LocalIpAddress, LocalPort);
	event_base_dispatch(base);
}
示例#4
0
/** The cfg_str may be a path to a file like...
 *
 *    /full/path
 *      or...
 *    ./relative/path
 *      or...
 *    ../another/relative/path
 *
 *  But not...
 *
 *    incorrect/relative/path
 *
 *  Paths are detected by the first character of  '/' or '.'.
 *
 *  The contents of the file should be in cfg_str format.
 */
int cproxy_init(char *cfg_str,
                char *behavior_str,
                int nthreads,
                struct event_base *main_base) {
    assert(nthreads > 1); // Main + at least one worker.
    assert(nthreads == settings.num_threads);

    if (cproxy_core_initted == false) {
        cproxy_core_initted = true;

        gethostname(cproxy_hostname, sizeof(cproxy_hostname));

        cproxy_init_a2a();
        cproxy_init_a2b();
        cproxy_init_b2b();
    }

    if ((cfg_str == NULL || strlen(cfg_str) <= 0) &&
        (false == settings.enable_mcmux_mode)) {
        return 0;
    }

    if (behavior_str != NULL &&
        (behavior_str[0] == '.' ||
         behavior_str[0] == '/')) {
        char *buf = readfile(behavior_str);
        if (buf != NULL) {
            int rv = cproxy_init(cfg_str, buf, nthreads, main_base);
            free(buf);
            return rv;
        } else {
            moxi_log_write("ERROR: could not read behavior file: %s\n", behavior_str);
            if (ml->log_mode != ERRORLOG_STDERR) {
                fprintf(stderr, "ERROR: could not read behavior file: %s\n", behavior_str);
            }
            exit(EXIT_FAILURE);
        }
    }

    if ((false == settings.enable_mcmux_mode) &&
        (cfg_str[0] == '.' || cfg_str[0] == '/')) {
        char *buf = readfile(cfg_str);
        if (buf != NULL) {
            int rv = cproxy_init(buf, behavior_str, nthreads, main_base);
            free(buf);
            return rv;
        } else {
            moxi_log_write("ERROR: could not read cfg file: %s\n", cfg_str);
            if (ml->log_mode != ERRORLOG_STDERR) {
                fprintf(stderr, "ERROR: could not read cfg file: %s\n", cfg_str);
            }
            exit(EXIT_FAILURE);
        }
    }

    if (behavior_str == NULL) {
        behavior_str = "";
    }

    // The vbucket feature only works in binary protocol.
    //
    behavior_default_g.downstream_protocol = proxy_downstream_binary_prot;

    char *env_usr = getenv("MOXI_SASL_PLAIN_USR");
    if (env_usr != NULL) {
        strncpy(behavior_default_g.usr, env_usr, sizeof(behavior_default_g.usr) - 1);
        behavior_default_g.usr[sizeof(behavior_default_g.usr) - 1] = '\0';

        moxi_log_write("env: MOXI_SASL_PLAIN_USR (%d)\n",
                       strlen(behavior_default_g.usr));
    }

    char *env_pwd = getenv("MOXI_SASL_PLAIN_PWD");
    if (env_pwd != NULL) {
        strncpy(behavior_default_g.pwd, env_pwd, sizeof(behavior_default_g.pwd) - 1);
        behavior_default_g.pwd[sizeof(behavior_default_g.pwd) - 1] = '\0';

        moxi_log_write("env: MOXI_SASL_PLAIN_PWD (%d)\n",
                       strlen(behavior_default_g.pwd));
    }

    proxy_behavior behavior =
        cproxy_parse_behavior(behavior_str,
                              behavior_default_g);

    if (behavior.cycle > 0) {
        msec_cycle = behavior.cycle;
    }

    msec_clockevent_base = main_base;
    msec_clock_handler(0, 0, NULL);

    if (true == settings.enable_mcmux_mode) {
        return cproxy_init_mcmux_mode(settings.port,
                                      behavior,
                                      nthreads);
    }

    // Not jid format and not a URL, so it must be a simple cmd-line
    // or file-based config.
    //
    if (strchr(cfg_str, '@') == NULL &&
        strstr(cfg_str, "http://") == NULL) {
        return cproxy_init_string(cfg_str,
                                  behavior,
                                  nthreads);
    }

    if (settings.verbose > 2) {
        cproxy_dump_behavior(&behavior, "cproxy_init_agent", 2);
    }

    return cproxy_init_agent(cfg_str,
                             behavior,
                             nthreads);
}