Main Page   Class Hierarchy   Compound List   File List   Compound Members  

DynLib.cpp

00001 /********************************************************************
00002 ** Copyright (C) 2000 SOMELib Project
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the
00016 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017 ** Boston, MA  02111-1307, USA.
00018 **
00019 *******************************************************************/
00020 
00021 #include "DynLib.h"
00022 
00023 using namespace SOME;
00024 
00025 DynLib::DynLib():
00026         lib(NULL)
00027 {}
00028 
00029 
00030 
00031 bool DynLib::loadLibrary(const char* filepath)
00032 {
00033     unloadLibrary();
00034 
00035     lib = dlopen(filepath, RTLD_LAZY);
00036     if (lib == NULL)
00037     {
00038         //TODO: Find a better way to display error messages
00039         //This may get in the way with programs that wish to
00040         //load full directories
00041         std::cerr << "Could not find the lib: " << dlerror() << std::endl;
00042         return valid_lib = false;
00043     }
00044 
00045     dlerror();
00046     file_path = filepath;
00047     return valid_lib = true;
00048 }
00049 
00050 void* DynLib::getFunction(const char* func)
00051 {
00052     if (!valid_lib)
00053     {
00054         std::cerr << "Cannot getFunction out of invalid lib\n";
00055         return 0;
00056     }
00057 
00058     void* func_ptr = dlsym(lib, func);
00059     const char* error;
00060     error = dlerror();
00061     if (error)
00062     {
00063         std::cerr << "Could not load function: " << func << ". Error message: " << error << std::endl;
00064         valid_lib = false;
00065         return 0;
00066     }
00067     return func_ptr;
00068 }
00069 
00070 void DynLib::unloadLibrary()
00071 {
00072     if (lib)
00073     {
00074         if (dlclose(lib) != 0)
00075             std::cerr << "Error closing lib: " << dlerror() << std::endl;
00076     }
00077     lib = NULL;
00078     valid_lib = false;
00079     dlerror();
00080 }
00081 
00082 bool DynLib::parsePath( const std::string &path, std::string &return_dir, std::string &return_pattern )
00083 {}
00084 
00085 
00086 
00087 std::list < std::string > DynLib::enumPlatformDirectory( const std::string& path )
00088 {}
00089 

Generated at Fri Dec 8 14:24:48 2000 for SOMELib by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000