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 = shl_load(filepath, BIND_DEFERRED, 0L);
00036     if (lib == NULL)
00037     {
00038         std::cerr << "Error loading the lib: ";
00039         perror("");
00040         std::cerr << std::endl;
00041         return valid_lib = false;
00042     }
00043 
00044     file_path = filepath;
00045     return valid_lib = true;
00046 }
00047 
00048 void* DynLib::getFunction(const char* func)
00049 {
00050     if (!valid_lib)
00051     {
00052         std::cerr << "Cannot getFunction out of invalid lib\n";
00053         return 0;
00054     }
00055 
00056     void* func_ptr;
00057     if (shl_findsym(&lib, func, TYPE_UNDEFINED, func_ptr) != 0)
00058     {
00059         std::cerr << "Could not load function: " << func << ". Error message: ";
00060         perror("");
00061         std::cerr << std::endl;
00062         valid_lib = false;
00063         return 0;
00064     }
00065     return func_ptr;
00066 }
00067 
00068 void DynLib::unloadLibrary()
00069 {
00070     if (lib)
00071     {
00072         if (shl_unload(lib) != 0)
00073         {
00074             std::cerr << "Error closing lib: ";
00075             perror("");
00076             std::cerr << std::endl;
00077         }
00078     }
00079     lib = NULL;
00080     valid_lib = false;
00081 }
00082 
00083 bool DynLib::parsePath( const std::string &path, std::string &return_dir, std::string &return_pattern )
00084 {}
00085 
00086 
00087 
00088 std::list < std::string > DynLib::enumPlatformDirectory( const std::string& path )
00089 {}
00090 

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