1 /*
2   Copyright 2008-2011 David Robillard <http://drobilla.net>
3 
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.
7 
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.
15 */
16 
17 /**
18    @file
19    C header for the LV2 URI Map extension <http://lv2plug.in/ns/ext/uri-map>.
20 
21    This extension defines a simple mechanism for plugins to map URIs to
22    integers, usually for performance reasons (e.g. processing events typed by
23    URIs in real time). The expected use case is for plugins to map URIs to
24    integers for things they 'understand' at instantiation time, and store those
25    values for use in the audio thread without doing any string comparison.
26    This allows the extensibility of RDF with the performance of integers (or
27    centrally defined enumerations).
28 */
29 
30 #ifndef LV2_URI_MAP_H
31 #define LV2_URI_MAP_H
32 
33 #define LV2_URI_MAP_URI "http://lv2plug.in/ns/ext/uri-map"
34 
35 #include <stdint.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42    Opaque pointer to host data.
43 */
44 typedef void* LV2_URI_Map_Callback_Data;
45 
46 /**
47    URI Map Feature.
48 
49    To support this feature the host must pass an LV2_Feature struct to the
50    plugin's instantiate method with URI "http://lv2plug.in/ns/ext/uri-map"
51    and data pointed to an instance of this struct.
52 */
53 typedef struct {
54 	/**
55 	   Opaque pointer to host data.
56 
57 	   The plugin MUST pass this to any call to functions in this struct.
58 	   Otherwise, it must not be interpreted in any way.
59 	*/
60 	LV2_URI_Map_Callback_Data callback_data;
61 
62 	/**
63 	   Get the numeric ID of a URI from the host.
64 
65 	   @param callback_data Must be the callback_data member of this struct.
66 	   @param map The 'context' of this URI. Certain extensions may define a
67 	   URI that must be passed here with certain restrictions on the return
68 	   value (e.g. limited range). This value may be NULL if the plugin needs
69 	   an ID for a URI in general. Extensions SHOULD NOT define a context
70 	   unless there is a specific need to do so, e.g. to restrict the range of
71 	   the returned value.
72 	   @param uri The URI to be mapped to an integer ID.
73 
74 	   This function is referentially transparent; any number of calls with the
75 	   same arguments is guaranteed to return the same value over the life of a
76 	   plugin instance (though the same URI may return different values with a
77 	   different map parameter). However, this function is not necessarily very
78 	   fast: plugins SHOULD cache any IDs they might need in performance
79 	   critical situations.
80 
81 	   The return value 0 is reserved and indicates that an ID for that URI
82 	   could not be created for whatever reason. Extensions MAY define more
83 	   precisely what this means in a certain context, but in general plugins
84 	   SHOULD handle this situation as gracefully as possible. However, hosts
85 	   SHOULD NOT return 0 from this function in non-exceptional circumstances
86 	   (e.g. the URI map SHOULD be dynamic). Hosts that statically support only
87 	   a fixed set of URIs should not expect plugins to function correctly.
88 	*/
89 	uint32_t (*uri_to_id)(LV2_URI_Map_Callback_Data callback_data,
90 	                      const char*               map,
91 	                      const char*               uri);
92 } LV2_URI_Map_Feature;
93 
94 #ifdef __cplusplus
95 }  /* extern "C" */
96 #endif
97 
98 #endif /* LV2_URI_MAP_H */
99