Example #1
0
def test1_trans_topology_a():
    ao = ActiveObject()
    ao.start_at(outer)
    pp(ao.spy_full())
    assert (ao.spy_full() == [
        'START', 'SEARCH_FOR_SUPER_SIGNAL:outer', 'ENTRY_SIGNAL:outer',
        'INIT_SIGNAL:outer', '<- Queued:(0) Deferred:(0)'
    ])
    pp(ao.spy_full())
    print(ao.trace())
    event_w = Event(signal=signals.WaitComplete)
    ao.clear_trace()
    ao.post_fifo(event_w)
    import time
    time.sleep(0.1)
    pp(ao.spy_rtc())
    print(ao.trace())

    # clear the spy and the trace
    ao.clear_spy()
    ao.clear_trace()

    # post a number of events and see what happens
    event_wait_complete = Event(signal=signals.WaitComplete)
    event_reset_chart = Event(signal=signals.ResetChart)
    ao.post_fifo(event_wait_complete)
    ao.post_fifo(event_reset_chart)
    ao.post_fifo(event_wait_complete)
    ao.post_fifo(event_reset_chart)
    time.sleep(0.3)
    print(ao.trace())
    pp(ao.spy_full())
def test1_trans_topology_a():
  ao = ActiveObject()
  ao.start_at(outer)
  pp(ao.spy_full())
  assert(ao.spy_full() ==
    ['START',
     'SEARCH_FOR_SUPER_SIGNAL:outer',
     'ENTRY_SIGNAL:outer',
     'INIT_SIGNAL:outer',
     '<- Queued:(0) Deferred:(0)']
  )
  pp(ao.spy_full())
  print(ao.trace())
  event_w = Event(signal=signals.WaitComplete)
  ao.clear_trace()
  ao.post_fifo(event_w)
  import time
  time.sleep(0.1)
  pp(ao.spy_rtc())
  print(ao.trace())

  # stop the threads
  ao.stop()

  # clear the spy and the trace
  ao.clear_spy()
  ao.clear_trace()

  # post a number of events and see what happens
  event_wait_complete = Event(signal=signals.WaitComplete)
  event_reset_chart = Event(signal=signals.ResetChart)
  ao.post_fifo(event_wait_complete)
  ao.post_fifo(event_reset_chart)
  ao.post_fifo(event_wait_complete)
  ao.post_fifo(event_reset_chart)
  time.sleep(0.3)
  print(ao.trace())
  pp(ao.spy_full())
Example #3
0
@spy_on
def c2(chart, e):
    status = return_status.UNHANDLED
    if (e.signal == signals.ENTRY_SIGNAL):
        print("c2 entered")
        status = return_status.HANDLED
    elif (e.signal == signals.A):
        status = chart.trans(c1)
    else:
        chart.temp.fun = c
        status = return_status.SUPER
    return status


if __name__ == "__main__":
    ao = ActiveObject('start_example')
    print("calling: start_at(c2)")
    ao.start_at(c2)

    time.sleep(0.2)
    print(ao.trace())  # print what happened from the start_at call
    ao.clear_trace()  # clear our instrumentation

    print("sending B, then A, then A:")
    ao.post_fifo(Event(signal=signals.B))
    ao.post_fifo(Event(signal=signals.A))
    ao.post_fifo(Event(signal=signals.A))
    time.sleep(0.2)
    print(ao.trace())  # print what happened