Formatting Operation Results

You must implement the member format() of each class you derive from ostc_ServerOperation. The protocol for this function is defined by ostc_ServerOperation::format().

In order to send the results of execute() to the thin client, the Server converts each return value into one or more ostc_Objects. It does this by calling format() on each return value.

If execute() passed a nonzero void* to ostc_OperationResult::setReturnValue(), the void* is considered to be the only return value. If execute() passed a nonzero os_cursor* to setReturnValue(), each element that can be visited with the cursor is a return value. If execute() passed a nonzero os_collection* to setReturnValue(), each element of the collection is a return value.

Example

void txfer_operation::format(
      const void * OSobj, 
      ostc_ObjectList * ostcList, 
      ostc_OperationResult*)
{
      Account * acct = (Account*)OSobj;

      ostc_Object * obj = ostcList->addObject();

      obj->setValue("name", acct->getName());
      obj->setValue("val", acct->getBalance());
}

OSobj is the return value being converted. Since it is passed in as a void*, format() must cast it to the appropriate type.

ostcList is an empty list of ostc_Objects. format() adds one or more objects to the list (with ostc_ObjectList::addObject()) and sets their attribute values, so that the list ends up containing the object or objects into which OSobj is to be converted.

In this example, a pointer to a float is converted into an ostc_Object with a single attribute, val, whose value is the float. The value is set with ostc_Object::setValue().

Click here for the example in context.

Execution Postprocessing

For nonincremental operations, the Server calls ostc_ServerOperation::operationComplete() when execute() and all associated format() executions complete. For incremental operations, the Server calls ostc_ServerOperation::operationComplete() when execute() and the first batch of associated format() executions complete.

By default, ostc_ServerOperation::operationComplete() deletes the collection or cursor, if any, passed to setReturnValue(). You can override the default implementation by implementing operationComplete() in the derived type.



[previous] [next]