X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fstream.c;h=359b0d4196e4bad5ce900f230c6cee9ce6cf8a6a;hb=ee75afdf55f45c216a5285eb2d6eadd934aac59c;hp=e470cd98bc62f9e6a6c8187ca06ee6b97b74d155;hpb=ae4e727a7abfdb7df9cb93769a0799494ec75254;p=palacios-OLD.git diff --git a/palacios/src/devices/stream.c b/palacios/src/devices/stream.c index e470cd9..359b0d4 100644 --- a/palacios/src/devices/stream.c +++ b/palacios/src/devices/stream.c @@ -27,33 +27,23 @@ struct stream_state { - void *stream; - struct vm_device *frontend_dev; + v3_stream_t stream; + + struct v3_dev_char_ops * char_ops; }; -static int stream_read(char *buf, uint_t length, void *private_data) -{ - struct vm_device *dev = (struct vm_device *) private_data; - struct stream_state *state = (struct stream_state *) dev->private_data; - - return V3_StreamRead(state->stream,buf,length); -} -static int stream_write(char *buf, uint_t length, void *private_data) +static int stream_write(uint8_t * buf, uint64_t length, void * private_data) { struct vm_device *dev = (struct vm_device *) private_data; struct stream_state *state = (struct stream_state *) dev->private_data; - return V3_StreamWrite(state->stream,buf,length); + return v3_stream_write(state->stream, buf, length); } -static struct v3_stream_ops stream_ops = { - .write = stream_write, - .read = stream_read -}; static struct v3_device_ops dev_ops = { .free = NULL, @@ -64,48 +54,44 @@ static struct v3_device_ops dev_ops = { static int stream_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { - v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend"); - const char * frontend_tag = v3_cfg_val(frontend_cfg, "tag"); - struct vm_device * frontend = v3_find_dev(vm, frontend_tag); + // v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend"); char * dev_id = v3_cfg_val(cfg, "ID"); - char * path = v3_cfg_val(cfg, "localname"); + char * stream_name = v3_cfg_val(cfg, "stream"); + struct stream_state * state = NULL; - /* read configuration */ - V3_ASSERT(frontend_cfg); - V3_ASSERT(frontend_tag); - V3_ASSERT(frontend); - - /* allocate state */ - state = (struct cons_state *)V3_Malloc(sizeof(struct stream_state)); + state = (struct stream_state *)V3_Malloc(sizeof(struct stream_state)); + V3_ASSERT(state); - state->frontend_dev = frontend; - V3_ASSERT(path); - - /* The system is responsible for interpreting the localname of the stream */ - state->stream = V3_StreamOpen(ttypath, STREAM_OPEN_MODE_READ | STREAM_OPEN_MODE_WRITE); - if (!state->stream) { - PrintError("Could not open localname %s\n", path); + + + state->stream = v3_stream_open(vm, stream_name); + + if (state->stream == NULL) { + PrintError("Could not open stream %s\n", stream_name); V3_Free(state); return -1; } - /* allocate device */ - struct vm_device *dev = v3_allocate_device(dev_id, &dev_ops, state); - V3_ASSERT(dev); + state->char_ops->write = stream_write; + + struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state); + + if (dev == NULL) { + PrintError("Could not allocate device %s\n", dev_id); + return -1; + } - /* attach device to virtual machine */ if (v3_attach_device(vm, dev) == -1) { PrintError("Could not attach device %s\n", dev_id); V3_Free(state); return -1; } - /* attach to front-end display adapter */ - v3_console_register_cga(frontend, &cons_ops, dev); - return 0; + + return 0; } -device_register("CURSES_CONSOLE", cons_init) +device_register("STREAM", stream_init)