def _get_current_sid(): """INTERNAL: get current SID.""" try: token = OpenThreadToken(GetCurrentThread(), MAXIMUM_ALLOWED, True) except WindowsError: token = OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED) sid = GetTokenInformation(token, TokenUser)[0] return sid
def __init__(self, dParams): PlatformBase.__init__(self, dParams) # # Since the code runs on all platforms, we have to do a lot of # importing here instead of at the top of the file where it's normally located. # from win32com import universal from win32com.client import gencache, DispatchBaseClass from win32com.client import constants, getevents import win32com import pythoncom import win32api import winerror from win32con import DUPLICATE_SAME_ACCESS from win32api import GetCurrentThread, GetCurrentThreadId, DuplicateHandle, GetCurrentProcess import threading self.winerror = winerror pid = GetCurrentProcess() self.tid = GetCurrentThreadId() handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS) self.handles = [] self.handles.append(handle) # Hack the COM dispatcher base class so we can modify method and # attribute names to match those in xpcom. if _g_dCOMForward['setattr'] is None: _g_dCOMForward['getattr'] = DispatchBaseClass.__dict__[ '__getattr__'] _g_dCOMForward['setattr'] = DispatchBaseClass.__dict__[ '__setattr__'] setattr(DispatchBaseClass, '__getattr__', _CustomGetAttr) setattr(DispatchBaseClass, '__setattr__', _CustomSetAttr) # Hack the exception base class so the users doesn't need to check for # XPCOM or COM and do different things. ## @todo # # Make sure the gencache is correct (we don't quite follow the COM # versioning rules). # self.flushGenPyCache(win32com.client.gencache) win32com.client.gencache.EnsureDispatch('VirtualBox.Session') win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox') win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBoxClient') self.oIntCv = threading.Condition() self.fInterrupted = False _ = dParams
def _sync_task(self): SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) while self._runing: status = self.bus.wait_sync(self.rx_poll_interval) fr_cycle = self.bus.get_fr_cycle() for setter in self._fr_cycle_setter: setter(fr_cycle) if status == 0: self._tx_task() elif status > 0: self._rx_task()
def _rx_task(self): SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) while self._runing: msg = self._msg_read(self.rx_poll_interval) if msg is not None and msg.direction == 'Rx': if self._rx_once and self.MsgCompare(msg): self._rx_once = False self._read_msg = msg self._rx_event.set() for reader in self._readers: reader(msg)
def _tx_task(self): SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) while self._runing: end_time = self.tx_poll_interval + time.time() with self._tx_lock: for sender in self._senders: msg = sender() if type(msg) is list: for m in msg: self._msg_send(m) elif msg is not None: self._msg_send(msg) time_left = end_time - time.time() time_left = max(0, int(time_left * 1000)) WaitForSingleObject(self._tx_event, time_left) ResetEvent(self._tx_event)
def __init__(self, params): from win32com import universal from win32com.client import gencache, DispatchBaseClass from win32com.client import constants, getevents import win32com import pythoncom import win32api from win32con import DUPLICATE_SAME_ACCESS from win32api import GetCurrentThread, GetCurrentThreadId, DuplicateHandle, GetCurrentProcess import threading pid = GetCurrentProcess() self.tid = GetCurrentThreadId() handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS) self.handles = [] self.handles.append(handle) _COMForward['getattr'] = DispatchBaseClass.__dict__['__getattr__'] DispatchBaseClass.__getattr__ = CustomGetAttr _COMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__'] DispatchBaseClass.__setattr__ = CustomSetAttr win32com.client.gencache.EnsureDispatch('VirtualBox.Session') win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox') self.oIntCv = threading.Condition() self.fInterrupted = False
def __init__(self, dParams): PlatformBase.__init__(self, dParams) # # Since the code runs on all platforms, we have to do a lot of # importing here instead of at the top of the file where it's normally located. # from win32com import universal from win32com.client import gencache, DispatchBaseClass from win32com.client import constants, getevents import win32com import pythoncom import win32api import winerror from win32con import DUPLICATE_SAME_ACCESS from win32api import GetCurrentThread, GetCurrentThreadId, DuplicateHandle, GetCurrentProcess import threading self.winerror = winerror # Setup client impersonation in COM calls. try: pythoncom.CoInitializeSecurity(None, None, None, pythoncom.RPC_C_AUTHN_LEVEL_DEFAULT, pythoncom.RPC_C_IMP_LEVEL_IMPERSONATE, None, pythoncom.EOAC_NONE, None) except: _, oXcpt, _ = sys.exc_info(); if isinstance(oXcpt, pythoncom.com_error) and self.xcptGetStatus(oXcpt) == -2147417831: # RPC_E_TOO_LATE print("Warning: CoInitializeSecurity was already called"); else: print("Warning: CoInitializeSecurity failed: ", oXctp); # Remember this thread ID and get its handle so we can wait on it in waitForEvents(). self.tid = GetCurrentThreadId() pid = GetCurrentProcess() self.aoHandles = [DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS),]; # type: list[PyHANDLE] # Hack the COM dispatcher base class so we can modify method and # attribute names to match those in xpcom. if _g_dCOMForward['setattr'] is None: _g_dCOMForward['getattr'] = DispatchBaseClass.__dict__['__getattr__'] _g_dCOMForward['setattr'] = DispatchBaseClass.__dict__['__setattr__'] setattr(DispatchBaseClass, '__getattr__', _CustomGetAttr) setattr(DispatchBaseClass, '__setattr__', _CustomSetAttr) # Hack the exception base class so the users doesn't need to check for # XPCOM or COM and do different things. ## @todo # # Make sure the gencache is correct (we don't quite follow the COM # versioning rules). # self.flushGenPyCache(win32com.client.gencache) win32com.client.gencache.EnsureDispatch('VirtualBox.Session') win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox') win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBoxClient') self.oClient = None ##< instance of client used to support lifetime of VBoxSDS self.oIntCv = threading.Condition() self.fInterrupted = False _ = dParams