From 4720c31bb08f5c6d1c8ddb616463c6fba9b350a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 28 Mar 2009 04:10:16 +0000 Subject: [PATCH] Spiced it up a little... It now shows a form to select settings before starting QEMU and the applet. Currently has keymap selection. Allows killing qemu before the end of the timeout. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29751 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- 3rdparty/mmu_man/onlinedemo/haiku.php | 374 ++++++++++++++++++++++---- 1 file changed, 328 insertions(+), 46 deletions(-) diff --git a/3rdparty/mmu_man/onlinedemo/haiku.php b/3rdparty/mmu_man/onlinedemo/haiku.php index 8290c293bc..bf0816e5c9 100755 --- a/3rdparty/mmu_man/onlinedemo/haiku.php +++ b/3rdparty/mmu_man/onlinedemo/haiku.php @@ -33,14 +33,21 @@ define("APPLET_HEIGHT", "768"); define("VNCPORTBASE", 5900); // timeout before the demo session is killed, as argument to /bin/sleep -define("SESSION_TIMEOUT", "10m"); +define("SESSION_TIMEOUT", "20m"); // path to qemu binary define("QEMU_BASE", "/usr/local"); define("QEMU_BIN", QEMU_BASE . "/bin/qemu"); define("QEMU_KEYMAPS", QEMU_BASE . "/share/qemu/keymaps"); // default arguments: no network, emulate tablet, readonly image file. -define("QEMU_ARGS","-net none -usbdevice wacom-tablet -snapshot"); +define("QEMU_ARGS", "" + ."-monitor /dev/null " + ."-serial none " + ."-parallel none " + ." -net none " + ."-usbdevice wacom-tablet " + ."-vga vmware " + ."-snapshot"); // absolute path to the image. define("QEMU_IMAGE_PATH","/home/revol/haiku/trunk/generated.x86/haiku.image"); // qemu 0.8.2 needs "", qemu 0.9.1 needs ":" @@ -52,16 +59,54 @@ define("QEMU_PIDFILE_TMPL", "qemu-haiku-pid-"); // name of session variable holding the qemu slot; not yet used correctly define("QEMU_IDX_VAR", "QEMU_HAIKU_SESSION_VAR"); +define("BGCOLOR", "#336698"); + +$vnckeymap = "en-us"; + +// statics +$count = $_SESSION['compteur']; +//$count = $GLOBALS['compteur']; +$closing = 0; +$do_kill = 0; +$do_run = 0; + +// parse args +if (isset($_GET['close'])) + $closing = 1; + +if (isset($_GET['kill'])) + $do_kill = 1; + +if (isset($_GET['run'])) + $do_run = 1; + +if (isset($_GET['frame'])) {} + session_start(); -if (isset($_GET['frame'])) { -} +//echo "do_run: " . $do_run . "
\n"; +//echo "do_kill: " . $do_kill . "
\n"; ?> Haiku Online Demo + "; -} else +else echo ""; +function out($str) +{ + echo "
$str
\n"; + ob_flush(); + flush(); +} + function dbg($str) { - echo "
$str
\n"; + echo "
$str
\n"; + ob_flush(); + flush(); } function err($str) { - echo "
$str
\n"; + echo "
$str
\n"; + ob_flush(); + flush(); } function make_qemu_sessionfile_name($idx) @@ -121,6 +170,25 @@ function find_qemu_slot() return -1; } +function total_qemu_slots() +{ + return MAX_QEMUS; +} + + +function available_qemu_slots() +{ + $count = 0; + for ($idx = 0; $idx < MAX_QEMUS; $idx++) { + $pidfile = make_qemu_pidfile_name($idx); + $sessfile = make_qemu_sessionfile_name($idx); + //dbg("checking \"$pidfile\", \"$sessfile\"..."); + if (!file_exists($pidfile) && !file_exists($sessfile)) + $count++; + } + return $count; +} + function qemu_slot() { return $_SESSION[QEMU_IDX_VAR]; @@ -136,6 +204,16 @@ function vnc_port() return VNCPORTBASE + vnc_display(); } +function vnc_addr_display() +{ + return $_SERVER['SERVER_ADDR'] . ":" . vnc_display(); +} + +function vnc_url() +{ + return "vnc://" . vnc_addr_display(); +} + function is_my_session_valid() { if (!isset($_SESSION[QEMU_IDX_VAR])) @@ -153,11 +231,40 @@ function is_my_session_valid() } +function list_keymaps() +{ + $bads = array('.', '..', 'common', 'modifiers'); + $keymaps = scandir(QEMU_KEYMAPS); + foreach ($keymaps as $key => $map) { + if (in_array($map, $bads)) + unset($keymaps[$key]); + } + return $keymaps; +} + + +function in_keymaps($keymap) +{ + $keymaps = list_keymaps(); + + if ($keymap == "") + return false; + if (in_array($keymap, $keymaps)) + return true; + + return false; +} function probe_keymap() { global $vnckeymap; + if (is_string($_GET['keymap']) && in_keymaps($_GET['keymap'])) + { + $vnckeymap = $_GET['keymap']; + dbg("Overriden keymap '" . $vnckeymap . "' in arguments."); + return; + } // if the browser advertised a prefered lang... if (!isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) return; @@ -166,23 +273,131 @@ function probe_keymap() $langs = str_replace(" ", "", $langs); $langs = split(",", $langs); //print_r($langs); - $keymaps = scandir(QEMU_KEYMAPS); //print_r($keymaps); foreach($langs as $lang) { - foreach($keymaps as $keymap) + if (in_keymaps($lang)) { - if ($keymap == $lang) - { - dbg("Detected keymap '" . $keymap . "' from browser headers."); - $vnckeymap = $keymap; - return; - } + $vnckeymap = $lang; + dbg("Detected keymap '" . $vnckeymap . "' from browser headers."); + return; } } } +function output_options_form() +{ + global $vnckeymap; + $idx = qemu_slot(); + echo "
"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + $modes = array("1024x768"/*, "800x600"*/); + echo "\n"; + echo "\n"; + echo "\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "Select your keymap:"; + echo "\n"; + echo ""; + echo "
\n"; + echo "Select display size:"; + echo "\n"; + echo ""; + + echo "
\n"; + echo "Click here to enable sound:"; + echo "\n"; + echo "Sound"; + echo "
\n"; + //out("Click here to enable sound:"); + echo "\n"; + echo "
\n"; + echo "Click here to start the session:"; + echo "\n"; + echo ""; + echo "
\n"; + echo "
\n"; + out("NOTE: You will need a Java-enabled browser to display the VNC Applet needed by this demo."); + out("You can however use instead an external VNC viewer."); + ob_flush(); + flush(); +} + +function output_kill_form() +{ + echo "
"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + echo "Click here to kill the session:"; + echo "\n"; + echo ""; + echo "
\n"; + echo "
\n"; + ob_flush(); + flush(); +} + + function start_qemu() { global $vnckeymap; @@ -223,6 +438,40 @@ function start_qemu() dbg("Ready for a " . SESSION_TIMEOUT . " session."); } +function stop_qemu() +{ + $qemuidx = qemu_slot(); + $pidfile = make_qemu_pidfile_name($qemuidx); + if (file_exists($pidfile)) { + $pid = file_get_contents($pidfile); + //out("PID:" . $pid); + system("/bin/kill -TERM " . $pid); + unlink($pidfile); + } + $sessionfile = make_qemu_sessionfile_name($qemuidx); + if (file_exists($sessionfile)) { + unlink($sessionfile); + } + unset($_SESSION[QEMU_IDX_VAR]); + + out("reloading..."); + sleep(1); + echo "\n"; + out("Click here to reload the page."); +} + +function output_vnc_info() +{ + out("You can use an external VNC client, click " . + "here " . + "or enter " . vnc_addr_display() . " in your " . + "VNC viewer.
"); +} function output_applet_code() { @@ -232,40 +481,73 @@ function output_applet_code() $vncjpath = VNCJAVA_PATH; $jar = VNCJAR; $class = VNCCLASS; - echo " - - - - - There should be a java applet here... make sure you have a JVM and it's enabled! - "; + echo ""; + echo "
"; + echo "\n"; + //not needed + //echo "\n"; + echo "\n"; + echo "\n"; + //echo ""; + echo "\n"; + echo "\n"; + //echo "\n"; + //echo "\n"; + echo "There should be a java applet here... "; + echo "make sure you have a JVM and it's enabled!
\n"; + echo "If you do not have Java you can use an external VNC "; + echo "client as described above.\n"; + + echo "
\n"; + echo "
"; + ob_flush(); + flush(); + // scroll to the top of the applet + echo "\n"; + ob_flush(); + flush(); } +out("
Available displays: " . + available_qemu_slots() . "/" . total_qemu_slots() . + "
"); + + +probe_keymap(); + + dbg("Checking if session is running..."); +$qemuidx = -1; if (is_my_session_valid()) { - dbg("Session running"); + dbg("Session running."); $qemuidx = qemu_slot(); -} else if ($closing != 1) { - dbg("Need to start qemu"); + if ($do_kill) { + dbg("closing..."); + stop_qemu(); + } +} else if (!$do_kill && $do_run) { + dbg("Need to start qemu."); - probe_keymap(); $qemuidx = start_qemu(); + out("Waiting for vnc server..."); + sleep(5); } -if ($qemuidx >= 0) { - if ($closing) { - dbg("closing..."); - unlink(make_qemu_sessionfile_name($qemuidx)); - //unlink(make_qemu_sessionfile_name($qemuidx)); - sleep(1); - //echo ""; - } else { - dbg("Waiting for vnc server..."); - sleep(5); - output_applet_code(); - } + +if ($qemuidx >= 0 && !$do_kill) { + output_kill_form(); + output_vnc_info(); + echo "
\n"; + output_applet_code(); +} else { + output_options_form(); }