Package joy :: Module remote :: Class Sink
[hide private]
[frames] | no frames]

Class Sink

source code


Concrete class remote.Sink

This Plan subclass may be used to relay via UDP JoyApp events (including all pygame events) from a remote.Source running in another JoyApp, potentially on another machine.

Events are serialized into a JSON string and sent over separate UDP packets. TIMEREVENTS are ignored.

Additionally, any JSON packets that contain dictionaries without the 'type' key may be shunted to a separate queue, for application specific processing. This queue is windowed in time, i.e. will hold at most X seconds worth of packets, as specified by the allowMisc constructor parameter. Its contents are accessible via queueIter().

Instance Methods [hide private]
 
__init__(self, app, bnd=DEFAULT_BINDING, rate=100, convert=None, allowMisc=None)
Attributes: bnd -- 2-tuple -- binding address for socket, in socket library format rate -- integer -- maximal number of events processed each time-slice sock -- socket / None -- socket only exists while plan is running convert -- callable -- convert incoming event dictionaries.
source code
 
onStart(self)
(default)
source code
 
onStop(self)
(default)
source code
 
setAllowMisc(self, allow)
(re)set the depth of the misc event queue
source code
 
flushMisc(self)
flush the misc event queue
source code
 
setSink(self, bnd)
Set the socket binding address.
source code
 
onEvent(self, evt)
(default) Event handler.
source code
 
_clearQueue(self)
(private) clear old events from misc queue
source code
 
queueIter(self)
Iterate over the custom packets in the queue...
source code

Inherited from plans.Plan: behavior, forDuration, isRunning, push, start, step, stop, untilTime

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  DEFAULT_BINDING = '0.0.0.0', DEFAULT_PORT
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, app, bnd=DEFAULT_BINDING, rate=100, convert=None, allowMisc=None)
(Constructor)

source code 

Attributes:
  bnd -- 2-tuple -- binding address for socket, in socket library format
  rate -- integer -- maximal number of events processed each time-slice
  sock -- socket / None -- socket only exists while plan is running
  convert -- callable -- convert incoming event dictionaries.
    Allows remote joysticks/keys to be remapped. Returns None if
    event should be ignored
    By default, only KEYUP and KEYDOWN events are allowed
  allowMisc -- float / None -- number of seconds of "misc" packets 
    to store in self.queue or None to disallow non-event packets

Overrides: object.__init__

onStart(self)

source code 

(default)

Override this method to perform operations when Plan starts but before the first events are processed.

Overrides: plans.Plan.onStart
(inherited documentation)

onStop(self)

source code 

(default)

Override this method to perform operations when Plan terminates.

Overrides: plans.Plan.onStop
(inherited documentation)

setSink(self, bnd)

source code 

Set the socket binding address.

Will take effect next time the plan is started

onEvent(self, evt)

source code 
(default)
Event handler. Override this method to handle all events that 
were push()-ed to this Plan.

The sequential behavior() in this plan only runs if onEvent
returned True.

All Plan-s recieve a copy of all TIMEREVENT events. If your
sequential code does not need any other events, and just wants
to execute in parallel with other Plan-s, it is safe to leave
the default onEvent method, which always returns True 

NOTE: 
  onEvent MUST return True or False. Other values raise an 
  exception at runtime. 

Overrides: plans.Plan.onEvent
(inherited documentation)

queueIter(self)

source code 
Iterate over the custom packets in the queue
Yields pairs (ts, pkt)
  ts -- float -- arrival time
  pkt -- dictionary -- packet contents