[libavg-devel] Dynamic Node Creation Enhancements
Nick Hebner
hebnern at gmail.com
Tue Feb 5 09:14:00 CET 2008
Hey All,
Over the weekend, I took a little break from audio to work on some
enhancements to dynamic node creation. With the included patch, nodes may be
created through Player::createNode(typeString, argsPythonDictionary). (e.g.
newNode = Player.createNode("video", {"href":"video.mpg"}) ). To support
this, I have reworked how arguments are passed to node constructors, and
created a generic registration mechanism for adding support for different
types of nodes (also resulting in the ability to dynamically build/change
the avg DTD). The changes are discussed below.
NodeDefinition
A NodeDefinition is basically represents all of the information formerly
found in the avg DTD, that is information about what a type of node is. It
is composed of a type string, all valid arguments and their default values,
all valid child nodes, and a function that may be used to build a node of
this type (Node::buildNode() is a generic template NodeBuilder function that
can be used in most cases). NodeDefinitions may be extended by subclasses,
making inheritance of arguments/child nodes simple. Each node type now
implements a static getNodeDefinition() function which returns the
information about the type.
NodeFactory
NodeDefinitions are registered with a NodeFactory, which can then construct
nodes of the registered type. The NodeFactory handles validation of
arguments passed to the create function based on the registered
NodeDefinition of the type being created. Also, all unset args are replaced
with the default values defined in the NodeDefinition for the type so the
node constructor may safely request any arg defined in its NodeDefinition.
Additionally, the NodeFactory can dynamically build a DTD from the complete
set of NodeDefinitions currently registered with it. The DTD contains a
single special entity called %anyNode; which contains a | separated list of
all of the node types registered, and can be used for generic container
nodes (e.g. avg and div). The dynamic nature of the DTD is very flexible,
and has been designed with the idea of node plugins in mind, however, it is
now less visible then before. It would be nice to make the full DTD
available to the designer (should we add a Player::getDTD() that returns the
current DTD string in python?).
Arg/ArgList
An ArgList is the structure passed to node constructors. It may be build
from either an xmlNode or a python dictionary object. It provides a simple
interface for getting arguments in various formats.
The dynamic node tests currently in place have been expanded to use both
interfaces, and all still pass.
Well, thats all I have for now. Please let me know what you think of the
attached patch.
Thanks,
Nick Hebner
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.datenhain.de/pipermail/libavg-devel/attachments/20080205/5a465ae0/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dyn_nodes.patch
Type: text/x-patch
Size: 81734 bytes
Desc: not available
Url : http://mail.datenhain.de/pipermail/libavg-devel/attachments/20080205/5a465ae0/attachment-0001.bin
More information about the libavg-devel
mailing list