Esempio n. 1
0
void CMDRead::execute()
{
    std::string line;

    std::ifstream input(filename.c_str());
    if(!input)
    {
        std::cout << "Could not open the given file, please check and try again" << std::endl;
    }
    else
    {
        while(std::getline(input, line))
        {
            Dispatcher* dispatcher = new Dispatcher(const_cast<char*>(line.c_str()));
            dispatcher->run();
        }
    }

    input.close();
}
Esempio n. 2
0
int main(int argc, char** argv)
{
    typedef FeedSynthetic<real_t> feed_t;
    
    datetime_t start = to_datetime("2010-01-01");
    datetime_t end 	 = to_datetime("2010-12-31");
    
    std::shared_ptr<feed_t> ptr(new feed_t(start, end, Frequency::Day));
    
    std::vector<feed_t::Data> data = {
        {"QQQ", 115, 0.2, 0.1}, 
        {"MSFT", 60, 0.2, 0.1}, 
        {"GOOG", 771, 0.2, 0.1}};
    
    ptr->add_values_from_generator(data);
    
    Dispatcher dispatcher;
    dispatcher.add_subject(ptr);
    dispatcher.run();
    return 0;
}
Esempio n. 3
0
int echo_entry(config_opt config_opts[])
{
	int i, port, socket_type;
	char proto[5];
	int worker_model = DISPATCHER_WORKER_MODEL_SINGLE;
	int num_workers = 5;

	for(i=0;;i++)
	{
		if (!strcmp(config_opts[i].name, ""))
		{
			// End of options
			break;
		}
		if (!strcmp(config_opts[i].name, "port"))
		{
			port = atoi(config_opts[i].value);
			if (port <= 0 || port >= 65535)
			{
				fprintf(stderr, "Invalid port specification: %s\n", config_opts[i].value);
				return 1;
			}
		}
		else if (!strcmp(config_opts[i].name, "proto"))
		{
			strncpy(proto, config_opts[i].value, sizeof(proto));
			proto[sizeof(proto)-1] = 0;
			if (!strcmp(proto, "tcp"))
			{
				socket_type = SOCK_STREAM;
			}
			else if (!strcmp(proto, "udp"))
			{
				socket_type = SOCK_DGRAM;
			}
			else
			{
				fprintf(stderr, "Invalid proto specification '%s'. Must be one of: tcp, udp\n", config_opts[i].value);
				return 1;
			}
		}
		else if (!strcmp(config_opts[i].name, "worker_model"))
		{
			if (!strcmp(config_opts[i].value, "single"))
			{
				worker_model = DISPATCHER_WORKER_MODEL_SINGLE;
			}
			else if (!strcmp(config_opts[i].value, "postfork"))
			{
				worker_model = DISPATCHER_WORKER_MODEL_POSTFORK;
			}
			else if (!strcmp(config_opts[i].value, "prefork"))
			{
				worker_model = DISPATCHER_WORKER_MODEL_PREFORK;
			}
			else if (!strcmp(config_opts[i].value, "thread"))
			{
				worker_model = DISPATCHER_WORKER_MODEL_THREAD;
			}
			else
			{
				fprintf(stderr, "Invalid worker_model specification: %s\n", config_opts[i].value);
				return 1;
			}
		}
		else if (!strcmp(config_opts[i].name, "num_workers"))
		{
			num_workers = atoi(config_opts[i].value);
			if (num_workers <= 0 || num_workers > 200)
			{
				fprintf(stderr, "Invalid num_workers specification: %s\n", config_opts[i].value);
				return 1;
			}
		}
		else
		{
			fprintf(stderr, "Unsupported option: %s\n", config_opts[i].name);
			return 1;
		}
	}

	Socket *sock = Socket_init(0);
	sock->create(sock, AF_INET, socket_type);
	if (sock == NULL)
	{
		fprintf(stderr, "Failed to create socket\n");
		return 1;
	}

	sock->set_flag(sock, O_NONBLOCK);
	if (sock->bind(sock, "0.0.0.0", port) < 0)
	{
		fprintf(stderr, "Bind to socket failed\n");
		return 1;
	}
	if (socket_type == SOCK_STREAM)
	{
		if (sock->listen(sock, 5) < 0)
		{
			fprintf(stderr, "Listen on socket failed\n");
			return 1;
		}
	}

	Dispatcher * disp = Dispatcher_init(worker_model, num_workers);
	disp->add_listener(disp, sock, echo_dispatcher_poll_callback, echo_dispatcher_run_callback, echo_dispatcher_cleanup_callback);
	disp->run(disp);

	disp->destroy(disp);
	sock->destroy(sock);

	return 0;
}
Esempio n. 4
0
int doMain(int argc, char* argv[])
{
    Dispatcher disp;
    return disp.run(argc, argv);
}