render_remote.h
changeset 15 e7f0697814dc
parent 11 082bfaf38cf0
child 16 50995bbe442a
equal deleted inserted replaced
14:5a2246f5be78 15:e7f0697814dc
     6 
     6 
     7 #include "render.h"
     7 #include "render.h"
     8 #include "remote_node.h"
     8 #include "remote_node.h"
     9 
     9 
    10 /*
    10 /*
    11  * Execute a render_t operation on a remote render_node
    11  * Execute a render operation on a remote render_node
    12  */
    12  */
    13 
    13 
    14 
    14 
    15 #define RENDER_PORT_NAME "6159"
    15 #define RENDER_PORT_NAME "6159"
    16 
    16 
    17 struct remote_render_ctx;
    17 struct render_remote;
    18 
    18 
    19 /*
    19 /*
    20  * Execute the given render operation on the render_node at the given remote address.
    20  * Execute the given render operation on the render_node at the given remote
       
    21  * address, and buffer the data stream.
    21  *
    22  *
    22  * The various callback functions must all be provided.
    23  * The various callback functions must all be provided!
    23  *
    24  *
    24  * cb_sent will be invoked after the request has succesfully been written, and before cb_data is called.
    25  * cb_sent
    25  * cb_data is called whenever new data has been received. See also, render_remote_set_chunk_size
    26  *  Will be invoked once we have a pretty good guess that the render will
    26  * cb_done is called after our last call to cb_data (note: see render_remote_shake)
    27  *  complete succesfully.
    27  * cb_fail is called when an error is encountered. This can (and will) happen at any time!
       
    28  *
    28  *
    29  * Returns NULL on error, or a handle that can be used for cancel/etc on success
    29  * cb_data
       
    30  *  Will be invoked after cb_sent has been called whenever any new data has
       
    31  *  been received into our buffer, once we've buffered all the data, or after
       
    32  *  render_remote_flush.
       
    33  *
       
    34  * cb_done
       
    35  *  The request was terminated succesfully and all data has been read out of
       
    36  *  our buffer by cb_data
       
    37  *
       
    38  * cb_fail 
       
    39  *  The request was terminated abnormally. This may happen at any time, except
       
    40  *  after cb_done has been called.
       
    41  *
       
    42  * The returned struct render_remote can be used as a handle for the control
       
    43  * functions, and it is the caller's responsibility to free it using
       
    44  * render_remote_free after cb_done/cb_fail has been called, or alternatively,
       
    45  * cancel it using render_remote_cancel.
       
    46  *
       
    47  * Returns NULL on error, or a handle on success
    30  */
    48  */
    31 struct remote_render_ctx *render_remote (
    49 struct render_remote *render_remote (
    32         struct render *render,              // what to render
    50         struct render *render,              // what to render
    33         struct remote_node *remote_node,    // what render node to use
    51         struct remote_node *remote_node,    // what render node to use
    34         void (*cb_sent)(void *arg),
    52         void (*cb_sent)(void *arg),
    35         void (*cb_data)(struct evbuffer *buf, void *arg),
    53         void (*cb_data)(struct evbuffer *buf, void *arg),
    36         void (*cb_done)(void *arg),
    54         void (*cb_done)(void *arg),
    37         void (*cb_fail)(void *arg),
    55         void (*cb_fail)(void *arg),
    38         void *cb_arg
    56         void *cb_arg
    39 );
    57 );
    40 
    58 
    41 /*
    59 /*
    42  * Cancel the given request. No more callbacks will be called, buffered data is
    60  * Execute the given render operation on the render_node at the given remote
    43  * discarded and the remote render process will cancel ASAP.
    61  * address, and let the user handle the read I/O events.
       
    62  *
       
    63  * The various callback functions must all be provided!
       
    64  *
       
    65  * cb_sent
       
    66  *  Will be called once the request has been sent.
       
    67  *
       
    68  * cb_fail
       
    69  *  Will be called if sending the request fails.
       
    70  *
       
    71  * cb_io_data
       
    72  *  Will be called once when there is data on the socket to receive. Must be
       
    73  *  re-enabled using render_remote_again each time.
    44  */
    74  */
    45 void render_remote_cancel (struct remote_render_ctx *ctx);
    75 struct render_remote *render_remote_rawio (
       
    76         struct render *render,
       
    77         struct remote_node *remote_node,
       
    78         void (*cb_sent)(void *arg),
       
    79         void (*cb_fail)(void *arg),
       
    80         void (*cb_io_data)(evutil_socket_t, short, void*),
       
    81         void *cb_arg
       
    82 );
    46 
    83 
    47 /*
    84 /*
    48  * Controls the behaviour of when cb_data is called, and how remote data is read in.
    85  * Controls the behaviour of when cb_data is called, and how remote data is read in.
    49  *
    86  *
    50  * recv_threshold sets a threshold for calling cb_data - cb_data will only be
    87  * recv_threshold sets a threshold for calling cb_data - cb_data will only be
    57  * If the buffer contains more than recv_threshold + unread_buffer bytes, we
    94  * If the buffer contains more than recv_threshold + unread_buffer bytes, we
    58  * will stop accepting bytes from the remote end, and cb_data will not be
    95  * will stop accepting bytes from the remote end, and cb_data will not be
    59  * called any more.
    96  * called any more.
    60  *
    97  *
    61  * This means that there is a potential for deadlock if the buffer is full. You
    98  * This means that there is a potential for deadlock if the buffer is full. You
    62  * MUST call render_remote_shake once you are ready to start consuming the
    99  * MUST call render_remote_again once you are ready to start consuming the
    63  * buffer again.
   100  * buffer again.
    64  *
   101  *
    65  * Only call this once cb_sent has fired
   102  * Only valid for normal buffered renders.
    66  */
   103  */
    67 int render_remote_set_recv (struct remote_render_ctx *ctx, size_t recv_threshold, size_t unread_buffer);
   104 void render_remote_set_recv (struct render_remote *ctx, size_t recv_threshold, size_t unread_buffer);
    68 
   105 
    69 /*
   106 /*
    70  * Call cb_data with the current set of buffered input data immediately,
   107  * For buffered I/O, call cb_data with the current set of buffered input data
    71  * regardless of whether or not the buffer contains any data, or any new
   108  * immediately, regardless of whether or not the buffer contains any data, or
    72  * data has been received.
   109  * any new data has been received. Only call this once cb_sent has been invoked.
       
   110  */
       
   111 void render_remote_flush (struct render_remote *ctx);
       
   112 
       
   113 /*
       
   114  * For non-buffered I/O, reschedule the cb_io_data event to be called when more
       
   115  * data is received.
       
   116  */
       
   117 int render_remote_reschedule (struct render_remote *ctx);
       
   118 
       
   119 /*
       
   120  * Cancel the given request. No more callbacks will be called, the ctx is freed
       
   121  * and the remote render process will cancel ASAP.
    73  *
   122  *
    74  * Only call this after cb_sent and before cb_done/cb_fail.
   123  * For buffered I/O, the any buffered data is discarded.
       
   124  *
       
   125  * Note that you do not need to call render_remote_free after this.
    75  */
   126  */
    76 int render_remote_shake (struct remote_render_ctx *ctx);
   127 void render_remote_cancel (struct render_remote *ctx);
       
   128 
       
   129 /*
       
   130  * Free the render_remote ctx and its assoicated resources. Only valid after a
       
   131  * cb_done/cb_fail, otherwise use render_remote_cancel.
       
   132  */
       
   133 void render_remote_free (struct render_remote *ctx);
    77 
   134 
    78 #endif /* RENDER_REMOTE_H */
   135 #endif /* RENDER_REMOTE_H */