Changeset df9e43c in lilv


Ignore:
Timestamp:
11/07/15 12:18:17 (22 months ago)
Author:
David Robillard <d@…>
Branches:
master
Children:
59601f4
Parents:
2a7e795
Message:

Remove unloaded plugins from world plugin list

git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@5810 a436a847-0d15-0410-975c-d299462d15a1

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/lilv_internal.h

    rdb1f217 rdf9e43c  
    157157    LilvSpec*          specs; 
    158158    LilvPlugins*       plugins; 
     159    LilvPlugins*       zombies; 
    159160    LilvNodes*         loaded_files; 
    160161    ZixTree*           libs; 
  • src/world.c

    r95979c0 rdf9e43c  
    4040    world->plugin_classes = lilv_plugin_classes_new(); 
    4141    world->plugins        = lilv_plugins_new(); 
     42    world->zombies        = lilv_plugins_new(); 
    4243    world->loaded_files   = zix_tree_new( 
    4344        false, lilv_resource_node_cmp, NULL, (ZixDestroyFunc)lilv_node_free); 
     
    134135    world->plugins = NULL; 
    135136 
     137    LILV_FOREACH(plugins, i, world->zombies) { 
     138        const LilvPlugin* p = lilv_plugins_get(world->zombies, i); 
     139        lilv_plugin_free((LilvPlugin*)p); 
     140    } 
     141    zix_tree_free((ZixTree*)world->zombies); 
     142    world->zombies = NULL; 
     143 
    136144    zix_tree_free((ZixTree*)world->loaded_files); 
    137145    world->loaded_files = NULL; 
     
    323331 
    324332/** Get an element of a collection of any object with an LilvHeader by URI. */ 
    325 struct LilvHeader* 
    326 lilv_collection_get_by_uri(const ZixTree*  const_seq, 
    327                            const LilvNode* uri) 
     333static ZixTreeIter* 
     334lilv_collection_find_by_uri(const ZixTree* seq, const LilvNode* uri) 
    328335{ 
    329336    if (!lilv_node_is_uri(uri)) { 
     
    331338    } 
    332339 
    333     ZixTree*          seq = (ZixTree*)const_seq; 
    334340    struct LilvHeader key = { NULL, (LilvNode*)uri }; 
    335341    ZixTreeIter*      i   = NULL; 
    336     ZixStatus         st  = zix_tree_find(seq, &key, &i); 
    337     if (!st) { 
    338         return (struct LilvHeader*)zix_tree_get(i); 
    339     } 
    340  
    341     return NULL; 
     342    const ZixStatus   st  = zix_tree_find(seq, &key, &i); 
     343 
     344    return st ? NULL : i; 
     345} 
     346 
     347/** Get an element of a collection of any object with an LilvHeader by URI. */ 
     348struct LilvHeader* 
     349lilv_collection_get_by_uri(const ZixTree* seq, const LilvNode* uri) 
     350{ 
     351    ZixTreeIter* const i = lilv_collection_find_by_uri(seq, uri); 
     352 
     353    return i ? (struct LilvHeader*)zix_tree_get(i) : NULL; 
    342354} 
    343355 
     
    378390                      const SordNode* bundle) 
    379391{ 
    380     LilvNode*   plugin_uri = lilv_node_new_from_node(world, plugin_node); 
    381     LilvPlugin* plugin     = (LilvPlugin*)lilv_plugins_get_by_uri( 
     392    LilvNode*    plugin_uri = lilv_node_new_from_node(world, plugin_node); 
     393    ZixTreeIter* z          = NULL; 
     394    LilvPlugin*  plugin     = (LilvPlugin*)lilv_plugins_get_by_uri( 
    382395        world->plugins, plugin_uri); 
    383396 
     
    398411            return; 
    399412        } 
     413    } else if ((z = lilv_collection_find_by_uri(world->zombies, plugin_uri))) { 
     414        // Plugin bundle has been re-loaded, move from zombies to plugins 
     415        plugin = zix_tree_get(z); 
     416        zix_tree_remove(world->zombies, z); 
     417        zix_tree_insert((ZixTree*)world->plugins, plugin, NULL); 
     418        lilv_node_free(plugin_uri); 
     419        plugin->loaded = false; 
    400420    } else { 
    401421        // Add new plugin to the world 
     
    683703    } 
    684704 
    685     // Unload any files, including manifest.ttl 
     705    // Find all loaded files that are inside the bundle 
    686706    LilvNodes* files = lilv_nodes_new(); 
    687707    LILV_FOREACH(nodes, i, world->loaded_files) { 
     
    696716    } 
    697717 
     718    // Unload all loaded files in the bundle 
    698719    LILV_FOREACH(nodes, i, files) { 
    699720        const LilvNode* file = lilv_nodes_get(world->plugins, i); 
     
    702723 
    703724    lilv_nodes_free(files); 
     725 
     726    /* Remove any plugins in the bundle from the plugin list.  Since the 
     727       application may still have a pointer to the LilvPlugin, it can not be 
     728       destroyed here.  Instead, we move it to the zombie plugin list, so it 
     729       will not be in the list returned by lilv_world_get_all_plugins() but can 
     730       still be used. 
     731    */ 
     732    ZixTreeIter* i = zix_tree_begin(world->plugins); 
     733    while (i != zix_tree_end(world->plugins)) { 
     734        LilvPlugin*  p    = (LilvPlugin*)zix_tree_get(i); 
     735        ZixTreeIter* next = zix_tree_iter_next(i); 
     736 
     737        if (lilv_node_equals(lilv_plugin_get_bundle_uri(p), bundle_uri)) { 
     738            zix_tree_remove(world->plugins, i); 
     739            zix_tree_insert(world->zombies, p, NULL); 
     740        } 
     741 
     742        i = next; 
     743    } 
    704744 
    705745    // Drop everything in bundle graph 
  • test/lilv_test.c

    rdb1f217 rdf9e43c  
    19831983                  PLUGIN_NAME("Second name") " ."); 
    19841984 
     1985    // Check that plugin is no longer in the world's plugin list 
     1986    TEST_ASSERT(lilv_plugins_size(plugins) == 0); 
     1987 
    19851988    // Load new bundle 
    19861989    lilv_world_load_bundle(world, bundle_uri); 
    19871990 
    1988     // TODO: Mechanism to actually remove plugin from world list 
    1989  
    1990     // Check that plugin is present again 
     1991    // Check that plugin is present again and is the same LilvPlugin 
    19911992    const LilvPlugin* plug2 = lilv_plugins_get_by_uri(plugins, plugin_uri_value); 
    19921993    TEST_ASSERT(plug2); 
     1994    TEST_ASSERT(plug2 == plug); 
    19931995 
    19941996    // Check that plugin now has new name 
Note: See TracChangeset for help on using the changeset viewer.