Events#

Event Module#

class miros.event.OrderedDictWithParams#
If your subclass <name_of_subclass> has the following init:

def __init__(self,*args,**kwargs):

self[‘RET_SUPER’] = 1 self[‘RET_SUPER_SUB’] = 2 self[‘UNHANDLED’] = 3

Any object constructed from it will have to following attributes:

obj = <name_of_subclass> obj.RET_SUPER => 1 obj.RET_SUPER_SUB => 2 obj.UNHANDLED => 3

To post-pend an item to the object which will also have a named parameter:

obj = <name_of_subclass> obj.append(“NEW_NAMED_ATTRIBUTE”) ob.NEW_NAMED_ATTRIBUTE => 4

This of this class as being an extensible ENUM which isn’t immutable. All of the enums are wrapped up within an OrderedDict, so you get all of it’s methods as well as the clean interface to the attribute.

ReturnStatusSource#

class miros.event.ReturnStatusSource(*args, **kwargs)#

A class which contains all of the state returns codes

To construct the object

state_returns = ReturnCodes()

To get the number:

state_returns.RET_SUPER => 1

To add a return code:

state_returns.append(‘RET_ZZ’) state_returns.RET_ZZ => 12

SignalSource#

class miros.event.SignalSource(*args, **kwargs)#

A class which contains all of the state signal types

To get the basic system signals:

signals = Signal()

To append a new signal

signals = Signal.append(‘OVEN_OFF’)

To get the number:

signal.ENTRY_SIGNAL => 1 signal[‘OVEN_OFF’] => 12 signal.OVER_OFF => 12

name_for_signal(signal)#

get the name of a signal number as a string

Signal#

miros.event.Signal#

alias of <miros.singleton.SingletonDecorator object>

Event#

class miros.event.Event(signal, payload=None)#

An event should be constructed, used, then garbage collected. An event is a temporary thing. However if an event uses a signal that hasn’t been seen before, that signal will be added to the list of global signals as a new enumerated value.

# Make an event (this should happen internally):

e = Event(signal=signals.ENTRY_SIGNAL) # existing signal assert(e.signal == signals.ENTRY_SIGNAL) assert(e.signal_name == ‘ENTRY_SIGNAL’)

# Make an event, which will construct a signal internally:

e = Event(signal =’OVEN_OFF’, payload=’any object can go here’) # new signal assert(e.signal == 5) # if it is the first unseen signal in the system assert(e.signal_name == ‘OVEN_OFF’) assert(signals.OVER_OFF == 5)

static dumps(event)#

Required for serialization prior to sending an event across an IO stream/networks.

Due to the dynamic nature of the Event/signals object, an event object can not just be pickled. Instead the object must be passed through this ‘Event.dumps’ function, then de-serialized using the ‘Event.loads’ function.

The numbering parity of the signal is not guaranteed across a network, but, the signal name will be unique within all of the signals objects expressed on each machine. This is because signals are constructed dynamically. So if one machine defines the signal ‘A’ before ‘B’ and another just defines ‘B’. The internal signals numbers for ‘B’ will not be the same for each machine. This doesn’t matter, since it is the signal name ‘B’ that distinguishes the signal within a statechart and each machine will have the ‘B’ signal defined once.

This ‘dumps’ method pulls out the signal name and payload, creates a dictionary from them then turns it into a json object. The signal number is ignored during the process.

Example:

json_event = Event.dumps(Event(signal=signals.Mary))

has_payload()#
Example:

event = Event(signal=signals.Mary, payload=[1,2,3]) event.has_payload() # => True

static loads(json_event)#

De-serializes a serialized Event object. An event object can not be serialized using pickle due to it’s dynamic nature. For this reason the ‘Event.dumps’ method provides custom serialization for events. This ‘loads’ method is for deserializing a serialized event object. See the example for clarity.

Example:

json_event = Event.dumps(Event(signal=signals.Mary)) event = Event.loads(json_event) print(event) # => Mary::<>