Implementing format()

ostc_ServerOperation::format()

virtual void format(
      const void* value, 
      ostc_ObjectList* values, 
      ostc_OperationResult* result
) =0;

Converts C++ objects that result from execute() into ostc_Objects.

For a given class that you derive from ostc_ServerOperation, you must implement this function in the subtype. ostc_ServerOperation::execute() is a pure virtual that specifies the protocol for the function you must implement.

value is the object being converted.

values is an initially empty list of ostc_Objects.

result is the operation result whose return values are being formatted.

The function should call ostc_ObjectList::addObject() to add to values the object or objects that result from converting value.

After execute() completes, the Component Server calls this function for each return value.

If execute() passes a nonzero void* to ostc_OperationResult()::setReturnValue(), the void* is considered to be the only return value, so the Server calls format() once, passing the void* as the value argument.

If execute() passes a nonzero os_cursor* to ostc_OperationResult()::setReturnValue() (and does not pass a nonzero void* to ostc_OperationResult()::setReturnValue()), the Server calls format() on each element that can be visited with the cursor.

If execute() passes a nonzero os_collection* to ostc_OperationResult()::setReturnValue() (and does not pass a nonzero void* or os_cursor* to ostc_OperationResult()::setReturnValue()), the Server calls format() on each element of the collection.

The Server calls this function within the same ObjectStore transaction in which execute() is performed (unless the operation result is incremental). You do not have to start a transaction explicitly in order to access persistent data within this function.

Your implementation of format() must be reentrant. That is, you are responsible for synchronizing access to any transient state that could be shared across Server threads. In addition, for operations that use shared_update transactions, you must synchronize access to persistent data if that is necessary to prevent interference among threads.

Click here for an example.



[previous] [next]