home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2503 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.2 KB  |  59 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32serviceutil
  5. import win32service
  6. import win32event
  7. import servicemanager
  8. import win32gui
  9. import win32gui_struct
  10. import win32con
  11. GUID_DEVINTERFACE_USB_DEVICE = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}'
  12.  
  13. class EventDemoService(win32serviceutil.ServiceFramework):
  14.     _svc_name_ = 'PyServiceEventDemo'
  15.     _svc_display_name_ = 'Python Service Event Demo'
  16.     _svc_description_ = 'Demonstrates a Python service which takes advantage of the extra notifications'
  17.     
  18.     def __init__(self, args):
  19.         win32serviceutil.ServiceFramework.__init__(self, args)
  20.         self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
  21.         filter = win32gui_struct.PackDEV_BROADCAST_DEVICEINTERFACE(GUID_DEVINTERFACE_USB_DEVICE)
  22.         self.hdn = win32gui.RegisterDeviceNotification(self.ssh, filter, win32con.DEVICE_NOTIFY_SERVICE_HANDLE)
  23.  
  24.     
  25.     def GetAcceptedControls(self):
  26.         rc = win32serviceutil.ServiceFramework.GetAcceptedControls(self)
  27.         rc |= win32service.SERVICE_ACCEPT_PARAMCHANGE | win32service.SERVICE_ACCEPT_NETBINDCHANGE | win32service.SERVICE_CONTROL_DEVICEEVENT | win32service.SERVICE_ACCEPT_HARDWAREPROFILECHANGE | win32service.SERVICE_ACCEPT_POWEREVENT | win32service.SERVICE_ACCEPT_SESSIONCHANGE
  28.         return rc
  29.  
  30.     
  31.     def SvcOtherEx(self, control, event_type, data):
  32.         if control == win32service.SERVICE_CONTROL_DEVICEEVENT:
  33.             info = win32gui_struct.UnpackDEV_BROADCAST(data)
  34.             msg = 'A device event occurred: %x - %s' % (event_type, info)
  35.         elif control == win32service.SERVICE_CONTROL_HARDWAREPROFILECHANGE:
  36.             msg = 'A hardware profile changed: type=%s, data=%s' % (event_type, data)
  37.         elif control == win32service.SERVICE_CONTROL_POWEREVENT:
  38.             msg = 'A power event: setting %s' % data
  39.         elif control == win32service.SERVICE_CONTROL_SESSIONCHANGE:
  40.             msg = 'Session event: type=%s, data=%s' % (event_type, data)
  41.         else:
  42.             msg = 'Other event: code=%d, type=%s, data=%s' % (control, event_type, data)
  43.         servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, 61440, (msg, ''))
  44.  
  45.     
  46.     def SvcStop(self):
  47.         self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
  48.         win32event.SetEvent(self.hWaitStop)
  49.  
  50.     
  51.     def SvcDoRun(self):
  52.         win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE)
  53.         servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STOPPED, (self._svc_name_, ''))
  54.  
  55.  
  56. if __name__ == '__main__':
  57.     win32serviceutil.HandleCommandLine(EventDemoService)
  58.  
  59.