From: Owen Smith Date: Mon, 27 Jun 2016 16:35:44 +0000 (+0100) Subject: Add XenIfaceDevice X-Git-Tag: 8.2.0-rc1~24 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7736d88f5a81a67ab77478ea97a9280b1bb93b6e;p=pvdrivers%2Fwin%2Fxeniface.git Add XenIfaceDevice XenIfaceDevice is a CDevice subclass that abstracts the IOCTL interface by managing the conversion to/from IOCTL inputs/outputs. Signed-off-by: Owen Smith Fix VS2013 build. Signed-off-by: Paul Durrant --- diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp index b48d032..192d682 100644 --- a/src/xenagent/service.cpp +++ b/src/xenagent/service.cpp @@ -171,7 +171,7 @@ CXenAgent::~CXenAgent() /*virtual*/ CDevice* CXenAgent::Create(const wchar_t* path) { - return new CDevice(path); + return new CXenIfaceDevice(path); } /*virtual*/ void CXenAgent::OnDeviceAdded(CDevice* dev) diff --git a/src/xenagent/service.h b/src/xenagent/service.h index f8e4b67..af554c9 100644 --- a/src/xenagent/service.h +++ b/src/xenagent/service.h @@ -39,6 +39,7 @@ #define SVC_DESC "Monitors and provides various metrics to XenStore" #include "devicelist.h" +#include "xenifacedevice.h" class CXenAgent : public IDeviceCreator { diff --git a/src/xenagent/xenifacedevice.cpp b/src/xenagent/xenifacedevice.cpp new file mode 100644 index 0000000..98e4d2f --- /dev/null +++ b/src/xenagent/xenifacedevice.cpp @@ -0,0 +1,155 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include + +#include "xenifacedevice.h" +#include "devicelist.h" +#include "xeniface_ioctls.h" + +CXenIfaceDevice::CXenIfaceDevice(const wchar_t* path) : CDevice(path) +{} + +/*virtual*/ CXenIfaceDevice::~CXenIfaceDevice() +{} + +// store interface +bool CXenIfaceDevice::StoreRead(const std::string& path, std::string& value) +{ + DWORD bytes(0); + char* buffer; + bool result; + + Ioctl(IOCTL_XENIFACE_STORE_READ, + (void*)path.c_str(), (DWORD)path.length() + 1, + NULL, 0, + &bytes); + + buffer = new char[bytes + 1]; + if (buffer == NULL) + return false; + + result = Ioctl(IOCTL_XENIFACE_STORE_READ, + (void*)path.c_str(), (DWORD)path.length() + 1, + buffer, bytes); + + buffer[bytes] = 0; + if (result) + value = buffer; + + delete [] buffer; + return result; +} + +bool CXenIfaceDevice::StoreWrite(const std::string& path, const std::string& value) +{ + bool result; + size_t length = path.length() + 1 + value.length() + 1 + 1; + char* buffer = new char[length]; + if (buffer == NULL) + return false; + + memcpy(buffer, path.c_str(), path.length()); + buffer[path.length()] = 0; + + memcpy(buffer + path.length() + 1, value.c_str(), value.length()); + buffer[path.length() + 1 + value.length()] = 0; + buffer[length - 1] = 0; + + result = Ioctl(IOCTL_XENIFACE_STORE_WRITE, buffer, (DWORD)length, NULL, 0); + delete [] buffer; + return result; +} + +bool CXenIfaceDevice::StoreRemove(const std::string& path) +{ + return Ioctl(IOCTL_XENIFACE_STORE_REMOVE, + (void*)path.c_str(), (DWORD)path.length() + 1, + NULL, 0); +} + +bool CXenIfaceDevice::StoreAddWatch(const std::string& path, HANDLE evt, void** ctxt) +{ + XENIFACE_STORE_ADD_WATCH_IN in = { (PCHAR)path.c_str(), (DWORD)path.length() + 1, evt }; + XENIFACE_STORE_ADD_WATCH_OUT out = { NULL }; + if (!Ioctl(IOCTL_XENIFACE_STORE_ADD_WATCH, + &in, (DWORD)sizeof(in), + &out, (DWORD)sizeof(out))) + return false; + *ctxt = out.Context; + return true; +} + +bool CXenIfaceDevice::StoreRemoveWatch(void* ctxt) +{ + XENIFACE_STORE_REMOVE_WATCH_IN in = { ctxt }; + return Ioctl(IOCTL_XENIFACE_STORE_REMOVE_WATCH, + &in, (DWORD)sizeof(in), + NULL, 0); +} + +// suspend interface +bool CXenIfaceDevice::SuspendRegister(HANDLE evt, void** ctxt) +{ + XENIFACE_SUSPEND_REGISTER_IN in = { evt }; + XENIFACE_SUSPEND_REGISTER_OUT out = { NULL }; + if (!Ioctl(IOCTL_XENIFACE_SUSPEND_REGISTER, + &in, (DWORD)sizeof(in), + &out, (DWORD)sizeof(out))) + return false; + *ctxt = out.Context; + return true; +} + +bool CXenIfaceDevice::SuspendDeregister(void* ctxt) +{ + XENIFACE_SUSPEND_REGISTER_OUT in = { ctxt }; + return Ioctl(IOCTL_XENIFACE_SUSPEND_DEREGISTER, + &in, (DWORD)sizeof(in), + NULL, 0); +} + +// sharedinfo interface +bool CXenIfaceDevice::SharedInfoGetTime(FILETIME* time) +{ + return Ioctl(IOCTL_XENIFACE_SHAREDINFO_GET_TIME, + NULL, 0, + time, sizeof(FILETIME)); +} + +// logging +bool CXenIfaceDevice::Log(const std::string& msg) +{ + return Ioctl(IOCTL_XENIFACE_LOG, + (void*)msg.c_str(), (DWORD)msg.length() + 1, + NULL, 0); +} diff --git a/src/xenagent/xenifacedevice.h b/src/xenagent/xenifacedevice.h new file mode 100644 index 0000000..163b193 --- /dev/null +++ b/src/xenagent/xenifacedevice.h @@ -0,0 +1,63 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __XENAGENT_XENIFACEDEVICE_H__ +#define __XENAGENT_XENIFACEDEVICE_H__ + +#include +#include +#include "devicelist.h" + +class CXenIfaceDevice : public CDevice +{ +public: + CXenIfaceDevice(const wchar_t* path); + virtual ~CXenIfaceDevice(); + +public: // store interface + bool StoreRead(const std::string& path, std::string& value); + bool StoreWrite(const std::string& path, const std::string& value); + bool StoreRemove(const std::string& path); + bool StoreAddWatch(const std::string& path, HANDLE evt, void** ctxt); + bool StoreRemoveWatch(void* ctxt); + +public: // suspend interface + bool SuspendRegister(HANDLE evt, void** ctxt); + bool SuspendDeregister(void* ctxt); + +public: // sharedinfo interface + bool SharedInfoGetTime(FILETIME* time); + +public: // logging + bool Log(const std::string& msg); +}; + +#endif diff --git a/vs2012/xenagent/xenagent.vcxproj b/vs2012/xenagent/xenagent.vcxproj index 6c9c91c..37db3fd 100644 --- a/vs2012/xenagent/xenagent.vcxproj +++ b/vs2012/xenagent/xenagent.vcxproj @@ -195,10 +195,12 @@ + + diff --git a/vs2013/xenagent/xenagent.vcxproj b/vs2013/xenagent/xenagent.vcxproj index b72705a..4f5db55 100644 --- a/vs2013/xenagent/xenagent.vcxproj +++ b/vs2013/xenagent/xenagent.vcxproj @@ -199,10 +199,12 @@ + +