2 Copyright (C) 2010-2011 David Robillard <http://drobilla.net>
3 Copyright (C) 2010 Leonard Ritter <paniq@paniq.org>
5 This header is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published
7 by the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This header is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13 License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this header; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place, Suite 330, Boston, MA 01222-1307 USA
22 C API for the LV2 Persist extension <http://lv2plug.in/ns/ext/persist>.
35 #define LV2_PERSIST_URI "http://lv2plug.in/ns/ext/persist"
38 A host-provided function to store a value under a given key.
39 @param callback_data Must be the callback_data passed to LV2_Persist.save().
40 @param key The key (predicate) to store @a value under (URI mapped integer).
41 @param value Pointer to the value (object) to be stored.
42 @param size The size of the data at @a value in bytes.
43 @param type The type of @a value (URI mapped integer).
44 @param pod True iff @a value is POD.
45 @return 0 on success, otherwise a non-zero error code.
47 The host passes a callback of this type to LV2_Persist.save().
48 This callback is called repeatedly by the plugin within
49 LV2_Persist.save() to store all the key/value records that describe
52 If @a pod is true, @a value is guaranteed to be architecture-independent POD
53 (i.e. a region of memory that does not contain pointers or references to
54 non-persistent resources and can safely be copied and stored with a simple
55 memcpy). Note that this definition of POD is more strict than exclusively
56 in-memory definitions since the value MUST be architecture independent;
57 e.g. endianness must be considered (so basic numeric types are typically NOT
58 POD). Hosts MAY fail to store the value, particularly if it is
59 non-POD. Plugins MUST gracefully handle this situation, even though state
60 may not be fully restored. Hosts SHOULD support any POD value, even if the
61 host does not know anything about its type. Plugins SHOULD express their
62 state entirely with POD values whenever possible, and use non-POD values
63 only where necessary. Plugins SHOULD use common RDF types and/or types from
64 the Atom extension <http://lv2plug.in/ns/ext/atom> whenever possible since
65 hosts are likely to already contain the necessary implementation.
67 Note that @a size MUST be > 0, and @a value MUST point to a valid region of
68 memory @a size bytes long (this is required to make restore unambiguous).
70 The plugin MUST NOT attempt to use this function outside of the
71 LV2_Persist.restore() context.
73 typedef int (*LV2_Persist_Store_Function)(
82 A host-provided function to retrieve a value under a given key.
83 @param callback_data Must be the callback_data passed to LV2_Persist.restore().
84 @param key The key (predicate) of the value to retrieve (URI mapped integer).
85 @param size (Output) If non-NULL, set to the size of the restored value.
86 @param type (Output) If non-NULL, set to the type of the restored value.
87 @param pod (Output) If non-NULL, set to true iff @a value is POD.
88 @return A pointer to the restored value (object), or NULL if no value
89 has been stored under @a key.
91 A callback of this type is passed by the host to LV2_Persist.restore(). This
92 callback is called repeatedly by the plugin within LV2_Persist.restore() to
93 retrieve the values of any keys it requires to restore its state.
95 The returned value MUST remain valid until LV2_Persist.restore() returns.
97 The plugin MUST NOT attempt to use this function, or any value returned from
98 it, outside of the LV2_Persist.restore() context. Returned values MAY be
99 copied for later use if necessary, assuming the plugin knows how to
100 correctly do so (e.g. the value is POD, or the plugin understands the type).
102 typedef const void* (*LV2_Persist_Retrieve_Function)(
110 Persist Extension Data.
112 When the plugin's extension_data is called with argument LV2_PERSIST_URI,
113 the plugin MUST return an LV2_Persist structure, which remains valid for
114 the lifetime of the plugin.
116 The host can use the contained function pointers to save and restore the
117 state of a plugin instance at any time (provided the threading restrictions
118 for the given function are met).
120 The typical use case is to save the plugin's state when a project is
121 saved, and to restore the state when a project has been loaded. Other
122 uses are possible (e.g. cloning plugin instances or taking a snapshot
125 Stored data is only guaranteed to be compatible between instances of plugins
126 with the same URI (i.e. if a change to a plugin would cause a fatal error
127 when restoring state saved by a previous version of that plugin, the plugin
128 URI MUST change just as it must when ports change incompatibly). Plugin
129 authors should consider this possibility, and always store sensible data
130 with meaningful types to avoid such compatibility issues in the future.
132 typedef struct _LV2_Persist {
135 Save plugin state using a host-provided @a store callback.
137 @param instance The instance handle of the plugin.
138 @param store The host-provided store callback.
139 @param callback_data An opaque pointer to host data, e.g. the map or
140 file where the values are to be stored. If @a store is called,
141 this MUST be passed as its callback_data parameter.
143 The plugin is expected to store everything necessary to completely
144 restore its state later (possibly much later, in a different
145 process, on a completely different machine, etc.)
147 The @a callback_data pointer and @a store function MUST NOT be
148 used beyond the scope of save().
150 This function has its own special threading class: it may not be
151 called concurrently with any "Instantiation" function, but it
152 may be called concurrently with functions in any other class,
153 unless the definition of that class prohibits it (e.g. it may
154 not be called concurrently with a "Discovery" function, but it
155 may be called concurrently with an "Audio" function. The plugin
156 is responsible for any locking or lock-free techniques necessary
157 to make this possible.
159 Note that in the simple case where state is only modified by
160 restore(), there are no synchronization issues since save() is
161 never called concurrently with restore() (though run() may read
164 Plugins that dynamically modify state while running, however,
165 must take care to do so in such a way that a concurrent call to
166 save() will save a consistent representation of plugin state for a
167 single instant in time.
169 void (*save)(LV2_Handle instance,
170 LV2_Persist_Store_Function store,
171 void* callback_data);
174 Restore plugin state using a host-provided @a retrieve callback.
176 @param instance The instance handle of the plugin.
177 @param retrieve The host-provided retrieve callback.
178 @param callback_data An opaque pointer to host data, e.g. the map or
179 file from which the values are to be restored. If @a retrieve is
180 called, this MUST be passed as its callback_data parameter.
182 The plugin MAY assume a restored value was set by a previous call to
183 LV2_Persist.save() by a plugin with the same URI.
185 The plugin MUST gracefully fall back to a default value when a
186 value can not be retrieved. This allows the host to reset the
187 plugin state with an empty map.
189 The @a callback_data pointer and @a store function MUST NOT be used
190 beyond the scope of restore().
192 This function is in the "Instantiation" threading class as defined
193 by LV2. This means it MUST NOT be called concurrently with any other
194 function on the same plugin instance.
196 void (*restore)(LV2_Handle instance,
197 LV2_Persist_Retrieve_Function retrieve,
198 void* callback_data);
206 #endif /* LV2_PERSIST_H */