Hi all,
I was looking at some code and got curious, because i haven't seen this NotifyProtocol very often (if at all):
protocol.NotifyProtocol(221/*NT_RUN_ACTION*/, 49, null);
Is there a difference/increase in efficiency for using CheckTrigger -> Trigger -> Action vs NotifyProtocol 221 to directly run an action?
Hi,
That depends on the situation.
A CheckTrigger executes the content of the trigger.
Pros: Conditions can be added to execute if-else actions. Multiple actions can be executed. Existing triggers can be re-used. More clear for a future developer if a trigger exists that it could be used somewhere in a QAction. Easier for the (future) validator to analyze if the trigger actually exists.
Cons: Developer needs to add xml tags for the trigger. Slight performance cost as SLProtocol first needs to check the content of the trigger before executing the actions if only one action needs to be executed.
An NT_RUN_ACTION directly executes the action that needs to run.
Pros: Don't need to add xml tags for the trigger. Directly targets the action to be executed.
Cons: When multiple actions need to be executed (multiple NotifyProtocols) then this will come with a higher performance cost as more inter-process calls between SLScripting and SLProtocol are needed.
To summarize: if you only need to execute one action from a QAction then the NT_RUN_ACTION will have a slight performance gain and it will save some developing time because the trigger xml doesn't need to be added. However, I would clearly add a comment next to that action indicating that it is being used in a QAction, else a future developer could think that the action is not used and could be tempted to remove it.
Definitely use a CheckTrigger as soon as more actions need to be executed (and I would not start refactoring existing drivers that have a CheckTrigger with one action, as the performance gain will not really be noticeable)