Bookshelf Contents Previous Next Glossary Index Search

Programming Modules

Up to this point you have learned more about plugins than modules. The plugin example above can be loaded by MotionSampler but the module it implements doesn't do anything. Now you will learn what modules do and how to implement them.

Module implementation is like most C++ class programming. Remember, a module is implemented as a subclass of PDLSource, PDLFilter, or PDLSink. MotionSampler manipulates modules through the methods defined in these classes. Because many of these methods are virtual, most aspects of a module are implemented by the subclasses. In this case, the subclasses just happen to be dynamically loaded.

Module Constructors and Destructors

A new module is constructed when you select a module type name in the Plugin Module Library of the Pipeline editor mode and then click the Use Module button.

In this case, the module is created with an empty string, "", for a name and its internal state variables default to values set in the module's constructor.

New modules are also created when a pipeline file is retrieved in MotionSampler. This time, the module instance is given the name found in the file and its parameters are set to whatever values are also found in the file.

A module is destroyed whenever a pipeline is cleared or replaced or when a user selects Delete from a module's menu which appears as follows:

A module's constructor and destructor define what happens when new modules are created and existing ones are destroyed. Since modules are always created indirectly by module factories, only one constructor is necessary. A module constructor has only one argument, its name, and this is typically used to initialize the name of the parent class.

The constructors for PDLSource, PDLFilter, and PDLSink each require two parameters: an instance name, and a module type name. The module type name must always be the same as the type name provided to the corresponding AddPlugin() call made in PDLInitializePlugin.

Example: Abbreviating Type Name Code

The following example shows that a module can define an abbreviated type name, which is used in some parts of the MotionSampler interface instead of the longer type name, by calling SetAbbrevType() during construction.

void
PDLInitializePlugin(void* catalog)
{
	PDLFilterFactory::AddPlugin(catalog, "ExampleFilt", new 
ExFiltFactory);
}
...
ExampleFilt::ExampleFilt(const char* n) : PDLFilter(n, "ExampleFilt")
{
	SetAbbrevType("X-Filt");
}

A module's constructor is usually where a module sets default values for internal variables and creates inlets and outlets. Manipulating inlets and outlets is described in more detail in the next section.

A module's destructor is usually very simple and often unneeded. Modules only need to delete any memory which is allocated by the module. Since inlets and outlets are deleted automatically, many modules have nothing to delete in the destructor.



Bookshelf Contents Previous Next Glossary Index Search

[email protected]
Copyright © 1998, Alias|Wavefront, a division of Silicon Graphics Limited. All rights reserved.