# -*- generated by 1.0.12 -*-
import da
PatternExpr_175 = da.pat.TuplePattern([da.pat.ConstantPattern('Y')])
PatternExpr_185 = da.pat.TuplePattern([da.pat.ConstantPattern('Z')])
_config_object = {}

class P(da.DistProcess):

    def __init__(self, procimpl, props):
        super().__init__(procimpl, props)
        self._events.extend([da.pat.EventPattern(da.pat.ReceivedEvent, '_PReceivedEvent_0', PatternExpr_175, sources=None, destinations=None, timestamps=None, record_history=None, handlers=[self._P_handler_174]), da.pat.EventPattern(da.pat.ReceivedEvent, '_PReceivedEvent_1', PatternExpr_185, sources=None, destinations=None, timestamps=None, record_history=None, handlers=[self._P_handler_184])])

    def setup(self, **rest_290):
        super().setup(**rest_290)
        self._state.d = 1
        self._state.x = 1

    def run(self):
        super()._label('l', block=False)
        _st_label_195 = 0
        while True:
            if (_st_label_195 == 2):
                break
            elif (_st_label_195 == 1):
                super()._label('l', block=True)
            _st_label_195 = 1
            if (self._state.d == 1):
                self.output('d is 1.')
            elif (self._state.x == 1):
                self.output('x is 1.')
            else:
                self.output('neither d nor x is 1.')
                _st_label_195 += 1

    def _P_handler_174(self):
        self._state.d = 0
    _P_handler_174._labels = None
    _P_handler_174._notlabels = None

    def _P_handler_184(self):
        self._state.x = 0
    _P_handler_184._labels = None
    _P_handler_184._notlabels = None

class Q(da.DistProcess):

    def __init__(self, procimpl, props):
        super().__init__(procimpl, props)
        self._events.extend([])

    def setup(self, ps, **rest_290):
        super().setup(ps=ps, **rest_290)
        self._state.ps = ps
        pass

    def run(self):
        self.output("Sending 'X'.")
        self.send(('X',), to=self._state.ps)
        super()._label('_st_label_228', block=False)
        _st_label_228 = 0
        self._timer_start()
        while (_st_label_228 == 0):
            _st_label_228 += 1
            if False:
                _st_label_228 += 1
            elif self._timer_expired:
                _st_label_228 += 1
            else:
                super()._label('_st_label_228', block=True, timeout=2)
                _st_label_228 -= 1
        self.output("Sending 'X'.")
        self.send(('X',), to=self._state.ps)
        super()._label('_st_label_239', block=False)
        _st_label_239 = 0
        self._timer_start()
        while (_st_label_239 == 0):
            _st_label_239 += 1
            if False:
                _st_label_239 += 1
            elif self._timer_expired:
                _st_label_239 += 1
            else:
                super()._label('_st_label_239', block=True, timeout=2)
                _st_label_239 -= 1
        self.output("Sending 'Y'.")
        self.send(('Y',), to=self._state.ps)
        super()._label('_st_label_250', block=False)
        _st_label_250 = 0
        self._timer_start()
        while (_st_label_250 == 0):
            _st_label_250 += 1
            if False:
                _st_label_250 += 1
            elif self._timer_expired:
                _st_label_250 += 1
            else:
                super()._label('_st_label_250', block=True, timeout=2)
                _st_label_250 -= 1
        self.output("Sending 'Z'.")
        self.send(('Z',), to=self._state.ps)
        while False:
            self.output('Fail!')

class Node_(da.NodeProcess):

    def __init__(self, procimpl, props):
        super().__init__(procimpl, props)
        self._events.extend([])

    def run(self):
        ps = self.new(P, [], 1)
        qs = self.new(Q, [ps], 1)
        self._start(ps)
        self._start(qs)
