Handling commands, Example: handle_set, Writing streamnet device drivers 3-2 – ClearOne Writing StreamNet User Manual
Page 12: Figure 3-2 command routing within the driver
Writing StreamNet Device Drivers
3-2
All specifications subject to change without notification. All rights reserved. Copyright © 2007 NetStreams
Main +1 512.977-9393 / fax +1 512.977.9398 / Toll Free Technical Support +1 866-353-3496
3600 W. Parmer Lane, Suite 100; Austin, TX 78727 /
www.netstreams.com.
NOTE
Figure 3-2
Command routing within the driver
Handling Commands
It is always possible to
define an appropriate
command-specific
handler, so that the
default_command_hand
ler is not needed.
Programming best-
practices state that a
fallback
default_command_hand
ler should be defined
even if it is not intended
for use.
For a device driver to receive and handle commands, it is necessary to define Lua
functions with predefined names based on the command to be handled. The routine
that needs to be defined is “handle_
the lower cased version of the ASCII command). For example, if a driver needs to
handle #SET commands, it needs to define a function handle_set within the driver. As
a fall-back mechanism, if no command-specific function is defined, the function
“default_command_handler” will be invoked if defined.
If the command is generic to the entire device, the necessary function should be
defined in the outermost control scope of the Lua file, and will be invoked with only
the command as a parameter.
Example: Handle_Set
function
handle_set(cmd)
if
(cmd.params[1] == “heat”)
then
… handle the #set heat command
end
end
function
default_command_handler(cmd)
Is the command
addressed to a
subnode?
Is there a subnode
specific command
handler?
Is there a Control
specific command
handler?
Ye
s
Ye
s
No
No
No
Ye
s
Is there a subnode
default command
handler?
Ye
s
Is there a Control
specific command
handler?
No
No
Ye
s
Streamnet command is routed to the appropriate section of the Lua driver code
Start
Call Control default
command handler
Call Control specific
command handler
Call Control specific
command handler
Call Control default
command handler
Call subnode specific
command handler
Call subnode default
command handler