コード例 #1
0
void playmp_controller::finish_side_turn()
{
	play_controller::finish_side_turn();

	//halt and cancel the countdown timer
	reset_countdown();
}
コード例 #2
0
void playmp_controller::finish_side_turn(){
	play_controller::finish_side_turn();

	//just in case due to an exception turn_data_ has not been deleted in after_human_turn
	delete turn_data_;
	turn_data_ = NULL;

	//halt and cancel the countdown timer
	reset_countdown();
}
コード例 #3
0
ファイル: luci-bwc.c プロジェクト: 8devices/luci
static int run_daemon(void)
{
	FILE *info;
	uint32_t rxb, txb, rxp, txp;
	uint32_t udp, tcp, other;
	uint16_t rate;
	uint8_t rssi, noise;
	float lf1, lf5, lf15;
	char line[1024];
	char ifname[16];
	int i;
	void *iw;
	struct sigaction sa;

	struct stat s;
	const char *ipc = stat("/proc/net/nf_conntrack", &s)
		? "/proc/net/ip_conntrack" : "/proc/net/nf_conntrack";

	switch (fork())
	{
		case -1:
			perror("fork()");
			return -1;

		case 0:
			if (chdir("/") < 0)
			{
				perror("chdir()");
				exit(1);
			}

			close(0);
			close(1);
			close(2);
			break;

		default:
			return 0;
	}

	/* setup USR1 signal handler to reset timer */
	sa.sa_handler = reset_countdown;
	sa.sa_flags   = SA_RESTART;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGUSR1, &sa, NULL);

	/* write pid */
	if (writepid())
	{
		fprintf(stderr, "Failed to write pid file: %s\n", strerror(errno));
		return 1;
	}

	/* initialize iwinfo */
	iw = iwinfo_open();

	/* go */
	for (reset_countdown(0); countdown >= 0; countdown--)
	{
		/* alter progname for ps, top */
		memset(progname, 0, prognamelen);
		snprintf(progname, prognamelen, "luci-bwc %d", countdown);

		if ((info = fopen("/proc/net/dev", "r")) != NULL)
		{
			while (fgets(line, sizeof(line), info))
			{
				if (strchr(line, '|'))
					continue;

				if (sscanf(line, IF_SCAN_PATTERN, ifname, &rxb, &rxp, &txb, &txp))
				{
					if (strncmp(ifname, "lo", sizeof(ifname)))
						update_ifstat(ifname, rxb, rxp, txb, txp);
				}
			}

			fclose(info);
		}

		if (iw)
		{
			for (i = 0; i < 5; i++)
			{
#define iwinfo_checkif(pattern) \
				do {                                                      \
					snprintf(ifname, sizeof(ifname), pattern, i);         \
					if (iwinfo_update(iw, ifname, &rate, &rssi, &noise))  \
					{                                                     \
						update_radiostat(ifname, rate, rssi, noise);      \
						continue;                                         \
					}                                                     \
				} while(0)

				iwinfo_checkif("wlan%d");
				iwinfo_checkif("ath%d");
				iwinfo_checkif("wl%d");
			}
		}

		if ((info = fopen(ipc, "r")) != NULL)
		{
			udp   = 0;
			tcp   = 0;
			other = 0;

			while (fgets(line, sizeof(line), info))
			{
				if (strstr(line, "TIME_WAIT"))
					continue;

				if (sscanf(line, "%*s %*d %s", ifname) || sscanf(line, "%s %*d", ifname))
				{
					if (!strcmp(ifname, "tcp"))
						tcp++;
					else if (!strcmp(ifname, "udp"))
						udp++;
					else
						other++;
				}
			}

			update_cnstat(udp, tcp, other);

			fclose(info);
		}

		if ((info = fopen("/proc/loadavg", "r")) != NULL)
		{
			if (fscanf(info, LD_SCAN_PATTERN, &lf1, &lf5, &lf15))
			{
				update_ldstat((uint16_t)(lf1  * 100),
							  (uint16_t)(lf5  * 100),
							  (uint16_t)(lf15 * 100));
			}

			fclose(info);
		}

		sleep(STEP_TIME);
	}

	unlink(PID_PATH);

	if (iw)
		iwinfo_close(iw);

	return 0;
}
コード例 #4
0
// *************************************************************************************************
// @fn          init_global_variables
// @brief       Initialize global variables.
// @param       none
// @return      none
// *************************************************************************************************
void init_global_variables(void)
{
    // --------------------------------------------
    // Apply default settings

    // set menu pointers to default menu items
    //		ptrMenu_L1 = &menu_L1_Time;
			ptrMenu_L1 = &menu_L1_Countdown;
    //      ptrMenu_L1 = &menu_L1_Alarm;
    //      ptrMenu_L1 = &menu_L1_Heartrate;
    //      ptrMenu_L1 = &menu_L1_Speed;
    //      ptrMenu_L1 = &menu_L1_Temperature;
    //      ptrMenu_L1 = &menu_L1_Altitude;
    //      ptrMenu_L1 = &menu_L1_Acceleration;
     		ptrMenu_L2 = &menu_L2_Date;
    //      ptrMenu_L2 = &menu_L2_Stopwatch;
    //      ptrMenu_L2 = &menu_L2_Rf;
    //      ptrMenu_L2 = &menu_L2_Ppt;
    //      ptrMenu_L2 = &menu_L2_Sync;
    //      ptrMenu_L2 = &menu_L2_Distance;
    //      ptrMenu_L2 = &menu_L2_Calories;
    //      ptrMenu_L2 = &menu_L2_Battery;
    //      ptrMenu_L2 = &menu_L2_RFBSL;

    // Assign LINE1 and LINE2 display functions
    fptr_lcd_function_line1 = ptrMenu_L1->display_function;
    fptr_lcd_function_line2 = ptrMenu_L2->display_function;

    // Init system flags
    button.all_flags = 0;
    sys.all_flags = 0;
    request.all_flags = 0;
    display.all_flags = 0;
    message.all_flags = 0;

    // Force full display update when starting up
    display.flag.full_update = 1;

#ifndef ISM_US
    // Use metric units when displaying values
    sys.flag.use_metric_units = 1;
#endif

    // Read calibration values from info memory
    read_calibration_values();

    // Set system time to default value
    reset_clock();

    // Set date to default value
    reset_date();

    // Set alarm time to default value
    reset_alarm();

    // Set buzzer to default value
    reset_buzzer();

    // Reset stopwatch
    reset_stopwatch();

    // Reset altitude measurement
    reset_altitude_measurement();

    // Reset acceleration measurement
    reset_acceleration();

    // Reset countdown
    reset_countdown();

    // Reset BlueRobin stack
    reset_bluerobin();

    // Reset SimpliciTI stack
    reset_rf();

    // Reset temperature measurement
    reset_temp_measurement();

    // Reset battery measurement
    reset_batt_measurement();
    battery_measurement();
}
コード例 #5
0
void playmp_controller::linger(upload_log& log)
{
	LOG_NG << "beginning end-of-scenario linger\n";
	browse_ = true;
	linger_ = true;
	// If we need to set the status depending on the completion state
	// we're needed here.
	gui_->set_game_mode(game_display::LINGER_MP);

	// this is actually for after linger mode is over -- we don't want to
	// stay stuck in linger state when the *next* scenario is over.
	gamestate_.classification().completion = "running";
	// End all unit moves
	for (unit_map::iterator u = units_.begin(); u != units_.end(); u++) {
		u->second.set_user_end_turn(true);
	}
	//current_team().set_countdown_time(0);
	//halt and cancel the countdown timer
	reset_countdown();

	set_end_scenario_button();

	// switch to observer viewpoint
	gui_->set_team(0,true);
	gui_->recalculate_minimap();
	gui_->invalidate_all();
	gui_->draw(true,true);

	bool quit;
	do {
		quit = true;
		try {
			// reimplement parts of play_side()
			player_number_ = first_player_;
			turn_data_ = new turn_info(player_number_, replay_sender_, undo_stack_);
			turn_data_->host_transfer().attach_handler(this);

			play_human_turn();
			turn_over_ = true;  // We don't want to linger mode to add end_turn to replay
			after_human_turn();
			LOG_NG << "finished human turn" << std::endl;
		} catch (game::load_game_exception&) {
			LOG_NG << "caught load-game-exception" << std::endl;
			// this should not happen, the option to load a game is disabled
			log.quit(turn());
			throw;
		} catch (end_level_exception&) {
			// thrown if the host ends the scenario and let us advance
			// to the next level
			LOG_NG << "caught end-level-exception" << std::endl;
			reset_end_scenario_button();
			throw;
		} catch (end_turn_exception&) {
			// thrown if the host leaves the game (sends [leave_game]), we need
			// to stay in this loop to stay in linger mode, otherwise the game
			// gets aborted
			LOG_NG << "caught end-turn-exception" << std::endl;
			quit = false;
		} catch (network::error&) {
			LOG_NG << "caught network-error-exception" << std::endl;
			quit = false;
		}
	} while (!quit);

	reset_end_scenario_button();

	LOG_NG << "ending end-of-scenario linger\n";
}
コード例 #6
0
// *************************************************************************************************
// @fn          wakeup_event
// @brief       Process external / internal wakeup events.
// @param       none
// @return      none
// *************************************************************************************************
void wakeup_event(void)
{
	// Enable idle timeout
	sys.flag.idle_timeout_enabled = 1;

	// If buttons are locked, only display "buttons are locked" message
	if (button.all_flags && sys.flag.lock_buttons)
	{
		// Show "buttons are locked" message synchronously with next second tick
		if (!(BUTTON_NUM_IS_PRESSED && BUTTON_DOWN_IS_PRESSED))
		{
			message.flag.prepare     = 1;
			message.flag.type_locked = 1;
		}
		
		// Clear buttons
		button.all_flags = 0;	
	}
	// Process long button press event (while button is held)
	else if (button.flag.up_long)
	{
		// Clear button event
		button.flag.up_long = 0;

		// Call sub menu function
		//ptrMenu_L1->mx_function(LINE1);

		// Set display update flag
		//display.flag.full_update = 1;
	}
	else if (button.flag.down_long)
	{
		// Clear button event
		button.flag.down_long = 0;

		// Call sub menu function
		//ptrMenu_L2->mx_function(LINE2);

		// Stop Countdown and Countup
		stop_countdown();
		stop_countup();

		// Reset Countdown and Countup
		reset_countdown();
		reset_countup();

		// Set display update flag
		display.flag.full_update = 1;	
	}
	// Process single button press event (after button was released)
	else if (button.all_flags)
	{
		// M1 button event ---------------------------------------------------------------------
		// (Short) Advance to next menu item
		if(button.flag.star) 
		{
			/*
			// SW1 IS NOW LOCATED IN PORTS.C FOR IMPROVED RESPONSE
			*/

			// Clean up display before activating next menu item 
			//fptr_lcd_function_line1(LINE1, DISPLAY_LINE_CLEAR);
			
			// Go to next menu entry
			//ptrMenu_L1 = ptrMenu_L1->next;
				
			// Assign new display function
			//fptr_lcd_function_line1 = ptrMenu_L1->display_function;

			// Set Line1 display update flag
			//display.flag.line1_full_update = 1;

			// Clear button flag
			button.flag.star = 0;
		}
		// NUM button event ---------------------------------------------------------------------
		// (Short) Advance to next menu item
		else if(button.flag.num || button.flag.num_long)
		{
			// SW2
			// Enable buzzer
			sCountdown.buzzer = 1;

			// Clean up display before activating next menu item 
			//fptr_lcd_function_line2(LINE2, DISPLAY_LINE_CLEAR);

			// Go to next menu entry
			//ptrMenu_L2 = ptrMenu_L2->next;

			// Assign new display function
			//fptr_lcd_function_line2 = ptrMenu_L2->display_function;

			// Set Line2 display update flag
			//display.flag.line2_full_update = 1;

			// Clear button flag
			button.flag.num_long = 0;
			button.flag.num = 0;
		}	
		// UP button event ---------------------------------------------------------------------
		// Activate user function for Line1 menu item
		else if(button.flag.up) 	
		{
			// Call direct function
			//ptrMenu_L1->sx_function(LINE1);

			// UP BUTTON
			// Start / pause / reset Countdown and Countup
			if (sCountdown.mode == COUNTDOWN_MODE_OFF || sCountdown.mode == COUNTDOWN_MODE_RESET)
			{
				if (sCountdown.minute == 0 && sCountdown.second == 0 || sCountup.minute == 10 && sCountup.second == 0)
				{
					reset_countdown();
					reset_countup();
					display.flag.full_update = 1;
				}
				else {
					// Start Countdown and Countup
					start_countdown();
					start_countup();
				}
			}
			else
			{
				// Stop Countdown and Countup
				stop_countdown();
				//stop_countup();
			}


			// Set Line1 display update flag
			//display.flag.line1_full_update = 1;
	
			// Clear button flag	
			button.flag.up = 0;
		}			
		// DOWN button event ---------------------------------------------------------------------
		// Activate user function for Line2 menu item
		else if(button.flag.down) 	
		{
			// Call direct function
			//ptrMenu_L2->sx_function(LINE2);

			// DOWN BUTTON
			// Enable power saving using drawFlag
			sCountdown.drawFlag = 1;

			// When in COUNTDOWN_MODE_RESET state, allow alteration of Countdown start point
			if (sCountdown.mode == COUNTDOWN_MODE_RESET)
			{
				// Decrement minutes
				sCountdown.minute--;

				// Stop decrements at 0 or below
				if (sCountdown.minute == 0)
				{
					sCountdown.minute = 10;
				}

				sCountdown.drawFlag = 2;
				display.flag.update_countdown = 1;
			}

			// Set Line1 display update flag
			//display.flag.line2_full_update = 1;
	
			// Clear button flag	
			button.flag.down = 0;
		}			
	}
	
	// Process internal events
	if (sys.all_flags)
	{
		// Idle timeout ---------------------------------------------------------------------
		if (sys.flag.idle_timeout)
		{
			// Clear timeout flag	
			sys.flag.idle_timeout = 0;	
			
			// Clear display
			clear_display();	

			// Set display update flags
			display.flag.full_update = 1;
		}
	}
	
	// Disable idle timeout
	sys.flag.idle_timeout_enabled = 0;
}
コード例 #7
0
void playmp_controller::linger()
{
	LOG_NG << "beginning end-of-scenario linger\n";
	browse_ = true;
	linger_ = true;
	// If we need to set the status depending on the completion state
	// we're needed here.
	gui_->set_game_mode(game_display::LINGER_MP);

	// this is actually for after linger mode is over -- we don't want to
	// stay stuck in linger state when the *next* scenario is over.
	set_completion setter(saved_game_,"running");
	// End all unit moves
	gamestate_.board_.set_all_units_user_end_turn();
	//current_team().set_countdown_time(0);
	//halt and cancel the countdown timer
	reset_countdown();

	set_end_scenario_button();

	if ( get_end_level_data_const().transient.reveal_map ) {
		// Change the view of all players and observers
		// to see the whole map regardless of shroud and fog.
		update_gui_to_player(gui_->viewing_team(), true);
	}
	bool quit;
	do {
		quit = true;
		try {
			// reimplement parts of play_side()
			player_number_ = first_player_;
			turn_data_.send_data();
			end_turn_ = false;
			play_human_turn();
			after_human_turn();
			LOG_NG << "finished human turn" << std::endl;
		} catch (game::load_game_exception&) {
			LOG_NG << "caught load-game-exception" << std::endl;
			// this should not happen, the option to load a game is disabled
			throw;
		} catch (end_level_exception&) {
			// thrown if the host ends the scenario and let us advance
			// to the next level
			LOG_NG << "caught end-level-exception" << std::endl;
			reset_end_scenario_button();
			throw;
		} catch (end_turn_exception&) {
			// thrown if the host leaves the game (sends [leave_game]), we need
			// to stay in this loop to stay in linger mode, otherwise the game
			// gets aborted
			LOG_NG << "caught end-turn-exception" << std::endl;
			quit = false;
		} catch (network::error&) {
			LOG_NG << "caught network-error-exception" << std::endl;
			quit = false;
		}
	} while (!quit);

	reset_end_scenario_button();

	LOG_NG << "ending end-of-scenario linger\n";
}
コード例 #8
0
void playmp_controller::linger()
{
	mouse_handler_.do_right_click(false);

	browse_ = true;
	linger_ = true;
	// If we need to set the status depending on the completion state
	// we're needed here.
	gui_->set_game_mode(game_display::LINGER_MP);

	// this is actually for after linger mode is over -- we don't want to
	// stay stuck in linger state when the *next* scenario is over.
	gamestate_.classification().completion = "running";
	//current_team().set_countdown_time(0);
	//halt and cancel the countdown timer
	reset_countdown();

	set_end_scenario_button();

	if ( get_end_level_data().reveal_map ) {
		// switch to observer viewpoint
		gui_->set_team(0,true);
		gui_->recalculate_minimap();
		gui_->invalidate_all();
		gui_->draw(true,true);
	}
	bool quit;
	start_pass_scenario_anim(get_end_level_data().result);
	do {
		quit = true;
		try {
			// reimplement parts of play_side()
			player_number_ = first_player_;
			init_turn_data();

			play_human_turn();
			after_human_turn();
			release_turn_data();
			LOG_NG << "finished human turn" << std::endl;
		} catch (game::load_game_exception&) {
			LOG_NG << "caught load-game-exception" << std::endl;
			// this should not happen, the option to load a game is disabled
			throw;
		} catch (end_level_exception&) {
			// thrown if the host ends the scenario and let us advance
			// to the next level
			LOG_NG << "caught end-level-exception" << std::endl;
			reset_end_scenario_button();
			throw;
		} catch (end_turn_exception&) {
			// thrown if the host leaves the game (sends [leave_game]), we need
			// to stay in this loop to stay in linger mode, otherwise the game
			// gets aborted
			LOG_NG << "caught end-turn-exception" << std::endl;
			quit = false;
		} catch (network::error&) {
			LOG_NG << "caught network-error-exception" << std::endl;
			quit = false;
		}
	} while (!quit);

	if (gui_->pass_scenario_anim_id() != -1) {
		gui_->erase_area_anim(gui_->pass_scenario_anim_id());
	}

	reset_end_scenario_button();

	LOG_NG << "ending end-of-scenario linger\n";
}