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 /** 39 Opaque pointer to host data for LV2_URID_Map. 40 */ 41 typedef void* LV2_URID_Map_Handle; 42 43 /** 44 Opaque pointer to host data for LV2_URID_Unmap. 45 */ 46 typedef void* LV2_URID_Unmap_Handle; 47 48 /** 49 URI mapped to an integer. 50 */ 51 typedef uint32_t LV2_URID; 52 53 /** 54 URID Map Feature (LV2_URID__map) 55 */ 56 typedef struct _LV2_URID_Map { 57 /** 58 Opaque pointer to host data. 59 60 This MUST be passed to map_uri() whenever it is called. 61 Otherwise, it must not be interpreted in any way. 62 */ 63 LV2_URID_Map_Handle handle; 64 65 /** 66 Get the numeric ID of a URI. 67 68 If the ID does not already exist, it will be created. 69 70 This function is referentially transparent; any number of calls with the 71 same arguments is guaranteed to return the same value over the life of a 72 plugin instance. Note, however, that several URIs MAY resolve to the 73 same ID if the host considers those URIs equivalent. 74 75 This function is not necessarily very fast or RT-safe: plugins SHOULD 76 cache any IDs they might need in performance critical situations. 77 78 The return value 0 is reserved and indicates that an ID for that URI 79 could not be created for whatever reason. However, hosts SHOULD NOT 80 return 0 from this function in non-exceptional circumstances (i.e. the 81 URI map SHOULD be dynamic). 82 83 @param handle Must be the callback_data member of this struct. 84 @param uri The URI to be mapped to an integer ID. 85 */ 86 LV2_URID (*map)(LV2_URID_Map_Handle handle, 87 const char* uri); 88 } LV2_URID_Map; 89 90 /** 91 URI Unmap Feature (LV2_URID__unmap) 92 */ 93 typedef struct _LV2_URID_Unmap { 94 /** 95 Opaque pointer to host data. 96 97 This MUST be passed to unmap() whenever it is called. 98 Otherwise, it must not be interpreted in any way. 99 */ 100 LV2_URID_Unmap_Handle handle; 101 102 /** 103 Get the URI for a previously mapped numeric ID. 104 105 Returns NULL if @p urid is not yet mapped. Otherwise, the corresponding 106 URI is returned in a canonical form. This MAY not be the exact same 107 string that was originally passed to LV2_URID_Map::map(), but it MUST be 108 an identical URI according to the URI syntax specification (RFC3986). A 109 non-NULL return for a given @p urid will always be the same for the life 110 of the plugin. Plugins that intend to perform string comparison on 111 unmapped URIs SHOULD first canonicalise URI strings with a call to 112 map_uri() followed by a call to unmap_uri(). 113 114 @param handle Must be the callback_data member of this struct. 115 @param urid The ID to be mapped back to the URI string. 116 */ 117 const char* (*unmap)(LV2_URID_Unmap_Handle handle, 118 LV2_URID urid); 119 } LV2_URID_Unmap; 120 121 #endif /* LV2_URID_H */ 122