Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsshlhandler.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmstools/mmsshlhandler.h"
00034 #include "mmstools/mmsfile.h"
00035 #ifdef __HAVE_DL__
00036 #include <dlfcn.h>
00037 #endif
00038 
00039 MMSShlHandler::~MMSShlHandler() {
00040 #ifndef __HAVE_DL__
00041     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00042 #else
00043 
00044     if(this->isloaded) {
00045         dlclose(this->handle);
00046     }
00047 #endif
00048 }
00049 
00050 void MMSShlHandler::close() {
00051 #ifndef __HAVE_DL__
00052     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00053 #else
00054 
00055     if(this->isloaded) {
00056         dlclose(this->handle);
00057         this->isloaded = false;
00058     } else {
00059         throw MMSShlError(0,"shared library " + this->name + " is not loaded");
00060     }
00061 #endif
00062 }
00063 
00064 void MMSShlHandler::open() {
00065 #ifndef __HAVE_DL__
00066     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00067 #else
00068 
00069     if(this->isloaded) {
00070         throw MMSShlError(0,"shared library " + this->name + " is alread loaded");
00071     }
00072     else {
00073         this->handle = dlopen(this->name.c_str(),RTLD_NOW);
00074 
00075         if(this->handle == NULL)
00076             throw MMSShlError(0,"shared library " + this->name + " cannot be loaded: " + dlerror());
00077 
00078         this->isloaded = true;
00079     }
00080 #endif
00081 }
00082 
00083 void MMSShlHandler::setName(string name) {
00084 #ifndef __HAVE_DL__
00085     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00086 #else
00087 
00088     this->name = name;
00089 #endif
00090 }
00091 
00092 string MMSShlHandler::getName() {
00093 #ifndef __HAVE_DL__
00094     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00095 #else
00096 
00097     return this->name;
00098 #endif
00099 }
00100 
00101 void *MMSShlHandler::getFunction(string name) {
00102 #ifndef __HAVE_DL__
00103     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00104 #else
00105 
00106     void *ret = NULL;
00107 
00108     if(this->isloaded) {
00109         ret = dlsym(this->handle,name.c_str());
00110         if(ret == NULL)
00111             throw MMSShlError(0,"symbol " + name + " cannot be retrieved: " + dlerror());
00112     } else {
00113         throw MMSShlError(0,"shared library " + this->name + " is not loaded");
00114     }
00115 
00116     return ret;
00117 #endif
00118 }
00119 
00120 bool MMSShlHandler::isLoaded() {
00121 #ifndef __HAVE_DL__
00122     throw MMSShlError(0, "Compile with use_dl (libdl support)");
00123 #else
00124     return this->isloaded;
00125 #endif
00126 
00127 }

Generated by doxygen