2

I am using Rhapsody 8.2.1 - and just learning some of the basics.

I have it compiling (with MSVC 2012), generating code and running. To begin with I had a class counter with one attribute int m_count with a constructor that print "hello" and a state chart with one state start with a default transition going to it - the default transaction sets m_count = 3. start::stateEntry() action which does printf("start - stateEntry m_count = %d\r\n", m_count);.

So, next I added a timer event going from state start --> start every second. Which does m_count -= 1

So... as you might expect, when I run this I get:

start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
start - stateEntry m_count = -1
      etc...

Now I when m_count == 0 I want to transition to a new state done. So to achieve this I add a new state and join the two states with a state transition going from start --> done. I name the state transition evTrigger (as I saw in a tutorial) and press ctrl+enter. This has the effect of adding:

  • A new event called evTrigger
  • A new triggered operation called counter::evTrigger() (a member of class counter).

When I open the transition the "Trigger" says evTrigger in Default - so I guess it is referring to the event, not the triggered operation.

Now I try to use it, I add the following code into the entry action of state start:

if (m_count <= 0)
{
    GEN(evTrigger());
}

And in the entry of state done I put the code: printf("stateEntry - Done!\r\n");

Ok, so this works - I get:

start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
stateEntry - done!

But I can't use the triggered operation that was made for me called evTrigger(). Why not? If I call evTrigger() instead of GEN(evTrigger()); it compiles but the event transition does not trigger (it keeps counting down below zero). Why?

I then make two new items to test events and triggered operation separately, and I use each in a new transition from start to done so there are 3 transition with different triggers:

  • new event evTriggerEvent
  • new triggered operation trTriggerOperation

So the state diagram looks like:

*
|  /m_count = 3;
|
|       +---------+      evTrigger              +---------+
+-----> |  start  |---------------------------->|  done   |
        |---------|                             |---------|
        |         |                             |         |
        |         |      trTriggerOperation     |         |
        |         |---------------------------->|         |
        |         |                             |         |
        |         |                             |         |
        |         |      evTriggerEvent         |         |
        |         |---------------------------->|         |
        +---------+                             +---------+
          |     ^
          |     | tm(1000)/m_count -=1;
          +-----+

And the start entry action looks like this:

if (m_count <= 0)
{
    //GEN(evTrigger());        <----- works
    //trTriggerOperation();    <----- appears to do nothing
    //GEN(evTriggerEvent());   <----- works
}

I then un-comment one at a time (ensuring the other two are commented out) and test them, I get the following results (results also commented above):

GEN(evTrigger()) - Works:

start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
stateEntry - done!

trTriggerOperation() - Does not trigger the transaction...

start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
start - stateEntry m_count = -1
start - stateEntry m_count = -2
      etc...

GEN(evTriggerEvent()) - Works:

start - stateEntry m_count = 3
start - stateEntry m_count = 2
start - stateEntry m_count = 1
start - stateEntry m_count = 0
stateEntry - done!

So my questions are:

  • Why does ctrl+enter generation both an event and a triggered operation - when simply and event would do the same job?
  • What is the purpose of the triggered action (it does not do what intuitively it should)?
  • What is the correct way to use a triggered action (if I am doing it wrong)?

Update

I just noticed - I can create an event on its own. But when I use the event in a transition trigger a triggered operation is automatically created in the class operations... I can't delete it because it is being used - now I am even more confused :(

The main issue is that the documentation/examples on Rhapsody is very poor... most forums are tumbleweeds, so this brings up a further question: is this a dead / dying product or what?!

code_fodder
  • 15,263
  • 17
  • 90
  • 167

1 Answers1

3

Ctrl+Enter simply takes you off edit mode when you type text on top of a transition/state/any other graphic element - it is not supposed to create triggered operations.

A triggered operation is a synchronous operation (like primitive operation) that may trigger a transition in state machine. The difference between that and an event is that when you call a triggered operation it is performed synchronously (the caller is waiting for the transition/run to completion step in the state machine to be completed). When you generate/send event the event goes into an event queue and the caller (the one doing the GEN call) is not waiting.

You call a triggered operation just like you call a primitive operation (e.g. myInstance->myTrigOp(myArgValue)). Triggered operations can have arguments and may return a value, however there is a special way to access the arguments and set the return value from the state machine actions.

Please refer to triggered operation in the Rhapsody Help system if you want more information on how to use triggered operations.

L Y E S - C H I O U K H
  • 4,765
  • 8
  • 40
  • 57
  • Thanks for the information : ) "`it is not supposed to create triggered operations`" - and yet it does!. "`You call a triggered operation just like you call a primitive operation`", but as in my example it did not work - and as I mentioned the Rhapsody "help" system is poor at best. – code_fodder Mar 06 '18 at 07:33