A single plug-in module can, and often will, contain multiple servers. This page describes the approach that I have found useful for organizing and maintaining a related set of servers.
When writing a class that will be a server or exported object, I always add a static intialize() function as a member of the class. Placing it at the top of the class declaration helps remind you to change the initialization if you change the set of interfaces that your class supports.
| class CInstance :
public CLxImpl_PackageInstance,
public CLxImpl_MeshInfluence,
public CLxImpl_ItemInfluence,
public CLxImpl_WeightMapDeformerItem
{
public:
static void
initialize ()
{
CLxGenericPolymorph *srv;
|
| srv = new CLxPolymorph<CInstance>;
srv->AddInterface (new CLxIfc_PackageInstance <CInstance>);
srv->AddInterface (new CLxIfc_MeshInfluence <CInstance>);
srv->AddInterface (new CLxIfc_ItemInfluence <CInstance>);
srv->AddInterface (new CLxIfc_WeightMapDeformerItem<CInstance>);
lx::AddSpawner (SPWNAME_INSTANCE, srv);
}
...
};
|
| class CPackage :
public CLxImpl_Package,
public CLxImpl_SceneItemListener
{
public:
static void
initialize ()
{
CLxGenericPolymorph *srv;
|
| srv = new CLxPolymorph<CPackage>;
srv->AddInterface (new CLxIfc_Package <CPackage>);
srv->AddInterface (new CLxIfc_SceneItemListener<CPackage>);
srv->AddInterface (new CLxIfc_StaticDesc <CPackage>);
lx::AddServer (SRVNAME_ITEMTYPE, srv);
}
...
};
|
Finally there’s a single ‘’initialize(‘’) function, not declared as part of any namespace, that serves as the common entry point for all server and object initialization for the entire module. This is typically a file by itself, and it calls all the namespace-qualified initialize() functions. They could be declared in a header, but they are so ‘’pro forma’’ that hardly seems necessary.
| namespace Influence_General { extern void initialize (); };
namespace Falloff_Radial { extern void initialize (); };
namespace Command_Morph { extern void initialize (); };
|
| void
initialize ()
{
Influence_General :: initialize ();
Falloff_Radial :: initialize ();
Command_Morph :: initialize ();
}
|