This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
arcs2:understanding_the_example_application_loop.xml [2013/08/20 10:29]
didier [Understanding the example application loop.xml]
arcs2:understanding_the_example_application_loop.xml [2013/08/20 14:57] (current)
Line 1: Line 1:
 +====== Understanding the example application loop.xml ======
 +In the [[[[arcs2:​compiling_the_sample_library|previous tutorial]], we have seen how to compile
 +the sample library and how to execute an application related to it, namely the application described in file ''​loop.xml''​. In order to follow the explanations below, you may read the page concerning ARCS [[arcs2:​main_concepts|main concepts]].
 +===== Contextual part =====
 +This application must load the component library we previously compiled (''​sample'',​ you can notice you can strip the library name from its ''​lib''​ prefix as well as its extension. This way it is portable between unix-like systems and windows). It is composed of three components:
 +  * A component embedding a loop: this component has one slot named ''​setIterations(int)''​ which configures the number of iterations performed by the loop and two signals ''​newIteration(int)''​ which indicates the current iteration number and ''​sendToken(QString)''​ which is emitted once the loop is finished. At each iteration, the loop component displays the message: ''​[Loop] Emitting iteration...''​
 +  * A component displaying an integer presented through the slot ''​display(int)''​. The message once data are received is ''​[Display] Received integer...'';​
 +  * A special component acting as a state machine. This component is defined using a particular syntax in order to configure the state machine. It tells there is an initial state ''​start''​ and a final one called ''​end''​. A transition from ''​start''​ to ''​end''​ may occur if the state machine receives a token called ''​end''​. The instantiation of the state machine produces a component with a slot called ''​setToken(QString)''​ which is the actual token receiver.
 +In the application is also defined a constant that gives the number of iterations the loop must perform.
 +===== Configurational part =====
 +In this configuration,​ there is only one main process. It is controlled by the statemachine we previously defined. Therefore, we find two sheets named ''​start''​ and ''​end''​ (the same names as the names of the states from the statemachine). The empty sheet ''​end''​ is signaling it is the end of the application. The sheet ''​start''​ connects loop with display component and loop with statemachine. The actual run is started with the postconnection invocation.
 +===== Running behaviour =====
 +In our application,​ ''​setIterations(int)''​ starts the loop with a given number of iteration. Each iteration sends a ''​newIteration(int)''​ signal connected to the ''​display(int)''​ slot of display component, causing the display of the emitted integer. Once the loop is finished, it sends the ''​sendToken(QString)''​ signal with a token ''​end''​. It triggers a change of state in the statemachine that goes into the final state ''​end''​. Then the ''​start''​ sheet is undone and the ''​end''​ sheet is started and triggers the end of the application.
 +===== XML Description of the application =====
 +<code xml>
 +<​application mode="​event">​
 +  <​context>​ <!-- beginning of contextual part -->
 +    <​libraries>​
 +      <library path="​../​../​sample/​sample"/>​
 +    </​libraries>​
 +    <​components>​
 +      <​component id="​b"​ type="​Loop"​ />
 +      <​component id="​d"​ type="​DisplayInt"​ />
 +      <​component id="​s"​ type="​StateMachine">​
 +        <​statemachine>​
 +          <first name="​start"/>​
 +          <last name="​end"/>​
 +          <​transitions>​
 +            <​transition source="​start"​ token="​end"​ destination="​end"/>​
 +          </​transitions>​
 +        </​statemachine>​
 +      </​component>​
 +    </​components>​
 +    <​constants>​
 +      <​constant id="​iterations"​ type="​int">​5</​constant>​
 +    </​constants>​
 +  </​context>​
 +  ​
 +  <​processes>​ <!-- beginning of the configurational part -->
 +    <process controller="​s">​
 +      <sheet id="​start">​
 +        <​connections>​
 +          <link source="​b"​ signal="​newIteration(int)"​ destination="​d"​ slot="​display(int)"/>​
 +          <link source="​b"​ signal="​sendToken(QString)"​ destination="​s"​ slot="​setToken(QString)"​ />
 +        </​connections>​
 +        <​postconnections>​
 +          <invoke destination="​b"​ slot="​setIterations(int)"​ type="​constant">​iterations</​invoke>​
 +        </​postconnections>​
 +      </​sheet>​
 +      <sheet id="​end"/>​
 +    </​process>​
 +  </​processes>  ​