diff -Naur /yuval/Dev/qemu-cvs/qemu/configure /yuval/Dev/qemu-dbus/qemu/configure
--- /yuval/Dev/qemu-cvs/qemu/configure	2007-09-22 18:49:14.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/configure	2007-09-23 12:59:54.000000000 +0200
@@ -102,6 +102,8 @@
 darwin_user="no"
 build_docs="no"
 uname_release=""
+dbus="yes"
+dbus_service="org.qemu"
 
 # OS specific
 targetos=`uname -s`
@@ -291,6 +293,12 @@
   ;;
   --enable-uname-release=*) uname_release="$optarg"
   ;;
+  --disable-dbus) dbus="no"
+  ;;
+  --enable-dbus) dbus="yes"
+  ;;
+  --dbus-service=*) dbus_service="$optarg"
+  ;;
   --sparc_cpu=*)
       sparc_cpu="$optarg"
       case $sparc_cpu in
@@ -391,6 +399,9 @@
 echo "  --fmod-lib               path to FMOD library"
 echo "  --fmod-inc               path to FMOD includes"
 echo "  --enable-uname-release=R Return R for uname -r in usermode emulation"
+echo "  --enable-dbus            enable DBus monitor service"
+echo "  --disable-dbus           disable DBus monitor service"
+echo "  --dbus-service=service   set the dbus service name"
 echo "  --sparc_cpu=V            Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9"
 echo ""
 echo "NOTE: The object files are built at the place where configure is launched"
@@ -714,6 +725,7 @@
     echo "Target Sparc Arch $sparc_cpu"
 fi
 echo "kqemu support     $kqemu"
+echo "DBUS support	$dbus"
 echo "Documentation     $build_docs"
 [ ! -z "$uname_release" ] && \
 echo "uname -r          $uname_release"
@@ -888,6 +900,11 @@
   echo "CONFIG_VNC_TLS_LIBS=$vnc_tls_libs" >> $config_mak
   echo "#define CONFIG_VNC_TLS 1" >> $config_h
 fi
+if test "$dbus" = "yes" ; then
+  echo "CONFIG_DBUS=yes" >> $config_mak
+  echo "#define CONFIG_DBUS 1" >> $config_h
+  echo "#define DBUS_SERVICE \"$dbus_service\"" >> $config_h
+fi
 qemu_version=`head $source_path/VERSION`
 echo "VERSION=$qemu_version" >>$config_mak
 echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
diff -Naur /yuval/Dev/qemu-cvs/qemu/dbus/monitor-dbus.c /yuval/Dev/qemu-dbus/qemu/dbus/monitor-dbus.c
--- /yuval/Dev/qemu-cvs/qemu/dbus/monitor-dbus.c	1970-01-01 02:00:00.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/dbus/monitor-dbus.c	2007-09-23 13:00:47.000000000 +0200
@@ -0,0 +1,1506 @@
+/*
+ * Example/Unit-test D-Bus server code.
+ * Written by Shahar Frank <shaharf@qumranet.com>
+ *
+ * This code has been released into the Public Domain.
+ * You may do whatever you like with it.
+ */
+#include <dsrv.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <pthread.h>
+
+#include "vl.h"
+#include "error.h"
+#include "monitor.h"
+#include "monitor-dbus.h"
+
+pthread_t dbus_thread;
+char g_Devices[3][6]; //tmp
+
+static volatile int configured = 0;
+
+pthread_mutex_t conf_mutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t conf_cond = PTHREAD_COND_INITIALIZER;
+
+//
+// Debug interface functions
+//
+
+char *SetLogLevel(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nLogLevel;
+
+    dsrv_method_arg(method, "LogLevel", &nLogLevel);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%c) method called", 
+        method->name,
+        nLogLevel
+    );
+
+    dsrv_log_level = nLogLevel;
+
+    return NULL;
+}
+
+//
+// Configuration interface functions
+//
+
+char *Config_boot(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    int nDeviceLetter;
+
+    dsrv_method_arg(method, "DeviceLetter", &nDeviceLetter);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%c) method called", 
+        method->name,
+        nDeviceLetter
+    );
+
+    if (
+        boot_device != 'a' && 
+#if defined(TARGET_SPARC) || defined(TARGET_I386)
+        // Network boot
+        boot_device != 'n' &&
+#endif
+        boot_device != 'c' && 
+        boot_device != 'd'
+    ) {
+        nRC = 1;
+    } else {
+        boot_device = nDeviceLetter;
+    }
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_usb_add(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC;
+    char *szDevName;
+
+    dsrv_method_arg(method, "DeviceName", &szDevName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDevName
+    );
+
+    nRC = usb_device_add(szDevName);
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_usb_del(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC;
+    char *szDevName;
+
+    dsrv_method_arg(method, "DeviceName", &szDevName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDevName
+    );
+
+    nRC = usb_device_del(szDevName);
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Config_usb(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fUSB;
+
+    dsrv_method_arg(method, "State", &fUSB);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fUSB ? "True" : "False"
+    );
+
+    usb_enabled = (int) fUSB;
+
+    return NULL;
+}
+
+char *Monitor_ListUsbDevices(DSrvMethod * method, DBusMessage * msg, void *user) {
+    USBDevice *dev;
+    USBPort *port;
+    const char *speed_str;
+    int n = 10;
+
+    DSrvArray *array;
+    char szUsbDevice[256];
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s() method called", 
+        method->name
+    );
+
+    if (!(array = dsrv_method_basic_array_return (method, "Info", NULL, &n)))
+        DSRV_PANIC (NULL, "dsrv_method_basic_array failed");
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s - after dsrv_method_basic_array_return", 
+        method->name
+    );
+
+    if (!usb_enabled) {
+        return NULL;
+    }
+
+    for (
+        port = used_usb_ports; 
+        port; 
+        port = port->next
+    ) {
+        dev = port->dev;
+        if (!dev) {
+            continue;
+        }
+
+        switch(dev->speed) {
+            case USB_SPEED_LOW: 
+                speed_str = "1.5"; 
+            break;
+            case USB_SPEED_FULL: 
+                speed_str = "12"; 
+            break;
+            case USB_SPEED_HIGH: 
+                speed_str = "480"; 
+            break;
+            default:
+                speed_str = "?"; 
+            break;
+        }
+
+        snprintf (
+            szUsbDevice,
+            256,
+            "  Device %d.%d, Speed %s Mb/s, Product %s\n",
+            0, 
+            dev->addr, 
+            speed_str, 
+            dev->devname
+        );
+
+        DSRV_LOG (
+            dsrv_method_server(method), 
+            DSRV_LOG_VERBOSE,
+            "%s - adding info: %s", 
+            method->name,
+            szUsbDevice
+        );
+
+        dsrv_array_append_basic (array, szUsbDevice);
+    }
+
+    return NULL;
+}
+
+char *Monitor_ListNetworkDevices(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int n = 10;
+    VLANState *vsFirstVLAN;
+    VLANState *vlan;
+    VLANClientState *vc;
+
+    DSrvArray *array;
+    char szBuf[256];
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s() method called", 
+        method->name
+    );
+
+    if (!(array = dsrv_method_basic_array_return (method, "Info", NULL, &n)))
+        DSRV_PANIC (NULL, "dsrv_method_basic_array failed");
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s - after dsrv_method_basic_array_return", 
+        method->name
+    );
+
+    vsFirstVLAN = get_first_vlan();
+
+    for(vlan = vsFirstVLAN; vlan != NULL; vlan = vlan->next) {
+        for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
+            snprintf (
+                szBuf,
+                256,
+                "VLAN %d: %s",
+                vlan->id,
+                vc->info_str
+            );
+
+            DSRV_LOG (
+                dsrv_method_server(method), 
+                DSRV_LOG_VERBOSE,
+                "%s - adding info: %s", 
+                method->name,
+                szBuf
+            );
+
+            dsrv_array_append_basic (array, szBuf);
+        }
+    }
+
+    return NULL;
+}
+
+char *Config_SetLocaltime(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fUTC;
+
+    dsrv_method_arg(method, "IsUTC", &fUTC);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fUTC ? "True" : "False"
+    );
+
+    rtc_utc = (int) fUTC;
+
+    return NULL;
+}
+
+char *Config_SetFullScreen(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsFullScreen;
+
+    dsrv_method_arg(method, "IsFullScreen", &fIsFullScreen);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsFullScreen ? "True" : "False"
+    );
+
+    full_screen = (int) fIsFullScreen;
+
+    return NULL;
+}
+
+char *Config_Set_std_vga(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsSTDVGA;
+
+    dsrv_method_arg(method, "Is_std_vga", &fIsSTDVGA);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsSTDVGA ? "True" : "False"
+    );
+
+    cirrus_vga_enabled = (int) fIsSTDVGA;
+
+    return NULL;
+}
+
+char *Config_SetNoACPI(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsNoACPI;
+
+    dsrv_method_arg(method, "IsNoACPI", &fIsNoACPI);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsNoACPI ? "True" : "False"
+    );
+
+    acpi_enabled = (int) fIsNoACPI;
+
+    return NULL;
+}
+
+char *Config_SetNoQuit(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsNoQuit;
+
+    dsrv_method_arg(method, "IsNoQuit", &fIsNoQuit);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsNoQuit ? "True" : "False"
+    );
+
+    no_quit = (int) fIsNoQuit;
+
+    return NULL;
+}
+
+char *Config_SetNoGraphic(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsNoGraphic;
+
+    dsrv_method_arg(method, "IsNoGraphic", &fIsNoGraphic);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsNoGraphic ? "True" : "False"
+    );
+
+    nographic = (int) fIsNoGraphic;
+
+    return NULL;
+}
+
+char *Config_daemonize(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsDaemonize;
+
+    dsrv_method_arg(method, "IsDaemonize", &fIsDaemonize);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsDaemonize ? "True" : "False"
+    );
+
+    daemonize = (int) fIsDaemonize;
+
+    return NULL;
+}
+
+char *Config_SetNoReboot(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsNoReboot;
+
+    dsrv_method_arg(method, "IsNoReboot", &fIsNoReboot);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsNoReboot ? "True" : "False"
+    );
+
+    no_reboot = (int) fIsNoReboot;
+
+    return NULL;
+}
+
+char *Config_SetNoFDBootCheck(DSrvMethod * method, DBusMessage * msg, void *user) {
+//    int nState;
+    bool fIsNoFDBootCheck;
+
+    dsrv_method_arg(method, "IsNoFDBootCheck", &fIsNoFDBootCheck);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        fIsNoFDBootCheck ? "True" : "False"
+    );
+
+    fd_bootchk = (int) fIsNoFDBootCheck;
+
+    return NULL;
+}
+
+char *Config_snapshot(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nState;
+
+    dsrv_method_arg(method, "State", &nState);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d) method called", 
+        method->name,
+        nState
+    );
+
+    snapshot = nState;
+
+    return NULL;
+}
+
+char *Config_monitor(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDeviceName;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+    pstrcpy(monitor_device, sizeof(monitor_device), szDeviceName);
+
+    return NULL;
+}
+
+char *Monitor_AddSerial(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    char *szDeviceName;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+
+    if (serial_device_index >= MAX_SERIAL_PORTS) {
+        nRC = 1;
+    } else {
+        const char *devname;
+        if (devname[0] != '\0') {
+            //Close device before creating and opening a new one.
+        }
+
+        pstrcpy (
+            serial_devices[serial_device_index], 
+            sizeof(serial_devices[0]), 
+            optarg
+        );
+        devname = serial_devices[serial_device_index];
+
+        serial_hds[serial_device_index] = qemu_chr_open(devname);
+        if (!serial_hds[serial_device_index]) {
+            nRC = 2;
+        } else {
+            if (!strcmp(devname, "vc")) {
+                qemu_chr_printf(serial_hds[serial_device_index], "serial%d console\r\n", serial_device_index);
+            }
+            serial_device_index++;
+        }
+    }
+
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_RemoveSerial(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nIndex;
+
+    dsrv_method_arg(method, "DeviceID", &nIndex);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d) method called", 
+        method->name,
+        nIndex
+    );
+
+    qemu_chr_close(serial_hds[nIndex]);
+
+    return NULL;
+}
+
+char *Monitor_AddParallel(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    char *szDeviceName;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+
+    if (parallel_device_index >= MAX_SERIAL_PORTS) {
+        nRC = 1;
+    } else {
+        const char *devname;
+        if (devname[0] != '\0') {
+            //Close device before creating and opening a new one.
+        }
+
+        pstrcpy (
+            parallel_devices[parallel_device_index], 
+            sizeof(parallel_devices[0]), 
+            optarg
+        );
+        devname = parallel_devices[parallel_device_index];
+
+        parallel_hds[parallel_device_index] = qemu_chr_open(devname);
+        if (!parallel_hds[parallel_device_index]) {
+            nRC = 2;
+        } else {
+            if (!strcmp(devname, "vc")) {
+                qemu_chr_printf(parallel_hds[parallel_device_index], "parallel%d console\r\n", parallel_device_index);
+            }
+            parallel_device_index++;
+        }
+    }
+
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_RemoveParallel(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nIndex;
+
+    dsrv_method_arg(method, "DeviceID", &nIndex);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d) method called", 
+        method->name,
+        nIndex
+    );
+
+    qemu_chr_close(parallel_hds[nIndex]);
+
+    return NULL;
+}
+
+char *Config_ramsize(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    unsigned nSize;
+
+    dsrv_method_arg(method, "MegaBytes", &nSize);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d) method called", 
+        method->name,
+        nSize
+    );
+
+    if ((int)(nSize * 1024 * 1024) > PHYS_RAM_MAX_SIZE) {
+        nRC = 1;
+    } else {
+        ram_size = nSize * 1024 * 1024;
+    }
+
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Config_smp(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    unsigned nCPUs;
+
+    dsrv_method_arg(method, "CPUs", &nCPUs);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d) method called", 
+        method->name,
+        nCPUs
+    );
+
+    if (
+        nCPUs < 1 ||
+        nCPUs > MAX_CPUS
+    ) {
+        nRC = 1;
+    } else {
+        smp_cpus = nCPUs;
+    }
+
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+#ifdef HAS_AUDIO
+char *Config_SoundHWState(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    char *szName;
+    int nState;
+    struct soundhw *c;
+
+    dsrv_method_arg(method, "Name", &szName);
+    dsrv_method_arg(method, "State", &nState);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s,%d) method called", 
+        method->name,
+        szName,
+        nState
+    );
+
+    if (!strcmp (szName, "all")) {
+        for (c = soundhw; c->name; ++c) {
+            c->enabled = nState;
+        }
+    } else {
+        for (c = soundhw; c->name; ++c) {
+            if (!strncmp (c->name, szName, c->name > szName ? sizeof(szName) : sizeof(c->name))) {
+                c->enabled = nState;
+            }
+        }
+        if (!c->name) {
+            nRC = 1;
+        }
+    }
+
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+#endif // HAS_AUDIO
+char *MonitorSetFloppy(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nRC = 0;
+    int nIndex;
+    char *szImageName;
+
+    dsrv_method_arg(method, "Index", &nIndex);
+    dsrv_method_arg(method, "ImageName", &szImageName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d,%s) method called", 
+        method->name,
+        nIndex,
+        szImageName
+    );
+
+    if (nIndex > MAX_FD) {
+        nRC = 1;
+    } else {
+        if (fd_table[nIndex]) {
+            bdrv_close(fd_table[nIndex]);
+        }
+
+        bdrv_set_type_hint(fd_table[nIndex], BDRV_TYPE_FLOPPY);
+
+        if (
+            bdrv_open (
+                fd_table[nIndex], 
+                szImageName, 
+                snapshot ? BDRV_O_SNAPSHOT : 0
+            ) < 0
+        ) {
+            nRC = 2;
+        }
+    }
+
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Config_SetCdrom(DSrvMethod *method, DBusMessage *msg, void *user) {
+    int nRC = 0;
+    char *szImageName;
+
+    dsrv_method_arg(method, "ImageName", &szImageName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szImageName
+    );
+
+    if (cdrom_index >= 0) {
+        hd_filename[cdrom_index] = szImageName;
+    }
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s return = %d", 
+        method->name,
+        nRC
+    );
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_SetBlockDevice(DSrvMethod *method, DBusMessage *msg, void *user) {
+    int nRC = 0;
+    int nIndex;
+    char *szImageName;
+
+    dsrv_method_arg(method, "Index", &nIndex);
+    dsrv_method_arg(method, "ImageName", &szImageName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d,%s) method called", 
+        method->name,
+        nIndex,
+        szImageName
+    );
+
+    if (nIndex > MAX_DISKS) {
+        nRC = 1;
+    } else {
+        hd_filename[nIndex] = szImageName;
+        if (nIndex == cdrom_index) {
+            cdrom_index = -1;
+        }
+    }
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s return = %d", 
+        method->name,
+        nRC
+    );
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Config_AddNet(DSrvMethod *method, DBusMessage *msg, void *user) {
+    int nRC = 0;
+    char *szParameters;
+
+    dsrv_method_arg(method, "Parameters", &szParameters);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szParameters
+    );
+
+    if (nb_net_clients >= MAX_NET_CLIENTS) {
+        nRC = 1;
+    } else {
+        pstrcpy(
+            net_clients[nb_net_clients],
+            sizeof(net_clients[0]),
+            szParameters
+        );
+
+        nb_net_clients++;
+    }
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s return = %d", 
+        method->name,
+        nRC
+    );
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+
+}
+
+char *Config_BIOSDir(DSrvMethod *method, DBusMessage *msg, void *user) {
+    int nRC = 0;
+    char *szDirectory;
+
+    dsrv_method_arg(method, "Directory", &szDirectory);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDirectory
+    );
+
+    bios_dir = szDirectory;
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s return = %d", 
+        method->name,
+        nRC
+    );
+    dsrv_method_return (method, "ReturnCode", &nRC);
+
+    return NULL;
+
+}
+
+char *Monitor_LoadVM(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szFilename;
+
+    dsrv_method_arg(method, "Filename", &szFilename);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szFilename
+    );
+
+    do_loadvm(szFilename);
+
+    return NULL;
+}
+
+char *Config_vnc(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDisplay;
+
+    dsrv_method_arg(method, "Display", &szDisplay);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDisplay
+    );
+
+    vnc_display = szDisplay;
+
+    return NULL;
+}
+
+char *Monitor_commit(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDeviceName;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+    do_commit(szDeviceName);
+
+    return NULL;
+}
+
+char *Monitor_quit(DSrvMethod * method, DBusMessage * msg, void *user) {
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s() method called", 
+        method->name
+    );
+
+    exit(0);
+
+    return NULL;
+}
+
+char *Monitor_eject(DSrvMethod * method, DBusMessage * msg, void *user) {
+    int nForce;
+    char *szFilename;
+
+    dsrv_method_arg(method, "Force", &nForce);
+    dsrv_method_arg(method, "Filename", &szFilename);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%d,%s) method called", 
+        method->name,
+        nForce,
+        szFilename
+    );
+
+    do_eject(nForce, szFilename);
+
+    return NULL;
+}
+
+char *Monitor_change(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDeviceName;
+    char *szFilename;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+    dsrv_method_arg(method, "Filename", &szFilename);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s,%s) method called", 
+        method->name,
+        szDeviceName,
+        szFilename
+    );
+
+    do_change(szDeviceName, szFilename);
+
+    return NULL;
+}
+
+char *Monitor_savevm(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDeviceName;
+    int nRC;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+    nRC = mgmt_savevm(szDeviceName);
+
+    if (nRC != 0) {
+        DSRV_LOG (
+            dsrv_method_server(method), 
+            DSRV_LOG_ERROR,
+            "%s failed: %s", 
+            method->name,
+            GetLastError()
+        );
+    }
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_loadvm(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDeviceName;
+    int nRC;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+    nRC = mgmt_loadvm(szDeviceName);
+
+    if (nRC != 0) {
+        DSRV_LOG (
+            dsrv_method_server(method), 
+            DSRV_LOG_ERROR,
+            "%s failed: %s", 
+            method->name,
+            GetLastError()
+        );
+    }
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_delvm(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szDeviceName;
+    int nRC;
+
+    dsrv_method_arg(method, "DeviceName", &szDeviceName);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szDeviceName
+    );
+
+    nRC = mgmt_delvm(szDeviceName);
+
+    if (nRC != 0) {
+        DSRV_LOG (
+            dsrv_method_server(method), 
+            DSRV_LOG_ERROR,
+            "%s failed: %s", 
+            method->name,
+            GetLastError()
+        );
+    }
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_send_key(DSrvMethod * method, DBusMessage * msg, void *user) {
+    char *szKeys;
+    int nRC = 0;
+
+    dsrv_method_arg(method, "Keys", &szKeys);
+
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s(%s) method called", 
+        method->name,
+        szKeys
+    );
+
+    do_send_key(szKeys);
+
+    if (nRC != 0) {
+        DSRV_LOG (
+            dsrv_method_server(method), 
+            DSRV_LOG_ERROR,
+            "%s failed: %s", 
+            method->name,
+            GetLastError()
+        );
+    }
+
+    dsrv_method_return(method, "ReturnCode", &nRC);
+
+    return NULL;
+}
+
+char *Monitor_system_reset(DSrvMethod * method, DBusMessage * msg, void *user) {
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s() method called", 
+        method->name
+    );
+
+    qemu_system_reset_request();
+
+    return NULL;
+}
+
+char *Monitor_system_powerdown(DSrvMethod * method, DBusMessage * msg, void *user) {
+    DSRV_LOG (
+        dsrv_method_server(method), 
+        DSRV_LOG_VERBOSE,
+        "%s() method called", 
+        method->name
+    );
+
+    qemu_system_powerdown();
+
+    return NULL;
+}
+
+char *ConfigDone(DSrvMethod * method, DBusMessage * msg, void *user) {
+    pthread_mutex_lock(&conf_mutex);
+    configured = 1;
+    pthread_mutex_unlock(&conf_mutex);
+
+    pthread_cond_signal(&conf_cond);
+
+    return NULL;
+}
+
+void *dbus_main(void *arg)
+{
+    DSrvServer *server;
+    DSrvObject *object;
+    DSrvInterface *interface;
+    DSrvMethod *method;
+    char *err;
+    char szServiceName[256];
+    
+    dsrv_log_level = DSRV_LOG_WARN;
+    
+    // Create service name.
+    if (szDBusServiceName == NULL) {
+        snprintf (
+            szServiceName,
+            256,
+            "qemu.org.%d",
+            getpid()
+        );
+    } else {
+        strncpy (szServiceName, szDBusServiceName, 256);
+    }
+
+    // Initialize the server structure      
+    if (!(server = dsrv_server_new(szServiceName)))
+            DSRV_PANIC(server, "can't setup a server");
+
+    // Initialize an object - this is optional, interafaces can use rootobject
+    if (!(object = dsrv_object_new(server, NULL, "/Management")))
+            DSRV_PANIC(server, "can't alloc an object");
+
+    // Debug interface
+    if (!(interface = dsrv_interface_new(object, "org.qemu.Debug")))
+            DSRV_PANIC(server, "can't create Debug interface");
+
+    // SetLogLevel declaration and params
+    if (!(method = dsrv_method_new(interface, "SetLogLevel", SetLogLevel, NULL)))
+            DSRV_PANIC(server, "can't create SetLogLevel method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("LogLevel", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Capture interface
+    if (!(interface = dsrv_interface_new(object, "org.qemu.Configuration")))
+            DSRV_PANIC(server, "can't create Capture interface");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "ConfigDone", ConfigDone, NULL)))
+            DSRV_PANIC(server, "can't create ConfigDone method");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_UsbState", Config_usb, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetUsbState method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("State", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetLocaltime", Config_SetLocaltime, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetUsbState method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsUTC", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetFullScreen", Config_SetFullScreen, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetFullScreen method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsFullScreen", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_Set_std_vga declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_Set_std_vga", Config_Set_std_vga, NULL)))
+            DSRV_PANIC(server, "can't create Config_Set_std_vga method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Is_std_vga", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_Set_std_vga declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetNoACPI", Config_SetNoACPI, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetNoACPI method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Is_NoACPI", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_SetNoQuit declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetNoQuit", Config_SetNoQuit, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetNoQuit method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsNoQuit", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_SetNoFDBootCheck declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetNoFDBootCheck", Config_SetNoFDBootCheck, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetNoFDBootCheck method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsNoFDBootCheck", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_SetNoGraphic declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetNoGraphic", Config_SetNoGraphic, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetNoGraphic method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsNoGraphic", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_SetNoReboot declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetNoReboot", Config_SetNoReboot, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetNoReboot method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsNoReboot", 'b', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_daemonize declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_daemonize", Config_daemonize, NULL)))
+            DSRV_PANIC(server, "can't create Config_daemonize method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("IsDaemnoize", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "usb_add", Monitor_usb_add, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_usb_add method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "usb_del", Monitor_usb_del, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_usb_add method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_boot", Config_boot, NULL)))
+            DSRV_PANIC(server, "can't create Config_boot method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceLetter", 'y', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_snapshot", Config_snapshot, NULL)))
+            DSRV_PANIC(server, "can't create Config_snapshot method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("State", 'u', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_ramsize", Config_ramsize, NULL)))
+            DSRV_PANIC(server, "can't create Config_snapshot method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("MegaBytes", 'u', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // ConfigDone declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_smp", Config_smp, NULL)))
+            DSRV_PANIC(server, "can't create Config_smp method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("CPUs", 'u', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+#ifdef HAS_AUDIO
+    // Config_SoundHWState declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SoundHWState", Config_SoundHWState, NULL)))
+            DSRV_PANIC(server, "can't create Config_SoundHWState method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Name", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("State", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+#endif //HAS AUDIO
+
+    // MonitorSetFloppy declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_SetFloppy", MonitorSetFloppy, NULL)))
+            DSRV_PANIC(server, "can't create MonitorSetFloppy method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Index", 'u', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("ImageName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_SetBlockDevice declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_SetBlockDevice", Monitor_SetBlockDevice, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_SetBlockDevice method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Index", 'u', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("ImageName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_SetCdrom declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_SetCdrom", Config_SetCdrom, NULL)))
+            DSRV_PANIC(server, "can't create Config_SetCdrom method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("ImageName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_AddNet declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_AddNet", Config_AddNet, NULL)))
+            DSRV_PANIC(server, "can't create Config_AddNet method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Parameters", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_BIOSDir declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_BIOSDir", Config_BIOSDir, NULL)))
+            DSRV_PANIC(server, "can't create Config_BIOSDir method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Directory", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_monitor declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_monitor", Config_monitor, NULL)))
+            DSRV_PANIC(server, "can't create Config_monitor method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_AddSerial declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_AddSerial", Monitor_AddSerial, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_AddSerial method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_AddSerial declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_RemoveSerial", Monitor_RemoveSerial, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_RemoveSerial method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceID", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_AddParallel declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_AddParallel", Monitor_AddParallel, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_AddParallel method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_AddParallel declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_RemoveParallel", Monitor_RemoveParallel, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_RemoveParallel method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceID", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_LoadVM declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_LoadVM", Monitor_LoadVM, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_LoadVM method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Filename", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Config_vnc declaration and params
+    if (!(method = dsrv_method_new(interface, "Config_vnc", Config_vnc, NULL)))
+            DSRV_PANIC(server, "can't create Config_vnc method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Display", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_commit declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_commit", Monitor_commit, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_commit method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_quit declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_quit", Monitor_quit, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_quit method");
+
+    // Monitor_eject declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_eject", Monitor_eject, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_eject method");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("Force", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Filename", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_change declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_change", Monitor_change, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_change method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Filename", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_savevm declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_savevm", Monitor_savevm, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_savevm method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_loadvm declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_loadvm", Monitor_loadvm, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_loadvm method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_delvm declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_delvm", Monitor_delvm, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_delvm method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("DeviceName", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_send_keys declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_send_key", Monitor_send_key, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_send_key method");
+    if ((err = dsrv_method_arg_add(method, dsrv_param_new("Keys", 's', NULL, 256))))
+            DSRV_PANIC(server, "can't add method param");
+    if ((err = dsrv_method_return_add (method, dsrv_param_new("ReturnCode", 'i', NULL, 0))))
+            DSRV_PANIC(server, "can't add method param");
+
+    // Monitor_system_reset declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_system_reset", Monitor_system_reset, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_system_reset method");
+
+    // Monitor_system_powerdown declaration and params
+    if (!(method = dsrv_method_new(interface, "Monitor_system_powerdown", Monitor_system_powerdown, NULL)))
+            DSRV_PANIC(server, "can't create Monitor_system_reset method");
+
+
+    // Connect to bus daemon
+    if ((err = dsrv_server_connect(server, 1)))
+            DSRV_PANIC(server, "connect failed: %s", err);
+
+    DSRV_LOG(server, DSRV_LOG_INFO, "DBus server is connected");
+
+    // start the main loop
+    dsrv_server_serve(server);
+
+    return 0;
+}
+
+
+void dbus_monitor_wait(void)
+{
+    pthread_mutex_lock(&conf_mutex);
+    while (!configured) {
+        pthread_cond_wait(&conf_cond, &conf_mutex);
+    }
+    pthread_mutex_unlock(&conf_mutex);
+}
+
+void dbus_monitor_init(void)
+{
+	if (pthread_create(&dbus_thread, NULL, dbus_main, NULL))
+		perror("dbus thread create failed");
+}
diff -Naur /yuval/Dev/qemu-cvs/qemu/dbus/monitor-dbus.h /yuval/Dev/qemu-dbus/qemu/dbus/monitor-dbus.h
--- /yuval/Dev/qemu-cvs/qemu/dbus/monitor-dbus.h	1970-01-01 02:00:00.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/dbus/monitor-dbus.h	2007-09-23 13:00:47.000000000 +0200
@@ -0,0 +1,60 @@
+#ifndef __monitor_dbus_h
+#define __monitor_dbus_h
+
+#include "vl.h"
+
+void dbus_monitor_init(void);
+void dbus_monitor_wait(void);
+
+//migration function declaration
+void mgmt_migrate_set_speed(uint32_t nBytes);
+void do_migrate_set_speed(const char *value);
+void do_migrate_cancel(void);
+int mgmt_migrate(int detach, const char *uri);
+
+// External variables, definded in vl.c and we need to use.
+extern int usb_enabled;
+extern USBPort *used_usb_ports;
+extern int boot_device;
+extern int snapshot;
+extern int ram_size;
+extern int smp_cpus;
+#ifdef HAS_AUDIO
+extern struct soundhw soundhw[];
+#endif
+extern BlockDriverState *fd_table[MAX_FD];
+/* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
+   to store the VM snapshots */
+extern BlockDriverState *bs_table[MAX_DISKS + 1];
+extern char *hd_filename[MAX_DISKS];
+extern char *fd_filename[MAX_FD];
+extern int cyls;
+extern int heads;
+extern int secs;
+extern int translation;
+extern int rtc_utc;
+extern int full_screen;
+extern int win2k_install_hack;
+extern char net_clients[MAX_NET_CLIENTS][256];
+extern int nb_net_clients;
+extern int cirrus_vga_enabled;
+extern int acpi_enabled;
+extern int time_drift_fix;
+extern int use_rtc;
+extern int no_quit;
+extern int fd_bootchk;
+extern int nographic;
+extern char monitor_device[128];
+extern char serial_devices[MAX_SERIAL_PORTS][128];
+extern int serial_device_index;
+extern char parallel_devices[MAX_PARALLEL_PORTS][128];
+extern int parallel_device_index;
+extern int no_reboot;
+extern const char *vnc_display;
+extern int daemonize;
+extern USBPort *used_usb_ports;
+extern const char *szDBusServiceName;
+extern int cdrom_index;
+
+#endif // __monitor_dbus_h
+
diff -Naur /yuval/Dev/qemu-cvs/qemu/error.c /yuval/Dev/qemu-dbus/qemu/error.c
--- /yuval/Dev/qemu-cvs/qemu/error.c	1970-01-01 02:00:00.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/error.c	2007-09-23 13:00:08.000000000 +0200
@@ -0,0 +1,27 @@
+#include "error.h"
+#include "vl.h"
+
+char g_szLastError[1024];
+
+void SetLastError(char *szErrorMsg) {
+	strcpy (g_szLastError,szErrorMsg);
+}
+
+void SetLastError_vprintf(const char *fmt, va_list ap)
+{
+    char buf[4096];
+    vsnprintf(buf, sizeof(buf), fmt, ap);
+    SetLastError(buf);
+}
+
+void SetLastError_printf(const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    SetLastError_vprintf(fmt, ap);
+    va_end(ap);
+}
+
+const char *GetLastError() {
+	return g_szLastError;
+}
diff -Naur /yuval/Dev/qemu-cvs/qemu/error.h /yuval/Dev/qemu-dbus/qemu/error.h
--- /yuval/Dev/qemu-cvs/qemu/error.h	1970-01-01 02:00:00.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/error.h	2007-09-23 13:00:08.000000000 +0200
@@ -0,0 +1,27 @@
+#include "error.h"
+#include "vl.h"
+
+char g_szLastError[1024];
+
+void SetLastError(char *szErrorMsg) {
+	strcpy (g_szLastError,szErrorMsg);
+}
+
+void SetLastError_vprintf(const char *fmt, va_list ap)
+{
+    char buf[4096];
+    vsnprintf(buf, sizeof(buf), fmt, ap);
+    SetLastError(buf);
+}
+
+void SetLastError_printf(const char *fmt, ...)
+{
+    va_list ap;
+    va_start(ap, fmt);
+    SetLastError_vprintf(fmt, ap);
+    va_end(ap);
+}
+
+const char *GetLastError() {
+	return g_szLastError;
+}
diff -Naur /yuval/Dev/qemu-cvs/qemu/Makefile.target /yuval/Dev/qemu-dbus/qemu/Makefile.target
--- /yuval/Dev/qemu-cvs/qemu/Makefile.target	2007-09-16 23:07:47.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/Makefile.target	2007-09-23 15:29:52.000000000 +0200
@@ -368,6 +368,19 @@
 
 # must use static linking to avoid leaving stuff in virtual address space
 VL_OBJS=vl.o osdep.o readline.o monitor.o pci.o console.o loader.o isa_mmio.o
+ifdef CONFIG_DBUS
+CPPFLAGS+=-I$(SRC_PATH)/dbus
+VL_OBJS+=/usr/local/lib/dsrv.o
+
+DBUS_SERVER := monitor-dbus
+DBUS_SERVOBJ :=$(DBUS_SERVER).o
+VL_OBJS+=$(DBUS_SERVOBJ)
+
+error.o: error.c
+	$(CC) $(OP_CFLAGS) $(CPPFLAGS) -c -o $@ $<
+
+VL_OBJS+=error.o
+endif
 VL_OBJS+=cutils.o
 VL_OBJS+=host-utils.o
 VL_OBJS+=block.o block-raw.o
@@ -659,6 +672,27 @@
 %.o: %.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
 
+ifdef CONFIG_DBUS
+
+PKGCONF ?= pkg-config
+BINDTOOL ?= dbus-binding-tool
+
+DBUS_CFLAGS +=-I$(SRC_PATH)/dbus/
+DBUS_CFLAGS += $(shell $(PKGCONF) --cflags dbus-1)
+DBUS_LDFLAGS += $(shell $(PKGCONF) --libs dbus-1)
+LIBS += $(DBUS_LDFLAGS)
+
+DBUS_SERVOBJECT := qemu_mon
+VL_OBJS+=$(DBUS_SERVOBJ)
+
+$(DBUS_SERVOBJ): dbus/monitor-dbus.c $(DBUS_SERVHDR)
+	$(CC) $(CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) $(DBUS_CFLAGS) -c -o $@ $<
+
+#$(DBUS_SERVHDR): dbus/$(DBUS_SERVER).xml
+#	 $(BINDTOOL) --prefix=$(DBUS_SERVOBJECT) --mode=glib-server --output=$@ $<	
+
+endif
+
 %.o: %.S
 	$(CC) $(CPPFLAGS) -c -o $@ $<
 
diff -Naur /yuval/Dev/qemu-cvs/qemu/monitor.c /yuval/Dev/qemu-dbus/qemu/monitor.c
--- /yuval/Dev/qemu-cvs/qemu/monitor.c	2007-09-19 07:49:13.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/monitor.c	2007-09-23 13:00:07.000000000 +0200
@@ -199,7 +199,7 @@
     help_cmd(name);
 }
 
-static void do_commit(const char *device)
+void do_commit(const char *device)
 {
     int i, all_devices;
 
@@ -378,7 +378,7 @@
     return 0;
 }
 
-static void do_eject(int force, const char *filename)
+void do_eject(int force, const char *filename)
 {
     BlockDriverState *bs;
 
@@ -420,7 +420,7 @@
     }
 }
 
-static void do_change(const char *device, const char *target)
+void do_change(const char *device, const char *target)
 {
     if (strcmp(device, "vnc") == 0) {
 	do_change_vnc(target);
@@ -873,7 +873,7 @@
     return -1;
 }
 
-static void do_send_key(const char *string)
+void do_send_key(const char *string)
 {
     char keybuf[16], *q;
     uint8_t keycodes[16];
diff -Naur /yuval/Dev/qemu-cvs/qemu/monitor.h /yuval/Dev/qemu-dbus/qemu/monitor.h
--- /yuval/Dev/qemu-cvs/qemu/monitor.h	1970-01-01 02:00:00.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/monitor.h	2007-09-23 13:00:07.000000000 +0200
@@ -0,0 +1,10 @@
+#ifndef __monitor_h
+#define __monitor_h
+
+void do_commit(const char *device);
+void do_eject(int force, const char *filename);
+void do_change(const char *device, const char *filename);
+void do_send_key(const char *string);
+
+#endif // __monitor_h
+
diff -Naur /yuval/Dev/qemu-cvs/qemu/vl.c /yuval/Dev/qemu-dbus/qemu/vl.c
--- /yuval/Dev/qemu-cvs/qemu/vl.c	2007-09-17 23:25:20.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/vl.c	2007-09-23 15:29:47.000000000 +0200
@@ -22,6 +22,7 @@
  * THE SOFTWARE.
  */
 #include "vl.h"
+#include "error.h"
 
 #include <unistd.h>
 #include <fcntl.h>
@@ -125,6 +126,7 @@
 
 //#define DEBUG_UNUSED_IOPORT
 //#define DEBUG_IOPORT
+#define DEBUG_ACPI
 
 #define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024)
 
@@ -150,11 +152,18 @@
 /* Note: bs_table[MAX_DISKS] is a dummy block driver if none available
    to store the VM snapshots */
 BlockDriverState *bs_table[MAX_DISKS + 1], *fd_table[MAX_FD];
+char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
+int cyls, heads, secs, translation;
 BlockDriverState *pflash_table[MAX_PFLASH];
 BlockDriverState *sd_bdrv;
 BlockDriverState *mtd_bdrv;
 /* point to the block driver where the snapshots are managed */
 BlockDriverState *bs_snapshots;
+char serial_devices[MAX_SERIAL_PORTS][128];
+int serial_device_index;
+char parallel_devices[MAX_PARALLEL_PORTS][128];
+int parallel_device_index;
+char monitor_device[128];
 int vga_ram_size;
 static DisplayState display_state;
 int nographic;
@@ -190,13 +199,6 @@
 static VLANState *first_vlan;
 int smp_cpus = 1;
 const char *vnc_display;
-#if defined(TARGET_SPARC)
-#define MAX_CPUS 16
-#elif defined(TARGET_I386)
-#define MAX_CPUS 255
-#else
-#define MAX_CPUS 1
-#endif
 int acpi_enabled = 1;
 int fd_bootchk = 1;
 int no_reboot = 0;
@@ -216,6 +218,13 @@
 unsigned int nb_prom_envs = 0;
 const char *prom_envs[MAX_PROM_ENVS];
 #endif
+int snapshot;
+int nb_net_clients;
+char net_clients[MAX_NET_CLIENTS][256];
+int cdrom_index;
+#ifdef CONFIG_DBUS
+const char *szDBusServiceName = NULL;
+#endif
 
 #define TFR(expr) do { if ((expr) != -1) break; } while (errno == EINTR)
 
@@ -459,6 +468,77 @@
     abort();
 }
 
+#ifdef DEBUG_ACPI
+#define DBG_ACPI_MSG(buff, len) { \
+    fprintf(stderr,"HOST acpid: "); \
+    write(2, buff, len);            \
+    fprintf(stderr,"\n");           \
+    }
+#else
+#define DBG_ACPI_MSG(buff, len) { }
+#endif
+             
+
+void acpid_channel_event(void *dummy, int event)
+{
+ //   printf("acpid_channel_event: event=%d\n", event);
+	return;
+}
+int acpid_channel_ready(void *dummy)
+{
+    //printf("acpid_channel_ready ... \n");
+    return 1024;
+}
+
+uint8_t acpi_lid_sts = 0;
+uint8_t acpi_adp_sts = 0;
+
+void acpid_channel_handler(void *dummy, const uint8_t *buff, int len)
+{
+   static int event_flag=0;   // remove!!!
+
+    DBG_ACPI_MSG(buff, len);
+/*  
+  if (strstr(buff,"lid") != NULL) {
+        // We need to read real LID status open/close
+        // and after that update the acpi_lid_sts
+        if (!(event_flag & (1<<0))) {
+            event_flag |= (1<<0);
+            acpi_lid_sts = 0x5a;
+            cpu_outw(NULL,0xb00c,(1 << 11));  // LID_STS
+        }else {
+            event_flag &= ~(1<<0);
+        }
+       DBG_ACPI_MSG("It's a LID event.",strlen("It's a LID event."));
+    }else 
+*/
+    if (strstr(buff,"ac_adapter") != NULL) {
+        // We need to read real AC adapter status on/off
+        // and after that update the acpi_adp_sts
+        if (!(event_flag & (1<<1))) {
+            event_flag |= (1<<1);
+            acpi_adp_sts = 0xa5;  // AC offline
+        }else {
+            event_flag &= ~(1<<1); 
+            acpi_adp_sts = 0x5a;  // AC online
+        }
+        DBG_ACPI_MSG("It's a ADP event.",strlen("It's a ADP event."));
+    }else{
+       DBG_ACPI_MSG("It's unknown event.",strlen("It's unknown event."));
+    }
+}
+
+
+void acpi_lid_status(uint8_t status)
+{
+    DBG_ACPI_MSG("It's a real LID event.",strlen("It's a real LID event."));
+    if (status) {
+        acpi_lid_sts = 0x5a;
+        cpu_outw(NULL,0xb00c,(1 << 11));  // LID_STS
+    }
+}
+
+
 /***********************************************************/
 /* keyboard/mouse */
 
@@ -3276,6 +3356,9 @@
                 break;
             }
         }
+#ifdef DEBUG_ACPI	
+	printf("connected(ret=%d) to fd %d (look at /proc/%d/fd/%d)\n",ret, fd, getpid(),fd);
+#endif
         s->fd = fd;
         socket_set_nodelay(fd);
         if (s->connected)
@@ -4670,6 +4753,10 @@
     return ret;
 }
 
+VLANState *get_first_vlan (void) {
+	return first_vlan;
+}
+
 void do_info_network(void)
 {
     VLANState *vlan;
@@ -4685,7 +4772,7 @@
 /***********************************************************/
 /* USB devices */
 
-static USBPort *used_usb_ports;
+USBPort *used_usb_ports;
 static USBPort *free_usb_ports;
 
 /* ??? Maybe change this to register a hub to keep track of the topology.  */
@@ -4699,7 +4786,7 @@
     free_usb_ports = port;
 }
 
-static int usb_device_add(const char *devname)
+int usb_device_add(const char *devname)
 {
     const char *p;
     USBDevice *dev;
@@ -4748,7 +4835,7 @@
     return 0;
 }
 
-static int usb_device_del(const char *devname)
+int usb_device_del(const char *devname)
 {
     USBPort *port;
     USBPort **lastp;
@@ -5498,14 +5585,14 @@
     return ret;
 }
 
-void do_savevm(const char *name)
-{
+int mgmt_savevm(const char *name) {
     BlockDriverState *bs, *bs1;
     QEMUSnapshotInfo sn1, *sn = &sn1, old_sn1, *old_sn = &old_sn1;
     int must_delete, ret, i;
     BlockDriverInfo bdi1, *bdi = &bdi1;
     QEMUFile *f;
     int saved_vm_running;
+    int nRC = 0;
 #ifdef _WIN32
     struct _timeb tb;
 #else
@@ -5515,7 +5602,7 @@
     bs = get_bs_snapshots();
     if (!bs) {
         term_printf("No block device can accept snapshots\n");
-        return;
+        return 1;
     }
 
     /* ??? Should this occur after vm_stop?  */
@@ -5553,22 +5640,25 @@
     sn->vm_clock_nsec = qemu_get_clock(vm_clock);
 
     if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) {
-        term_printf("Device %s does not support VM state snapshots\n",
+        SetLastError_printf("Device %s does not support VM state snapshots\n",
                     bdrv_get_device_name(bs));
+        nRC = 2;
         goto the_end;
     }
 
     /* save the VM state */
     f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 1);
     if (!f) {
-        term_printf("Could not open VM state file\n");
+        SetLastError("Could not open VM state file\n");
+        nRC = 3;
         goto the_end;
     }
     ret = qemu_savevm_state(f);
     sn->vm_state_size = qemu_ftell(f);
     qemu_fclose(f);
     if (ret < 0) {
-        term_printf("Error %d while writing VM\n", ret);
+        SetLastError_printf("Error %d while writing VM\n", ret);
+        nRC = 4;
         goto the_end;
     }
 
@@ -5580,35 +5670,50 @@
             if (must_delete) {
                 ret = bdrv_snapshot_delete(bs1, old_sn->id_str);
                 if (ret < 0) {
-                    term_printf("Error while deleting snapshot on '%s'\n",
+                    SetLastError_printf("Error while deleting snapshot on '%s'\n",
                                 bdrv_get_device_name(bs1));
+                    nRC = 5;
                 }
             }
             ret = bdrv_snapshot_create(bs1, sn);
             if (ret < 0) {
-                term_printf("Error while creating snapshot on '%s'\n",
+                SetLastError_printf("Error while creating snapshot on '%s'\n",
                             bdrv_get_device_name(bs1));
+                nRC = 6;
             }
         }
     }
 
  the_end:
-    if (saved_vm_running)
+    if (saved_vm_running) {
         vm_start();
+    }
+    return (nRC);
+}
+
+void do_savevm(const char *name) {
+    int nRC;
+
+    nRC = mgmt_savevm(name);
+
+    if (nRC != 0) {
+        term_printf("%s",GetLastError());
+    }
 }
 
-void do_loadvm(const char *name)
+int mgmt_loadvm(const char *name)
 {
     BlockDriverState *bs, *bs1;
     BlockDriverInfo bdi1, *bdi = &bdi1;
     QEMUFile *f;
     int i, ret;
     int saved_vm_running;
+    int nRC = 0;
 
     bs = get_bs_snapshots();
     if (!bs) {
-        term_printf("No block device supports snapshots\n");
-        return;
+        SetLastError_printf("No block device supports snapshots\n");
+        return 1;
     }
 
     /* Flush all IO requests so they don't interfere with the new state.  */
@@ -5622,76 +5727,114 @@
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_goto(bs1, name);
             if (ret < 0) {
-                if (bs != bs1)
-                    term_printf("Warning: ");
                 switch(ret) {
                 case -ENOTSUP:
-                    term_printf("Snapshots not supported on device '%s'\n",
-                                bdrv_get_device_name(bs1));
+                    SetLastError_printf(
+                        "%sSnapshots not supported on device '%s'\n",
+                        (bs != bs1) ? "Warning: " : "",
+                        bdrv_get_device_name(bs1)
+                    );
                     break;
                 case -ENOENT:
-                    term_printf("Could not find snapshot '%s' on device '%s'\n",
-                                name, bdrv_get_device_name(bs1));
+                    SetLastError_printf(
+                        "%sCould not find snapshot '%s' on device '%s'\n",
+                        (bs != bs1) ? "Warning: " : "",
+                        name,
+                        bdrv_get_device_name(bs1)
+                    );
                     break;
                 default:
-                    term_printf("Error %d while activating snapshot on '%s'\n",
-                                ret, bdrv_get_device_name(bs1));
+                    SetLastError_printf(
+                        "%sError %d while activating snapshot on '%s'\n",
+                        (bs != bs1) ? "Warning: " : "",
+                        bdrv_get_device_name(bs1)
+                    );
                     break;
                 }
                 /* fatal on snapshot block device */
-                if (bs == bs1)
+                if (bs == bs1) {
+                    nRC = 2;
                     goto the_end;
+                }
             }
         }
     }
 
     if (bdrv_get_info(bs, bdi) < 0 || bdi->vm_state_offset <= 0) {
-        term_printf("Device %s does not support VM state snapshots\n",
+        SetLastError_printf("Device %s does not support VM state snapshots\n",
                     bdrv_get_device_name(bs));
-        return;
+        return 3;
     }
 
     /* restore the VM state */
     f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 0);
     if (!f) {
-        term_printf("Could not open VM state file\n");
+        SetLastError_printf("Could not open VM state file\n");
+        nRC = 4;
         goto the_end;
     }
     ret = qemu_loadvm_state(f);
     qemu_fclose(f);
     if (ret < 0) {
-        term_printf("Error %d while loading VM state\n", ret);
+        SetLastError_printf("Error %d while loading VM state\n", ret);
+        nRC = 5;
     }
  the_end:
     if (saved_vm_running)
         vm_start();
+    return (nRC);
 }
 
-void do_delvm(const char *name)
+int mgmt_delvm(const char *name)
 {
     BlockDriverState *bs, *bs1;
     int i, ret;
+    int nRC = 0;
 
     bs = get_bs_snapshots();
     if (!bs) {
-        term_printf("No block device supports snapshots\n");
-        return;
+        SetLastError_printf("No block device supports snapshots\n");
+        return 1;
     }
 
+    SetLastError("");
     for(i = 0; i <= MAX_DISKS; i++) {
         bs1 = bs_table[i];
         if (bdrv_has_snapshot(bs1)) {
             ret = bdrv_snapshot_delete(bs1, name);
             if (ret < 0) {
-                if (ret == -ENOTSUP)
-                    term_printf("Snapshots not supported on device '%s'\n",
+                if (ret == -ENOTSUP) {
+                    SetLastError_printf("%sSnapshots not supported on device '%s'\n",
+                                GetLastError(),
                                 bdrv_get_device_name(bs1));
-                else
-                    term_printf("Error %d while deleting snapshot on '%s'\n",
+                    nRC = 2;
+                } else {
+                    SetLastError_printf("%sError %d while deleting snapshot on '%s'\n",
+                                GetLastError(),
                                 ret, bdrv_get_device_name(bs1));
+                    nRC = 3;
+                }
             }
         }
     }
+
+    return (nRC);
+}
+
+void do_delvm(const char *name) {
+    int nRC = 0;
+    nRC = mgmt_delvm(name);
+
+    if (nRC != 0) {
+        term_printf ("%s", GetLastError());
+    }
+}
+void do_loadvm(const char *name) {
+    int nRC;
+    nRC = mgmt_loadvm(name);
+    if (nRC != 0) {
+        term_printf ("%s", GetLastError());
+    }
 }
 
 void do_info_snapshots(void)
@@ -7067,6 +7210,10 @@
            "-kernel-kqemu   enable KQEMU full virtualization (default is user mode only)\n"
            "-no-kqemu       disable KQEMU kernel module usage\n"
 #endif
+#ifdef CONFIG_DBUS
+           "-dbus-service name  Set dbus service name and enables DBus support\n"
+           "-dbus-disable-configuration  do not wait for dbus configuration\n"
+#endif
 #ifdef USE_CODE_COPY
            "-no-code-copy   disable code copy acceleration\n"
 #endif
@@ -7185,6 +7332,10 @@
     QEMU_OPTION_prom_env,
     QEMU_OPTION_old_param,
     QEMU_OPTION_clock,
+#ifdef CONFIG_DBUS
+    QEMU_OPTION_dbus_service,
+    QEMU_OPTION_dbus_disable_configuration,
+#endif
 };
 
 typedef struct QEMUOption {
@@ -7248,6 +7399,10 @@
     { "no-kqemu", 0, QEMU_OPTION_no_kqemu },
     { "kernel-kqemu", 0, QEMU_OPTION_kernel_kqemu },
 #endif
+#ifdef CONFIG_DBUS
+    { "dbus_service", HAS_ARG, QEMU_OPTION_dbus_service },
+    { "dbus_disable_configuration", 0, QEMU_OPTION_dbus_disable_configuration },
+#endif
 #if defined(TARGET_PPC) || defined(TARGET_SPARC)
     { "g", 1, QEMU_OPTION_g },
 #endif
@@ -7524,26 +7679,18 @@
     int use_gdbstub;
     const char *gdbstub_port;
 #endif
-    int i, cdrom_index, pflash_index;
-    int snapshot, linux_boot;
+    int i, pflash_index;
+    int linux_boot;
     const char *initrd_filename;
-    const char *hd_filename[MAX_DISKS], *fd_filename[MAX_FD];
     const char *pflash_filename[MAX_PFLASH];
     const char *sd_filename;
     const char *mtd_filename;
     const char *kernel_filename, *kernel_cmdline;
     DisplayState *ds = &display_state;
-    int cyls, heads, secs, translation;
-    char net_clients[MAX_NET_CLIENTS][256];
-    int nb_net_clients;
     int optind;
     const char *r, *optarg;
     CharDriverState *monitor_hd;
-    char monitor_device[128];
-    char serial_devices[MAX_SERIAL_PORTS][128];
-    int serial_device_index;
-    char parallel_devices[MAX_PARALLEL_PORTS][128];
-    int parallel_device_index;
+    CharDriverState *acpid_conn;
     const char *loadvm = NULL;
     QEMUMachine *machine;
     const char *cpu_model;
@@ -7552,6 +7699,10 @@
     int fds[2];
     const char *pid_file = NULL;
     VLANState *vlan;
+#ifdef CONFIG_DBUS
+    int dbus_allowed = 0;
+    int dbus_wait = 1;
+#endif
 
     LIST_INIT (&vm_change_state_head);
 #ifndef _WIN32
@@ -8005,6 +8156,15 @@
                 kqemu_allowed = 2;
                 break;
 #endif
+#ifdef CONFIG_DBUS
+            case QEMU_OPTION_dbus_service:
+                dbus_allowed = 1;
+                szDBusServiceName = optarg;
+            break;
+            case QEMU_OPTION_dbus_disable_configuration:
+                dbus_wait = 0;
+            break;
+#endif
             case QEMU_OPTION_usb:
                 usb_enabled = 1;
                 break;
@@ -8076,6 +8236,17 @@
         }
     }
 
+#ifdef CONFIG_DBUS
+    // The DBus service should be initalized here, after CLI is read and BEFORE it is manipulated / acted upon.
+    if (dbus_allowed) {
+        dbus_monitor_init();
+
+        if (dbus_wait) {
+		dbus_monitor_wait();
+	}
+    }
+#endif
+
 #ifndef _WIN32
     if (daemonize && !nographic && vnc_display == NULL) {
 	fprintf(stderr, "Can only daemonize if using -nographic or -vnc\n");
@@ -8388,6 +8559,15 @@
         }
     }
 
+    if (acpi_enabled) {
+        acpid_conn = qemu_chr_open("unix:/var/run/acpid.socket");
+        if (!acpid_conn)
+            fprintf(stderr, "qemu: could not connect to acpid");
+        else {
+            qemu_chr_add_handlers(acpid_conn, acpid_channel_ready, acpid_channel_handler, acpid_channel_event, NULL);
+        }
+    }
+
     machine->init(ram_size, vga_ram_size, boot_device,
                   ds, fd_filename, snapshot,
                   kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
diff -Naur /yuval/Dev/qemu-cvs/qemu/vl.h /yuval/Dev/qemu-dbus/qemu/vl.h
--- /yuval/Dev/qemu-cvs/qemu/vl.h	2007-09-20 15:24:53.000000000 +0200
+++ /yuval/Dev/qemu-dbus/qemu/vl.h	2007-09-23 12:59:39.000000000 +0200
@@ -38,6 +38,19 @@
 #include <fcntl.h>
 #include <sys/stat.h>
 
+#define PHYS_RAM_MAX_SIZE (2047 * 1024 * 1024)
+
+#define MAX_NET_CLIENTS 32
+
+#if defined(TARGET_SPARC)
+#define MAX_CPUS 16
+#elif defined(TARGET_I386)
+#define MAX_CPUS 255
+#else
+#define MAX_CPUS 1
+#endif
+
+
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
 #endif
@@ -329,6 +342,7 @@
     QEMUBH *bh;
 } CharDriverState;
 
+void qemu_chr_close(CharDriverState *chr);
 CharDriverState *qemu_chr_open(const char *filename);
 void qemu_chr_printf(CharDriverState *s, const char *fmt, ...);
 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len);
@@ -412,6 +426,7 @@
 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
 void qemu_handler_true(void *opaque);
 
+VLANState *get_first_vlan (void);
 void do_info_network(void);
 
 /* TAP win32 */
@@ -549,6 +564,9 @@
 void cpu_save(QEMUFile *f, void *opaque);
 int cpu_load(QEMUFile *f, void *opaque, int version_id);
 
+int mgmt_savevm(const char *name);
+int mgmt_loadvm(const char *name);
+int mgmt_delvm(const char *name);
 void do_savevm(const char *name);
 void do_loadvm(const char *name);
 void do_delvm(const char *name);
@@ -1158,6 +1176,8 @@
 
 #include "hw/smbus.h"
 
+void acpi_lid_status(uint8_t status);
+
 /* acpi.c */
 extern int acpi_enabled;
 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base);
@@ -1384,6 +1404,8 @@
 
 #define VM_USB_HUB_SIZE 8
 
+int usb_device_add(const char *devname);
+int usb_device_del(const char *devname);
 void do_usb_add(const char *devname);
 void do_usb_del(const char *devname);
 void usb_info(void);
