Ejemplo n.º 1
0
Archivo: shell.py Proyecto: ppalaga/tcf
 def onChannelOpen(self, channel):
     wrapper = sync.DispatchWrapper(channel)
     self.locals["channel"] = wrapper
     self.locals["disconnect"] = wrapper.close
     self.locals["cmd"] = sync.CommandControl(channel, interactive=True)
     self.locals["events"] = event.EventRecorder(channel)
     protocol.invokeAndWait(protocol.removeChannelOpenListener, self)
     wrapper.addChannelListener(self)
Ejemplo n.º 2
0
 def onChannelOpen(self, channel):
     wrapper = sync.DispatchWrapper(channel)
     self.locals["channel"] = wrapper
     self.locals["disconnect"] = wrapper.close
     self.locals["cmd"] = sync.CommandControl(channel, interactive=True)
     self.locals["events"] = event.EventRecorder(channel)
     protocol.invokeAndWait(protocol.removeChannelOpenListener, self)
     wrapper.addChannelListener(self)
Ejemplo n.º 3
0
 def __init__(self):
     locals = {  # @ReservedAssignment
         "connect": tcf.connect,
         "peers": print_peers()
     }
     protocol.startEventQueue()
     protocol.startDiscovery()
     protocol.invokeAndWait(protocol.addChannelOpenListener, self)
     code.InteractiveConsole.__init__(self, locals)
Ejemplo n.º 4
0
Archivo: shell.py Proyecto: ppalaga/tcf
 def __init__(self):
     locals = {  # @ReservedAssignment
         "connect": tcf.connect,
         "peers": print_peers()
     }
     protocol.startEventQueue()
     protocol.startDiscovery()
     protocol.invokeAndWait(protocol.addChannelOpenListener, self)
     code.InteractiveConsole.__init__(self, locals)
Ejemplo n.º 5
0
 def run(self):
     while service._alive:
         try:
             time.sleep(locator.DATA_RETENTION_PERIOD / 4 / 1000.)
             protocol.invokeAndWait(self._callable)
         except RuntimeError:
             # TCF event dispatch is shut down
             return
         except Exception as x:
             service._log("Unhandled exception in TCF discovery timer thread", x)
Ejemplo n.º 6
0
def test():
    global _services
    protocol.startEventQueue()
    atexit.register(protocol.getEventQueue().shutdown)
    # testTimer()
    try:
        c = tcf.connect("TCP:127.0.0.1:1534")
    except Exception as e:
        protocol.log(e)
        sys.exit()
    assert c.state == channel.STATE_OPEN
    if __TRACE:
        protocol.invokeAndWait(c.addTraceListener, TraceListener())
    _services = protocol.invokeAndWait(c.getRemoteServices)
    print "services=", _services

    if "RunControl" in _services:
        # RunControl must be first
        _services.remove("RunControl")
        _services.insert(0, "RunControl")
    for service in _services:
        testFct = globals().get("test" + service)
        if testFct:
            print "Testing service '%s'..." % service
            try:
                testFct(c)
                print "Completed test of service '%s'." % service
            except Exception as e:
                protocol.log("Exception testing %s" % service, e)
        else:
            print "No test for service '%s' found." % service
    try:
        testSyncCommands(c)
        testTasks(c)
        testEvents(c)
        testDataCache(c)
    except Exception as e:
        protocol.log(e)

    if c.state == channel.STATE_OPEN:
        time.sleep(5)
        protocol.invokeLater(c.close)
    time.sleep(2)
Ejemplo n.º 7
0
def test():
    global _services
    protocol.startEventQueue()
    atexit.register(protocol.getEventQueue().shutdown)
    # testTimer()
    try:
        c = tcf.connect("TCP:127.0.0.1:1534")
    except Exception as e:
        protocol.log(e)
        sys.exit()
    assert c.state == channel.STATE_OPEN
    if __TRACE:
        protocol.invokeAndWait(c.addTraceListener, TraceListener())
    _services = sorted(protocol.invokeAndWait(c.getRemoteServices))
    print("services=" + str(_services))

    if "RunControl" in _services:
        # RunControl must be first
        _services.remove("RunControl")
        _services.insert(0, "RunControl")
    for service in _services:
        testFct = globals().get("test" + service)
        if testFct:
            print("Testing service '%s'..." % service)
            try:
                testFct(c)
                print("Completed test of service '%s'." % service)
            except Exception as e:
                protocol.log("Exception testing %s" % service, e)
        else:
            print("No test for service '%s' found." % service)
    try:
        testSyncCommands(c)
        testTasks(c)
        testEvents(c)
        testDataCache(c)
    except Exception as e:
        protocol.log(e)

    if c.state == channel.STATE_OPEN:
        time.sleep(5)
        protocol.invokeLater(c.close)
    time.sleep(2)
Ejemplo n.º 8
0
 def run(self):
     try:
         while service._alive:
             sock = service.socket
             try:
                 data, addr = sock.recvfrom(MAX_PACKET_SIZE)
                 p = InputPacket(data, InetAddress(None, addr[0]), addr[1])
                 protocol.invokeAndWait(self._callable, p)
             except RuntimeError:
                 # TCF event dispatch is shutdown
                 return
             except socket.error as x:
                 if sock != service.socket: continue
                 # frequent  error on windows, unknown reason
                 if x.errno == 10054: continue
                 port = sock.getsockname()[1]
                 service._log("Cannot read from datagram socket at port %d" % port, x)
                 time.sleep(2)
     except Exception as x:
         service._log("Unhandled exception in socket reading thread", x)
Ejemplo n.º 9
0
Archivo: sync.py Proyecto: eswartz/emul
 def __getattr__(self, attr):
     val = getattr(self._channel, attr, None)
     if val:
         if self._interactive and type(val) in (types.FunctionType, types.MethodType):
             val = DispatchWrapper(val)
         return val
     services = protocol.invokeAndWait(self._channel.getRemoteServices)
     if attr == "services":
         return services
     if attr in services:
         return ServiceWrapper(self, attr)
     raise AttributeError("Unknown service: %s. Use one of %s" % (attr, services))
Ejemplo n.º 10
0
Archivo: sync.py Proyecto: eswartz/emul
 def invoke(self, service, command, *args, **kwargs):
     cmd = None
     if not protocol.isDispatchThread():
         if not kwargs.get("async"):
             cmd = protocol.invokeAndWait(self._invoke, service, command, *args, **kwargs)
             if cmd and self._interactive:
                 return cmd.getE()
         else:
             with self._lock:
                 self._queue.append((service, command, args, kwargs))
                 if len(self._queue) == 1:
                     protocol.invokeLater(self._processQueue)
             return
     return cmd
Ejemplo n.º 11
0
Archivo: sync.py Proyecto: eswartz/emul
 def __call__(self, *args, **kwargs):
     return protocol.invokeAndWait(self.inner, *args, **kwargs)
Ejemplo n.º 12
0
Archivo: sync.py Proyecto: eswartz/emul
 def __getattr__(self, attr):
     val = protocol.invokeAndWait(getattr, self.inner, attr)
     if type(val) in (types.FunctionType, types.MethodType):
         return DispatchWrapper(val)
     return val
Ejemplo n.º 13
0
Archivo: sync.py Proyecto: eswartz/emul
 def cancel(self):
     return protocol.invokeAndWait(self.token.cancel)