PDL_ServiceCallWithCallback

Description

Calls a device service with a callback response function. Callback responses can be either one-time or indefinite. If indefinite, you can later stop callback responses with the PDL_UnregisterServiceCallback API.

See Accessing Services for more information and examples.

Syntax

PDL_Err PDL_ServiceCallWithCallback(
  const char *uri,
  const char *payload,
  PDL_ServiceCallbackFunc callback,
  void *user,
  PDL_bool removeAfterResponse
);

Argument Description
uri Service's URI (Uniform Resource Identifier). Has the form: "palm://<service name>/<service type>".
callback Callback function for handling response.
payload JSON (JavaScript Object Notation) style parameters.
For example: "{ par1:"val1", par2:"val2", ...}"
Note that, in C code, the inner double quotes would need to be escaped with a backslash ("\").
user Can be a pointer to anything, or even used as 4-byte value. Sent back in callback invocation and can be used to uniquely identify service source.
removeAfterResponse PDL_TRUE if no further callbacks after first, PDL_FALSE otherwise.

Returns

PDL_ECONNECTION - Unable to dispatch service call.
PDL_NOERROR — Success.

Example

PDL_bool DisplayCallback(PDL_ServiceParameters *params, void *user)               
{
  char result[10];
  if (PDL_ParamExists(params, "state"))
  {
      PDL_GetParamString(params, "state", result, 10);
      fprintf(stdout, "Display state =%s\n", result);
  }
  else
  {
      fprintf(stdout, "Did not get display state\n");
  }
  return PDL_TRUE;
}

//**
//** Get state of display.
//**
void GetDisplayStatus()
{
  PDL_ServiceCallWithCallback(
      "palm://com.palm.display/status",
      "",
      DisplayCallback,
      NULL,
      PDL_TRUE);
}

See also:

  • PDL_ServiceCall
  • PDL_UnregisterServiceCallback
  • PDL_GetParamDouble
  • PDL_GetParamInt
  • PDL_GetParamString
  • PDL_ParamExists