From 6c118b8f8965a5fbb602ad556b584f6f8c0c26c0 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Thu, 3 May 2001 23:48:06 +0000 Subject: new devices are created by a (possibly externally provided) factory --- mixlib/mix_vm.c | 11 +++++++++++ mixlib/mix_vm.h | 5 +++++ mixlib/xmix_vm.c | 2 +- mixlib/xmix_vm.h | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mixlib/mix_vm.c b/mixlib/mix_vm.c index 9a39247..39b3e6f 100644 --- a/mixlib/mix_vm.c +++ b/mixlib/mix_vm.c @@ -76,8 +76,10 @@ mix_vm_new (void) vm->devices[i] = NULL; vm->clock = mix_vm_clock_new (); + vm->factory = mix_device_new; vm_reset_ (vm); + return vm; } @@ -116,6 +118,15 @@ mix_vm_connect_device (mix_vm_t *vm, mix_device_t *device) return old; } +/* install a device factory for automatic connection */ +void +mix_vm_set_device_factory (mix_vm_t *vm, mix_device_factory_t factory) +{ + g_return_if_fail (vm != NULL); + g_return_if_fail (factory != NULL); + vm->factory = factory; +} + /* Reset a vm (set state as of a newly created one) */ void mix_vm_reset (mix_vm_t * vm) diff --git a/mixlib/mix_vm.h b/mixlib/mix_vm.h index b64e197..c4663bc 100644 --- a/mixlib/mix_vm.h +++ b/mixlib/mix_vm.h @@ -51,6 +51,11 @@ mix_vm_delete(mix_vm_t * vm); extern mix_device_t * /* previously connected device */ mix_vm_connect_device (mix_vm_t *vm, mix_device_t *device); +/* install a device factory for automatic connection */ +typedef mix_device_t * (* mix_device_factory_t) (mix_device_type_t device); +extern void +mix_vm_set_device_factory (mix_vm_t *vm, mix_device_factory_t factory); + /* Reset a vm (set state as of a newly created one) */ extern void mix_vm_reset(mix_vm_t * vm); diff --git a/mixlib/xmix_vm.c b/mixlib/xmix_vm.c index e614cb4..c810a71 100644 --- a/mixlib/xmix_vm.c +++ b/mixlib/xmix_vm.c @@ -52,7 +52,7 @@ get_dev_ (mix_vm_t *vm, mix_fspec_t type) { if (type >= BD_NO_) return NULL; if (vm->devices[type] == NULL) - vm->devices[type] = mix_device_new (type); + vm->devices[type] = vm->factory (type); return vm->devices[type]; } diff --git a/mixlib/xmix_vm.h b/mixlib/xmix_vm.h index 7255d02..d5cbff4 100644 --- a/mixlib/xmix_vm.h +++ b/mixlib/xmix_vm.h @@ -49,6 +49,7 @@ struct mix_vm_t mix_vm_clock_t *clock; /* the vm clock */ mix_symbol_table_t *symbol_table; mix_src_file_t *src_file; /* source of last loaded code file */ + mix_device_factory_t factory; /* the factory for new devices */ }; /* Macros for accessing/modifying the above structure. -- cgit v1.2.3