]> xenbits.xensource.com Git - pvdrivers/win/xeniface.git/commitdiff
Add XenIfaceDevice
authorOwen Smith <owen.smith@citrix.com>
Mon, 27 Jun 2016 16:35:44 +0000 (17:35 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 7 Jul 2016 10:30:07 +0000 (11:30 +0100)
XenIfaceDevice is a CDevice subclass that abstracts the IOCTL
interface by managing the conversion to/from IOCTL inputs/outputs.

Signed-off-by: Owen Smith <owen.smith@citrix.com>
Fix VS2013 build.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenagent/service.cpp
src/xenagent/service.h
src/xenagent/xenifacedevice.cpp [new file with mode: 0644]
src/xenagent/xenifacedevice.h [new file with mode: 0644]
vs2012/xenagent/xenagent.vcxproj
vs2013/xenagent/xenagent.vcxproj

index b48d03208bb54e8b5f50b3ae59cc400db3f6ee47..192d682e405071d2ff2ee65a6e3206ba22ffe205 100644 (file)
@@ -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)
index f8e4b672f4dba2edda6e76ac99fc551491b295d4..af554c9ec58f5a5e668ca5de6b12d11f6d302cfe 100644 (file)
@@ -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 (file)
index 0000000..98e4d2f
--- /dev/null
@@ -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 <windows.h>
+#include <winioctl.h>
+
+#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 (file)
index 0000000..163b193
--- /dev/null
@@ -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 <windows.h>
+#include <string>
+#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
index 6c9c91c6ab2b3805f314da20c893c74b5d3aa692..37db3fd3e487a0a8e12304360718b6339d8b87b9 100644 (file)
   <ItemGroup>
     <ClCompile Include="..\..\src\xenagent\service.cpp"/>
     <ClCompile Include="..\..\src\xenagent\devicelist.cpp"/>
+    <ClCompile Include="..\..\src\xenagent\xenifacedevice.cpp"/>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\xenagent\service.h" />
     <ClInclude Include="..\..\src\xenagent\devicelist.h" />
+    <ClInclude Include="..\..\src\xenagent\xenifacedevice.h" />
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\..\src\xenagent\messages.mc">
index b72705a9194e0ef0646f3c36e0d308b6be22fd24..4f5db5572e6d0b16c413cc175d009d6fe2cd41fb 100644 (file)
   <ItemGroup>
     <ClCompile Include="..\..\src\xenagent\service.cpp"/>
     <ClCompile Include="..\..\src\xenagent\devicelist.cpp"/>
+    <ClCompile Include="..\..\src\xenagent\xenifacedevice.cpp"/>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\xenagent\service.h" />
     <ClInclude Include="..\..\src\xenagent\devicelist.h" />
+    <ClInclude Include="..\..\src\xenagent\xenifacedevice.h" />
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\..\src\xenagent\messages.mc">