summaryrefslogtreecommitdiffstats
path: root/qemu.h
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:32:14 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:32:14 -0800
commitcc490161f6af9e4a6842ee827e4bfc43bc4509d5 (patch)
treea60e0ed36ef1d3a43530c46562c86c9cd431744c /qemu.h
parent3bbe5328cd738976443822502e23fb3971c5f87b (diff)
downloadhardware_libhardware_legacy-cc490161f6af9e4a6842ee827e4bfc43bc4509d5.zip
hardware_libhardware_legacy-cc490161f6af9e4a6842ee827e4bfc43bc4509d5.tar.gz
hardware_libhardware_legacy-cc490161f6af9e4a6842ee827e4bfc43bc4509d5.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'qemu.h')
-rw-r--r--qemu.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/qemu.h b/qemu.h
new file mode 100644
index 0000000..5fcbfa7
--- /dev/null
+++ b/qemu.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _libs_hardware_qemu_h
+#define _libs_hardware_qemu_h
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifdef QEMU_HARDWARE
+
+/* returns 1 iff we're running in the emulator */
+extern int qemu_check(void);
+
+/* a structure used to hold enough state to connect to a given
+ * QEMU communication channel, either through a qemud socket or
+ * a serial port.
+ *
+ * initialize the structure by zero-ing it out
+ */
+typedef struct {
+ char is_inited;
+ char is_available;
+ char is_qemud;
+ char is_tty;
+ char device[32];
+} QemuChannel;
+
+/* try to open a qemu communication channel.
+ * returns a file descriptor on success, or -1 in case of
+ * error.
+ *
+ * 'channel' must be a QemuChannel structure that is empty
+ * on the first call. You can call this function several
+ * time to re-open the channel using the same 'channel'
+ * object to speed things a bit.
+ */
+extern int qemu_channel_open( QemuChannel* channel,
+ const char* name,
+ int mode );
+
+/* create a command made of a 4-hexchar prefix followed
+ * by the content. the prefix contains the content's length
+ * in hexadecimal coding.
+ *
+ * 'buffer' must be at last 6 bytes
+ * returns -1 in case of overflow, or the command's total length
+ * otherwise (i.e. content length + 4)
+ */
+extern int qemu_command_format( char* buffer,
+ int buffer_size,
+ const char* format,
+ ... );
+
+/* directly sends a command through the 'control' channel.
+ * this will open the channel, send the formatted command, then
+ * close the channel automatically.
+ * returns 0 on success, or -1 on error.
+ */
+extern int qemu_control_command( const char* fmt, ... );
+
+/* sends a question to the control channel, then receive an answer in
+ * a user-allocated buffer. returns the lenght of the answer, or -1
+ * in case of error.
+ *
+ * 'question' *must* have been formatted through qemu_command_format
+ */
+extern int qemu_control_query( const char* question, int questionlen,
+ char* answer, int answersize );
+
+#endif /* QEMU_HARDWARE */
+
+/* use QEMU_FALLBACK(call) to call a QEMU-specific callback */
+/* use QEMU_FALLBACK_VOID(call) if the function returns void */
+#ifdef QEMU_HARDWARE
+# define QEMU_FALLBACK(x) \
+ do { \
+ if (qemu_check()) \
+ return qemu_ ## x ; \
+ } while (0)
+# define QEMU_FALLBACK_VOID(x) \
+ do { \
+ if (qemu_check()) { \
+ qemu_ ## x ; \
+ return; \
+ } \
+ } while (0)
+#else
+# define QEMU_FALLBACK(x) ((void)0)
+# define QEMU_FALLBACK_VOID(x) ((void)0)
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _libs_hardware_qemu_h */