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

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

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 Specifying events

Examples

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: {}
  }
}

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;
    }
  }
}

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
          /* ... */
          /* ... */
        }
      }
    /* ... */
    /* ... */
    }
  /* ... */
  /* ... */
  }
}

NB The code between the $ characters is literally copied into the generated code so must adhere to the language definitions of the code to be generated. Also variable assignments are restricted to assignments for the types allowed in that language.

See also: