// Generated from service.y - manual changes will be lost
ifdef::sidebartoc[]
include::_Sidebar.adoc[]
endif::[]


























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.

****
[horizontal]
(26) `*attribute             ::=*` ::
   `"attribute"` <<grammar#dotgen-rule-identifier,`identifier`>> `"("` <<grammar#dotgen-rule-attribute-parameters,`attribute-parameters`>> `")"` <<grammar#dotgen-rule-opt-properties,`opt-properties`>> `";"`
(30) `*attribute-parameters  ::=*` ::
   `[` `{` <<grammar#dotgen-rule-attribute-parameter,`attribute-parameter`>> `","` `}` <<grammar#dotgen-rule-attribute-parameter,`attribute-parameter`>> `]`
(31) `*attribute-parameter   ::=*` ::
   <<grammar#dotgen-rule-parameter-dir,`parameter-dir`>> `(` <<grammar#dotgen-rule-parameter-variable,`parameter-variable`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>> +
                              `|` <<grammar#dotgen-rule-parameter-variable,`parameter-variable`>> `"::"` <<grammar#dotgen-rule-identifier,`identifier`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>> +
                              `|` `"::"` <<grammar#dotgen-rule-identifier,`identifier`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>> `)`
(125) `*opt-properties        ::=*` ::
   `[` `"{"` <<grammar#dotgen-rule-properties,`properties`>> `"}"` `]`
(126) `*properties            ::=*` ::
   `{` <<grammar#dotgen-rule-property,`property`>> `}`
****

Attributes can have a number of properties:
****
[horizontal]
(29) `*service-property      ::=*` ::
   `(` `"task"` <<grammar#dotgen-rule-identifier,`identifier`>> +
                              `|` `"interrupts"` <<grammar#dotgen-rule-identifier-list,`identifier-list`>> +
                              `|` `"before"` <<grammar#dotgen-rule-identifier-list,`identifier-list`>> +
                              `|` `"after"` <<grammar#dotgen-rule-identifier-list,`identifier-list`>> +
                              `|` `"validate"` <<grammar#dotgen-rule-codel,`codel`>> +
                              `|` `"local"` <<grammar#dotgen-rule-local-variables,`local-variables`>> +
                              `|` `"visibility"` <<grammar#dotgen-rule-visibility-attribute,`visibility-attribute`>> `)` `";"`
****

+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:

[source,C]
----
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

****
[horizontal]
(28) `*service-kind          ::=*` ::
   `"function"` +
                              `|` `"activity"`
(32) `*service-parameters    ::=*` ::
   `[` `{` <<grammar#dotgen-rule-service-parameter,`service-parameter`>> `","` `}` <<grammar#dotgen-rule-service-parameter,`service-parameter`>> `]`
(33) `*service-parameter     ::=*` ::
   <<grammar#dotgen-rule-parameter-dir,`parameter-dir`>> <<grammar#dotgen-rule-type-spec,`type-spec`>> <<grammar#dotgen-rule-declarator,`declarator`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>>
(125) `*opt-properties        ::=*` ::
   `[` `"{"` <<grammar#dotgen-rule-properties,`properties`>> `"}"` `]`
(126) `*properties            ::=*` ::
   `{` <<grammar#dotgen-rule-property,`property`>> `}`
(127) `*property              ::=*` ::
   <<grammar#dotgen-rule-component-property,`component-property`>> +
                              `|` <<grammar#dotgen-rule-interface-property,`interface-property`>> +
                              `|` <<grammar#dotgen-rule-task-property,`task-property`>> +
                              `|` <<grammar#dotgen-rule-service-property,`service-property`>> +
                              `|` <<grammar#dotgen-rule-codel-property,`codel-property`>> +
                              `|` <<grammar#dotgen-rule-throw-property,`throw-property`>>

(29) `*service-property      ::=*` ::
   `(` `"task"` <<grammar#dotgen-rule-identifier,`identifier`>> +
                              `|` `"interrupts"` <<grammar#dotgen-rule-identifier-list,`identifier-list`>> +
                              `|` `"before"` <<grammar#dotgen-rule-identifier-list,`identifier-list`>> +
                              `|` `"after"` <<grammar#dotgen-rule-identifier-list,`identifier-list`>> +
                              `|` `"validate"` <<grammar#dotgen-rule-codel,`codel`>> +
                              `|` `"local"` <<grammar#dotgen-rule-local-variables,`local-variables`>> +
                              `|` `"visibility"` <<grammar#dotgen-rule-visibility-attribute,`visibility-attribute`>> `)` `";"`
****






























































=== Function and activity parameters

****
[horizontal]
(31) `*attribute-parameter   ::=*` ::
   <<grammar#dotgen-rule-parameter-dir,`parameter-dir`>> `(` <<grammar#dotgen-rule-parameter-variable,`parameter-variable`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>> +
                              `|` <<grammar#dotgen-rule-parameter-variable,`parameter-variable`>> `"::"` <<grammar#dotgen-rule-identifier,`identifier`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>> +
                              `|` `"::"` <<grammar#dotgen-rule-identifier,`identifier`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>> `)`
(33) `*service-parameter     ::=*` ::
   <<grammar#dotgen-rule-parameter-dir,`parameter-dir`>> <<grammar#dotgen-rule-type-spec,`type-spec`>> <<grammar#dotgen-rule-declarator,`declarator`>> <<grammar#dotgen-rule-opt-initializer,`opt-initializer`>>

(44) `*parameter-dir         ::=*` ::
   `"in"` +
                              `|` `"out"` +
                              `|` `"inout"`
(45) `*parameter-variable    ::=*` ::
   <<grammar#dotgen-rule-identifier,`identifier`>> +
                              `|` <<grammar#dotgen-rule-parameter-variable,`parameter-variable`>> `"."` <<grammar#dotgen-rule-identifier,`identifier`>> +
                              `|` <<grammar#dotgen-rule-parameter-variable,`parameter-variable`>> `"["` <<grammar#dotgen-rule-positive-int-const,`positive-int-const`>> `"]"`
(46) `*opt-initializer       ::=*` ::
   `[` `"="` <<grammar#dotgen-rule-initializer,`initializer`>> `]`
(47) `*initializers          ::=*` ::
   `[` `{` <<grammar#dotgen-rule-initializer,`initializer`>> `","` `}` <<grammar#dotgen-rule-initializer,`initializer`>> `]`
(48) `*initializer           ::=*` ::
   <<grammar#dotgen-rule-initializer-value,`initializer-value`>> +
                              `|` `":"` <<grammar#dotgen-rule-string-literals,`string-literals`>> +
                              `|` <<grammar#dotgen-rule-initializer-value,`initializer-value`>> `":"` <<grammar#dotgen-rule-string-literals,`string-literals`>>
(49) `*initializer-value     ::=*` ::
   <<grammar#dotgen-rule-const-expr,`const-expr`>> +
                              `|` `"{"` <<grammar#dotgen-rule-initializers,`initializers`>> `"}"` +
                              `|` `"["` <<grammar#dotgen-rule-positive-int-const,`positive-int-const`>> `"]"` `"="` <<grammar#dotgen-rule-const-expr,`const-expr`>> +
                              `|` `"["` <<grammar#dotgen-rule-positive-int-const,`positive-int-const`>> `"]"` `"="` `"{"` <<grammar#dotgen-rule-initializers,`initializers`>> `"}"` +
                              `|` `"["` <<grammar#dotgen-rule-positive-int-const,`positive-int-const`>> `"]"` `"="` +
                              `|` `"."` <<grammar#dotgen-rule-identifier,`identifier`>> `"="` <<grammar#dotgen-rule-const-expr,`const-expr`>> +
                              `|` `"."` <<grammar#dotgen-rule-identifier,`identifier`>> `"="` `"{"` <<grammar#dotgen-rule-initializers,`initializers`>> `"}"` +
                              `|` `"."` <<grammar#dotgen-rule-identifier,`identifier`>> `"="`
****





































































































































































// eof
