Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


pci_front bugfix - do not propagate cmd reg write twice
[palacios.git] / palacios / src / interfaces / vmm_stream.c
index 66ce081..3a3ccf7 100644 (file)
 static struct v3_stream_hooks * stream_hooks = NULL;
 
 // VM can be NULL
-v3_stream_t v3_stream_open(struct v3_vm_info * vm, const char * name) {
-    V3_ASSERT(stream_hooks != NULL);
-    V3_ASSERT(stream_hooks->open != NULL);
+struct v3_stream * v3_stream_open(struct v3_vm_info * vm, const char * name, 
+                                 sint64_t (*input)(struct v3_stream * stream, uint8_t * buf, sint64_t len),
+                                 void * guest_stream_data) {
+    struct v3_stream * stream = NULL;
 
-    return stream_hooks->open(name, vm->host_priv_data);
-}
+    V3_ASSERT(vm, VCORE_NONE, stream_hooks != NULL);
+    V3_ASSERT(vm, VCORE_NONE, stream_hooks->open != NULL);
+
+    stream = V3_Malloc(sizeof(struct v3_stream));
+
+    if (!stream) {
+       PrintError(vm, VCORE_NONE, "Cannot allocate in opening a stream\n");
+       return NULL;
+    }
 
-int v3_stream_write(v3_stream_t stream, uint8_t * buf, uint32_t len) {
-    V3_ASSERT(stream_hooks != NULL);
-    V3_ASSERT(stream_hooks->write != NULL);
+    stream->input = input;
+    stream->guest_stream_data = guest_stream_data;
+    stream->host_stream_data = stream_hooks->open(stream, name, vm->host_priv_data);
 
-    return stream_hooks->write(stream, buf, len);
+    return stream;
 }
 
-void v3_stream_close(v3_stream_t stream) {
-    V3_ASSERT(stream_hooks != NULL);
-    V3_ASSERT(stream_hooks->close != NULL);
+sint64_t v3_stream_output(struct v3_stream * stream, uint8_t * buf, sint64_t len) {
+    V3_ASSERT(VM_NONE, VCORE_NONE, stream_hooks != NULL);
+    V3_ASSERT(VM_NONE, VCORE_NONE, stream_hooks->output != NULL);
 
-    return stream_hooks->close(stream);
+    return stream_hooks->output(stream, buf, len);
 }
 
+void v3_stream_close(struct v3_stream * stream) {
+    V3_ASSERT(VM_NONE, VCORE_NONE, stream_hooks != NULL);
+    V3_ASSERT(VM_NONE, VCORE_NONE, stream_hooks->close != NULL);
 
+    stream_hooks->close(stream);
+
+    V3_Free(stream);
+}
 
 
 
 void V3_Init_Stream(struct v3_stream_hooks * hooks) {
     stream_hooks = hooks;
-    PrintDebug("V3 stream inited\n");
+    PrintDebug(VM_NONE, VCORE_NONE, "V3 stream inited\n");
 
     return;
 }