One can associate multiple actions to a Thingfacet Attribute. You can do this by providing comma separated list of Action names. For example:
<String name="State" KnownBy="SyncImageAction,SyncPresetAction"/>
Here you can see two actions: SyncPresetAction and SyncImageActon which deal with camera preset and snapshot image respectively. Both the actions update the "State" attribute of a Camera Facet.
<!-- Actions --> <Action Name="SyncPresetAction" Documentation="Synchronize camera state and preset"> <Workflow Limit="1" Live="1" Timeout="PT20S"> <Task Name="Main" While="true"> <Event Name="Argument" As="ActionArgument"/> <Invoke Name="SetPreset" waitFor="Argument" skip-if="[%:[:AA:].Preset/no-value(Value):%]" delayAfter="PT5S" get="[%:[:AA:].URL.Value:%]/cgi-bin/decoder_control.cgi?[:UP:][%:amp:%]command=15[%:amp:%]sit=[%:[:AA:].Preset.Value:%]"/> <Output name="Result" as="ActionResult"> <Value> <State> [%:[%:@Output:%]/if([:POK:]) then 'ON' else 'OFF':%]</State> <Preset>[%:[%:@Output:%]/if([:POK:]) then '[%:[:AA:].Preset.Value:%]' else null():%]</Preset> </Value> </Output> </Task> </Workflow> </Action> <Action name="SyncImageAction" documentation="Synchronize camera state and snapshot image"> <Workflow Limit="1" Live="1" Timeout="PT10S"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="GetImage" waitFor="Argument" delay="PT1S" get="[%:[:AA:].URL.Value:%]/cgi-bin/video_snapshot.cgi?[:UP:]"/> <Output name="Result" as="ActionResult"> <Value> <State>[%:[%:@Output:%]/if([:IOK:]) then 'ON' else 'OFF':%]</State> <Image>[%:[%:@Output:%]/if([:IOK:]) then Invoke/GetImage/Message/Value/text() else '/img/no-image.jpg':%]</Image> </Value> </Output> </Task> </Workflow> </Action>
Rules for Selecting an Action:
TQLEngine Rules for selecting an Action are as follows. Please note that an Action is Triggered whenever there is a change detected between "Value" and "Known" values of a ThingFacet Attribute. A change is notified by Applications using TQL Update Query.
- Order of Action Names specified in KnownBy - The first Action Name gets first preference, second gets second preference and so on.
- Minimum number of Action (s) that satisfy the update criteria. This rule is used in conjunction with previous order of preference rule.
<ThingFacet name="Esky"> <Sid name="CameraId"/> <String name="URL"/> <String name="UserName"/> <String name="Password"/> <String name="State" KnownBy="SyncImageAction,SyncPresetAction"/> <String name="Image" KnownBy="SyncImageAction"/> <String name="Preset" KnownBy="SyncPresetAction"/> <Unique name="Camera" value="URL"/> <!-- Helpers --> <AA>[:#o#Event.Argument:]</AA> <UP>user=[%:[:AA:].UserName.Value:%][%:amp:%]pwd=[%:[:AA:].Password.Value:%]</UP> <POK>Invoke/SetPreset/Message/starts-with(Value, 'ok')</POK> <IOK>Invoke/GetImage/Message/starts-with(Value, 'data')</IOK> <!-- Actions --> <Action name="SyncPresetAction" documentation="Synchronize camera state and preset"> <Workflow Limit="1" Live="1" Timeout="PT20S"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="SetPreset" waitFor="Argument" skip-if="[%:[:AA:].Preset/no-value(Value):%]" delayAfter="PT5S" get="[%:[:AA:].URL.Value:%]/cgi-bin/decoder_control.cgi?[:UP:][%:amp:%]command=15[%:amp:%]sit=[%:[:AA:].Preset.Value:%]"/> <Output name="Result" as="ActionResult"> <Value> <State> [%:[%:@Output:%]/if([:POK:]) then 'ON' else 'OFF':%]</State> <Preset>[%:[%:@Output:%]/if([:POK:]) then '[%:[:AA:].Preset.Value:%]' else null():%]</Preset> </Value> </Output> </Task> </Workflow> </Action> <Action name="SyncImageAction" documentation="Synchronize camera state and snapshot image"> <Workflow Limit="1" Live="1" Timeout="PT10S"> <Task name="Main" while="true"> <Event name="Argument" as="ActionArgument"/> <Invoke name="GetImage" waitFor="Argument" delay="PT1S" get="[%:[:AA:].URL.Value:%]/cgi-bin/video_snapshot.cgi?[:UP:]"/> <Output name="Result" as="ActionResult"> <Value> <State>[%:[%:@Output:%]/if([:IOK:]) then 'ON' else 'OFF':%]</State> <Image>[%:[%:@Output:%]/if([:IOK:]) then Invoke/GetImage/Message/Value/text() else '/img/no-image.jpg':%]</Image> </Value> </Output> </Task> </Workflow> </Action> </ThingFacet>
For example in case of ESKY Camera Facet - here is the list the table of Attribute, Action Association and Attributes that get affected by Actions.
Attribute | Action(s) Association | Attribute(s) Being Updated By Action |
---|---|---|
State | SyncImageAction, SyncPresetAction | State, Image, Preset |
Image | SyncImageAction | State, Image |
Preset | SyncPresetAction | State, Preset |
Based on the above Action Association and Rules applied by the TQLEngine, table below gives possibilities:
User's (Applications) Desire to update using TQL Update Query | Action Selected by TQLEngine |
---|---|
Image | SyncImageAction |
Preset | SyncPresetAction |
Image, State | SyncImageAction |
State | SyncImageAction (* Note both Rules get applied) |