Project

General

Profile

Service declaration

Attribute declaration

Attributes are variables that control the behavior of the component. They are stored in the ids and they can be changed dynamically by the codels during execution. Genom provides a way to set and get attributes through the chosen middleware.

An "attribute" declaration creates a service that can either set or get one or several attibutes.

(25) attribute ::=

"attribute" identifier "(" attribute-parameters ")" opt-properties ";"

(29) attribute-parameters ::=

[ { attribute-parameter "," } attribute-parameter ]

(30) attribute-parameter ::=

parameter-dir ( parameter-variable opt-initializer
| parameter-variable "::" identifier opt-initializer
| "::" identifier opt-initializer )

(124) opt-properties ::=

[ "{" properties "}" ]

(125) properties ::=

{ property }

Attributes can have a number of properties:

(28) service-property ::=

( "task" identifier
| "interrupts" identifier-list
| "before" identifier-list
| "after" identifier-list
| "validate" codel
| "local" local-variables ) ";"

doc

A string that describes the functionality of the service.

validate

A "validate" codel can be declared to check the validity of input data and throw an exception in case of a problem. The validate codel is called before updating the value in the ids. The codel can throw an exception if the new value is not acceptable. In this case, the value of the corresponding ids member is not changed. If the codel returns no error, the value of the ids member is updated.

Example

This would declare an attribute for changing the speed of a moving thing:

component foo {
  ids { double velocity };

  exception invalid_speed;

  attribute SetSpeed(in velocity = 0.0: "Thing velocity")
  {
    doc "Change the velocity of a moving thing";
    validate check_velocity(local in velocity);
    throw invalid_speed;
  };
};

In this example SetSpeed is a setter for the velocity variable (in keyword). It is possible to specify a default value ("= 0.0") and a small documentation string that is used by interactive applications to guide the user.

This example is of course not functional. The velocity value should be used by other codels and services as the reference value for actually controlling the moving thing.

Function and activity declaration

(27) service-kind ::=

"function"
| "activity"

(31) service-parameters ::=

[ { service-parameter "," } service-parameter ]

(32) service-parameter ::=

parameter-dir type-spec declarator opt-initializer

(124) opt-properties ::=

[ "{" properties "}" ]

(125) properties ::=

{ property }

(126) property ::=

component-property
| interface-property
| task-property
| service-property
| codel-property
| throw-property

(28) service-property ::=

( "task" identifier
| "interrupts" identifier-list
| "before" identifier-list
| "after" identifier-list
| "validate" codel
| "local" local-variables ) ";"

Function and activity parameters

(30) attribute-parameter ::=

parameter-dir ( parameter-variable opt-initializer
| parameter-variable "::" identifier opt-initializer
| "::" identifier opt-initializer )

(32) service-parameter ::=

parameter-dir type-spec declarator opt-initializer

(43) parameter-dir ::=

"in"
| "out"
| "inout"

(44) parameter-variable ::=

identifier
| parameter-variable "." identifier
| parameter-variable "[" positive-int-const "]"

(45) opt-initializer ::=

[ "=" initializer ]

(46) initializers ::=

[ { initializer "," } initializer ]

(47) initializer ::=

initializer-value
| ":" string-literals
| initializer-value ":" string-literals

(48) initializer-value ::=

const-expr
| "{" initializers "}"
| "[" positive-int-const "]" "=" const-expr
| "[" positive-int-const "]" "=" "{" initializers "}"
| "[" positive-int-const "]" "="
| "." identifier "=" const-expr
| "." identifier "=" "{" initializers "}"
| "." identifier "="