[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH 07/20] Track a single device in the service.



Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/liteagent/DeviceList.cpp |  9 +++++++++
 src/liteagent/DeviceList.h   |  4 ++++
 src/liteagent/LiteAgent.cpp  | 21 ++++++++++++++++++++-
 src/liteagent/LiteAgent.h    |  3 +++
 4 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/liteagent/DeviceList.cpp b/src/liteagent/DeviceList.cpp
index 1cb3bf6..9033407 100644
--- a/src/liteagent/DeviceList.cpp
+++ b/src/liteagent/DeviceList.cpp
@@ -96,6 +96,11 @@ void CDevice::Close()
     m_handle = INVALID_HANDLE_VALUE;
 }
 
+const wchar_t* CDevice::Path() const
+{
+    return m_path.c_str();
+}
+
 bool CDevice::Ioctl(DWORD ioctl, void* in, DWORD insz, void* out, DWORD outsz, 
DWORD* bytes)
 {
     if (m_handle == INVALID_HANDLE_VALUE)
@@ -255,6 +260,8 @@ void CDeviceList::OnDeviceAdded(const std::wstring& path)
     }
 
     m_devs[handle] = dev;
+    if (m_impl)
+        m_impl->OnDeviceAdded(dev);
 }
 
 void CDeviceList::OnDeviceQueryRemove(HANDLE handle)
@@ -264,6 +271,8 @@ void CDeviceList::OnDeviceQueryRemove(HANDLE handle)
         return; // spurious event?
 
     CDevice* dev = it->second;
+    if (m_impl)
+        m_impl->OnDeviceRemoved(dev);
     dev->Close();
 }
 
diff --git a/src/liteagent/DeviceList.h b/src/liteagent/DeviceList.h
index 10df546..457a099 100644
--- a/src/liteagent/DeviceList.h
+++ b/src/liteagent/DeviceList.h
@@ -46,6 +46,8 @@ public:
     HANDLE Open(HANDLE svc);
     void Close();
 
+    const wchar_t* Path() const;
+
 protected:
     bool Ioctl(DWORD ioctl, void* in, DWORD insz, void* out, DWORD outsz, 
DWORD* bytes);
 
@@ -58,6 +60,8 @@ private:
 interface IDeviceCreator
 {
     virtual CDevice* Create(const wchar_t* path) = 0;
+    virtual void OnDeviceAdded(CDevice* dev) = 0;
+    virtual void OnDeviceRemoved(CDevice* dev) = 0;
 };
 
 class CDeviceList
diff --git a/src/liteagent/LiteAgent.cpp b/src/liteagent/LiteAgent.cpp
index 1eec87e..a7987dc 100644
--- a/src/liteagent/LiteAgent.cpp
+++ b/src/liteagent/LiteAgent.cpp
@@ -116,7 +116,7 @@ static CLiteAgent s_service;
     return s_service.__ServiceControlHandlerEx(req, evt, data, ctxt);
 }
 
-CLiteAgent::CLiteAgent() : m_handle(NULL), m_devs(GUID_INTERFACE_XENIFACE)
+CLiteAgent::CLiteAgent() : m_handle(NULL), m_devs(GUID_INTERFACE_XENIFACE), 
m_dev(NULL)
 {
     m_status.dwServiceType        = SERVICE_WIN32; 
     m_status.dwCurrentState       = SERVICE_START_PENDING; 
@@ -136,9 +136,28 @@ CLiteAgent::~CLiteAgent()
 
 /*virtual*/ CDevice* CLiteAgent::Create(const wchar_t* path)
 {
+    // create subclass of CDevice
     return new CDevice(path);
 }
 
+/*virtual*/ void CLiteAgent::OnDeviceAdded(CDevice* dev)
+{
+    CLiteAgent::Log("OnDeviceAdded(%ws)\n", dev->Path());
+    if (m_dev == NULL) {
+        m_dev = dev;
+        // setting active device
+    }
+}
+
+/*virtual*/ void CLiteAgent::OnDeviceRemoved(CDevice* dev)
+{
+    CLiteAgent::Log("OnDeviceRemoved(%ws)\n", dev->Path());
+    if (dev == m_dev) {
+        m_dev = NULL;
+        // active device
+    }
+}
+
 void CLiteAgent::OnServiceStart()
 {
     CLiteAgent::Log("OnServiceStart()\n");
diff --git a/src/liteagent/LiteAgent.h b/src/liteagent/LiteAgent.h
index 57ed9e7..261e737 100644
--- a/src/liteagent/LiteAgent.h
+++ b/src/liteagent/LiteAgent.h
@@ -58,6 +58,8 @@ public: // ctor/dtor
 
 public: // IDeviceCreator
     virtual CDevice* Create(const wchar_t* path);
+    virtual void OnDeviceAdded(CDevice* dev);
+    virtual void OnDeviceRemoved(CDevice* dev);
 
 private: // service events
     void OnServiceStart();
@@ -75,6 +77,7 @@ private: // service support
     HANDLE                  m_svc_stop;
     
     CDeviceList             m_devs;
+    CDevice*                m_dev;
 };
 
 #endif
-- 
1.9.4.msysgit.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.