SharedLibraryManager.cpp

Go to the documentation of this file.
00001 /*<!-------------------------------------------------------------------->
00002    @file   SharedLibraryPlatform.cpp
00003    @author Travis Fischer (fisch0920@gmail.com)
00004    @date   Summer 2008
00005    
00006    @brief
00007       Public interface to loading and unloading an arbitrary number of shared 
00008    libraries.
00009    <!-------------------------------------------------------------------->**/
00010 
00011 #include "SharedLibraryManager.h"
00012 #include "SharedLibraryPlatform.h"
00013 #include "SharedLibrary.h"
00014 
00015 SharedLibrary *SharedLibraryManager::load(const std::string &name, 
00016                                           int openFlags)
00017 {
00018    if (!isLoaded(name)) {
00019       SharedLibraryHandle *handle = m_platform->load(name, openFlags);
00020       
00021       // Check for load errors
00022       if (handle == NULL)
00023          return NULL;
00024       
00025       // Create a new entry in our library map
00026       m_map[name] = SharedLibraryReference(handle, 0);
00027    }
00028    
00029    // Increment refcount on reference entry
00030    m_map[name].refCount++;
00031    
00032    return new SharedLibrary(name, m_map[name].handle, m_platform);
00033 }
00034 
00035 bool SharedLibraryManager::unload(const std::string &name) {
00036    bool ret = false;
00037    
00038    if (isLoaded(name) && --m_map[name].refCount < 0) {
00039       ret = m_platform->unload(m_map[name].handle);
00040       m_map.erase(m_map.find(name));
00041    }
00042    
00043    return ret;
00044 }
00045 
00046 bool SharedLibraryManager::isLoaded(const std::string &name) const {
00047    return (m_map.find(name) != m_map.end());
00048 }
00049 
00050 void *SharedLibraryManager::getSymbol(const std::string &symbol) {
00051    SharedLibraryMapConstIter iter;
00052    void *handleToSymbol = NULL;
00053    
00054    for(iter = m_map.begin(); iter != m_map.end(); iter++) {
00055       handleToSymbol = m_platform->getSymbol(iter->second.handle, symbol);
00056       
00057       if (handleToSymbol != NULL)
00058          break;
00059    }
00060    
00061    return handleToSymbol;
00062 }
00063 
00064 std::string SharedLibraryManager::getLastError() {
00065    return m_platform->getLastError();
00066 }
00067 

Generated on 28 Feb 2009 for Milton by doxygen 1.5.6