ThingWorx Edge SDK Extensions for the C SDK > Loading Shape Libraries
  
Loading Shape Libraries
You can use a shape library on any platform in either of two ways:
The Edge Extension library of EdgeThingShapes can be statically linked to your application at compile time.
The Edge Extension library of EdgeThingShapes can be dynamically linked at runtime by using a shared library (Linux) or a dll (Windows).
The following sections explain these methods of loading shape libraries and more:
Dynamically Loading Edge Extension Libraries
Statically Linked Shape Libraries
Grouping Things Together by "Kind"
Adding an EdgeThingShape to an Existing Thing
Registering an EdgeThingShape
Dynamically Loading Edge Extension Libraries
To load a library dynamically at runtime, call:

void * twExt_LoadShapeLibrary(char * shapeLibraryName);
Note that shapeLibraryName must be the complete path to the shared library or dll if the TWXLIB environment variable is not set. If the variable is set, shapeLibraryName can be a partial path that is relative to the path specified in the TWXLIB environment variable. Note that shapeLibraryName should be just the name of the library to load. It should not include the file extension (.so or .dll.
When a shape library is loaded dynamically at runtime, that library must provide a library initialization function. This function must be named with the name of the shared library itself. For example, the shared library warehouseshapelib.so would require a function declared inside it that looks like this:

void* init_warehouseshapelib()
This function would be called by twExt_LoadShapeLibrary() as part of the dynamic library loading process.
Back to top
Statically Linked Shape Libraries
When statically linking a shape library, you are responsible for calling the initialization function for the library (init_<libraryname>()). You also need to call this initialization function if you are using shapes that are compiled directly into your application.
In general, call the initialization function from within your application's main() function. This call makes the library available for later use by twExt_CreateThingFromTemplate().
Back to top
Grouping Things Together by "Kind"
Given the name of a Thing (entityName) and the name of a ThingTemplate, the twExt_DoesThingImplementTemplate() function determines if the specified thing extends the requested thing template. This function returns TRUE if the thing does extend the thing template. This function is useful when you want to group things together by "kind" based on their thing template. An example would be if the thing template represented a model of devices and you want to group all the devices that are of this model. Here is the prototype of this function:

char twExt_DoesThingImplementTemplate(char *entityName, char *templateName);

Back to top
Adding an EdgeThingShape to an Existing Thing
If you want to add an EdgeThingShape to an existing thing, use the twExt_AddEdgeThingShape()function. This function supports an optional namespace name that will allow an EdgeThingShape to be added to the same thing more than once. Any properties or services that use a namespace will be added in a format like this: Property A in namespace B would appear in a thing as property B_A.
Here is the prototype of this function:

int twExt_AddEdgeThingShape(const char *entityName,
const char *shapeName,
const char *thing_namespace);
Back to top
Registering an EdgeThingShape
To add an EdgeThingShape to the map of available shapes ("register" it), use the twExt_RegisterShape() function. To make an EdgeThingShape available for use, specify it in the shape library init functions. Here is the prototype for this function:

void twExt_RegisterShape(const char *shapeName,
shapeHandlerFunction shapeConstructorFunction);

Back to top