mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/win32-vd_agent
synced 2026-02-01 19:38:56 +00:00
vdservice/vdi_port refactor: cosmetic changes
* move comment about ring to the proper file, vdi_port.h * introduce enums for EVENT indices (0,1 for Virtio, 0 for PCI) * move fill_events to cpp (leave the single lines inline).
This commit is contained in:
parent
0f92cbea70
commit
db2d109d69
@ -52,6 +52,10 @@ PCIVDIPort::~PCIVDIPort()
|
||||
}
|
||||
}
|
||||
|
||||
void PCIVDIPort::fill_events(HANDLE *handle) {
|
||||
handle[PCI_VDI_PORT_EVENT] = _event;
|
||||
}
|
||||
|
||||
bool PCIVDIPort::init()
|
||||
{
|
||||
DWORD io_ret_len;
|
||||
|
||||
@ -1,54 +1,59 @@
|
||||
/*
|
||||
Copyright (C) 2009 Red Hat, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _H_PCI_VDI_PORT
|
||||
#define _H_PCI_VDI_PORT
|
||||
|
||||
#include "vdi_port.h"
|
||||
|
||||
#define BUF_READ (1 << 0)
|
||||
#define BUF_WRITE (1 << 1)
|
||||
#define BUF_ALL (BUF_READ | BUF_WRITE)
|
||||
|
||||
class PCIVDIPort : public VDIPort {
|
||||
public:
|
||||
PCIVDIPort();
|
||||
~PCIVDIPort();
|
||||
virtual bool init();
|
||||
virtual const char *name() { return "PCIVDIPort"; }
|
||||
virtual int write();
|
||||
virtual int read();
|
||||
virtual unsigned get_num_events() { return 1; }
|
||||
virtual void fill_events(HANDLE *handle) {
|
||||
handle[0] = _event;
|
||||
}
|
||||
virtual void handle_event(int event);
|
||||
|
||||
private:
|
||||
HANDLE _handle;
|
||||
HANDLE _event;
|
||||
};
|
||||
|
||||
// Ring notes:
|
||||
// _end is one after the end of data
|
||||
// _start==_end means empty ring
|
||||
// _start-1==_end (modulo) means full ring
|
||||
// _start-1 is never used
|
||||
// ring_write & read on right side of the ring (update _end)
|
||||
// ring_read & write from left (update _start)
|
||||
|
||||
#endif
|
||||
/*
|
||||
Copyright (C) 2009 Red Hat, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _H_PCI_VDI_PORT
|
||||
#define _H_PCI_VDI_PORT
|
||||
|
||||
#include "vdi_port.h"
|
||||
|
||||
#define BUF_READ (1 << 0)
|
||||
#define BUF_WRITE (1 << 1)
|
||||
#define BUF_ALL (BUF_READ | BUF_WRITE)
|
||||
|
||||
enum {
|
||||
PCI_VDI_PORT_EVENT = 0,
|
||||
PCI_VDI_PORT_EVENT_COUNT
|
||||
};
|
||||
|
||||
class PCIVDIPort : public VDIPort {
|
||||
public:
|
||||
PCIVDIPort();
|
||||
~PCIVDIPort();
|
||||
virtual bool init();
|
||||
virtual const char *name() {
|
||||
return "PCIVDIPort";
|
||||
}
|
||||
virtual int write();
|
||||
virtual int read();
|
||||
virtual unsigned get_num_events() { return PCI_VDI_PORT_EVENT_COUNT; }
|
||||
virtual void fill_events(HANDLE* handle);
|
||||
virtual void handle_event(int event);
|
||||
|
||||
private:
|
||||
HANDLE _handle;
|
||||
HANDLE _event;
|
||||
};
|
||||
|
||||
// Ring notes:
|
||||
// _end is one after the end of data
|
||||
// _start==_end means empty ring
|
||||
// _start-1==_end (modulo) means full ring
|
||||
// _start-1 is never used
|
||||
// ring_write & read on right side of the ring (update _end)
|
||||
// ring_read & write from left (update _start)
|
||||
|
||||
#endif
|
||||
|
||||
@ -74,17 +74,17 @@ size_t VDIPort::ring_read(void* buf, size_t size)
|
||||
_read.start = _read.ring + (_read.start - _read.ring + n + m) % BUF_SIZE;
|
||||
return n + m;
|
||||
}
|
||||
|
||||
int VDIPort::handle_error()
|
||||
{
|
||||
switch (GetLastError()) {
|
||||
case ERROR_CONNECTION_INVALID:
|
||||
vd_printf("port reset");
|
||||
_write.start = _write.end = _write.ring;
|
||||
_read.start = _read.end = _read.ring;
|
||||
return VDI_PORT_RESET;
|
||||
default:
|
||||
vd_printf("port io failed: %u", GetLastError());
|
||||
return VDI_PORT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
int VDIPort::handle_error()
|
||||
{
|
||||
switch (GetLastError()) {
|
||||
case ERROR_CONNECTION_INVALID:
|
||||
vd_printf("port reset");
|
||||
_write.start = _write.end = _write.ring;
|
||||
_read.start = _read.end = _read.ring;
|
||||
return VDI_PORT_RESET;
|
||||
default:
|
||||
vd_printf("port io failed: %u", GetLastError());
|
||||
return VDI_PORT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,6 +28,14 @@
|
||||
#define VDI_PORT_BLOCKED 0
|
||||
#define VDI_PORT_RESET -1
|
||||
#define VDI_PORT_ERROR -2
|
||||
|
||||
// Ring notes:
|
||||
// _end is one after the end of data
|
||||
// _start==_end means empty ring
|
||||
// _start-1==_end (modulo) means full ring
|
||||
// _start-1 is never used
|
||||
// ring_write & read on right side of the ring (update _end)
|
||||
// ring_read & write from left (update _start)
|
||||
|
||||
typedef struct VDIPortBuffer {
|
||||
OVERLAPPED overlap;
|
||||
|
||||
@ -46,6 +46,24 @@ VirtioVDIPort::~VirtioVDIPort()
|
||||
}
|
||||
}
|
||||
|
||||
void VirtioVDIPort::fill_events(HANDLE *handle) {
|
||||
handle[VIRTIO_VDI_PORT_EVENT_WRITE] = _write.overlap.hEvent;
|
||||
handle[VIRTIO_VDI_PORT_EVENT_READ] = _read.overlap.hEvent;
|
||||
}
|
||||
|
||||
void VirtioVDIPort::handle_event(int event) {
|
||||
switch (event) {
|
||||
case VIRTIO_VDI_PORT_EVENT_WRITE:
|
||||
write_completion();
|
||||
break;
|
||||
case VIRTIO_VDI_PORT_EVENT_READ:
|
||||
read_completion();
|
||||
break;
|
||||
default:
|
||||
vd_printf("ERROR: unexpected event %d", event);
|
||||
}
|
||||
}
|
||||
|
||||
bool VirtioVDIPort::init()
|
||||
{
|
||||
_handle = CreateFile(VIOSERIAL_PORT_PATH, GENERIC_READ | GENERIC_WRITE , 0, NULL,
|
||||
|
||||
@ -3,23 +3,21 @@
|
||||
|
||||
#include "vdi_port.h"
|
||||
|
||||
enum {
|
||||
VIRTIO_VDI_PORT_EVENT_WRITE=0,
|
||||
VIRTIO_VDI_PORT_EVENT_READ,
|
||||
VIRTIO_VDI_PORT_EVENT_COUNT
|
||||
};
|
||||
|
||||
class VirtioVDIPort : public VDIPort {
|
||||
public:
|
||||
VirtioVDIPort();
|
||||
~VirtioVDIPort();
|
||||
virtual const char *name() { return "VirtioVDIPort"; }
|
||||
virtual const char *name() { return "VirtioVDIPort"; }
|
||||
virtual bool init();
|
||||
virtual unsigned get_num_events() { return 2; }
|
||||
virtual void fill_events(HANDLE *handle) {
|
||||
handle[0] = _write.overlap.hEvent;
|
||||
handle[1] = _read.overlap.hEvent;
|
||||
}
|
||||
virtual void handle_event(int event) {
|
||||
switch (event) {
|
||||
case 0: write_completion(); break;
|
||||
case 1: read_completion(); break;
|
||||
}
|
||||
}
|
||||
virtual unsigned get_num_events() { return VIRTIO_VDI_PORT_EVENT_COUNT; }
|
||||
virtual void fill_events(HANDLE *handle);
|
||||
virtual void handle_event(int event);
|
||||
virtual int write();
|
||||
virtual int read();
|
||||
|
||||
@ -32,13 +30,4 @@ private:
|
||||
HANDLE _handle;
|
||||
};
|
||||
|
||||
// Ring notes:
|
||||
// _end is one after the end of data
|
||||
// _start==_end means empty ring
|
||||
// _start-1==_end (modulo) means full ring
|
||||
// _start-1 is never used
|
||||
// ring_write & read on right side of the ring (update _end)
|
||||
// ring_read & write from left (update _start)
|
||||
|
||||
|
||||
#endif //_H_VIRTIO_VDI_PORT
|
||||
Loading…
Reference in New Issue
Block a user