aboutsummaryrefslogtreecommitdiffstats
path: root/android/console.c
diff options
context:
space:
mode:
authorOt ten Thije <ottenthije@google.com>2010-10-06 17:48:15 +0100
committerOt ten Thije <ottenthije@google.com>2010-10-28 13:47:54 +0100
commit2ff39a367738422c0ca1313cac8ff380e1fdd498 (patch)
treea85cd059101de7f5eac9cd1f205d8971b6a3910d /android/console.c
parentf5f9aed3f35a80d8112849d0d354a465acfbbcc5 (diff)
downloadexternal_qemu-2ff39a367738422c0ca1313cac8ff380e1fdd498.zip
external_qemu-2ff39a367738422c0ca1313cac8ff380e1fdd498.tar.gz
external_qemu-2ff39a367738422c0ca1313cac8ff380e1fdd498.tar.bz2
Control state snapshots from Android console.
This patch exposes Qemu's save, load, delete and list commands for state snapshots on the Android console. A level of indirection is added by means of the OutputChannel construct. This allows us to show the output of the Qemu commands on the console rather than on the monitor, while minimizing the differences with the upstream codebase. The new commands are exposed only when the configuration constant CONFIG_ANDROID_SNAPSHOTS is not 0. Change-Id: I558d5cd505d321fe2da5835713d341d151f60534
Diffstat (limited to 'android/console.c')
-rw-r--r--android/console.c135
1 files changed, 126 insertions, 9 deletions
diff --git a/android/console.c b/android/console.c
index af22fc6..4f1a976 100644
--- a/android/console.c
+++ b/android/console.c
@@ -36,6 +36,7 @@
#include "android/utils/bufprint.h"
#include "android/utils/debug.h"
#include "android/utils/stralloc.h"
+#include "android/config/config.h"
#include "tcpdump.h"
#include "net.h"
#include "monitor.h"
@@ -251,18 +252,25 @@ static void control_control_write( ControlClient client, const char* buff, in
}
}
-static void control_write( ControlClient client, const char* format, ... )
+static int control_vwrite( ControlClient client, const char* format, va_list args )
{
static char temp[1024];
- va_list args;
+ int ret = vsnprintf( temp, sizeof(temp), format, args );
+ temp[ sizeof(temp)-1 ] = 0;
+ control_control_write( client, temp, -1 );
+
+ return ret;
+}
+static int control_write( ControlClient client, const char* format, ... )
+{
+ int ret;
+ va_list args;
va_start(args, format);
- vsnprintf( temp, sizeof(temp), format, args );
+ ret = control_vwrite(client, format, args);
va_end(args);
- temp[ sizeof(temp)-1 ] = 0;
-
- control_control_write( client, temp, -1 );
+ return ret;
}
@@ -1929,6 +1937,109 @@ static const CommandDefRec event_commands[] =
{ NULL, NULL, NULL, NULL, NULL, NULL }
};
+#if CONFIG_ANDROID_SNAPSHOTS
+
+
+/********************************************************************************************/
+/********************************************************************************************/
+/***** ******/
+/***** S N A P S H O T C O M M A N D S ******/
+/***** ******/
+/********************************************************************************************/
+/********************************************************************************************/
+
+static int
+control_write_out_cb(void* opaque, const char* fmt, va_list ap)
+{
+ ControlClient client = opaque;
+ int ret = control_vwrite(client, fmt, ap);
+ return ret;
+}
+
+static int
+control_write_err_cb(void* opaque, const char* fmt, va_list ap)
+{
+ int ret = 0;
+ ControlClient client = opaque;
+ ret += control_write(client, "KO: ");
+ ret += control_vwrite(client, fmt, ap);
+ return ret;
+}
+
+static int
+do_snapshot_list( ControlClient client, char* args )
+{
+ int ret;
+ OutputChannel *out = output_channel_alloc(client, control_write_out_cb);
+ OutputChannel *err = output_channel_alloc(client, control_write_err_cb);
+ do_info_snapshots_oc(out, err);
+ ret = output_channel_written(err);
+ output_channel_free(out);
+ output_channel_free(err);
+
+ return ret > 0;
+}
+
+static int
+do_snapshot_save( ControlClient client, char* args )
+{
+ int ret;
+ OutputChannel *err = output_channel_alloc(client, control_write_err_cb);
+ do_savevm_oc(err, args);
+ ret = output_channel_written(err);
+ output_channel_free(err);
+
+ return ret > 0; // no output on error channel indicates success
+}
+
+static int
+do_snapshot_load( ControlClient client, char* args )
+{
+ int ret;
+ OutputChannel *err = output_channel_alloc(client, control_write_err_cb);
+ do_loadvm_oc(err, args);
+ ret = output_channel_written(err);
+ output_channel_free(err);
+
+ return ret > 0;
+}
+
+static int
+do_snapshot_del( ControlClient client, char* args )
+{
+ int ret;
+ OutputChannel *err = output_channel_alloc(client, control_write_err_cb);
+ do_delvm_oc(err, args);
+ ret = output_channel_written(err);
+ output_channel_free(err);
+
+ return ret > 0;
+}
+
+static const CommandDefRec snapshot_commands[] =
+{
+ { "list", "list available state snapshots",
+ "'avd snapshot list' will show a list of all state snapshots that can be loaded\r\n",
+ NULL, do_snapshot_list, NULL },
+
+ { "save", "save state snapshot",
+ "'avd snapshot save <name>' will save the current (run-time) state to a snapshot with the given name\r\n",
+ NULL, do_snapshot_save, NULL },
+
+ { "load", "load state snapshot",
+ "'avd snapshot load <name>' will load the state snapshot of the given name\r\n",
+ NULL, do_snapshot_load, NULL },
+
+ { "del", "delete state snapshot",
+ "'avd snapshot del <name>' will delete the state snapshot with the given name\r\n",
+ NULL, do_snapshot_del, NULL },
+
+ { NULL, NULL, NULL, NULL, NULL, NULL }
+};
+
+
+#endif
+
/********************************************************************************************/
/********************************************************************************************/
@@ -1985,13 +2096,19 @@ static const CommandDefRec vm_commands[] =
NULL, do_avd_start, NULL },
{ "status", "query virtual device status",
- "'avd status' will indicate wether the virtual device is running or not\r\n",
+ "'avd status' will indicate whether the virtual device is running or not\r\n",
NULL, do_avd_status, NULL },
{ "name", "query virtual device name",
"'avd name' will return the name of this virtual device\r\n",
NULL, do_avd_name, NULL },
+#if CONFIG_ANDROID_SNAPSHOTS
+ { "snapshot", "state snapshot commands",
+ "allows you to save and restore the virtual device state in snapshots\r\n",
+ NULL, NULL, snapshot_commands },
+#endif
+
{ NULL, NULL, NULL, NULL, NULL, NULL }
};
@@ -2313,8 +2430,8 @@ static const CommandDefRec main_commands[] =
"allows you to simulate an inbound SMS\r\n", NULL,
NULL, sms_commands },
- { "avd", "manager virtual device state",
- "allows to change (e.g. start/stop) the virtual device state\r\n", NULL,
+ { "avd", "control virtual device execution",
+ "allows you to control (e.g. start/stop) the execution of the virtual device\r\n", NULL,
NULL, vm_commands },
{ "window", "manage emulator window",