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 (#INCLUDE) so that this library can use 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 macros to declare the template, the properties, and the services.
* 
The code snippets below are excerpts from the warehouse.c file. The indentations were moved to the left enough spaces to fit the lines on the page. However, the structure of the indentations was preserved. 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);
}
Was this helpful?