VirtualBox

Changeset 20807 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jun 23, 2009 8:39:42 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48944
Message:

Python: better event wait routine, cleanup (callbacks still crash)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r20693 r20807  
    3434
    3535class PlatformMSCOM:
    36     # Class to fake access to constants in style of foo.bar.boo 
     36    # Class to fake access to constants in style of foo.bar.boo
    3737    class ConstantFake:
    3838        def __init__(self, parent, name):
     
    5050            import win32com
    5151            from win32com.client import constants
    52                
     52
    5353            if attr.startswith("__"):
    5454                raise AttributeError
    5555
    5656            consts = self.__dict__['_consts']
    57            
     57
    5858            fake = consts.get(attr, None)
    5959            if fake != None:
    60                return fake 
     60               return fake
    6161            try:
    6262               name = self.__dict__['_name']
    6363               parent = self.__dict__['_parent']
    64                while parent != None:                 
     64               while parent != None:
    6565                  if parent._name is not None:
    6666                    name = parent._name+'_'+name
    6767                  parent = parent._parent
    68                
     68
    6969               if name is not None:
    7070                  name += "_" + attr
     
    7575               fake = PlatformMSCOM.ConstantFake(self, attr)
    7676               consts[attr] = fake
    77                return fake 
     77               return fake
    7878
    7979
     
    104104            import pythoncom
    105105            import win32api
    106             self.constants = PlatformMSCOM.InterfacesWrapper()                       
     106            self.constants = PlatformMSCOM.InterfacesWrapper()
     107            from win32con import DUPLICATE_SAME_ACCESS
     108            from win32api import GetCurrentThread,GetCurrentThreadId,DuplicateHandle,GetCurrentProcess
     109            pid = GetCurrentProcess()
     110            self.tid = GetCurrentThreadId()
     111            handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS)
     112            self.handles = []
     113            self.handles.append(handle)
     114
    107115
    108116    def getSessionObject(self, vbox):
     
    118126    def getConstants(self):
    119127        return self.constants
    120    
     128
    121129    def getType(self):
    122130        return 'MSCOM'
     
    136144        pythoncom.CoUninitialize()
    137145
    138     def createCallback(self, iface, impl, arg):       
     146    def createCallback(self, iface, impl, arg):
    139147        d = {}
    140148        d['BaseClass'] = impl
    141149        d['arg'] = arg
    142         d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
     150        d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
    143151        str = ""
    144152        str += "import win32com.server.util\n"
     153        #str += "import win32com.server.register\n"
    145154        #str += "from win32com import universal\n"
    146         #str += "import pythoncom\n"
     155        str += "import pythoncom\n"
    147156        #str += "universal.RegisterInterfaces(tlb_guid, 0, 1, 0, ['"+iface+"'])\n"
    148157
     
    150159        str += "   _com_interfaces_ = ['"+iface+"']\n"
    151160        str += "   _typelib_guid_ = tlb_guid\n"
    152         str += "   _typelib_version_ = 1, 0\n"
    153         #str += "   _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"
     161        str += "   _typelib_version_ = 1, 0\n"
     162        #str += "   _reg_clsctx_ = pythoncom.CLSCTX_LOCAL_SERVER\n"
    154163        #str += "   _reg_clsid_ = '{F21202A2-959A-4149-B1C3-68B9013F3335}'\n"
    155164        #str += "   _reg_progid_ = 'VirtualBox."+iface+"Impl'\n"
     
    158167
    159168        str += "   def __init__(self): BaseClass.__init__(self, arg)\n"
    160         str += "result = win32com.server.util.wrap("+iface+"Impl())\n"       
     169        #str += "win32com.server.register.UseCommandLine("+iface+"Impl)\n"
     170
     171        str += "result = win32com.server.util.wrap("+iface+"Impl())\n"
    161172        exec (str,d,d)
    162173        return d['result']
    163174
    164175    def waitForEvents(self, timeout):
    165         from win32file import CloseHandle
    166         from win32con import DUPLICATE_SAME_ACCESS
    167         from win32api import GetCurrentThread,DuplicateHandle,GetCurrentProcess
    168         from win32event import MsgWaitForMultipleObjects, \
     176        from win32api import GetCurrentThreadId
     177        from win32event import MsgWaitForMultipleObjects, \
    169178                               QS_ALLINPUT, WAIT_TIMEOUT, WAIT_OBJECT_0
    170179        from pythoncom import PumpWaitingMessages
    171180
    172         pid = GetCurrentProcess()
    173         handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS)
    174        
    175         handles = []
    176         handles.append(handle)
    177 
    178         rc = MsgWaitForMultipleObjects(handles, 0, timeout, QS_ALLINPUT)
    179         if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(handles):
     181        if (self.tid != GetCurrentThreadId()):
     182            raise Exception("wait for events from the same thread you inited!")
     183
     184        rc = MsgWaitForMultipleObjects(self.handles, 0, timeout, QS_ALLINPUT)
     185        if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(self.handles):
    180186            # is it possible?
    181187            print "how come?"
    182188            pass
    183         elif rc==WAIT_OBJECT_0 + len(handles):
     189        elif rc==WAIT_OBJECT_0 + len(self.handles):
    184190            # Waiting messages
    185191            PumpWaitingMessages()
    186192        else:
     193            # Timeout
    187194            pass
    188         CloseHandle(handle)
    189195
    190196    def deinit(self):
    191197        import pythoncom
     198        from win32file import CloseHandle
     199
     200        for h in self.handles:
     201           if h is not None:
     202              CloseHandle(h)
     203        self.handles = None
    192204        pythoncom.CoUninitialize()
    193205        pass
     
    211223        import xpcom.components
    212224        return xpcom.components.interfaces
    213    
     225
    214226    def getType(self):
    215227        return 'XPCOM'
    216    
     228
    217229    def getRemote(self):
    218230        return False
     
    272284    def getConstants(self):
    273285        return None
    274    
     286
    275287    def getType(self):
    276288        return 'WEBSERVICE'
    277    
     289
    278290    def getRemote(self):
    279291        return True
     
    281293    def getArray(self, obj, field):
    282294        return obj.__getattr__(field)
    283    
     295
    284296    def initPerThread(self):
    285297        pass
     
    326338
    327339    def getArray(self, obj, field):
    328         return self.platform.getArray(obj, field)       
     340        return self.platform.getArray(obj, field)
    329341
    330342    def getVirtualBox(self):
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette