RemoteMessagingSystem::RemoteMessagingSystem (MessagingSystem* system, DistackInfo* info)
	: m_messagingSystem( system ), m_commSystem( NULL ), distackInfo( info) {

	//
	// create the communication system of choice
	//

	string remoteMessaging = Configuration::instance(distackInfo)->getRemoteMessaging ();

#ifdef OMNET_SIMULATION
	if (remoteMessaging == "OMNET_TCP")
		m_commSystem = new RemoteCommSystemOmnetTcp( distackInfo );
	else if (remoteMessaging == "OMNET_PATH")
		m_commSystem = new RemoteCommSystemOmnetPathbased( distackInfo );
	else if (remoteMessaging == "OMNET_RING")
		m_commSystem = new RemoteCommSystemOmnetRing( distackInfo );
	else
		m_commSystem = new RemoteCommSystemNone( distackInfo ); // default case: no comm
#else
	if (remoteMessaging == "TCP_SOCKET")
		m_commSystem = new RemoteCommSystemTcpSocket( distackInfo );
	else if (remoteMessaging == "GIST")
		m_commSystem = new RemoteCommSystemGist( distackInfo );
	else
		m_commSystem = new RemoteCommSystemNone( distackInfo ); // default case: no comm
#endif // OMNET_SIMULATION

	if (m_commSystem != NULL) {
		m_commSystem->setMessagingSystem (this);
		logging_debug( "running remote messaging system: " + m_commSystem->getName());
	} else {
		logging_warn( "no remote messaging system created. Remote messaging will fail!");
	}
}
Ejemplo n.º 2
0
void table_add_player(table *t, player *p)
{

	if (t->num_players == 3)
	{
		logging_critical("Can't add player %s to table %s because limit has been reached.", p->name, t->name);
		return;
	}

	*(t->players + t->num_players) = p;
	t->num_players++;

	send_str(p->socket, "Welcome to the table. Please wait for others to join.\n");
	send_str(p->socket, "(you can talk to other users in the room whilst you wait)\n");

	logging_debug("\nNow %i players on table %s. Waiting for %d more.\n",
		t->num_players,
		t->name,
		(3 - t->num_players)
	);

	table_broadcast(t, "Player %s has joined %s.\n", p->name, t->name);

	if (t->num_players == 3)
		init_new_game(t);

}
Ejemplo n.º 3
0
void deal_out_new_cards(table *t)
{
	int i;
	card *tmp;
	card *one, *two;

	clean_up_game(t);

	t->card_deck = generate_new_deck();

	//burn a card.
	tmp = (card*) stack_pop(t->card_deck);

	logging_debug("table %s, burning: %s", t->name, card_tostring(tmp));

	//first pass
	for (i = 0; i < t->num_players; i++)
	{
		t->players[i]->cards[0] = (card*) stack_pop(t->card_deck);
	}

	//second pass
	for (i = 0; i < t->num_players; i++)
	{
		t->players[i]->cards[1] = (card*) stack_pop(t->card_deck);

	//	send_str(t->players[i]->socket,
	//	logging_debug("%s, you have been dealt:\n%s,\n%s\n", t->players[i]->name, card_tostring(t->players[i]->cards[0]), card_tostring(t->players[i]->cards[1]));
		send_str(t->players[i]->socket, "%s, you have been dealt: %s, %s ", t->players[i]->name, card_tostring(t->players[i]->cards[0]), card_tostring(t->players[i]->cards[1]));
	}
	
}
Ejemplo n.º 4
0
void init_new_game(table *t)
{
	int i;
	player *p;

	t->state = IN_PROGRESS;
	t->current_player = 0;
	t->card_deck = NULL;

	logging_debug("A game has started on table: %s!", t->name);
	table_broadcast(t, "The game has started!!!\n");
	table_broadcast(t, "\n-- BEGIN LIST OF PLAYERS --\n");
	
	for (i = 0; i < t->num_players; i++)
	{
		p = t->players[i];
		table_broadcast(t, "%d: %s\n", (i + 1), p->name);
	}

	table_broadcast(t, "-- END LIST OF PLAYERS --\n");

	//print the game rules
	table_broadcast(t, "Hopefully you already know how to play\n");
	table_broadcast(t, "Texas Hold'em Poker. You will be dealt\n");
	table_broadcast(t, "Your two cards and you make your choices\n");
	table_broadcast(t, "(when prompted to) of\n");
	table_broadcast(t, "b <<amount>> to bet or raise\n");
	table_broadcast(t, "c            to call\n");
	table_broadcast(t, "f            to fold\n");

	deal_out_new_cards(t);

	t->deck = generate_new_deck();
	
	//deal out the cards
	for (i = 0; i < t->num_players; i++)
	{
		p = t->players[i];
		p->card_one = (card*) stack_pop(t->deck);
		send_str(t->players[i]->socket, "Your first card is a %s\n", card_tostring(p->card_one));
		logging_info("%s dealt %s", t->players[i]->name, card_tostring(p->card_one));
	}

	for (i = 0; i < t->num_players; i++)
	{
		p = t->players[i];
		p->card_two = (card*) stack_pop(t->deck);
		send_str(t->players[i]->socket, "Your second card is a %s\n", card_tostring(p->card_two));
		logging_info("%s dealt %s", t->players[i]->name, card_tostring(p->card_two));
	}

}
Ejemplo n.º 5
0
/**
 * @brief Initialize the NSSI RPC mechanism.
 *
 * This implementation of \b nssi_rpc_init initializes the
 * Portals library and interface so that we can use Portals
 * as the underlying communication protocol.
 *
 * @param pid  @input The ID to use for this process.
 */
int nssi_rpc_init(
    const nssi_rpc_transport rpc_transport,
    const nssi_rpc_encode    rpc_encode,
    const char              *url)
{
    int rc;

    NNTI_transport_id_t transport_id;

    log_debug(rpc_debug_level, "************************************************************ entered");

    if (rpc_initialized) return NSSI_OK;

    /* check to see if logging is enabled */
    if (logger_not_initialized()) {
        logger_set_file(stderr);
    }

    /* make sure the timer works properly */
//    rc = nssi_timer_test();
//    if (rc != NSSI_OK) {
//        log_fatal(rpc_debug_level, "nssi_timer_test() failed");
//        return rc;
//    }

    /* stash the transport and encoding types so we know how to cleanup on exit */
//    transport = rpc_transport;
    encoding  = rpc_encode;

    /* initialize the transport mechanism */
    switch (rpc_transport) {
        case NSSI_RPC_PTL:
            transport_id=NNTI_TRANSPORT_PORTALS;
            break;
        case NSSI_RPC_IB:
            transport_id=NNTI_TRANSPORT_IB;
            break;
        case NSSI_RPC_LUC:
            transport_id=NNTI_TRANSPORT_LUC;
            break;
        case NSSI_RPC_GEMINI:
            transport_id=NNTI_TRANSPORT_GEMINI;
            break;
        case NSSI_RPC_MPI:
            transport_id=NNTI_TRANSPORT_MPI;
            break;
        default:
            rc = NSSI_ENOENT;
            log_error(rpc_debug_level, "the transport scheme %d does not exist", rpc_transport);
            return rc;
    }

    rc = NNTI_init(
            transport_id,
            url,
            &transports[rpc_transport]);
    if (rc != NNTI_OK) {
        log_fatal(rpc_debug_level,"failed");
        return rc;
    }

    /* initialize the xdr-encoding mechanism */
    switch (rpc_encode) {
        case NSSI_RPC_XDR:
            rc = nssi_xdr_init();
            if (rc != NSSI_OK) {
                log_fatal(rpc_debug_level,"failed, %d", rc);
                return rc;
            }
            break;

        default:
            rc = NSSI_ENOENT;
            log_error(rpc_debug_level, "the transport scheme "
            "does not exist");
            return rc;
    }

    config_init(&nssi_config);
    config_get_from_env(&nssi_config);
    if (nssi_config.use_buffer_queue) {
        trios_buffer_queue_init(
                &send_bq,
                nssi_config.buffer_queue_initial_size,
                nssi_config.buffer_queue_max_size,
                nssi_config.buffer_queue_create_if_empty,
                &transports[rpc_transport],
                NNTI_SEND_SRC,
                NSSI_SHORT_REQUEST_SIZE);
        trios_buffer_queue_init(
                &recv_bq,
                nssi_config.buffer_queue_initial_size,
                nssi_config.buffer_queue_max_size,
                nssi_config.buffer_queue_create_if_empty,
                &transports[rpc_transport],
                NNTI_RECV_DST,
                NSSI_SHORT_RESULT_SIZE);
        trios_buffer_queue_init(
                &rdma_target_bq,
                nssi_config.rdma_buffer_queue_initial_size,
                nssi_config.rdma_buffer_queue_max_size,
                nssi_config.rdma_buffer_queue_create_if_empty,
                &transports[rpc_transport],
                (NNTI_buf_ops_t)(NNTI_GET_SRC|NNTI_PUT_DST),
                nssi_config.rdma_buffer_queue_buffer_size);
        trios_buffer_queue_init(
                &rdma_get_bq,
                nssi_config.rdma_buffer_queue_initial_size,
                nssi_config.rdma_buffer_queue_max_size,
                nssi_config.rdma_buffer_queue_create_if_empty,
                &transports[rpc_transport],
                NNTI_GET_DST,
                nssi_config.rdma_buffer_queue_buffer_size);
        trios_buffer_queue_init(
                &rdma_put_bq,
                nssi_config.rdma_buffer_queue_initial_size,
                nssi_config.rdma_buffer_queue_max_size,
                nssi_config.rdma_buffer_queue_create_if_empty,
                &transports[rpc_transport],
                NNTI_PUT_SRC,
                nssi_config.rdma_buffer_queue_buffer_size);
    }

    rpc_initialized = true;

    if (logging_debug(rpc_debug_level)) {
        fprint_NNTI_peer(logger_get_file(), "transports[rpc_transport].me",
                "end of nssi_rpc_init", &transports[rpc_transport].me);
    }

    log_debug(rpc_debug_level, "************************************************************  exit");

    return NSSI_OK;
}
Ejemplo n.º 6
0
Module::Module ( ModuleConfiguration config, DistackInfo* info )
#endif // OMNET_SIMULATION
:	m_name			(config.name),
	m_library		(config.library, info, m_libraryPaths),
	m_internal		(NULL),
	distackInfo		(info)
{
#ifdef OMNET_SIMULATION
	m_distackModule = omnetModule;	
#endif // OMNET_SIMULATION

	//
	// init the module library by calling its create-function
	//

	m_internal = m_library.functionCall<DistackModuleInterface*,unsigned int> 
					(MODULE_INTERFACE_ENTRYFUNCTION, ID_COUNTER++);

	goodstate = (m_internal != NULL);
	
	logging_debug( "loading module library " + config.library + " " + 
			(goodstate ? "succeeded" : "failed"));

	if (m_internal != NULL) {

		m_internal->distackInfo = distackInfo;
	
#ifdef OMNET_SIMULATION

		//
		// configure the timers for the node in OMNET_SIMULATION
		// 
		
		Timer* timer = dynamic_cast<Timer*> (m_internal);
		if (timer != NULL)
			m_distackModule->registerTimer (timer);

		//
		// set the DistackModuleInterface distackModule, so that
		// the modules can access the omnet module
		//

		m_internal->omnetModule = m_distackModule;
		timer->setDistackModule (m_distackModule);

#endif // OMNET_SIMULATION

		//
		// configure the module with the stuff from the xml config file
		//

		goodstate &= m_internal->configure (config);

		//
		// if the module needs some packet parsing capabilities then 
		// we configure its PacketFactory to the global factory
		//

		m_library.functionCall<int,PacketFactory*> 
			(MODULE_INTERFACE_INIT_PACKETFACTORY, PacketFactory::instance ());

		//
		// if the module wants logging, configure it
		//

		m_library.functionCall<int,Log*> 
			(MODULE_INTERFACE_INIT_LOGGING, Log::instance(distackInfo));
	
	} // if (m_internal != NULL)
}
Ejemplo n.º 7
0
void logging_debugfv(const char *format, va_list vargs) {
    char message[logging_MESSAGE_MAX_LENGTH];
    vsnprintf(message, sizeof(message), format, vargs);
    logging_debug(message);
}