ThingWorx Edge SDK Extensions for the C SDK > Examples of Using Edge Extensions with the C SDK > Warehouse Shape Library
  
Warehouse Shape Library
The ../examples/warehouselib/ subdirectory contains a library of thing shapes and an Edge Thing Template (ETT):
Warehouse thing template (the ETT)
Inventory thing shape
Address thing shape
These shapes are all defined in the file, warehouse.c. At the top of this file, notice that the header files, twExt_.h and twMacros.h are “included” so that this library can take advantage of the functions for Edge Extensions and the macros that simplify the creation of Edge Extensions. Take a closer look at how this library uses macros to create the ETT and the thing shapes.
Using Macros to Create the Edge Thing Template and the Thing Shapes
The Warehouse Edge Thing Template (ETT), the Inventory thing shape, and the Address thing shape in this example all use macros, including to declare the template, the properties, and the services.
* 
The code snippets below have been excerpted from the warehouse.c file and the indentations moved to the left enough spaces so all the lines fit on the page. The structure of the indentations is preserved here. To use any of the code, copy from the warehouse.c file.
The DECLARE macro is used to declare the ETT and each thing shape, as follows:
For the Warehouse ETT:
TW_DECLARE_TEMPLATE(thingName, "Warehouse Template", TW_THING_TEMPLATE_GENERIC);
For the Inventory thing shape:
TW_DECLARE_SHAPE(thingName, "Inventory Shape",namespace);
For the Address thing shape:
TW_DECLARE_SHAPE(thingName,"Address Shape",namespace
A less verbose version of the DECLARE macro is used to define properties for the ETT and thing shapes, as follows:
For the Warehouse ETT:
TW_PROPERTY("instanceName", "Instance Name", TW_STRING);
For the Inventory thing shape:
TW_PROPERTY("inventory", "A list of inventory", TW_INFOTABLE);
For the Address thing shape:
TW_PROPERTY("category", "What category of business this is.", TW_STRING);
TW_PROPERTY("firstName", "Your First Name", TW_STRING);
TW_PROPERTY("lastName", "Your Last Name", TW_STRING);
TW_PROPERTY("address", "Where this business is located", TW_STRING);
TW_PROPERTY("city", TW_NO_DESCRIPTION, TW_STRING);
TW_PROPERTY("state", TW_NO_DESCRIPTION, TW_STRING);
TW_PROPERTY("zip", TW_NO_DESCRIPTION, TW_STRING);
TW_PROPERTY("yearsAtLocation", "", TW_NUMBER);
Recall that for these property declarations, you can but do not need to use DECLARE.
Services are created for the two thing shapes, using the TW_DECLARE_SERVICE macro (no services on the ETT), as follows:
For the Inventory thing shape:
TW_DECLARE_SERVICE("addProduct",
"Adds a product to the Inventory",
TW_MAKE_DATASHAPE(TW_SHAPE_NAME_NONE,
TW_DS_ENTRY("description", "Description of Inventory Item" ,TW_STRING),
TW_DS_ENTRY("price", "Price of Inventory Item" ,TW_NUMBER)
),
TW_NOTHING,
TW_NO_RETURN_DATASHAPE,
addProduct
);
TW_DECLARE_SERVICE("currentInventory",
"Displays the Inventory",
TW_NO_PARAMETERS,
TW_INFOTABLE,
TW_MAKE_DATASHAPE(TW_SHAPE_NAME_NONE,
TW_DS_ENTRY("description", "Description of Inventory Item" ,TW_STRING),
TW_DS_ENTRY("price", "Price of Inventory Item" ,TW_NUMBER)
),
currentInventory
);
For the Address thing shape:
TW_DECLARE_SERVICE("generateSalutation",
"Creates a salutation sentence.",
TW_MAKE_DATASHAPE(TW_SHAPE_NAME_NONE,
TW_DS_ENTRY("title", "Ms,Mrs,Dr or Mr" ,TW_STRING)
),
TW_STRING,
TW_NO_RETURN_DATASHAPE,
generateSalutation
);
Initializing This Library
To initialize this library, you couple init_ with the name of the library, which in this case is warehouse
void init_libwarehouse(){
twExt_RegisterTemplate("WarehouseTemplate", constructWarehouseTemplate);
twExt_RegisterShape("AddressShape", constructAddressShape);
twExt_RegisterShape("InventoryShape", constructInventoryShape);
}