Next: , Previous: , Up: Specifying Behaviour   [Contents][Index]


3.6.10 Using illegal

To specify that an event is not allowed at a certain stage, the keyword illegal can be used.

3.6.10.1 Syntax

The keyword illegal is used to indicate that an event is not allowed:

on intf1.evt1(), intf2.evt2(): illegal;

Here ’intf1.evt1’ and ’intf2.evt2’ are event instances, which refer to interface variables ’intf1’ and ’intf2’ and to events ’evt1’ and ’evt2’.

Note: do not use illegal in conditional statements (if / if else) or functions in interface definitions ! This is because an event can only be declared illegal in a direct way due to the declarative character of interfaces. (Or in other words: in an interface one declares the expected behaviour and an illegal inside conditional statements or functions would require an evaluation of the conditional statement or function for the be expected behaviour.)

3.6.10.2 Examples

3.6.10.3 A timer where depending on the state certain events are allowed and others not

This example shows the interface specification for a timer. Initially a timer can be created and it is not allowed to cancel the timer before creation. When the timer has been created it is not possible to request again creation of the timer.

interface iTimer
{
// interface for a basic timer
    in void createTimer();
    in void cancelTimer();
    out void timeout();
    behaviour
    {
        enum State {Idle, Busy};
        State state = State.Idle;
        [state.Idle]
        {
            on createTimer: state = State.Busy;
            on cancelTimer: illegal;
        }
        [state.Busy]
        {
            on createTimer: illegal;
            on cancelTimer: state = State.Idle;
            on inevitable:
            {
                timeout;
                state = State.Idle;
            }
        }
    }
}

3.6.10.4 Incorrect and correct interface definition with a conditional illegal

An interface has to be defined that does not allows a second event (checkModel in this case) before the asynchronous reply (checkModelRes) has been sent to the first event.

The following code snippet shows an incorrect interface definition with an illegal inside an if-else construction.

 [state.Authenticated]
    {
      on checkModel:
      {
         if (ModelCheckOngoing == false)
         {
            reply(res.Ok);
            ModelCheckOngoing = true;
         }
         else illegal;
      }
      on inevitable:
      {
          if (ModelCheckOngoing == true)
          {
              ModelCheckOngoing = false;
              checkModelRes;
          }
      }
   }
}

The following snippet shows how to correctly define this:.

[state.Authenticated]
{
      [!ModelCheckOngoing] on checkModel:
      {
          reply(res.Ok);
          ModelCheckOngoing = true;
      }
      [ModelCheckOngoing] on checkModel: illegal;
      [ModelCheckOngoing] on inevitable:
      {
        ModelCheckOngoing = false;
        checkModelRes;
      }
}

See also:


Next: , Previous: , Up: Specifying Behaviour   [Contents][Index]