2 Copyright 2012-2016 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 @defgroup worker Worker
20 Support for non-realtime plugin operations, see
21 <http://lv2plug.in/ns/ext/worker> for details.
33 #define LV2_WORKER_URI "http://lv2plug.in/ns/ext/worker" ///< http://lv2plug.in/ns/ext/worker
34 #define LV2_WORKER_PREFIX LV2_WORKER_URI "#" ///< http://lv2plug.in/ns/ext/worker#
36 #define LV2_WORKER__interface LV2_WORKER_PREFIX "interface" ///< http://lv2plug.in/ns/ext/worker#interface
37 #define LV2_WORKER__schedule LV2_WORKER_PREFIX "schedule" ///< http://lv2plug.in/ns/ext/worker#schedule
44 Status code for worker functions.
47 LV2_WORKER_SUCCESS
= 0, /**< Completed successfully. */
48 LV2_WORKER_ERR_UNKNOWN
= 1, /**< Unknown error. */
49 LV2_WORKER_ERR_NO_SPACE
= 2 /**< Failed due to lack of space. */
52 /** Opaque handle for LV2_Worker_Interface::work(). */
53 typedef void* LV2_Worker_Respond_Handle
;
56 A function to respond to run() from the worker method.
58 The `data` MUST be safe for the host to copy and later pass to
59 work_response(), and the host MUST guarantee that it will be eventually
60 passed to work_response() if this function returns LV2_WORKER_SUCCESS.
62 typedef LV2_Worker_Status (*LV2_Worker_Respond_Function
)(
63 LV2_Worker_Respond_Handle handle
,
68 Plugin Worker Interface.
70 This is the interface provided by the plugin to implement a worker method.
71 The plugin's extension_data() method should return an LV2_Worker_Interface
72 when called with LV2_WORKER__interface as its argument.
74 typedef struct _LV2_Worker_Interface
{
76 The worker method. This is called by the host in a non-realtime context
77 as requested, possibly with an arbitrary message to handle.
79 A response can be sent to run() using `respond`. The plugin MUST NOT
80 make any assumptions about which thread calls this method, except that
81 there are no real-time requirements and only one call may be executed at
82 a time. That is, the host MAY call this method from any non-real-time
83 thread, but MUST NOT make concurrent calls to this method from several
86 @param instance The LV2 instance this is a method on.
87 @param respond A function for sending a response to run().
88 @param handle Must be passed to `respond` if it is called.
89 @param size The size of `data`.
90 @param data Data from run(), or NULL.
92 LV2_Worker_Status (*work
)(LV2_Handle instance
,
93 LV2_Worker_Respond_Function respond
,
94 LV2_Worker_Respond_Handle handle
,
99 Handle a response from the worker. This is called by the host in the
100 run() context when a response from the worker is ready.
102 @param instance The LV2 instance this is a method on.
103 @param size The size of `body`.
104 @param body Message body, or NULL.
106 LV2_Worker_Status (*work_response
)(LV2_Handle instance
,
111 Called when all responses for this cycle have been delivered.
113 Since work_response() may be called after run() finished, this provides
114 a hook for code that must run after the cycle is completed.
116 This field may be NULL if the plugin has no use for it. Otherwise, the
117 host MUST call it after every run(), regardless of whether or not any
118 responses were sent that cycle.
120 LV2_Worker_Status (*end_run
)(LV2_Handle instance
);
121 } LV2_Worker_Interface
;
123 /** Opaque handle for LV2_Worker_Schedule. */
124 typedef void* LV2_Worker_Schedule_Handle
;
127 Schedule Worker Host Feature.
129 The host passes this feature to provide a schedule_work() function, which
130 the plugin can use to schedule a worker call from run().
132 typedef struct _LV2_Worker_Schedule
{
136 LV2_Worker_Schedule_Handle handle
;
139 Request from run() that the host call the worker.
141 This function is in the audio threading class. It should be called from
142 run() to request that the host call the work() method in a non-realtime
143 context with the given arguments.
145 This function is always safe to call from run(), but it is not
146 guaranteed that the worker is actually called from a different thread.
147 In particular, when free-wheeling (e.g. for offline rendering), the
148 worker may be executed immediately. This allows single-threaded
149 processing with sample accuracy and avoids timing problems when run() is
150 executing much faster or slower than real-time.
152 Plugins SHOULD be written in such a way that if the worker runs
153 immediately, and responses from the worker are delivered immediately,
154 the effect of the work takes place immediately with sample accuracy.
156 The `data` MUST be safe for the host to copy and later pass to work(),
157 and the host MUST guarantee that it will be eventually passed to work()
158 if this function returns LV2_WORKER_SUCCESS.
160 @param handle The handle field of this struct.
161 @param size The size of `data`.
162 @param data Message to pass to work(), or NULL.
164 LV2_Worker_Status (*schedule_work
)(LV2_Worker_Schedule_Handle handle
,
167 } LV2_Worker_Schedule
;
173 #endif /* LV2_WORKER_H */