Changeset 2105
- Timestamp:
- 06/14/09 15:28:29 (15 months ago)
- Location:
- trunk/slv2/src
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/slv2/src/plugin.c
r2094 r2105 31 31 #include "slv2/util.h" 32 32 #include "slv2_internal.h" 33 #ifdef SLV2_DYN_MANIFEST 34 #include <dlfcn.h> 35 #endif 33 36 34 37 … … 44 47 plugin->bundle_uri = slv2_value_new_librdf_uri(world, bundle_uri); 45 48 plugin->binary_uri = NULL; 49 #ifdef SLV2_DYN_MANIFEST 50 plugin->dynman_uri = NULL; 51 #endif 46 52 plugin->plugin_class = NULL; 47 53 plugin->data_uris = slv2_values_new(); … … 51 57 plugin->num_ports = 0; 52 58 59 /*printf("PLUGIN %s DATA URIs: %p\n", 60 slv2_value_as_string(plugin->plugin_uri), 61 (void*)plugin->data_uris);*/ 62 53 63 return plugin; 54 64 } … … 67 77 slv2_value_free(p->binary_uri); 68 78 p->binary_uri = NULL; 79 80 #ifdef SLV2_DYN_MANIFEST 81 slv2_value_free(p->dynman_uri); 82 p->dynman_uri = NULL; 83 #endif 69 84 70 85 if (p->ports) { … … 206 221 librdf_parser_parse_into_model(p->world->parser, data_uri, NULL, p->rdf); 207 222 } 223 224 #ifdef SLV2_DYN_MANIFEST 225 // Load and parse dynamic manifest data, if this is a library 226 if (p->dynman_uri) { 227 const char* lib_path = slv2_uri_to_path(slv2_value_as_string(p->dynman_uri)); 228 void* lib = dlopen(lib_path, RTLD_LAZY); 229 if (!lib) { 230 SLV2_WARNF("Unable to open dynamic manifest %s\n", slv2_value_as_string(p->dynman_uri)); 231 return; 232 } 233 234 typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, const LV2_Dyn_Manifest_Feature *const *); 235 OpenFunc open_func = (OpenFunc)dlsym(lib, "lv2_dyn_manifest_open"); 236 LV2_Dyn_Manifest_Handle handle = NULL; 237 if (open_func) 238 open_func(&handle, &dman_features); 239 240 typedef int (*GetDataFunc)(LV2_Dyn_Manifest_Handle handle, 241 FILE* fp, 242 const char* uri); 243 GetDataFunc get_data_func = (GetDataFunc)dlsym(lib, "lv2_dyn_manifest_get_data"); 244 if (get_data_func) { 245 FILE* fd = tmpfile(); 246 get_data_func(handle, fd, slv2_value_as_string(p->plugin_uri)); 247 rewind(fd); 248 librdf_parser_parse_file_handle_into_model(p->world->parser, 249 fd, 0, slv2_value_as_librdf_uri(p->plugin_uri), p->rdf); 250 fclose(fd); 251 } 252 253 typedef int (*CloseFunc)(LV2_Dyn_Manifest_Handle); 254 CloseFunc close_func = (CloseFunc)dlsym(lib, "lv2_dyn_manifest_close"); 255 if (close_func) 256 close_func(handle); 257 } 258 #endif 259 assert(p->rdf); 208 260 } 209 261 -
trunk/slv2/src/slv2_internal.h
r2090 r2105 16 16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 17 */ 18 19 #include "slv2-config.h" 18 20 19 21 #ifndef __SLV2_INTERNAL_H__ … … 31 33 #include "slv2/types.h" 32 34 #include "slv2/lv2_ui.h" 33 35 #ifdef SLV2_DYN_MANIFEST 36 #include "lv2_dyn_manifest.h" 37 #endif 38 39 #define SLV2_NS_RDFS (const unsigned char*)"http://www.w3.org/2000/01/rdf-schema#" 40 #define SLV2_NS_SLV2 (const unsigned char*)"http://drobilla.net/ns/slv2#" 34 41 35 42 /* ********* PORT ********* */ … … 60 67 SLV2Value bundle_uri; ///< Bundle directory plugin was loaded from 61 68 SLV2Value binary_uri; ///< lv2:binary 69 //#ifdef SLV2_DYN_MANIFEST 70 SLV2Value dynman_uri; ///< dynamic manifest binary 71 //#endif 62 72 SLV2PluginClass plugin_class; 63 73 raptor_sequence* data_uris; ///< rdfs::seeAlso … … 245 255 char* slv2_get_lang(); 246 256 257 258 /* ********* Dynamic Manifest ********* */ 259 #ifdef SLV2_DYN_MANIFEST 260 static const LV2_Dyn_Manifest_Feature* const dman_features = { NULL }; 261 #endif 262 247 263 #define SLV2_ERROR(str) fprintf(stderr, "ERROR: %s: " str, __func__) 248 264 #define SLV2_ERRORF(fmt, ...) fprintf(stderr, "ERROR: %s: " fmt, __func__, __VA_ARGS__) -
trunk/slv2/src/world.c
r2103 r2105 25 25 #include <string.h> 26 26 #include <librdf.h> 27 #include <dlfcn.h>28 27 #include "slv2/types.h" 29 28 #include "slv2/world.h" … … 32 31 #include "slv2_internal.h" 33 32 #ifdef SLV2_DYN_MANIFEST 34 #include "lv2_dyn_manifest.h"33 #include <dlfcn.h> 35 34 #endif 36 35 … … 222 221 librdf_query* query = librdf_new_query(world->world, "sparql", NULL, query_str, NULL); 223 222 librdf_query_results* query_results = librdf_query_execute(query, manifest_model); 224 while (!librdf_query_results_finished(query_results)) { 225 librdf_node* dynman_node = librdf_query_results_get_binding_value(query_results, 0); 223 for (; !librdf_query_results_finished(query_results); librdf_query_results_next(query_results)) { 226 224 librdf_node* binary_node = librdf_query_results_get_binding_value(query_results, 1); 227 225 228 if (librdf_node_get_type(binary_node) == LIBRDF_NODE_TYPE_RESOURCE) { 229 const char* lib_path = slv2_uri_to_path( 230 (const char*)librdf_uri_as_string(librdf_node_get_uri(binary_node))); 231 232 if (lib_path) { 233 void* lib = dlopen(lib_path, RTLD_NOW); 234 235 // Open dynamic manifest 236 typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, 237 const LV2_Dyn_Manifest_Feature *const *); 238 OpenFunc open_func = (OpenFunc)dlsym(lib, "lv2_dyn_manifest_open"); 239 open_func(&handle, &features); 240 241 // Get subjects (what would be in the manifest) 242 typedef int (*GetSubjectsFunc)(LV2_Dyn_Manifest_Handle, FILE*); 243 GetSubjectsFunc get_subjects_func = (GetSubjectsFunc)dlsym(lib, 244 "lv2_dyn_manifest_get_subjects"); 245 if (get_subjects_func) { 246 printf("DYNAMIC MANIFEST <%s> @ <%s> {\n", 247 librdf_uri_as_string(librdf_node_get_uri(dynman_node)), 248 librdf_uri_as_string(librdf_node_get_uri(binary_node))); 249 //FILE* dyn_manifest = tmpfile(); 250 FILE* dyn_manifest = fopen("/tmp/naspro.ttl", "w+"); 251 get_subjects_func(handle, dyn_manifest); 252 rewind(dyn_manifest); 253 librdf_parser_parse_file_handle_into_model(world->parser, 254 dyn_manifest, 0, manifest_uri, manifest_model); 255 fclose(dyn_manifest); 256 } 257 } 258 226 if (librdf_node_get_type(binary_node) != LIBRDF_NODE_TYPE_RESOURCE) 227 continue; 228 229 const unsigned char* lib_uri = librdf_uri_as_string(librdf_node_get_uri(binary_node)); 230 const char* lib_path = slv2_uri_to_path((const char*)lib_uri); 231 if (!lib_path) 232 continue; 233 234 void* lib = dlopen(lib_path, RTLD_LAZY); 235 if (!lib) 236 continue; 237 238 // Open dynamic manifest 239 typedef int (*OpenFunc)(LV2_Dyn_Manifest_Handle*, const LV2_Dyn_Manifest_Feature *const *); 240 OpenFunc open_func = (OpenFunc)dlsym(lib, "lv2_dyn_manifest_open"); 241 if (open_func) 242 open_func(&handle, &features); 243 244 // Get subjects (the data that would be in manifest.ttl) 245 typedef int (*GetSubjectsFunc)(LV2_Dyn_Manifest_Handle, FILE*); 246 GetSubjectsFunc get_subjects_func = (GetSubjectsFunc)dlsym(lib, 247 "lv2_dyn_manifest_get_subjects"); 248 if (!get_subjects_func) 249 continue; 250 251 librdf_storage* dyn_manifest_storage = slv2_world_new_storage(world); 252 librdf_model* dyn_manifest_model = librdf_new_model(world->world, 253 dyn_manifest_storage, NULL); 254 255 FILE* fd = tmpfile(); 256 get_subjects_func(handle, fd); 257 rewind(fd); 258 librdf_parser_parse_file_handle_into_model(world->parser, 259 fd, 0, librdf_node_get_uri(binary_node), dyn_manifest_model); 260 fclose(fd); 261 262 // Query plugins from dynamic manifest 263 librdf_query* dyn_query = librdf_new_query(world->world, "sparql", NULL, 264 (const unsigned char*) 265 "PREFIX : <http://lv2plug.in/ns/lv2core#>\n" 266 "PREFIX dynman: <http://lv2plug.in/ns/ext/dynmanifest#>\n" 267 "SELECT DISTINCT ?plugin WHERE {\n" 268 " ?plugin a :Plugin .\n" 269 "}", NULL); 270 271 // Add ?plugin rdfs:seeAlso ?binary to dynamic model 272 librdf_query_results* r = librdf_query_execute(dyn_query, dyn_manifest_model); 273 for (; !librdf_query_results_finished(r); librdf_query_results_next(r)) { 274 librdf_node* plugin = librdf_query_results_get_binding_value(r, 0); 275 librdf_node* predicate = librdf_new_node_from_uri_string(world->world, 276 (const unsigned char*)(SLV2_NS_RDFS "seeAlso")); 277 librdf_node* object = librdf_new_node_from_node(binary_node); 278 librdf_model_add(dyn_manifest_model, plugin, predicate, object); 259 279 } 260 261 librdf_query_results_next(query_results); 280 librdf_free_query_results(r); 281 librdf_free_query(dyn_query); 282 283 /*printf("*************************************************\n"); 284 librdf_model_print(dyn_manifest_model, stdout); 285 printf("*************************************************\n");*/ 286 287 // Merge dynamic model into main manifest model 288 librdf_stream* dyn_manifest_stream = librdf_model_as_stream(dyn_manifest_model); 289 librdf_model_add_statements(manifest_model, dyn_manifest_stream); 290 librdf_free_stream(dyn_manifest_stream); 291 librdf_free_model(dyn_manifest_model); 292 librdf_free_storage(dyn_manifest_storage); 262 293 } 263 294 librdf_free_query_results(query_results); … … 279 310 librdf_node* subject = plugin_node; 280 311 librdf_node* predicate = librdf_new_node_from_uri_string(world->world, 281 ( unsigned char*)"http://www.w3.org/2000/01/rdf-schema#seeAlso");312 (const unsigned char*)(SLV2_NS_RDFS "seeAlso")); 282 313 librdf_node* object = librdf_new_node_from_uri(world->world, 283 314 manifest_uri); 284 285 315 librdf_model_add(world->model, subject, predicate, object); 286 316 … … 288 318 subject = librdf_new_node_from_node(plugin_node); 289 319 predicate = librdf_new_node_from_uri_string(world->world, 290 ( unsigned char*)"http://drobilla.net/ns/slv2#bundleURI");320 (const unsigned char*)(SLV2_NS_SLV2 "bundleURI")); 291 321 object = librdf_new_node_from_uri(world->world, bundle_uri->val.uri_val); 292 322 … … 313 343 librdf_node* subject = spec_node; 314 344 librdf_node* predicate = librdf_new_node_from_uri_string(world->world, 315 ( unsigned char*)"http://www.w3.org/2000/01/rdf-schema#seeAlso");345 (const unsigned char*)(SLV2_NS_RDFS "seeAlso")); 316 346 librdf_node* object = librdf_new_node_from_uri(world->world, 317 347 manifest_uri); … … 322 352 subject = librdf_new_node_from_node(spec_node); 323 353 predicate = librdf_new_node_from_uri_string(world->world, 324 ( unsigned char*)"http://drobilla.net/ns/slv2#bundleURI");354 (const unsigned char*)(SLV2_NS_SLV2 "bundleURI")); 325 355 object = librdf_new_node_from_uri(world->world, bundle_uri->val.uri_val); 326 356 … … 592 622 "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" 593 623 "PREFIX slv2: <http://drobilla.net/ns/slv2#>\n" 594 "SELECT DISTINCT ?plugin ?data ?bundle\n" 595 "WHERE { ?plugin a :Plugin; slv2:bundleURI ?bundle; rdfs:seeAlso ?data }\n"; 624 "SELECT DISTINCT ?plugin ?data ?bundle WHERE {\n" 625 " ?plugin a :Plugin ;\n" 626 " slv2:bundleURI ?bundle ;\n" 627 " rdfs:seeAlso ?data .\n" 628 "}\n"; 596 629 597 630 librdf_query* q = librdf_new_query(world->world, "sparql", … … 659 692 plugin->world = world; 660 693 661 // FIXME: check for duplicates 662 raptor_sequence_push(plugin->data_uris, 663 slv2_value_new_librdf_uri(plugin->world, data_uri)); 694 #ifdef SLV2_DYN_MANIFEST 695 const char* const data_uri_str = (const char*)librdf_uri_as_string(data_uri); 696 void* lib = dlopen(slv2_uri_to_path(data_uri_str), RTLD_LAZY); 697 if (lib) { 698 plugin->dynman_uri = slv2_value_new_librdf_uri(world, data_uri); 699 librdf_query_results_next(results); 700 } else 701 #endif 702 if (data_uri) { 703 assert(plugin->data_uris); 704 // FIXME: check for duplicates 705 raptor_sequence_push(plugin->data_uris, 706 slv2_value_new_librdf_uri(plugin->world, data_uri)); 707 } 664 708 } 665 709
