The generate event instruction is used to generate an event in an event source, which can be an object or service.
An event can only be generated if it has been declared in the event source. If the event source is an object, then the event must be declared in the type and generated in the factory. If the event source is a service, then the event is declared and generated in the service.
The type of a generated event is always a child type of:
li_obix.li_events.ty_object_event if the event source is an objectli_obix.li_events.ty_service_event if the event source is a service.For more information about Obix's event mechanism, please refer to the section called “Event”.
Table 8.20. generate event syntax
| Production | Syntax | Links |
|---|---|---|
generate_event_instruction | "generate" "event" event_id "from" expression | the section called “generate event instruction” |
event_id specifies which event is to be generated. It must match with an event identifier declared in the event source.
expression specifies the generated event (also called event object or event data). Its type must be compatible to the type declared in the event source. For example, type button in a GUI framework declares it generates event mouse_clicked of type mouse_clicked_event. Then factory button can generate a mouse_clicked event through any expression of type mouse_clicked_event.
Example 8.23. Simple generate event example
Suppose type tea_machine generates event tea_ready each time command make_tea has finished its job:
type tea_machine command make_tea end event tea_ready type:tea_ready_event end end
Type tea_ready_event can simply be defined as:
type tea_ready_event default_factory:yes inherit object_event end end
And factory tea_machine can be implemented as:
factory tea_machine type:tea_machine
command make_tea
script
// some instructions to make tea
// ...
generate event tea_ready from fa_tea_ready_event.co_create ( source = this )
end
end
creator create kind:in_all end
endSee Example 8.24, “Simple on event example” for an example of how to register an event listener to a tea_machine object.
For a more complete example, see also: Example 6.10, “Events in a television delivery stack”