/**
 * Perform a platform reboot
 *
 * @param [in] unused
 *
 * @return E_ERR_SUCCESS if successful
 * @return E_ERR_FAILED otherwise
 */
e_mmgr_errors_t platform_reboot(modem_info_t *unused)
{
    e_mmgr_errors_t ret = E_ERR_SUCCESS;

    (void)unused;
    LOG_INFO("PLATFORM REBOOT. [SHTDWN] Reboot requested by %s", MODULE_NAME);

    /* force commit buffer cache to disk to prevent data lost */
    sync();
    broadcast_action(E_ACTION_INTENT_REBOOT);
    return ret;
}
Exemplo n.º 2
0
int Gobang::handle_player_action(sprite_t* p, const uint8_t body[], int len)
{
	TRACE_LOG("Gobang Handle Player Action: uid=%u, grpid=%lu",
				p->id, m_gamegrp->id);

struct actpkg {
	uint32_t uid;
	Chess_Pos_Type row, col;
} __attribute__((__packed__));

	if ( started_check(p, len, sizeof(actpkg)) == -1 ) return -1;

	int i = 0;
	actpkg apkg;
	UNPKG_UINT(body, apkg.uid, i);
	UNPKG_UINT(body, apkg.row, i);
	UNPKG_UINT(body, apkg.col, i);
	if ( (p->id != apkg.uid) || (m_nxmover != apkg.uid) ) {
		ERROR_RETURN( ("UserID Mismatch, uid=%u, %u, %u",
						p->id, apkg.uid, m_nxmover), -1 );
	}

	REMOVE_TIMER(p, timerid);
	if ( place_chess(apkg.row, apkg.col) == -1 ) return -1;

	broadcast_action(body, p->id);
	++m_nsteps; // increase number of chesses placed

	std::vector<ChessCoord> adjchesses;
	if ( determine_winner(apkg.row, apkg.col, adjchesses) ) {
		notify_winner(p->id, adjchesses);
		m_nxmover = 0;
		send_game_score(p, 0, 1);

		DEBUG_LOG("Gobang Winner Determined\t[winner=%u]", p->id);
		return GER_end_of_game;
	} else if (draw()) {
		notify_winner(0);
		m_nxmover = 0;
		send_game_score(p, 2, 2);
		return GER_draw_game;
	}

	set_nxmover();
	sprite_t* op = get_sprite_from_gamegrp(m_nxmover, m_gamegrp);
	time_t exptm = time(0) + 62;
	timerid = ADD_TIMER_EVENT(op, on_timer_expire, 0, exptm);
	return 0;
}