1 /*
2   Copyright 2008-2012 David Robillard <http://drobilla.net>
3   Copyright 2011 Gabriel M. Beddingfield <gabrbedd@gmail.com>
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 urid.h
20    C header for the LV2 URID extension <http://lv2plug.in/ns/ext/urid>
21 */
22 
23 #ifndef LV2_URID_H
24 #define LV2_URID_H
25 
26 #define LV2_URID_URI     "http://lv2plug.in/ns/ext/urid"
27 #define LV2_URID_PREFIX  LV2_URID_URI "#"
28 
29 #define LV2_URID__map   LV2_URID_PREFIX "map"
30 #define LV2_URID__unmap LV2_URID_PREFIX "unmap"
31 
32 /* Legacy defines */
33 #define LV2_URID_MAP_URI   LV2_URID__map
34 #define LV2_URID_UNMAP_URI LV2_URID__unmap
35 
36 #include <stdint.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /**
43    Opaque pointer to host data for LV2_URID_Map.
44 */
45 typedef void* LV2_URID_Map_Handle;
46 
47 /**
48    Opaque pointer to host data for LV2_URID_Unmap.
49 */
50 typedef void* LV2_URID_Unmap_Handle;
51 
52 /**
53    URI mapped to an integer.
54 */
55 typedef uint32_t LV2_URID;
56 
57 /**
58    URID Map Feature (LV2_URID__map)
59 */
60 typedef struct _LV2_URID_Map {
61 	/**
62 	   Opaque pointer to host data.
63 
64 	   This MUST be passed to map_uri() whenever it is called.
65 	   Otherwise, it must not be interpreted in any way.
66 	*/
67 	LV2_URID_Map_Handle handle;
68 
69 	/**
70 	   Get the numeric ID of a URI.
71 
72 	   If the ID does not already exist, it will be created.
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.  Note, however, that several URIs MAY resolve to the
77 	   same ID if the host considers those URIs equivalent.
78 
79 	   This function is not necessarily very fast or RT-safe: plugins SHOULD
80 	   cache any IDs they might need in performance critical situations.
81 
82 	   The return value 0 is reserved and indicates that an ID for that URI
83 	   could not be created for whatever reason.  However, hosts SHOULD NOT
84 	   return 0 from this function in non-exceptional circumstances (i.e. the
85 	   URI map SHOULD be dynamic).
86 
87 	   @param handle Must be the callback_data member of this struct.
88 	   @param uri The URI to be mapped to an integer ID.
89 	*/
90 	LV2_URID (*map)(LV2_URID_Map_Handle handle,
91 	                const char*         uri);
92 } LV2_URID_Map;
93 
94 /**
95    URI Unmap Feature (LV2_URID__unmap)
96 */
97 typedef struct _LV2_URID_Unmap {
98 	/**
99 	   Opaque pointer to host data.
100 
101 	   This MUST be passed to unmap() whenever it is called.
102 	   Otherwise, it must not be interpreted in any way.
103 	*/
104 	LV2_URID_Unmap_Handle handle;
105 
106 	/**
107 	   Get the URI for a previously mapped numeric ID.
108 
109 	   Returns NULL if @p urid is not yet mapped.  Otherwise, the corresponding
110 	   URI is returned in a canonical form.  This MAY not be the exact same
111 	   string that was originally passed to LV2_URID_Map::map(), but it MUST be
112 	   an identical URI according to the URI syntax specification (RFC3986).  A
113 	   non-NULL return for a given @p urid will always be the same for the life
114 	   of the plugin.  Plugins that intend to perform string comparison on
115 	   unmapped URIs SHOULD first canonicalise URI strings with a call to
116 	   map_uri() followed by a call to unmap_uri().
117 
118 	   @param handle Must be the callback_data member of this struct.
119 	   @param urid The ID to be mapped back to the URI string.
120 	*/
121 	const char* (*unmap)(LV2_URID_Unmap_Handle handle,
122 	                     LV2_URID              urid);
123 } LV2_URID_Unmap;
124 
125 #ifdef __cplusplus
126 }  /* extern "C" */
127 #endif
128 
129 #endif /* LV2_URID_H */
130