neuray API Programmer's Manual

mi::bridge::IServer_job Class Reference

[Bridge server]

Description

Represents the server-side part of a job that can be executed by the Bridge server. The corresponding client-side part of the job must return the same ID from mi::neuraylib::ISerializable::get_class_id() and be registered as a Bridge job on the client.

The server-side part must implement mi::neuraylib::ISerializable::deserialize() to deserialize the data that is sent by mi::bridge::IClient_job::serialize(), and mi::bridge::IServer_job::execute() to serialize the result of the job which is consumed by mi::bridge::IClient_job::receive_remote_result(),

It is recommended to derived your implementation from mi::bridge::Server_job and overriding only the required methods.

Public Member Functions

virtual void cancel() =0
Called if the Bridge transaction is aborted or if an error occurs. More...
virtual void execute( IServer_transaction* transaction, neuraylib::​ISerializer* serializer, IServer_job_info* job_info) =0
Executes a job on behalf of a Bridge client. More...

Member Functions

virtual void mi::​bridge::​IServer_job::cancel() [pure virtual]

Called if the Bridge transaction is aborted or if an error occurs. The job execution should be stopped as quickly as possible, no result will be written to the client.

virtual void mi::​bridge::​IServer_job::execute( IServer_transaction* transaction, neuraylib::​ISerializer* serializer, IServer_job_info* job_info) [pure virtual]

Executes a job on behalf of a Bridge client. Intermediate results can be sent to the client by calling mi::neuraylib::ISerializer::flush() on serializer. All data serialized until that point will be delivered in a single call to mi::bridge::IClient_job::receive_remote_result() on the client with the last_result flag set to false. When execute() returns any data not yet flushed will be flushed and mi::bridge::IClient_job::receive_remote_result() will be called one last time with last_result flag set to true.

Example 1: No intermediate results are required. The execute() method simply serializes the result and returns. The receive_remote_result() method will be called once with the full result and last_result flag set to true.

Example 2: Progress feedback. During execution of the job periodically one mi::Float32 representing the percentage of the work done is serialized periodically and the serializer is flushed. Finally, when the job is done the final result is serialized and the method returns. On the client side receive_remote_result() parses a single mi::Float32 for every call with the last_result flag set to false and updates a progress bar. When last_result is true it deserializes the entire result and is done.

Example 3: Custom protocol. Whenever the server is done with a partial result it is flushed as a chunk to the client for processing. The server is preparing multiple different types of results, so the chunk always begins with an mi::Uint8 which identifies the type of the chunk and the data to expect. After flushing the last chunk the execute() method returns without any pending data. On the client side receive_remote_result() will check the last_result flag. If true, then the job is done, no more data to parse. If false the first mi::Uint8 is deserialized and the rest of the data is deserialized depending on the type of the chunk and then processed.

Parameters

transaction
The Bridge transaction to be used for the job execution.
serializer
The serializer to be used to send the result back to the client.
job_info
Additional information about this job.