Changeset 52:c7665b68fe67 in finroc_core-java


Ignore:
Timestamp:
01.12.2010 01:19:33 (9 years ago)
Author:
Max Reichardt <reichardt@…>
Branch:
default
Phase:
public
Convert:
svn:fc394f53-5a1c-4f87-a64a-968f46d709a5/trunk@53
Message:

Added code that calls dlclose() for all dlopen-ed libraries when program ends

File:
1 edited

Legend:

Unmodified
Added
Removed
  • org/finroc/core/plugin/Plugins.java

    r50 r52  
    2929import org.finroc.core.finstructable.FinstructableGroup; 
    3030import org.finroc.jc.annotation.Const; 
     31import org.finroc.jc.annotation.CppInclude; 
     32import org.finroc.jc.annotation.CppPrepend; 
    3133import org.finroc.jc.annotation.CppType; 
    3234import org.finroc.jc.annotation.InCpp; 
     
    4951 * This class is used for managing the Runtime's plugins 
    5052 */ 
     53@CppInclude("RuntimeEnvironment.h") 
     54@CppPrepend( { 
     55    "Plugins::DLCloser::~DLCloser() {", 
     56    "    RuntimeEnvironment::shutdown();", 
     57    "    for (size_t i = 0; i < loaded.size(); i++) {", 
     58    "        _dlclose(loaded.get(i));", 
     59    "    }", 
     60    "}" 
     61}) 
    5162public class Plugins { /*implements HTTPResource*/ 
    5263 
     
    269280    } 
    270281 
     282    /*Cpp 
     283    // closes dlopen-ed libraries 
     284    class DLCloser { 
     285    public: 
     286        util::SimpleList<void*> loaded; 
     287 
     288        DLCloser() : loaded() {} 
     289        ~DLCloser(); 
     290    }; 
     291     */ 
     292 
    271293    /** 
    272294     * Returns/loads CreateModuleAction with specified name and specified .so file. 
     
    280302        // dynamically loaded .so files 
    281303        //Cpp static util::SimpleList<util::String> loaded; 
     304        //Cpp static DLCloser dlcloser; 
    282305 
    283306        // try to find module among existing modules 
     
    302325        if (!alreadyLoaded) { 
    303326            loaded.add(group); 
    304             if (_dlopen(group.getCString(), _RTLD_NOW | _RTLD_GLOBAL)) { 
     327            void* handle = _dlopen(group.getCString(), _RTLD_NOW | _RTLD_GLOBAL); 
     328            if (handle) { 
     329                dlcloser.loaded.add(handle); 
    305330                return loadModuleType(group, name); 
    306331            } else { 
Note: See TracChangeset for help on using the changeset viewer.