Next: , Previous: , Up: The Dezyne Modeling Language   [Contents][Index]


3.5 Using Data Variables and Parameters

Data variables are used as input for or output from external components.

Apart from assignment, data operation / manipulation is done in handwritten code.

3.5.1 Data Syntax

Use the keyword extern to define a datatype in Dezyne and the external datatype it will be transformed to when code is generated:

extern datatypeInternal $datatypeExternal$;

After the definition variables of this type can be used to further define event (or method) signatures.

See also:

3.5.2 Data Examples

3.5.2.1 Using an character type in an interface definition

This example shows an interface definition for an handwritten component that will evaluate input based on a character type.

Note that in interface definitions there is no data handling at all and therefore no parentheses and parameters are needed in e.g. on event statements.

interface IAlarmConsole
{
  extern char $char$;
  in void KeyPressed(char key);
  in void Initialize();
  behaviour
  {
    on KeyPressed: {}
    on Initialize: {}
  }
}

3.5.2.2 Using character and integer type in an interface definition

This example shows an interface definition for a handwritten component that will accept characters for a PIN code and will also return the complete code.

interface ICodeBuilder
{
  extern char $char$;
  extern xint $int$;         // as int is a Dezyne keyword, xint is used
  enum Result
  {
    CharAdded,
    InvalidChar,
    CodeComplete,
    BufferCleared
  };
  in Result AddDigit(in char digit);
  in void GetCode(out xint code);
  behaviour
  {
    enum State {Building, Complete};
    State state = State.Building;
    [state.Building]
    {
      on AddDigit: reply(Result.CharAdded);
      on AddDigit: reply(Result.InvalidChar);
      on AddDigit: {reply(Result.CodeComplete); state = State.Complete;}
      on AddDigit: reply(Result.BufferCleared);
      on GetCode: {}
    }
    [state.Complete]
    {
      on AddDigit: illegal;
      on GetCode: state = State.Building;
    }
  }
}

3.5.2.3 Passing data parameters between components

This example shows how to pass parameters between components, using the interfaces of the examples above.

component AlarmConsole
{
  provides IAlarmConsole alarmConsole;
  requires ICodeBuilder codestore;
  requires IAlarmSystem alarmSystem;
  /* ...  */
  /* ...  */
  behaviour
  {
    /* ...  */
    /* ...  */
    [state.Unarmed]
    {
      /* ...  */
      /* ...  */
      on alarmConsole.KeyPressed(key):                         // parameter key contains value of the key pressed on the console
      {
        ICodeBuilder.Result val = codestore.AddDigit(key);     // add the value to the pincode
        if (val == ICodeBuilder.Result.CodeComplete)           // if the pincode is complete
        {
          xint pin;
          codestore.GetCode(pin);                              // get the value of the pin code
          IAlarmSystem.Result val = alarmSystem.SwitchOn(pin); // turn on the alarm system with the pin code
          /* ...  */
          /* ...  */
        }
      }
    /* ...  */
    /* ...  */
    }
  /* ...  */
  /* ...  */
  }
}

See also:


Next: , Previous: , Up: The Dezyne Modeling Language   [Contents][Index]