render_remote.h
author Tero Marttila <terom@fixme.fi>
Fri, 06 Jun 2008 18:35:46 +0300
changeset 11 082bfaf38cf0
parent 8 4d38ccbeb93e
child 15 e7f0697814dc
permissions -rw-r--r--
* massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
* the beginnings of render_multi, really not done yet

committer: Tero Marttila <terom@fixme.fi>
#ifndef RENDER_REMOTE_H
#define RENDER_REMOTE_H

#include <event2/util.h>
#include <event2/buffer.h>

#include "render.h"
#include "remote_node.h"

/*
 * Execute a render_t operation on a remote render_node
 */


#define RENDER_PORT_NAME "6159"

struct remote_render_ctx;

/*
 * Execute the given render operation on the render_node at the given remote address.
 *
 * The various callback functions must all be provided.
 *
 * cb_sent will be invoked after the request has succesfully been written, and before cb_data is called.
 * cb_data is called whenever new data has been received. See also, render_remote_set_chunk_size
 * cb_done is called after our last call to cb_data (note: see render_remote_shake)
 * cb_fail is called when an error is encountered. This can (and will) happen at any time!
 *
 * Returns NULL on error, or a handle that can be used for cancel/etc on success
 */
struct remote_render_ctx *render_remote (
        struct render *render,              // what to render
        struct remote_node *remote_node,    // what render node to use
        void (*cb_sent)(void *arg),
        void (*cb_data)(struct evbuffer *buf, void *arg),
        void (*cb_done)(void *arg),
        void (*cb_fail)(void *arg),
        void *cb_arg
);

/*
 * Cancel the given request. No more callbacks will be called, buffered data is
 * discarded and the remote render process will cancel ASAP.
 */
void render_remote_cancel (struct remote_render_ctx *ctx);

/*
 * Controls the behaviour of when cb_data is called, and how remote data is read in.
 *
 * recv_threshold sets a threshold for calling cb_data - cb_data will only be
 * called if the buffer contains at least recv_threshold bytes. Note that
 * cb_data is only called once new data has been receieved from the remote end.
 * If cb_data doesn't drain the buffer, cb_data will be called again once more
 * data has been received from the remote end.
 *
 * unread_buffer can be used to control the amount of unread data in cb_data.
 * If the buffer contains more than recv_threshold + unread_buffer bytes, we
 * will stop accepting bytes from the remote end, and cb_data will not be
 * called any more.
 *
 * This means that there is a potential for deadlock if the buffer is full. You
 * MUST call render_remote_shake once you are ready to start consuming the
 * buffer again.
 *
 * Only call this once cb_sent has fired
 */
int render_remote_set_recv (struct remote_render_ctx *ctx, size_t recv_threshold, size_t unread_buffer);

/*
 * Call cb_data with the current set of buffered input data immediately,
 * regardless of whether or not the buffer contains any data, or any new
 * data has been received.
 *
 * Only call this after cb_sent and before cb_done/cb_fail.
 */
int render_remote_shake (struct remote_render_ctx *ctx);

#endif /* RENDER_REMOTE_H */