Applying EdgeThingShapes at Runtime
The ability to compose a Thing not only at compile time but dynamically at runtime enables you to later assemble Things using external tools such as ThingWorx Composer. Normally, a Thing is constructed at compile time by a developer. However, the ability to create a Thing and then provide it with capabilities at runtime is also supported, both as local C functions and on the platform. On the platform, this dynamic capability is supported by functions in the EdgeGenericThingTemplate, which is the base constructor of all template-based Things. These dynamic capabilities include:
• Loading shape libraries
• Adding shapes to existing Things
• Returning a list of shapes implemented on this Thing
To load a shape library at runtime you normally call twLoadShapeLibrary(char * shapeLibraryName). Any Edge Thing created based on EdgeGenericThingTemplate exposes a function called, loadShapeLibrary(shapeLibrary) to the platform. This function can be called on the platform to cause the remote process to load the specified dynamic library if it is found. To apply a registered shape to an existing Thing at runtime, use the following command:
void twExt_AddEdgeThingShape(char* entityName,char* shapeName);
This command runs the constructor and configures the requested ThingShape if it has already been loaded. This function is also exposed to the platform and appears as the function twExt_DoesThingImplementShape() to any Edge Thing that is created based on the EdgeGenericThingTemplate.
Lastly, any entity can be queried for the shapes that it currently supports by using the following call:
void twExt_GetEdgeThingShapes(char* entityName);
This function is also exposed to the platform through EdgeGenericThingTemplate as getEdgeThingShapes();.