Conditional wires

Conditional Wires Example

This Specification example shows how to use conditional wires. It's action-out returns a different system tray message (using the message block) based on which command triggered the application.

The example Specification contains two commands, one identified as blue, the other as red. When a tag associated to one of these commands triggers the application, the Specification sends the command id (shunted from command-id-in) into to two different regex-matcher blocks (named matcherRed and matcherBlue). Each regex-matcher block compares against a short text string (supplied by two different text-source blocks) for a match. Only one of the two regex-matcher blocks can produce a match. Therefore, the matches-out pin of one of the two regex-matcher blocks will be true, the other false. This true-false condition forms the basis of the conditional wiring in this example.

Two text-source blocks each define a different message for the message block to use. Both of these text sources are wired to the same message block. However, the message block can only accept one of the two messages. This is where Conditional Wires functionality is applied: both wires contain a condition, which must be a boolean value. The matches-out of the regex-matcher blocks provides the condition value for these wires.

Notes:

  • Concurrent wiring/shunting: Note how the command-id-in is shunted twice. Once to the text-in input pin on the matcherRed block, and once to the text-in input pin on the matcherBlue block. The ability to wire a pin more than once is new functionality along with Conditional Wiring. It obsoletes the need for "tee" blocks (such as tee-boolean).
  • Debugging: It is important to ensure that your conditional wirings produce logical results. For example, if a condition could occur in which both matches-out pins of the two regex-matcher blocks were to result in true, an error would result because the message block's in pin can only accept one input.
<?xml version="1.0" encoding="UTF-8"?>
<specification xmlns="http://www.touchatag.com/schema/configurator/specification-1.0">
    <application>
		<!-- Two commands are declared, depending on the triggered command, a different text will be returned to the client -->
        <command id="blue" name="blue pill"/>
        <command id="red" name="red pill"/>
    </application>
    <blueprint>
		<superblock id="conditionalwires">
			<breakdown>
				<block id="txtBluePill" ref="urn:touchatag:block:text-source">
					<property name="Value">
						<text>You take the blue pill, the story ends, you wake up in your bed and believe whatever you want to believe.</text>
					</property>
				</block>
				<block id="txtRedPill" ref="urn:touchatag:block:text-source">
                    <property name="Value">
                        <text>You take the red pill, you stay in Wonderland, and I show you how deep the rabbit hole goes.</text>
                    </property>
                </block>
				<block id="regexRed" ref="urn:touchatag:block:text-source">
                    <property name="Value">
                        <text>(red)</text>
                    </property>
                </block>
				<block id="regexBlue" ref="urn:touchatag:block:text-source">
                    <property name="Value">
                        <text>(blue)</text>
                    </property>
                </block>
				<block id="matcherRed" ref="urn:touchatag:block:regex-matcher"/>
				<block id="matcherBlue" ref="urn:touchatag:block:regex-matcher"/>
				<block id="message" ref="urn:touchatag:block:message"/>
			</breakdown>
			<wiringscheme>
				<!-- The commmand id is wired into the regex matcher to check which command was issued -->
				<shunt from="command-id-in" to="matcherRed:text-in"/>
				<wire from="regexRed:out" to="matcherRed:regex-in"/>
				<shunt from="command-id-in" to="matcherBlue:text-in"/>
                <wire from="regexBlue:out" to="matcherBlue:regex-in"/>
				<!-- The two possible texts are wired into the message and are made conditional, based on which command id was issued -->	
				<wire from="txtBluePill:out" to="message:in" condition="matcherBlue:matches-out"/>
				<wire from="txtRedPill:out" to="message:in" condition="matcherRed:matches-out"/>
				<shunt from="message:out" to="action-out"/>
			</wiringscheme>
		</superblock>
	</blueprint>
	
</specification>

This example uses the following blocks :