ThingWorx C SDK
twMacros.h
1 /***************************************
2  * Copyright 2017, PTC, Inc.
3  ***************************************/
4 
5 #ifndef TW_C_SDK_TWMACROS_H
6 #define TW_C_SDK_TWMACROS_H
7 
8 /***************************************
9  * Copyright 2017, PTC, Inc.
10  ***************************************/
11 
12 #define TW_THING_TEMPLATE_GENERIC "GenericEdgeThingTemplate"
13 #define TW_THING_TEMPLATE_EMPTY "EmptyTemplate"
14 #define TW_UNUSED_VARIABLE(x) ((void)x)
15 
26 #define VAR_ARG_END NULL
27 
41 #define TW_DECLARE_SHAPE(aThingName,shapeName,thing_namespace) const char* _tw_thing_name=aThingName;const char* _tw_thing_namespace = thing_namespace;const char* _tw_shape_name=shapeName;TW_UNUSED_VARIABLE(_tw_thing_namespace);TW_UNUSED_VARIABLE(_tw_thing_name);TW_UNUSED_VARIABLE(_tw_shape_name);
42 
51 #define TW_SHAPE(aThingName,shapeName,thing_namespace) const char* _tw_thing_name=aThingName;const char* _tw_thing_namespace = thing_namespace;const char* _tw_shape_name=shapeName;TW_UNUSED_VARIABLE(_tw_thing_namespace);TW_UNUSED_VARIABLE(_tw_thing_name);TW_UNUSED_VARIABLE(_tw_shape_name);
52 
61 #define TW_DECLARE_TEMPLATE(aThingName,templateName,inheritsTemplate) const char* _tw_thing_name=aThingName;const char* _tw_thing_namespace = TW_NO_NAMESPACE;const char* _tw_template_name=templateName;twExt_InheritFromTemplate(aThingName, inheritsTemplate);TW_UNUSED_VARIABLE(_tw_thing_name);TW_UNUSED_VARIABLE(_tw_thing_namespace);TW_UNUSED_VARIABLE(_tw_template_name);
62 
70 #define TW_TEMPLATE(aThingName,templateName,inheritsTemplate) const char* _tw_thing_name=aThingName;const char* _tw_thing_namespace = TW_NO_NAMESPACE;const char* _tw_template_name=templateName;twExt_InheritFromTemplate(aThingName, inheritsTemplate);TW_UNUSED_VARIABLE(_tw_thing_name);TW_UNUSED_VARIABLE(_tw_thing_namespace);TW_UNUSED_VARIABLE(_tw_template_name);
71 
82 #define TW_DECLARE_EVENT(eventName,eventDescription,eventDataShape) twApi_RegisterEvent(TW_THING, _tw_thing_name, eventName, eventDescription, eventDataShape);
83 
93 #define TW_EVENT(eventName,eventDescription,eventDataShape) twApi_RegisterEvent(TW_THING, _tw_thing_name, eventName, eventDescription, eventDataShape)
94 
112 #define TW_PROPERTY(propertyName,description,type) twExt_RegisterStandardProperty(_tw_thing_name, propertyName, _tw_thing_namespace ,type, description, TW_PUSH_TYPE_ALWAYS,REPORT_ALL_CHANGES)
113 
127 #define TW_PROPERTY_LONG(propertyName,description,type,pushType,threshold) twExt_RegisterStandardProperty(_tw_thing_name, propertyName, _tw_thing_namespace ,type, description, pushType,threshold)
128 
138 #define TW_ADD_NUMBER_ASPECT(propertyName,aspectName,valuedouble) twApi_AddAspectToProperty(_tw_thing_name, propertyName, aspectName, twPrimitive_CreateFromNumber(valuedouble))
139 
149 #define TW_ADD_BOOLEAN_ASPECT(propertyName,aspectName,valuebool) twApi_AddAspectToProperty(_tw_thing_name, propertyName, aspectName, twPrimitive_CreateFromBoolean(valuebool))
150 
161 #define TW_ADD_STRING_ASPECT(propertyName,aspectName,valuestring) twApi_AddAspectToProperty(_tw_thing_name, propertyName, aspectName, twPrimitive_CreateFromString(valuestring, TRUE))
162 
181 #define TW_SET_PROPERTY(thingName, propertyName,value) twExt_SetPropertyValue(thingName, propertyName, value,0,0)
182 
191 #define TW_GET_PROPERTY(thingName, propertyName) twExt_GetPropertyValue(thingName,propertyName)->val
192 
199 #define TW_GET_PROPERTY_TYPE(thingName, propertyName) twExt_GetPropertyValue(thingName,propertyName)->type
200 
208 #define TW_GET_STRING_PROPERTY(thingName, propertyName) twExt_GetPropertyValue(thingName,propertyName)->val.bytes.data
209 
219 #define TW_PUSH_PROPERTIES_FOR(thingName,force) twApi_PushSubscribedProperties(thingName, force);
220 
230 #define TW_BIND() twApi_BindThing(_tw_thing_name);
231 
251 #define TW_MAKE_DATASHAPE(shapeName,firstShape,...) twDataShape_CreateFromEntries(shapeName,firstShape,##__VA_ARGS__,VAR_ARG_END)
252 
263 #define TW_DECLARE_DS_ENTRY(fieldName,description,type) twDataShapeEntry_Create(fieldName, description, type)
264 
275 #define TW_DS_ENTRY(fieldName,description,type) twDataShapeEntry_Create(fieldName, description, type)
276 
298 #define TW_DECLARE_SERVICE(serviceName, description,inputShape,outputType,outputShape,serviceHandler) twExt_RegisterNamespacedService(_tw_thing_name, serviceName, _tw_thing_namespace , description, inputShape, outputType, outputShape, serviceHandler, NULL)
299 
314 #define TW_SERVICE(serviceName, description,inputShape,outputType,outputShape,serviceHandler) twExt_RegisterNamespacedService(_tw_thing_name, serviceName, _tw_thing_namespace , description, inputShape, outputType, outputShape, serviceHandler, NULL)
315 
323 #define TW_GET_STRING_PARAM(params,paramName) twInfoTable_GetString(params, #paramName, 0, &paramName);
324 
332 #define TW_GET_NUMBER_PARAM(params,paramName) twInfoTable_GetNumber(params, #paramName, 0, &paramName);
333 
347 #define TW_MAKE_NUMBER(numberValue) twPrimitive_CreateFromNumber((double)numberValue)
348 
356 #define TW_MAKE_INT(intValue) twPrimitive_CreateFromInteger(intValue)
357 
365 #define TW_MAKE_STRING(stringValue) twPrimitive_CreateFromString((char*)stringValue,TRUE)
366 
374 #define TW_MAKE_BOOL(boolValue) twPrimitive_CreateFromBoolean(boolValue)
375 
383 #define TW_MAKE_DATETIME(timestamp) twPrimitive_CreateFromDatetime(timestamp)
384 
392 #define TW_MAKE_DATETIME_NOW twPrimitive_CreateFromDatetime(twGetSystemTime(TRUE))
393 
400 #define TW_MAKE_EMPTY twPrimitive_Create()
401 
411 #define TW_MAKE_LOC(latitude,longitude,elevation) twPrimitive_CreateFromLocationAndDelete(twCreateLocationFrom(latitude,longitude,elevation))
412 
426 #define TW_DECLARE_IT_ROW(primitive,...) twInfoTable_CreateRowFromEntries(primitive,##__VA_ARGS__,VAR_ARG_END)
427 
434 #define TW_IT_ROW(primitive,...) twInfoTable_CreateRowFromEntries(primitive,##__VA_ARGS__,VAR_ARG_END)
435 
443 #define TW_MAKE_INFOTABLE(dataShape,...) twInfoTable_CreateInfoTableFromRows(dataShape,##__VA_ARGS__,VAR_ARG_END)
444 
452 #define TW_MAKE_IT(dataShape,...) twInfoTable_CreateInfoTableFromRows(dataShape,##__VA_ARGS__,VAR_ARG_END)
453 
467 #define TW_MAKE_THING(thingName,templateName,...) char * _tw_thing_name=thingName;const char* _tw_thing_namespace = TW_NO_NAMESPACE;twExt_CreateThingFromTemplate(thingName,templateName,##__VA_ARGS__,VAR_ARG_END);TW_UNUSED_VARIABLE(_tw_thing_namespace);TW_UNUSED_VARIABLE(_tw_thing_name)
468 
482 #define TW_FIRE_EVENT(thingName,eventName,eventInfoTable) twApi_FireEvent(TW_THING, thingName, eventName, eventInfoTable, -1, TRUE)
483 
494 #define TW_ADD_FILE_TRANSFER_SHAPE() twFileManager_Create()
495 
502 #define TW_SHARE_DIRECTORY(alias,path) twFileManager_AddVirtualDir(_tw_thing_name, alias, path)
503 
505  #endif //TW_C_SDK_TWMACROS_H