/[svn]/linuxsampler/trunk/src/hostplugins/lv2/lv2_state.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/hostplugins/lv2/lv2_state.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2343 - (show annotations) (download) (as text)
Sun Apr 29 16:14:45 2012 UTC (11 years, 11 months ago) by persson
File MIME type: text/x-c++hdr
File size: 14571 byte(s)
* fixed configure script error with old autoconf versions
* LV2: use the new lv2 package if present
* lsatomic.h: use gcc provided atomic functions if building with gcc
  4.7 and C++11
* added comments in lsatomic.h

1 /*
2 Copyright 2010-2012 David Robillard <http://drobilla.net>
3 Copyright 2010 Leonard Ritter <paniq@paniq.org>
4
5 Permission to use, copy, modify, and/or distribute this software for any
6 purpose with or without fee is hereby granted, provided that the above
7 copyright notice and this permission notice appear in all copies.
8
9 THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /**
19 @file state.h
20 C API for the LV2 State extension <http://lv2plug.in/ns/ext/state>.
21 */
22
23 #ifndef LV2_STATE_H
24 #define LV2_STATE_H
25
26 #include <stddef.h>
27 #include <stdint.h>
28
29 // LinuxSampler modification: use lv2.h instead of
30 // lv2/lv2plug.in/ns/lv2core/lv2.h, to support older lv2core packages
31 #include <lv2.h>
32
33 #define LV2_STATE_URI "http://lv2plug.in/ns/ext/state"
34 #define LV2_STATE_PREFIX LV2_STATE_URI "#"
35
36 #define LV2_STATE__State LV2_STATE_PREFIX "State"
37 #define LV2_STATE__interface LV2_STATE_PREFIX "interface"
38 #define LV2_STATE__makePath LV2_STATE_PREFIX "makePath"
39 #define LV2_STATE__mapPath LV2_STATE_PREFIX "mapPath"
40 #define LV2_STATE__state LV2_STATE_PREFIX "state"
41
42 #ifdef __cplusplus
43 extern "C" {
44 #else
45 # include <stdbool.h>
46 #endif
47
48 typedef void* LV2_State_Handle;
49 typedef void* LV2_State_Map_Path_Handle;
50 typedef void* LV2_State_Make_Path_Handle;
51
52 /**
53 Flags describing value characteristics.
54
55 These flags are used along with the value's type URI to determine how to
56 (de-)serialise the value data, or whether it is even possible to do so.
57 */
58 typedef enum {
59
60 /**
61 Plain Old Data.
62
63 Values with this flag contain no pointers or references to other areas
64 of memory. It is safe to copy POD values with a simple memcpy and store
65 them for the duration of the process. A POD value is not necessarily
66 safe to trasmit between processes or machines (e.g. filenames are POD),
67 see LV2_STATE_IS_PORTABLE for details.
68
69 Implementations MUST NOT attempt to copy or serialise a non-POD value if
70 they do not understand its type (and thus know how to correctly do so).
71 */
72 LV2_STATE_IS_POD = 1,
73
74 /**
75 Portable (architecture independent) data.
76
77 Values with this flag are in a format that is usable on any
78 architecture. A portable value saved on one machine can be restored on
79 another machine regardless of architecture. The format of portable
80 values MUST NOT depend on architecture-specific properties like
81 endianness or alignment. Portable values MUST NOT contain filenames.
82 */
83 LV2_STATE_IS_PORTABLE = 1 << 1,
84
85 /**
86 Native data.
87
88 This flag is used by the host to indicate that the saved data is only
89 going to be used locally in the currently running process (e.g. for
90 instance duplication or snapshots), so the plugin should use the most
91 efficient representation possible and not worry about serialisation
92 and portability.
93 */
94 LV2_STATE_IS_NATIVE = 1 << 2
95
96 } LV2_State_Flags;
97
98 /** A status code for state functions. */
99 typedef enum {
100 LV2_STATE_SUCCESS = 0, /**< Completed successfully. */
101 LV2_STATE_ERR_UNKNOWN = 1, /**< Unknown error. */
102 LV2_STATE_ERR_BAD_TYPE = 2, /**< Failed due to unsupported type. */
103 LV2_STATE_ERR_BAD_FLAGS = 3, /**< Failed due to unsupported flags. */
104 LV2_STATE_ERR_NO_FEATURE = 4, /**< Failed due to missing features. */
105 LV2_STATE_ERR_NO_PROPERTY = 5 /**< Failed due to missing property. */
106 } LV2_State_Status;
107
108 /**
109 A host-provided function to store a property.
110 @param handle Must be the handle passed to LV2_State_Interface.save().
111 @param key The key to store @p value under (URID).
112 @param value Pointer to the value to be stored.
113 @param size The size of @p value in bytes.
114 @param type The type of @p value (URID).
115 @param flags LV2_State_Flags for @p value.
116 @return 0 on success, otherwise a non-zero error code.
117
118 The host passes a callback of this type to LV2_State_Interface.save(). This
119 callback is called repeatedly by the plugin to store all the properties that
120 describe its current state.
121
122 DO NOT INVENT NONSENSE URI SCHEMES FOR THE KEY. Best is to use keys from
123 existing vocabularies. If nothing appropriate is available, use http URIs
124 that point to somewhere you can host documents so documentation can be made
125 resolvable (e.g. a child of the plugin or project URI). If this is not
126 possible, invent a URN scheme, e.g. urn:myproj:whatever. The plugin MUST
127 NOT pass an invalid URI key.
128
129 The host MAY fail to store a property for whatever reason, but SHOULD
130 store any property that is LV2_STATE_IS_POD and LV2_STATE_IS_PORTABLE.
131 Implementations SHOULD use the types from the LV2 Atom extension
132 (http://lv2plug.in/ns/ext/atom) wherever possible. The plugin SHOULD
133 attempt to fall-back and avoid the error if possible.
134
135 Note that @p size MUST be > 0, and @p value MUST point to a valid region of
136 memory @p size bytes long (this is required to make restore unambiguous).
137
138 The plugin MUST NOT attempt to use this function outside of the
139 LV2_State_Interface.restore() context.
140 */
141 typedef LV2_State_Status (*LV2_State_Store_Function)(
142 LV2_State_Handle handle,
143 uint32_t key,
144 const void* value,
145 size_t size,
146 uint32_t type,
147 uint32_t flags);
148
149 /**
150 A host-provided function to retrieve a property.
151 @param handle Must be the handle passed to LV2_State_Interface.restore().
152 @param key The key of the property to retrieve (URID).
153 @param size (Output) If non-NULL, set to the size of the restored value.
154 @param type (Output) If non-NULL, set to the type of the restored value.
155 @param flags (Output) If non-NULL, set to the flags for the restored value.
156 @return A pointer to the restored value (object), or NULL if no value
157 has been stored under @p key.
158
159 A callback of this type is passed by the host to
160 LV2_State_Interface.restore(). This callback is called repeatedly by the
161 plugin to retrieve any properties it requires to restore its state.
162
163 The returned value MUST remain valid until LV2_State_Interface.restore()
164 returns. The plugin MUST NOT attempt to use this function, or any value
165 returned from it, outside of the LV2_State_Interface.restore() context.
166 */
167 typedef const void* (*LV2_State_Retrieve_Function)(
168 LV2_State_Handle handle,
169 uint32_t key,
170 size_t* size,
171 uint32_t* type,
172 uint32_t* flags);
173
174 /**
175 LV2 Plugin State Interface.
176
177 When the plugin's extension_data is called with argument
178 LV2_STATE__interface, the plugin MUST return an LV2_State_Interface
179 structure, which remains valid for the lifetime of the plugin.
180
181 The host can use the contained function pointers to save and restore the
182 state of a plugin instance at any time, provided the threading restrictions
183 of the functions are met.
184
185 Stored data is only guaranteed to be compatible between instances of plugins
186 with the same URI (i.e. if a change to a plugin would cause a fatal error
187 when restoring state saved by a previous version of that plugin, the plugin
188 URI MUST change just as it must when ports change incompatibly). Plugin
189 authors should consider this possibility, and always store sensible data
190 with meaningful types to avoid such problems in the future.
191 */
192 typedef struct _LV2_State_Interface {
193
194 /**
195 Save plugin state using a host-provided @p store callback.
196
197 @param instance The instance handle of the plugin.
198 @param store The host-provided store callback.
199 @param handle An opaque pointer to host data which MUST be passed as the
200 handle parameter to @p store if it is called.
201 @param flags Flags describing desired properties of this save. These
202 flags may be used to determine the most appropriate values to store.
203 @param features Extensible parameter for passing any additional
204 features to be used for this save.
205
206 The plugin is expected to store everything necessary to completely
207 restore its state later. Plugins SHOULD store simple POD data whenever
208 possible, and consider the possibility of state being restored much
209 later on a different machine.
210
211 The @p handle pointer and @p store function MUST NOT be used
212 beyond the scope of save().
213
214 This function has its own special threading class: it may not be called
215 concurrently with any "Instantiation" function, but it may be called
216 concurrently with functions in any other class, unless the definition of
217 that class prohibits it (e.g. it may not be called concurrently with a
218 "Discovery" function, but it may be called concurrently with an "Audio"
219 function. The plugin is responsible for any locking or lock-free
220 techniques necessary to make this possible.
221
222 Note that in the simple case where state is only modified by restore(),
223 there are no synchronization issues since save() is never called
224 concurrently with restore() (though run() may read it during a save).
225
226 Plugins that dynamically modify state while running, however, must take
227 care to do so in such a way that a concurrent call to save() will save a
228 consistent representation of plugin state for a single instant in time.
229 */
230 LV2_State_Status (*save)(LV2_Handle instance,
231 LV2_State_Store_Function store,
232 LV2_State_Handle handle,
233 uint32_t flags,
234 const LV2_Feature *const * features);
235
236 /**
237 Restore plugin state using a host-provided @p retrieve callback.
238
239 @param instance The instance handle of the plugin.
240 @param retrieve The host-provided retrieve callback.
241 @param handle An opaque pointer to host data which MUST be passed as the
242 handle parameter to @p retrieve if it is called.
243 @param flags Currently unused.
244 @param features Extensible parameter for passing any additional
245 features to be used for this restore.
246
247 The plugin MAY assume a restored value was set by a previous call to
248 LV2_State_Interface.save() by a plugin with the same URI.
249
250 The plugin MUST gracefully fall back to a default value when a value can
251 not be retrieved. This allows the host to reset the plugin state with
252 an empty map.
253
254 The @p handle pointer and @p store function MUST NOT be used
255 beyond the scope of restore().
256
257 This function is in the "Instantiation" threading class as defined by
258 LV2. This means it MUST NOT be called concurrently with any other
259 function on the same plugin instance.
260 */
261 LV2_State_Status (*restore)(LV2_Handle instance,
262 LV2_State_Retrieve_Function retrieve,
263 LV2_State_Handle handle,
264 uint32_t flags,
265 const LV2_Feature *const * features);
266
267 } LV2_State_Interface;
268
269 /**
270 Feature data for state:mapPath (LV2_STATE__mapPath).
271 */
272 typedef struct {
273
274 /**
275 Opaque host data.
276 */
277 LV2_State_Map_Path_Handle handle;
278
279 /**
280 Map an absolute path to an abstract path for use in plugin state.
281 @param handle MUST be the @p handle member of this struct.
282 @param absolute_path The absolute path of a file.
283 @return An abstract path suitable for use in plugin state.
284
285 The plugin MUST use this function to map any paths that will be stored
286 in plugin state. The returned value is an abstract path which MAY not
287 be an actual file system path; @ref absolute_path() MUST be used to map
288 it to an actual path in order to use the file.
289
290 Plugins MUST NOT make any assumptions about abstract paths except that
291 they can be mapped back to the absolute path of the "same" file (though
292 not necessarily the same original path) using @ref absolute_path().
293
294 This function may only be called within the context of
295 LV2_State_Interface methods. The caller is responsible for freeing the
296 returned value with free().
297 */
298 char* (*abstract_path)(LV2_State_Map_Path_Handle handle,
299 const char* absolute_path);
300
301 /**
302 Map an abstract path from plugin state to an absolute path.
303 @param handle MUST be the @p handle member of this struct.
304 @param abstract_path An abstract path (e.g. a path from plugin state).
305 @return An absolute file system path.
306
307 The plugin MUST use this function in order to actually open or otherwise
308 use any paths loaded from plugin state.
309
310 This function may only be called within the context of
311 LV2_State_Interface methods. The caller is responsible for freeing the
312 returned value with free().
313 */
314 char* (*absolute_path)(LV2_State_Map_Path_Handle handle,
315 const char* abstract_path);
316
317 } LV2_State_Map_Path;
318
319 /**
320 Feature data for state:makePath (@ref LV2_STATE__makePath).
321 */
322 typedef struct {
323
324 /**
325 Opaque host data.
326 */
327 LV2_State_Make_Path_Handle handle;
328
329 /**
330 Return a path the plugin may use to create a new file.
331 @param handle MUST be the @p handle member of this struct.
332 @param path The path of the new file within a namespace unique to this
333 plugin instance.
334 @return The absolute path to use for the new file.
335
336 This function can be used by plugins to create files and directories,
337 either at state saving time (if this feature is passed to
338 LV2_State_Interface.save()) or any time (if this feature is passed to
339 LV2_Descriptor.instantiate()).
340
341 The host MUST do whatever is necessary for the plugin to be able to
342 create a file at the returned path (e.g. using fopen), including
343 creating any leading directories.
344
345 If this function is passed to LV2_Descriptor.instantiate(), it may be
346 called from any non-realtime context. If it is passed to
347 LV2_State_Interface.save(), it may only be called within the dynamic
348 scope of that function call.
349
350 The caller is responsible for freeing the returned value with free().
351 */
352 char* (*path)(LV2_State_Make_Path_Handle handle,
353 const char* path);
354
355 } LV2_State_Make_Path;
356
357 #ifdef __cplusplus
358 } /* extern "C" */
359 #endif
360
361 #endif /* LV2_STATE_H */

  ViewVC Help
Powered by ViewVC