summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-05-03 23:48:06 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-05-03 23:48:06 +0000
commit6c118b8f8965a5fbb602ad556b584f6f8c0c26c0 (patch)
tree925941099ee1d4be16a50a240397e639061ff878
parent49083add823f626a3f0d3b121491e0e66aacbe7c (diff)
downloadmdk-6c118b8f8965a5fbb602ad556b584f6f8c0c26c0.tar.gz
mdk-6c118b8f8965a5fbb602ad556b584f6f8c0c26c0.tar.bz2
new devices are created by a (possibly externally provided) factory
-rw-r--r--mixlib/mix_vm.c11
-rw-r--r--mixlib/mix_vm.h5
-rw-r--r--mixlib/xmix_vm.c2
-rw-r--r--mixlib/xmix_vm.h1
4 files changed, 18 insertions, 1 deletions
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.