ThingWorx Edge C SDK > Steps for Setting Up Applications > Define Service Callback Functions
Define Service Callback Functions
The service callback function is registered to be called when a request for a specific service is received from ThingWorx platform.
typedef enum msgCodeEnum (*service_cb) (const char * entityName, const char * serviceName, twInfoTable * params,twInfoTable** content, void * userdata)
The following parameters are passed to this callback function:
entityName — the name of the entity this request is for (Thing, Resource, for example). Guaranteed to not be NULL.
serviceName — the name of the service being requested
twInfoTable *params — a pointer to an twInfoTable that contains all the parameters for the service. May be NULL if service has no parameters. (For information on InfoTables, see the section, twInfoTable )
twInfoTable ** content — a pointer to a pointer to a twInfoTable. content is guaranteed to not be NULL. *content is not.
A new instance of a twInfoTable should be created on the heap and a pointer to it returned.
userdata — any user data value that was passed in when the callback was registered.
The return value of the function is TWX_SUCCESS if the request completes successfully or an appropriate error code if not (should be a message code enumeration as defined in twDefinitions.h).
Here is an example of handling a single service in a callback:
Service Callbacks
/* Example of handling a single service in a callback */
enum msgCodeEnum addNumbersService(const char * entityName, const char * serviceName, twInfoTable * params, twInfoTable ** content, void * userdata) {
double a, b, res;
TW_LOG(TW_TRACE,"addNumbersService - Function called");
if (!params || !content) {
TW_LOG(TW_ERROR,"addNumbersService - NULL params or content pointer");

twInfoTable_GetNumber(params, "a", 0, &a);
twInfoTable_GetNumber(params, "b", 0, &b);
res = a + b;
*content = twInfoTable_CreateFromNumber("result", res);
if (*content) return SUCCESS;