Inside the function, a plugin is expected to tell MotionSampler how to construct each of the modules that the plugin implements. This is done using a special structure called a factory. A factory has one main purpose: it constructs classes of a specific type when its Fabricate() method is called. Just as each module is a subclass of PDLSource, PDLFilter, or PDLSink, a factory is a subclass of PDLSourceFactory, PDLFilterFactory, or PDLSinkFactory.
At start-up, plugins add a factory corresponding to each module they implement to the catalog pointer provided as an argument. The catalog is a list of module factories.
MotionSampler has three module catalogs: one for sources, one for filters, and one for sinks. At start-up, MotionSampler loads all the plugins it finds and calls each plugin's PDLInitializePlugin(). With each plugin, one or more factories are added to one of the module catalogs. When MotionSampler is finished starting, no modules have actually been constructed, but all the factories are available to create them when needed. MotionSampler creates the module lists in the pipeline editor by looking in each factory catalog and gathering module type names. A module is not actually constructed until you add it to a pipeline or until a pipeline including that module is retrieved from a file.
The following example adds to the last example by defining a factory capable of constructing a very basic filter class.
#include <PDLFilter.h>
class ExampleFilt : public PDLFilter
{
public:
ExampleFilt(const char* n);
};
struct ExFiltFactory : public PDLFilterFactory
{
virtual PDLFilter* Fabricate(const char* n) { return new
ExampleFilt(n); }
}
PDLDeclarePluginID(PDL_FILTER_ID);
void
PDLInitializePlugin(void* catalog)
{
PDLFilterFactory::AddPlugin(catalog, "ExampleFilt", new
ExFiltFactory);
}
ExampleFilt::ExampleFilt(const char* n)
: PDLFilter(n, "ExampleFilt")
{
}
Each factory base class (PDLSourceFactory, PDLFilterFactory, PDLSinkFactory) provides a static method called AddPlugin() which is used to add the module factory to the catalog.
AddPlugin() takes three arguments:
If you want the plugin in the above example to define more than one module, declare more module classes and make an additional call to AddPlugin() for each one as follows:
void
PDLInitializePlugin(void* catalog)
{
PDLFilterFactory::AddPlugin(catalog, "ExampleFilt", new
ExFiltFactory); PDLFilterFactory::AddPlugin(catalog, "ExampleFilt2",
new ExFilt2Factory); PDLFilterFactory::AddPlugin(catalog,
"ExampleFilt3", new ExFilt3Factory);
}