Update of /cvsroot/pywin32/pywin32/win32/Demos/service
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28146/win32/Demos/service
Modified Files:
serviceEvents.py
Log Message:
Support for RegisterDeviceNotification and related structures, including a
new demo and updates to serviceEvents demo.
Index: serviceEvents.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/service/serviceEvents.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** serviceEvents.py 12 Feb 2008 12:53:07 -0000 1.2
--- serviceEvents.py 4 May 2008 10:45:54 -0000 1.3
***************
*** 1,8 ****
--- 1,21 ----
# A Demo of a service that takes advantage of the additional notifications
# available in later Windows versions.
+
+ # Note that all output is written as event log entries - so you must install
+ # and start the service, then look at the event log for messages as events
+ # are generated.
+
+ # Events are generated for USB device insertion and removal, power state
+ # changes and hardware profile events - so try putting your computer to
+ # sleep and waking it, inserting a memory stick, etc then check the event log
+
import win32serviceutil, win32service
import win32event
import servicemanager
+ # Most event notification support lives around win32gui
+ import win32gui, win32gui_struct, win32con
+ GUID_DEVINTERFACE_USB_DEVICE = "{A5DCBF10-6530-11D2-901F-00C04FB951ED}"
+
class EventDemoService(win32serviceutil.ServiceFramework):
_svc_name_ = "PyServiceEventDemo"
***************
*** 13,16 ****
--- 26,35 ----
win32serviceutil.ServiceFramework.__init__(self, args)
self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
+ # register for a device notification - we pass our service handle
+ # instead of a window handle.
+ filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE(
+ GUID_DEVINTERFACE_USB_DEVICE)
+ self.hdn = win32gui.RegisterDeviceNotification(self.ssh, filter,
+ win32con.DEVICE_NOTIFY_SERVICE_HANDLE)
# Override the base class so we can accept additional events.
***************
*** 20,23 ****
--- 39,43 ----
rc |= win32service.SERVICE_ACCEPT_PARAMCHANGE \
| win32service.SERVICE_ACCEPT_NETBINDCHANGE \
+ | win32service.SERVICE_CONTROL_DEVICEEVENT \
| win32service.SERVICE_ACCEPT_HARDWAREPROFILECHANGE \
| win32service.SERVICE_ACCEPT_POWEREVENT \
***************
*** 30,35 ****
# This is only showing a few of the extra events - see the MSDN
# docs for "HandlerEx callback" for more info.
! # XXX can't do SERVICE_CONTROL_DEVICEEVENT until we wrap RegisterDeviceNotification.
! if control == win32service.SERVICE_CONTROL_HARDWAREPROFILECHANGE:
msg = "A hardware profile changed: type=%s, data=%s" % (event_type, data)
elif control == win32service.SERVICE_CONTROL_POWEREVENT:
--- 50,57 ----
# This is only showing a few of the extra events - see the MSDN
# docs for "HandlerEx callback" for more info.
! if control == win32service.SERVICE_CONTROL_DEVICEEVENT:
! info = win32gui_struct.UnpackDEV_BROADCAST(data)
! msg = "A device event occurred: %x - %s" % (event_type, info)
! elif control == win32service.SERVICE_CONTROL_HARDWAREPROFILECHANGE:
msg = "A hardware profile changed: type=%s, data=%s" % (event_type, data)
elif control == win32service.SERVICE_CONTROL_POWEREVENT:
|