2 Copyright 2012 David Robillard <http://drobilla.net>
4 Permission to use, copy, modify, and/or distribute this software for any
5 purpose with or without fee is hereby granted, provided that the above
6 copyright notice and this permission notice appear in all copies.
8 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 @file worker.h C header for the LV2 Worker extension
19 <http://lv2plug.in/ns/ext/worker>.
27 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
29 #define LV2_WORKER_URI "http://lv2plug.in/ns/ext/worker"
30 #define LV2_WORKER_PREFIX LV2_WORKER_URI "#"
32 #define LV2_WORKER__interface LV2_WORKER_PREFIX "interface"
33 #define LV2_WORKER__schedule LV2_WORKER_PREFIX "schedule"
36 A status code for worker functions.
39 LV2_WORKER_SUCCESS = 0, /**< Completed successfully. */
40 LV2_WORKER_ERR_UNKNOWN = 1, /**< Unknown error. */
41 LV2_WORKER_ERR_NO_SPACE = 2 /**< Failed due to lack of space. */
44 typedef void* LV2_Worker_Respond_Handle;
47 A function to respond to run() from the worker method.
49 The @p data MUST be safe for the host to copy and later pass to
50 work_response(), and the host MUST guarantee that it will be eventually
51 passed to work_response() if this function returns LV2_WORKER_SUCCESS.
53 typedef LV2_Worker_Status (*LV2_Worker_Respond_Function)(
54 LV2_Worker_Respond_Handle handle,
59 LV2 Plugin Worker Interface.
61 This is the interface provided by the plugin to implement a worker method.
62 The plugin's extension_data() method should return an LV2_Worker_Interface
63 when called with LV2_WORKER__interface as its argument.
65 typedef struct _LV2_Worker_Interface {
67 The worker method. This is called by the host in a non-realtime context
68 as requested, possibly with an arbitrary message to handle.
70 A response can be sent to run() using @p respond. The plugin MUST NOT
71 make any assumptions about which thread calls this method, other than
72 the fact that there are no real-time requirements.
74 @param instance The LV2 instance this is a method on.
75 @param respond A function for sending a response to run().
76 @param handle Must be passed to @p respond if it is called.
77 @param size The size of @p data.
78 @param data Data from run(), or NULL.
80 LV2_Worker_Status (*work)(LV2_Handle instance,
81 LV2_Worker_Respond_Function respond,
82 LV2_Worker_Respond_Handle handle,
87 Handle a response from the worker. This is called by the host in the
88 run() context when a response from the worker is ready.
90 @param instance The LV2 instance this is a method on.
91 @param size The size of @p body.
92 @param body Message body, or NULL.
94 LV2_Worker_Status (*work_response)(LV2_Handle instance,
99 Called when all responses for this cycle have been delivered.
101 Since work_response() may be called after run() finished, this provides
102 a hook for code that must run after the cycle is completed.
104 This field may be NULL if the plugin has no use for it. Otherwise, the
105 host MUST call it after every run(), regardless of whether or not any
106 responses were sent that cycle.
108 LV2_Worker_Status (*end_run)(LV2_Handle instance);
109 } LV2_Worker_Interface;
111 typedef void* LV2_Worker_Schedule_Handle;
113 typedef struct _LV2_Worker_Schedule {
117 LV2_Worker_Schedule_Handle handle;
120 Request from run() that the host call the worker.
122 This function is in the audio threading class. It should be called from
123 run() to request that the host call the work() method in a non-realtime
124 context with the given arguments.
126 This function is always safe to call from run(), but it is not
127 guaranteed that the worker is actually called from a different thread.
128 In particular, when free-wheeling (e.g. for offline rendering), the
129 worker may be executed immediately. This allows single-threaded
130 processing with sample accuracy and avoids timing problems when run() is
131 executing much faster or slower than real-time.
133 Plugins SHOULD be written in such a way that if the worker runs
134 immediately, and responses from the worker are delivered immediately,
135 the effect of the work takes place immediately with sample accuracy.
137 The @p data MUST be safe for the host to copy and later pass to work(),
138 and the host MUST guarantee that it will be eventually passed to work()
139 if this function returns LV2_WORKER_SUCCESS.
141 @param handle The handle field of this struct.
142 @param size The size of @p data.
143 @param data Message to pass to work(), or NULL.
145 LV2_Worker_Status (*schedule_work)(LV2_Worker_Schedule_Handle handle,
148 } LV2_Worker_Schedule;
150 #endif /* LV2_WORKER_H */