Commit 0bd488500244aee6596097b564eb95a32823a6d9

Authored by bellard
1 parent 946fc947

API for changes in VM state (malc)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1614 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 50 additions and 3 deletions
@@ -2935,9 +2935,47 @@ void gui_update(void *opaque) @@ -2935,9 +2935,47 @@ void gui_update(void *opaque)
2935 qemu_mod_timer(gui_timer, GUI_REFRESH_INTERVAL + qemu_get_clock(rt_clock)); 2935 qemu_mod_timer(gui_timer, GUI_REFRESH_INTERVAL + qemu_get_clock(rt_clock));
2936 } 2936 }
2937 2937
  2938 +struct vm_change_state_entry {
  2939 + VMChangeStateHandler *cb;
  2940 + void *opaque;
  2941 + LIST_ENTRY (vm_change_state_entry) entries;
  2942 +};
  2943 +
  2944 +static LIST_HEAD(vm_change_state_head, vm_change_state_entry) vm_change_state_head;
  2945 +
  2946 +VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
  2947 + void *opaque)
  2948 +{
  2949 + VMChangeStateEntry *e;
  2950 +
  2951 + e = qemu_mallocz(sizeof (*e));
  2952 + if (!e)
  2953 + return NULL;
  2954 +
  2955 + e->cb = cb;
  2956 + e->opaque = opaque;
  2957 + LIST_INSERT_HEAD(&vm_change_state_head, e, entries);
  2958 + return e;
  2959 +}
  2960 +
  2961 +void qemu_del_vm_change_state_handler(VMChangeStateEntry *e)
  2962 +{
  2963 + LIST_REMOVE (e, entries);
  2964 + qemu_free (e);
  2965 +}
  2966 +
  2967 +static void vm_state_notify(int running)
  2968 +{
  2969 + VMChangeStateEntry *e;
  2970 +
  2971 + for (e = vm_change_state_head.lh_first; e; e = e->entries.le_next) {
  2972 + e->cb(e->opaque, running);
  2973 + }
  2974 +}
  2975 +
2938 /* XXX: support several handlers */ 2976 /* XXX: support several handlers */
2939 -VMStopHandler *vm_stop_cb;  
2940 -VMStopHandler *vm_stop_opaque; 2977 +static VMStopHandler *vm_stop_cb;
  2978 +static void *vm_stop_opaque;
2941 2979
2942 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque) 2980 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque)
2943 { 2981 {
@@ -2956,6 +2994,7 @@ void vm_start(void) @@ -2956,6 +2994,7 @@ void vm_start(void)
2956 if (!vm_running) { 2994 if (!vm_running) {
2957 cpu_enable_ticks(); 2995 cpu_enable_ticks();
2958 vm_running = 1; 2996 vm_running = 1;
  2997 + vm_state_notify(1);
2959 } 2998 }
2960 } 2999 }
2961 3000
@@ -2969,6 +3008,7 @@ void vm_stop(int reason) @@ -2969,6 +3008,7 @@ void vm_stop(int reason)
2969 vm_stop_cb(vm_stop_opaque, reason); 3008 vm_stop_cb(vm_stop_opaque, reason);
2970 } 3009 }
2971 } 3010 }
  3011 + vm_state_notify(0);
2972 } 3012 }
2973 } 3013 }
2974 3014
@@ -3588,7 +3628,8 @@ int main(int argc, char **argv) @@ -3588,7 +3628,8 @@ int main(int argc, char **argv)
3588 QEMUMachine *machine; 3628 QEMUMachine *machine;
3589 char usb_devices[MAX_VM_USB_PORTS][128]; 3629 char usb_devices[MAX_VM_USB_PORTS][128];
3590 int usb_devices_index; 3630 int usb_devices_index;
3591 - 3631 +
  3632 + LIST_INIT (&vm_change_state_head);
3592 #if !defined(CONFIG_SOFTMMU) 3633 #if !defined(CONFIG_SOFTMMU)
3593 /* we never want that malloc() uses mmap() */ 3634 /* we never want that malloc() uses mmap() */
3594 mallopt(M_MMAP_THRESHOLD, 4096 * 1024); 3635 mallopt(M_MMAP_THRESHOLD, 4096 * 1024);
@@ -97,8 +97,14 @@ int strstart(const char *str, const char *val, const char **ptr); @@ -97,8 +97,14 @@ int strstart(const char *str, const char *val, const char **ptr);
97 97
98 extern int vm_running; 98 extern int vm_running;
99 99
  100 +typedef struct vm_change_state_entry VMChangeStateEntry;
  101 +typedef void VMChangeStateHandler(void *opaque, int running);
100 typedef void VMStopHandler(void *opaque, int reason); 102 typedef void VMStopHandler(void *opaque, int reason);
101 103
  104 +VMChangeStateEntry *qemu_add_vm_change_state_handler(VMChangeStateHandler *cb,
  105 + void *opaque);
  106 +void qemu_del_vm_change_state_handler(VMChangeStateEntry *e);
  107 +
102 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque); 108 int qemu_add_vm_stop_handler(VMStopHandler *cb, void *opaque);
103 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque); 109 void qemu_del_vm_stop_handler(VMStopHandler *cb, void *opaque);
104 110