ThingWorx C SDK
Macros
Service Declaration Macros

Macros

#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)
 Defines a service name on your Thing, specifies its input and return parameters and maps it to en existing C function. More...
 
#define TW_SERVICE(serviceName, description, inputShape, outputType, outputShape, serviceHandler)   twExt_RegisterNamespacedService(_tw_thing_name, serviceName, _tw_thing_namespace , description, inputShape, outputType, outputShape, serviceHandler, NULL)
 A shorter version of TW_DECLARE_SERVICE. Defines a service name on your Thing, specifies its input and return parameters and maps it to en existing C function. More...
 
#define TW_GET_STRING_PARAM(params, paramName)   twInfoTable_GetString(params, #paramName, 0, &paramName);
 A utility macro that can be used to extract a String parameter from the first row of an InfoTable. It is intended to be used inside Service handlers to extract input parameters that are assumed to be Strings from the input InfoTable. More...
 
#define TW_GET_NUMBER_PARAM(params, paramName)   twInfoTable_GetNumber(params, #paramName, 0, &paramName);
 A utility macro that can be used to extract a double/Number parameter from the first row of an InfoTable. It is intended to be used inside Service handlers to extract input parameters that are assumed to be Numbers from the input InfoTable. More...
 

Detailed Description

Macro Definition Documentation

#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)

Defines a service name on your Thing, specifies its input and return parameters and maps it to en existing C function.

Parameters
serviceNameconst char * [in] The name of the DataShape to create. DataShape names are optional and the constant TW_SHAPE_NAME_NONE can be used if no name is required.
descriptionA text description of the purpose of this service. If no description is required use TW_NO_DESCRIPTION
inputShapetwDataShape* [in] A DataShape created using the macro TW_MAKE_DATASHAPE that represents the input parameters of your Service.
outputTypetwPrimitive * [in] A ThingWorx primitive type representing the return type for your Service. Use one of the enum BaseType values. Examples are {TW_STRING,TW_NUMBER,TW_BOOLEAN,TW_INFOTABLE}
outputShapetwDataShape* [in] A DataShapeEntry created using the macro TW_MAKE_DATASHAPE that should only be used if outputType is TW_INFOTABLE to define the DataShape to be used by the returned InfoTable. If outputType is anything other than TW_INFOTABLE this parameter should be TW_NO_RETURN_DATASHAPE.
serviceHandlerservice_cb [in] A pointer to a C function of type service_cb. Example: enum msgCodeEnum myServiceFunction(const char * entityName, const char * serviceName, twInfoTable * params, twInfoTable ** content, void * userdata);
Returns
TW_OK on success. {TW_INVALID_PARAM,TW_NULL_OR_INVALID_API_SINGLETON,TW_ERROR_ALLOCATING_MEMORY} on failure
#define TW_GET_NUMBER_PARAM (   params,
  paramName 
)    twInfoTable_GetNumber(params, #paramName, 0, &paramName);

A utility macro that can be used to extract a double/Number parameter from the first row of an InfoTable. It is intended to be used inside Service handlers to extract input parameters that are assumed to be Numbers from the input InfoTable.

Parameters
paramstwInfoTable* An InfoTable passed into a Service handler function containing its input parameters.
paramNameconst char * [in] The name of the parameter to extract from the first row of the params InfoTable.
Returns
a double containing the Number field value
#define TW_GET_STRING_PARAM (   params,
  paramName 
)    twInfoTable_GetString(params, #paramName, 0, &paramName);

A utility macro that can be used to extract a String parameter from the first row of an InfoTable. It is intended to be used inside Service handlers to extract input parameters that are assumed to be Strings from the input InfoTable.

Parameters
paramstwInfoTable* An infotable passed into a Service handler function containing its input parameters.
paramNameconst char * [in] The name of the parameter to extract from the first row of the params InfoTable.
Returns
A const char* to the requested string
#define TW_SERVICE (   serviceName,
  description,
  inputShape,
  outputType,
  outputShape,
  serviceHandler 
)    twExt_RegisterNamespacedService(_tw_thing_name, serviceName, _tw_thing_namespace , description, inputShape, outputType, outputShape, serviceHandler, NULL)

A shorter version of TW_DECLARE_SERVICE. Defines a service name on your Thing, specifies its input and return parameters and maps it to en existing C function.

Parameters
serviceNameconst char * [in] The name of the DataShape to create. DataShape names are optional and the constant TW_SHAPE_NAME_NONE can be used if no name is required.
descriptionA text description of the purpose of this service. If no description is required use TW_NO_DESCRIPTION
inputShapetwDataShape* [in] A DataShape created using the macro TW_MAKE_DATASHAPE that represents the input parameters of your Service.
outputTypetwPrimitive * [in] A ThingWorx primitive type representing the return type for your Service. Use one of the enum BaseType values. Examples are {TW_STRING,TW_NUMBER,TW_BOOLEAN,TW_INFOTABLE}
outputShapetwDataShape* [in] A DataShapeEntry created using the macro TW_MAKE_DATASHAPE that should only be used if outputType is TW_INFOTABLE to define the DataShape to be used by the returned InfoTable. If outputType is anything other than TW_INFOTABLE this parameter should be TW_NO_RETURN_DATASHAPE.
serviceHandlerservice_cb [in] A pointer to a C function of type service_cb. Example: enum msgCodeEnum myServiceFunction(const char * entityName, const char * serviceName, twInfoTable * params, twInfoTable ** content, void * userdata);
Returns
TW_OK on success. {TW_INVALID_PARAM,TW_NULL_OR_INVALID_API_SINGLETON,TW_ERROR_ALLOCATING_MEMORY} on failure